Chromium Code Reviews| Index: src/heap.cc |
| diff --git a/src/heap.cc b/src/heap.cc |
| index 3a8b609173b891ab0f05518849dae3ce189ce18d..4ba8d26279e19b335439cd25360b25090091b62c 100644 |
| --- a/src/heap.cc |
| +++ b/src/heap.cc |
| @@ -3713,8 +3713,8 @@ MaybeObject* Heap::AllocateJSObject(JSFunction* constructor, |
| Map::cast(initial_map)->set_constructor(constructor); |
| } |
| // Allocate the object based on the constructors initial map. |
| - MaybeObject* result = |
| - AllocateJSObjectFromMap(constructor->initial_map(), pretenure); |
| + MaybeObject* result = AllocateJSObjectFromMap( |
| + constructor->initial_map(), pretenure); |
| #ifdef DEBUG |
| // Make sure result is NOT a global object if valid. |
| Object* non_failure; |
| @@ -3724,6 +3724,73 @@ MaybeObject* Heap::AllocateJSObject(JSFunction* constructor, |
| } |
| +MaybeObject* Heap::AllocateJSArrayAndStorage( |
| + ElementsKind elements_kind, |
| + int length, |
| + int capacity, |
| + ArrayStorageAllocationMode mode, |
| + PretenureFlag pretenure) { |
| + ASSERT(capacity >= length); |
| + MaybeObject* maybe_array = AllocateJSArray(elements_kind, |
| + pretenure); |
|
Jakob Kummerow
2012/01/23 17:16:55
nit: can fit in one line
danno
2012/01/26 21:32:34
Done.
|
| + JSArray* array; |
| + if (!maybe_array->To(&array)) return maybe_array; |
| + |
| + if (capacity == 0) { |
| + ASSERT(length == 0); |
|
Jakob Kummerow
2012/01/23 17:16:55
nit: unnecessary, covered by ASSERT(capacity >= le
danno
2012/01/26 21:32:34
Done.
|
| + array->set_length(Smi::FromInt(0)); |
| + array->set_elements(empty_fixed_array()); |
| + return array; |
| + } |
| + |
| + FixedArrayBase* elms; |
| + if (elements_kind == FAST_DOUBLE_ELEMENTS) { |
| + if (mode == DONT_INITIALIZE_ARRAY_ELEMENTS) { |
| + MaybeObject* maybe_elms = |
| + AllocateUninitializedFixedDoubleArray(capacity); |
| + if (!maybe_elms->To(&elms)) return maybe_elms; |
|
Jakob Kummerow
2012/01/23 17:16:55
This line occurs four times. You could move it out
danno
2012/01/26 21:32:34
Done.
|
| + } else { |
| + ASSERT(mode == INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE); |
| + MaybeObject* maybe_elms = |
| + AllocateFixedDoubleArrayWithHoles(capacity); |
| + if (!maybe_elms->To(&elms)) return maybe_elms; |
| + } |
| + } else { |
| + ASSERT(elements_kind == FAST_ELEMENTS || |
| + elements_kind == FAST_SMI_ONLY_ELEMENTS); |
| + if (mode == DONT_INITIALIZE_ARRAY_ELEMENTS) { |
| + MaybeObject* maybe_elms = |
| + AllocateUninitializedFixedArray(capacity); |
| + if (!maybe_elms->To(&elms)) return maybe_elms; |
| + } else { |
| + ASSERT(mode == INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE); |
| + MaybeObject* maybe_elms = |
| + AllocateFixedArrayWithHoles(capacity); |
| + if (!maybe_elms->To(&elms)) return maybe_elms; |
| + } |
| + } |
| + |
| + array->set_elements(elms); |
| + array->set_length(Smi::FromInt(length)); |
| + return array; |
| +} |
| + |
| + |
| +MaybeObject* Heap::AllocateJSArrayWithElements( |
| + FixedArrayBase* elements, |
| + ElementsKind elements_kind, |
| + PretenureFlag pretenure) { |
| + MaybeObject* maybe_array = AllocateJSArray(elements_kind, |
| + pretenure); |
|
Jakob Kummerow
2012/01/23 17:16:55
nit: can fit in one line
danno
2012/01/26 21:32:34
Done.
|
| + JSArray* array; |
| + if (!maybe_array->To(&array)) return maybe_array; |
| + |
| + array->set_elements(elements); |
| + array->set_length(Smi::FromInt(elements->length())); |
| + return array; |
| +} |
| + |
| + |
| MaybeObject* Heap::AllocateJSProxy(Object* handler, Object* prototype) { |
| // Allocate map. |
| // TODO(rossberg): Once we optimize proxies, think about a scheme to share |
| @@ -4228,6 +4295,25 @@ MaybeObject* Heap::AllocateRawTwoByteString(int length, |
| } |
| +MaybeObject* Heap::AllocateJSArray( |
| + ElementsKind elements_kind, |
| + PretenureFlag pretenure) { |
| + Context* global_context = isolate()->context()->global_context(); |
| + JSFunction* array_function = global_context->array_function(); |
| + Map* map = array_function->initial_map(); |
| + if (elements_kind == FAST_ELEMENTS || !FLAG_smi_only_arrays) { |
| + map = Map::cast(global_context->object_js_array_map()); |
| + } else if (elements_kind == FAST_DOUBLE_ELEMENTS) { |
| + map = Map::cast(global_context->double_js_array_map()); |
| + } else { |
| + ASSERT(elements_kind == FAST_SMI_ONLY_ELEMENTS); |
| + ASSERT(map == global_context->smi_js_array_map()); |
| + } |
| + |
| + return AllocateJSObjectFromMap(map, pretenure); |
| +} |
| + |
| + |
| MaybeObject* Heap::AllocateEmptyFixedArray() { |
| int size = FixedArray::SizeFor(0); |
| Object* result; |
| @@ -4418,15 +4504,36 @@ MaybeObject* Heap::AllocateUninitializedFixedDoubleArray( |
| PretenureFlag pretenure) { |
| if (length == 0) return empty_fixed_double_array(); |
| - Object* obj; |
| - { MaybeObject* maybe_obj = AllocateRawFixedDoubleArray(length, pretenure); |
| - if (!maybe_obj->ToObject(&obj)) return maybe_obj; |
| + Object* elements_object; |
| + MaybeObject* maybe_obj = AllocateRawFixedDoubleArray(length, pretenure); |
| + if (!maybe_obj->ToObject(&elements_object)) return maybe_obj; |
| + FixedDoubleArray* elements = |
| + reinterpret_cast<FixedDoubleArray*>(elements_object); |
|
Jakob Kummerow
2012/01/23 17:16:55
While you're at it, you could replace these five l
danno
2012/01/26 21:32:34
Unfortunately, you can't use FixedDoubleArray::cas
|
| + |
| + elements->set_map_no_write_barrier(fixed_double_array_map()); |
| + elements->set_length(length); |
| + return elements; |
| +} |
| + |
| + |
| +MaybeObject* Heap::AllocateFixedDoubleArrayWithHoles( |
| + int length, |
| + PretenureFlag pretenure) { |
| + if (length == 0) return empty_fixed_double_array(); |
| + |
| + Object* elements_object; |
| + MaybeObject* maybe_obj = AllocateRawFixedDoubleArray(length, pretenure); |
|
Jakob Kummerow
2012/01/23 17:16:55
Same suggestion here: three lines is better than f
danno
2012/01/26 21:32:34
Same here.
On 2012/01/23 17:16:55, Jakob wrote:
|
| + if (!maybe_obj->ToObject(&elements_object)) return maybe_obj; |
| + FixedDoubleArray* elements = |
| + reinterpret_cast<FixedDoubleArray*>(elements_object); |
| + |
| + for (int i = 0; i < length; ++i) { |
| + elements->set_the_hole(i); |
| } |
| - reinterpret_cast<FixedDoubleArray*>(obj)->set_map_no_write_barrier( |
| - fixed_double_array_map()); |
| - FixedDoubleArray::cast(obj)->set_length(length); |
| - return obj; |
| + elements->set_map_no_write_barrier(fixed_double_array_map()); |
| + elements->set_length(length); |
| + return elements; |
| } |
| @@ -4475,6 +4582,9 @@ MaybeObject* Heap::AllocateGlobalContext() { |
| } |
| Context* context = reinterpret_cast<Context*>(result); |
| context->set_map_no_write_barrier(global_context_map()); |
| + context->set_smi_js_array_map(undefined_value()); |
| + context->set_double_js_array_map(undefined_value()); |
| + context->set_object_js_array_map(undefined_value()); |
| ASSERT(context->IsGlobalContext()); |
| ASSERT(result->IsContext()); |
| return result; |