Commit 9104cfd9 authored by danno@chromium.org's avatar danno@chromium.org

Use CopyElements for SetFastDoubleElementsCapacityAndLength

Review URL: https://chromiumcodereview.appspot.com/9663002

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@11070 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent aaac4992
......@@ -508,8 +508,7 @@ BUILTIN(ArrayPush) {
}
FixedArray* new_elms = FixedArray::cast(obj);
AssertNoAllocation no_gc;
CopyObjectToObjectElements(&no_gc, elms, FAST_ELEMENTS, 0,
CopyObjectToObjectElements(elms, FAST_ELEMENTS, 0,
new_elms, FAST_ELEMENTS, 0, len);
FillWithHoles(heap, new_elms, new_length, capacity);
......@@ -645,8 +644,7 @@ BUILTIN(ArrayUnshift) {
if (!maybe_obj->ToObject(&obj)) return maybe_obj;
}
FixedArray* new_elms = FixedArray::cast(obj);
AssertNoAllocation no_gc;
CopyObjectToObjectElements(&no_gc, elms, FAST_ELEMENTS, 0,
CopyObjectToObjectElements(elms, FAST_ELEMENTS, 0,
new_elms, FAST_ELEMENTS, to_add, len);
FillWithHoles(heap, new_elms, new_length, capacity);
elms = new_elms;
......@@ -757,8 +755,7 @@ BUILTIN(ArraySlice) {
JSArray* result_array;
if (!maybe_array->To(&result_array)) return maybe_array;
AssertNoAllocation no_gc;
CopyObjectToObjectElements(&no_gc, elms, FAST_ELEMENTS, k,
CopyObjectToObjectElements(elms, FAST_ELEMENTS, k,
FixedArray::cast(result_array->elements()),
FAST_ELEMENTS, 0, result_len);
......@@ -831,9 +828,8 @@ BUILTIN(ArraySplice) {
if (!maybe_array->To(&result_array)) return maybe_array;
{
AssertNoAllocation no_gc;
// Fill newly created array.
CopyObjectToObjectElements(&no_gc, elms, FAST_ELEMENTS, actual_start,
CopyObjectToObjectElements(elms, FAST_ELEMENTS, actual_start,
FixedArray::cast(result_array->elements()),
FAST_ELEMENTS, 0, actual_delete_count);
}
......@@ -883,12 +879,11 @@ BUILTIN(ArraySplice) {
FixedArray* new_elms = FixedArray::cast(obj);
{
AssertNoAllocation no_gc;
// Copy the part before actual_start as is.
CopyObjectToObjectElements(&no_gc, elms, FAST_ELEMENTS, 0,
CopyObjectToObjectElements(elms, FAST_ELEMENTS, 0,
new_elms, FAST_ELEMENTS, 0, actual_start);
const int to_copy = len - actual_delete_count - actual_start;
CopyObjectToObjectElements(&no_gc, elms, FAST_ELEMENTS,
CopyObjectToObjectElements(elms, FAST_ELEMENTS,
actual_start + actual_delete_count,
new_elms, FAST_ELEMENTS,
actual_start + item_count, to_copy);
......@@ -973,14 +968,13 @@ BUILTIN(ArrayConcat) {
if (result_len == 0) return result_array;
// Copy data.
AssertNoAllocation no_gc;
int start_pos = 0;
FixedArray* result_elms(FixedArray::cast(result_array->elements()));
for (int i = 0; i < n_arguments; i++) {
JSArray* array = JSArray::cast(args[i]);
int len = Smi::cast(array->length())->value();
FixedArray* elms = FixedArray::cast(array->elements());
CopyObjectToObjectElements(&no_gc, elms, FAST_ELEMENTS, 0,
CopyObjectToObjectElements(elms, FAST_ELEMENTS, 0,
result_elms, FAST_ELEMENTS,
start_pos, len);
start_pos += len;
......
This diff is collapsed.
......@@ -88,6 +88,15 @@ class ElementsAccessor {
uint32_t key,
JSReceiver::DeleteMode mode) = 0;
// If kCopyToEnd is specified as the copy_size to CopyElements, it copies all
// of elements from source after source_start to the destination array.
static const int kCopyToEnd = -1;
// If kCopyToEndAndInitializeToHole is specified as the copy_size to
// CopyElements, it copies all of elements from source after source_start to
// destination array, padding any remaining uninitialized elements in the
// destination array with the hole.
static const int kCopyToEndAndInitializeToHole = -2;
// Copy elements from one backing store to another. Typically, callers specify
// the source JSObject or JSArray in source_holder. If the holder's backing
// store is available, it can be passed in source and source_holder is
......@@ -98,13 +107,16 @@ class ElementsAccessor {
ElementsKind destination_kind,
uint32_t destination_start,
int copy_size,
WriteBarrierMode mode,
FixedArrayBase* source = NULL) = 0;
MaybeObject* CopyElements(JSObject* from_holder,
FixedArrayBase* to,
ElementsKind to_kind,
WriteBarrierMode mode,
FixedArrayBase* from = NULL) {
return CopyElements(from_holder, 0, to, to_kind, 0, -1, from);
return CopyElements(from_holder, 0, to, to_kind, 0,
kCopyToEndAndInitializeToHole, mode, from);
}
virtual MaybeObject* AddElementsToFixedArray(Object* receiver,
......@@ -146,14 +158,14 @@ class ElementsAccessor {
};
void CopyObjectToObjectElements(AssertNoAllocation* no_gc,
FixedArray* from_obj,
void CopyObjectToObjectElements(FixedArray* from_obj,
ElementsKind from_kind,
uint32_t from_start,
FixedArray* to_obj,
ElementsKind to_kind,
uint32_t to_start,
int copy_size);
int copy_size,
WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
} } // namespace v8::internal
......
......@@ -1734,65 +1734,6 @@ bool FixedDoubleArray::is_the_hole(int index) {
}
void FixedDoubleArray::Initialize(FixedDoubleArray* from) {
int old_length = from->length();
ASSERT(old_length < length());
if (old_length * kDoubleSize >= OS::kMinComplexMemCopy) {
OS::MemCopy(FIELD_ADDR(this, kHeaderSize),
FIELD_ADDR(from, kHeaderSize),
old_length * kDoubleSize);
} else {
for (int i = 0; i < old_length; ++i) {
if (from->is_the_hole(i)) {
set_the_hole(i);
} else {
set(i, from->get_scalar(i));
}
}
}
int offset = kHeaderSize + old_length * kDoubleSize;
for (int current = from->length(); current < length(); ++current) {
WRITE_DOUBLE_FIELD(this, offset, hole_nan_as_double());
offset += kDoubleSize;
}
}
void FixedDoubleArray::Initialize(FixedArray* from) {
int old_length = from->length();
ASSERT(old_length <= length());
for (int i = 0; i < old_length; i++) {
Object* hole_or_object = from->get(i);
if (hole_or_object->IsTheHole()) {
set_the_hole(i);
} else {
set(i, hole_or_object->Number());
}
}
int offset = kHeaderSize + old_length * kDoubleSize;
for (int current = from->length(); current < length(); ++current) {
WRITE_DOUBLE_FIELD(this, offset, hole_nan_as_double());
offset += kDoubleSize;
}
}
void FixedDoubleArray::Initialize(SeededNumberDictionary* from) {
int offset = kHeaderSize;
for (int current = 0; current < length(); ++current) {
WRITE_DOUBLE_FIELD(this, offset, hole_nan_as_double());
offset += kDoubleSize;
}
for (int i = 0; i < from->Capacity(); i++) {
Object* key = from->KeyAt(i);
if (key->IsNumber()) {
uint32_t entry = static_cast<uint32_t>(key->Number());
set(entry, from->ValueAt(i)->Number());
}
}
}
WriteBarrierMode HeapObject::GetWriteBarrierMode(const AssertNoAllocation&) {
Heap* heap = GetHeap();
if (heap->incremental_marking()->IsMarking()) return UPDATE_WRITE_BARRIER;
......
......@@ -8448,23 +8448,23 @@ MaybeObject* JSObject::SetFastElementsCapacityAndLength(
if (!maybe->To(&new_map)) return maybe;
}
FixedArrayBase* old_elements_raw = elements();
FixedArrayBase* old_elements = elements();
ElementsKind elements_kind = GetElementsKind();
ElementsAccessor* accessor = ElementsAccessor::ForKind(elements_kind);
ElementsKind to_kind = (elements_kind == FAST_SMI_ONLY_ELEMENTS)
? FAST_SMI_ONLY_ELEMENTS
: FAST_ELEMENTS;
// int copy_size = Min(old_elements_raw->length(), new_elements->length());
accessor->CopyElements(this, new_elements, to_kind);
accessor->CopyElements(this, new_elements, to_kind, SKIP_WRITE_BARRIER);
if (elements_kind != NON_STRICT_ARGUMENTS_ELEMENTS) {
set_map_and_elements(new_map, new_elements);
} else {
FixedArray* parameter_map = FixedArray::cast(old_elements_raw);
FixedArray* parameter_map = FixedArray::cast(old_elements);
parameter_map->set(1, new_elements);
}
if (FLAG_trace_elements_transitions) {
PrintElementsTransition(stdout, elements_kind, old_elements_raw,
PrintElementsTransition(stdout, elements_kind, old_elements,
GetElementsKind(), new_elements);
}
......@@ -8497,27 +8497,15 @@ MaybeObject* JSObject::SetFastDoubleElementsCapacityAndLength(
}
FixedArrayBase* old_elements = elements();
ElementsKind elements_kind(GetElementsKind());
AssertNoAllocation no_gc;
if (old_elements->length() != 0) {
switch (elements_kind) {
case FAST_SMI_ONLY_ELEMENTS:
case FAST_ELEMENTS: {
elems->Initialize(FixedArray::cast(old_elements));
break;
}
case FAST_DOUBLE_ELEMENTS: {
elems->Initialize(FixedDoubleArray::cast(old_elements));
break;
}
case DICTIONARY_ELEMENTS: {
elems->Initialize(SeededNumberDictionary::cast(old_elements));
break;
}
default:
UNREACHABLE();
break;
}
ElementsKind elements_kind = GetElementsKind();
ElementsAccessor* accessor = ElementsAccessor::ForKind(elements_kind);
accessor->CopyElements(this, elems, FAST_DOUBLE_ELEMENTS,
SKIP_WRITE_BARRIER);
if (elements_kind != NON_STRICT_ARGUMENTS_ELEMENTS) {
set_map_and_elements(new_map, elems);
} else {
FixedArray* parameter_map = FixedArray::cast(old_elements);
parameter_map->set(1, elems);
}
if (FLAG_trace_elements_transitions) {
......@@ -8525,11 +8513,6 @@ MaybeObject* JSObject::SetFastDoubleElementsCapacityAndLength(
FAST_DOUBLE_ELEMENTS, elems);
}
ASSERT(new_map->has_fast_double_elements());
set_map(new_map);
ASSERT(elems->IsFixedDoubleArray());
set_elements(elems);
if (IsJSArray()) {
JSArray::cast(this)->set_length(Smi::FromInt(length));
}
......
......@@ -2338,10 +2338,6 @@ class FixedArray: public FixedArrayBase {
// FixedDoubleArray describes fixed-sized arrays with element type double.
class FixedDoubleArray: public FixedArrayBase {
public:
inline void Initialize(FixedArray* from);
inline void Initialize(FixedDoubleArray* from);
inline void Initialize(SeededNumberDictionary* from);
// Setter and getter for elements.
inline double get_scalar(int index);
MUST_USE_RESULT inline MaybeObject* get(int index);
......
......@@ -6769,6 +6769,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_StringBuilderConcat) {
ascii = false;
}
} else {
ASSERT(!elt->IsTheHole());
return isolate->Throw(isolate->heap()->illegal_argument_symbol());
}
if (increment > String::kMaxLength - position) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment