Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 3695 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3706 // Allocate the initial map if absent. | 3706 // Allocate the initial map if absent. |
| 3707 if (!constructor->has_initial_map()) { | 3707 if (!constructor->has_initial_map()) { |
| 3708 Object* initial_map; | 3708 Object* initial_map; |
| 3709 { MaybeObject* maybe_initial_map = AllocateInitialMap(constructor); | 3709 { MaybeObject* maybe_initial_map = AllocateInitialMap(constructor); |
| 3710 if (!maybe_initial_map->ToObject(&initial_map)) return maybe_initial_map; | 3710 if (!maybe_initial_map->ToObject(&initial_map)) return maybe_initial_map; |
| 3711 } | 3711 } |
| 3712 constructor->set_initial_map(Map::cast(initial_map)); | 3712 constructor->set_initial_map(Map::cast(initial_map)); |
| 3713 Map::cast(initial_map)->set_constructor(constructor); | 3713 Map::cast(initial_map)->set_constructor(constructor); |
| 3714 } | 3714 } |
| 3715 // Allocate the object based on the constructors initial map. | 3715 // Allocate the object based on the constructors initial map. |
| 3716 MaybeObject* result = | 3716 MaybeObject* result = AllocateJSObjectFromMap( |
| 3717 AllocateJSObjectFromMap(constructor->initial_map(), pretenure); | 3717 constructor->initial_map(), pretenure); |
| 3718 #ifdef DEBUG | 3718 #ifdef DEBUG |
| 3719 // Make sure result is NOT a global object if valid. | 3719 // Make sure result is NOT a global object if valid. |
| 3720 Object* non_failure; | 3720 Object* non_failure; |
| 3721 ASSERT(!result->ToObject(&non_failure) || !non_failure->IsGlobalObject()); | 3721 ASSERT(!result->ToObject(&non_failure) || !non_failure->IsGlobalObject()); |
| 3722 #endif | 3722 #endif |
| 3723 return result; | 3723 return result; |
| 3724 } | 3724 } |
| 3725 | 3725 |
| 3726 | 3726 |
| 3727 MaybeObject* Heap::AllocateJSArrayAndStorage( | |
| 3728 ElementsKind elements_kind, | |
| 3729 int length, | |
| 3730 int capacity, | |
| 3731 ArrayStorageAllocationMode mode, | |
| 3732 PretenureFlag pretenure) { | |
| 3733 ASSERT(capacity >= length); | |
| 3734 MaybeObject* maybe_array = AllocateJSArray(elements_kind, | |
| 3735 pretenure); | |
|
Jakob Kummerow
2012/01/23 17:16:55
nit: can fit in one line
danno
2012/01/26 21:32:34
Done.
| |
| 3736 JSArray* array; | |
| 3737 if (!maybe_array->To(&array)) return maybe_array; | |
| 3738 | |
| 3739 if (capacity == 0) { | |
| 3740 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.
| |
| 3741 array->set_length(Smi::FromInt(0)); | |
| 3742 array->set_elements(empty_fixed_array()); | |
| 3743 return array; | |
| 3744 } | |
| 3745 | |
| 3746 FixedArrayBase* elms; | |
| 3747 if (elements_kind == FAST_DOUBLE_ELEMENTS) { | |
| 3748 if (mode == DONT_INITIALIZE_ARRAY_ELEMENTS) { | |
| 3749 MaybeObject* maybe_elms = | |
| 3750 AllocateUninitializedFixedDoubleArray(capacity); | |
| 3751 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.
| |
| 3752 } else { | |
| 3753 ASSERT(mode == INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE); | |
| 3754 MaybeObject* maybe_elms = | |
| 3755 AllocateFixedDoubleArrayWithHoles(capacity); | |
| 3756 if (!maybe_elms->To(&elms)) return maybe_elms; | |
| 3757 } | |
| 3758 } else { | |
| 3759 ASSERT(elements_kind == FAST_ELEMENTS || | |
| 3760 elements_kind == FAST_SMI_ONLY_ELEMENTS); | |
| 3761 if (mode == DONT_INITIALIZE_ARRAY_ELEMENTS) { | |
| 3762 MaybeObject* maybe_elms = | |
| 3763 AllocateUninitializedFixedArray(capacity); | |
| 3764 if (!maybe_elms->To(&elms)) return maybe_elms; | |
| 3765 } else { | |
| 3766 ASSERT(mode == INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE); | |
| 3767 MaybeObject* maybe_elms = | |
| 3768 AllocateFixedArrayWithHoles(capacity); | |
| 3769 if (!maybe_elms->To(&elms)) return maybe_elms; | |
| 3770 } | |
| 3771 } | |
| 3772 | |
| 3773 array->set_elements(elms); | |
| 3774 array->set_length(Smi::FromInt(length)); | |
| 3775 return array; | |
| 3776 } | |
| 3777 | |
| 3778 | |
| 3779 MaybeObject* Heap::AllocateJSArrayWithElements( | |
| 3780 FixedArrayBase* elements, | |
| 3781 ElementsKind elements_kind, | |
| 3782 PretenureFlag pretenure) { | |
| 3783 MaybeObject* maybe_array = AllocateJSArray(elements_kind, | |
| 3784 pretenure); | |
|
Jakob Kummerow
2012/01/23 17:16:55
nit: can fit in one line
danno
2012/01/26 21:32:34
Done.
| |
| 3785 JSArray* array; | |
| 3786 if (!maybe_array->To(&array)) return maybe_array; | |
| 3787 | |
| 3788 array->set_elements(elements); | |
| 3789 array->set_length(Smi::FromInt(elements->length())); | |
| 3790 return array; | |
| 3791 } | |
| 3792 | |
| 3793 | |
| 3727 MaybeObject* Heap::AllocateJSProxy(Object* handler, Object* prototype) { | 3794 MaybeObject* Heap::AllocateJSProxy(Object* handler, Object* prototype) { |
| 3728 // Allocate map. | 3795 // Allocate map. |
| 3729 // TODO(rossberg): Once we optimize proxies, think about a scheme to share | 3796 // TODO(rossberg): Once we optimize proxies, think about a scheme to share |
| 3730 // maps. Will probably depend on the identity of the handler object, too. | 3797 // maps. Will probably depend on the identity of the handler object, too. |
| 3731 Map* map; | 3798 Map* map; |
| 3732 MaybeObject* maybe_map_obj = AllocateMap(JS_PROXY_TYPE, JSProxy::kSize); | 3799 MaybeObject* maybe_map_obj = AllocateMap(JS_PROXY_TYPE, JSProxy::kSize); |
| 3733 if (!maybe_map_obj->To<Map>(&map)) return maybe_map_obj; | 3800 if (!maybe_map_obj->To<Map>(&map)) return maybe_map_obj; |
| 3734 map->set_prototype(prototype); | 3801 map->set_prototype(prototype); |
| 3735 | 3802 |
| 3736 // Allocate the proxy object. | 3803 // Allocate the proxy object. |
| (...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4221 | 4288 |
| 4222 // Partially initialize the object. | 4289 // Partially initialize the object. |
| 4223 HeapObject::cast(result)->set_map_no_write_barrier(string_map()); | 4290 HeapObject::cast(result)->set_map_no_write_barrier(string_map()); |
| 4224 String::cast(result)->set_length(length); | 4291 String::cast(result)->set_length(length); |
| 4225 String::cast(result)->set_hash_field(String::kEmptyHashField); | 4292 String::cast(result)->set_hash_field(String::kEmptyHashField); |
| 4226 ASSERT_EQ(size, HeapObject::cast(result)->Size()); | 4293 ASSERT_EQ(size, HeapObject::cast(result)->Size()); |
| 4227 return result; | 4294 return result; |
| 4228 } | 4295 } |
| 4229 | 4296 |
| 4230 | 4297 |
| 4298 MaybeObject* Heap::AllocateJSArray( | |
| 4299 ElementsKind elements_kind, | |
| 4300 PretenureFlag pretenure) { | |
| 4301 Context* global_context = isolate()->context()->global_context(); | |
| 4302 JSFunction* array_function = global_context->array_function(); | |
| 4303 Map* map = array_function->initial_map(); | |
| 4304 if (elements_kind == FAST_ELEMENTS || !FLAG_smi_only_arrays) { | |
| 4305 map = Map::cast(global_context->object_js_array_map()); | |
| 4306 } else if (elements_kind == FAST_DOUBLE_ELEMENTS) { | |
| 4307 map = Map::cast(global_context->double_js_array_map()); | |
| 4308 } else { | |
| 4309 ASSERT(elements_kind == FAST_SMI_ONLY_ELEMENTS); | |
| 4310 ASSERT(map == global_context->smi_js_array_map()); | |
| 4311 } | |
| 4312 | |
| 4313 return AllocateJSObjectFromMap(map, pretenure); | |
| 4314 } | |
| 4315 | |
| 4316 | |
| 4231 MaybeObject* Heap::AllocateEmptyFixedArray() { | 4317 MaybeObject* Heap::AllocateEmptyFixedArray() { |
| 4232 int size = FixedArray::SizeFor(0); | 4318 int size = FixedArray::SizeFor(0); |
| 4233 Object* result; | 4319 Object* result; |
| 4234 { MaybeObject* maybe_result = | 4320 { MaybeObject* maybe_result = |
| 4235 AllocateRaw(size, OLD_DATA_SPACE, OLD_DATA_SPACE); | 4321 AllocateRaw(size, OLD_DATA_SPACE, OLD_DATA_SPACE); |
| 4236 if (!maybe_result->ToObject(&result)) return maybe_result; | 4322 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 4237 } | 4323 } |
| 4238 // Initialize the object. | 4324 // Initialize the object. |
| 4239 reinterpret_cast<FixedArray*>(result)->set_map_no_write_barrier( | 4325 reinterpret_cast<FixedArray*>(result)->set_map_no_write_barrier( |
| 4240 fixed_array_map()); | 4326 fixed_array_map()); |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4411 reinterpret_cast<FixedDoubleArray*>(result)->set_length(0); | 4497 reinterpret_cast<FixedDoubleArray*>(result)->set_length(0); |
| 4412 return result; | 4498 return result; |
| 4413 } | 4499 } |
| 4414 | 4500 |
| 4415 | 4501 |
| 4416 MaybeObject* Heap::AllocateUninitializedFixedDoubleArray( | 4502 MaybeObject* Heap::AllocateUninitializedFixedDoubleArray( |
| 4417 int length, | 4503 int length, |
| 4418 PretenureFlag pretenure) { | 4504 PretenureFlag pretenure) { |
| 4419 if (length == 0) return empty_fixed_double_array(); | 4505 if (length == 0) return empty_fixed_double_array(); |
| 4420 | 4506 |
| 4421 Object* obj; | 4507 Object* elements_object; |
| 4422 { MaybeObject* maybe_obj = AllocateRawFixedDoubleArray(length, pretenure); | 4508 MaybeObject* maybe_obj = AllocateRawFixedDoubleArray(length, pretenure); |
| 4423 if (!maybe_obj->ToObject(&obj)) return maybe_obj; | 4509 if (!maybe_obj->ToObject(&elements_object)) return maybe_obj; |
| 4424 } | 4510 FixedDoubleArray* elements = |
| 4511 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
| |
| 4425 | 4512 |
| 4426 reinterpret_cast<FixedDoubleArray*>(obj)->set_map_no_write_barrier( | 4513 elements->set_map_no_write_barrier(fixed_double_array_map()); |
| 4427 fixed_double_array_map()); | 4514 elements->set_length(length); |
| 4428 FixedDoubleArray::cast(obj)->set_length(length); | 4515 return elements; |
| 4429 return obj; | |
| 4430 } | 4516 } |
| 4431 | 4517 |
| 4432 | 4518 |
| 4519 MaybeObject* Heap::AllocateFixedDoubleArrayWithHoles( | |
| 4520 int length, | |
| 4521 PretenureFlag pretenure) { | |
| 4522 if (length == 0) return empty_fixed_double_array(); | |
| 4523 | |
| 4524 Object* elements_object; | |
| 4525 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:
| |
| 4526 if (!maybe_obj->ToObject(&elements_object)) return maybe_obj; | |
| 4527 FixedDoubleArray* elements = | |
| 4528 reinterpret_cast<FixedDoubleArray*>(elements_object); | |
| 4529 | |
| 4530 for (int i = 0; i < length; ++i) { | |
| 4531 elements->set_the_hole(i); | |
| 4532 } | |
| 4533 | |
| 4534 elements->set_map_no_write_barrier(fixed_double_array_map()); | |
| 4535 elements->set_length(length); | |
| 4536 return elements; | |
| 4537 } | |
| 4538 | |
| 4539 | |
| 4433 MaybeObject* Heap::AllocateRawFixedDoubleArray(int length, | 4540 MaybeObject* Heap::AllocateRawFixedDoubleArray(int length, |
| 4434 PretenureFlag pretenure) { | 4541 PretenureFlag pretenure) { |
| 4435 if (length < 0 || length > FixedDoubleArray::kMaxLength) { | 4542 if (length < 0 || length > FixedDoubleArray::kMaxLength) { |
| 4436 return Failure::OutOfMemoryException(); | 4543 return Failure::OutOfMemoryException(); |
| 4437 } | 4544 } |
| 4438 | 4545 |
| 4439 AllocationSpace space = | 4546 AllocationSpace space = |
| 4440 (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE; | 4547 (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE; |
| 4441 int size = FixedDoubleArray::SizeFor(length); | 4548 int size = FixedDoubleArray::SizeFor(length); |
| 4442 if (space == NEW_SPACE && size > kMaxObjectSizeInNewSpace) { | 4549 if (space == NEW_SPACE && size > kMaxObjectSizeInNewSpace) { |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 4468 | 4575 |
| 4469 | 4576 |
| 4470 MaybeObject* Heap::AllocateGlobalContext() { | 4577 MaybeObject* Heap::AllocateGlobalContext() { |
| 4471 Object* result; | 4578 Object* result; |
| 4472 { MaybeObject* maybe_result = | 4579 { MaybeObject* maybe_result = |
| 4473 AllocateFixedArray(Context::GLOBAL_CONTEXT_SLOTS); | 4580 AllocateFixedArray(Context::GLOBAL_CONTEXT_SLOTS); |
| 4474 if (!maybe_result->ToObject(&result)) return maybe_result; | 4581 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 4475 } | 4582 } |
| 4476 Context* context = reinterpret_cast<Context*>(result); | 4583 Context* context = reinterpret_cast<Context*>(result); |
| 4477 context->set_map_no_write_barrier(global_context_map()); | 4584 context->set_map_no_write_barrier(global_context_map()); |
| 4585 context->set_smi_js_array_map(undefined_value()); | |
| 4586 context->set_double_js_array_map(undefined_value()); | |
| 4587 context->set_object_js_array_map(undefined_value()); | |
| 4478 ASSERT(context->IsGlobalContext()); | 4588 ASSERT(context->IsGlobalContext()); |
| 4479 ASSERT(result->IsContext()); | 4589 ASSERT(result->IsContext()); |
| 4480 return result; | 4590 return result; |
| 4481 } | 4591 } |
| 4482 | 4592 |
| 4483 | 4593 |
| 4484 MaybeObject* Heap::AllocateFunctionContext(int length, JSFunction* function) { | 4594 MaybeObject* Heap::AllocateFunctionContext(int length, JSFunction* function) { |
| 4485 ASSERT(length >= Context::MIN_CONTEXT_SLOTS); | 4595 ASSERT(length >= Context::MIN_CONTEXT_SLOTS); |
| 4486 Object* result; | 4596 Object* result; |
| 4487 { MaybeObject* maybe_result = AllocateFixedArray(length); | 4597 { MaybeObject* maybe_result = AllocateFixedArray(length); |
| (...skipping 2180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6668 isolate_->heap()->store_buffer()->Compact(); | 6778 isolate_->heap()->store_buffer()->Compact(); |
| 6669 isolate_->heap()->store_buffer()->Filter(MemoryChunk::ABOUT_TO_BE_FREED); | 6779 isolate_->heap()->store_buffer()->Filter(MemoryChunk::ABOUT_TO_BE_FREED); |
| 6670 for (chunk = chunks_queued_for_free_; chunk != NULL; chunk = next) { | 6780 for (chunk = chunks_queued_for_free_; chunk != NULL; chunk = next) { |
| 6671 next = chunk->next_chunk(); | 6781 next = chunk->next_chunk(); |
| 6672 isolate_->memory_allocator()->Free(chunk); | 6782 isolate_->memory_allocator()->Free(chunk); |
| 6673 } | 6783 } |
| 6674 chunks_queued_for_free_ = NULL; | 6784 chunks_queued_for_free_ = NULL; |
| 6675 } | 6785 } |
| 6676 | 6786 |
| 6677 } } // namespace v8::internal | 6787 } } // namespace v8::internal |
| OLD | NEW |