Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(440)

Side by Side Diff: src/heap.cc

Issue 9073007: Store transitioned JSArray maps in global context (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: review feedback Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/heap.h ('k') | src/ia32/builtins-ia32.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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, pretenure);
3735 JSArray* array;
3736 if (!maybe_array->To(&array)) return maybe_array;
3737
3738 if (capacity == 0) {
3739 array->set_length(Smi::FromInt(0));
3740 array->set_elements(empty_fixed_array());
3741 return array;
3742 }
3743
3744 FixedArrayBase* elms;
3745 MaybeObject* maybe_elms = NULL;
3746 if (elements_kind == FAST_DOUBLE_ELEMENTS) {
3747 if (mode == DONT_INITIALIZE_ARRAY_ELEMENTS) {
3748 maybe_elms = AllocateUninitializedFixedDoubleArray(capacity);
3749 } else {
3750 ASSERT(mode == INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE);
3751 maybe_elms = AllocateFixedDoubleArrayWithHoles(capacity);
3752 }
3753 } else {
3754 ASSERT(elements_kind == FAST_ELEMENTS ||
3755 elements_kind == FAST_SMI_ONLY_ELEMENTS);
3756 if (mode == DONT_INITIALIZE_ARRAY_ELEMENTS) {
3757 maybe_elms = AllocateUninitializedFixedArray(capacity);
3758 } else {
3759 ASSERT(mode == INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE);
3760 maybe_elms = AllocateFixedArrayWithHoles(capacity);
3761 }
3762 }
3763 if (!maybe_elms->To(&elms)) return maybe_elms;
3764
3765 array->set_elements(elms);
3766 array->set_length(Smi::FromInt(length));
3767 return array;
3768 }
3769
3770
3771 MaybeObject* Heap::AllocateJSArrayWithElements(
3772 FixedArrayBase* elements,
3773 ElementsKind elements_kind,
3774 PretenureFlag pretenure) {
3775 MaybeObject* maybe_array = AllocateJSArray(elements_kind, pretenure);
3776 JSArray* array;
3777 if (!maybe_array->To(&array)) return maybe_array;
3778
3779 array->set_elements(elements);
3780 array->set_length(Smi::FromInt(elements->length()));
3781 return array;
3782 }
3783
3784
3727 MaybeObject* Heap::AllocateJSProxy(Object* handler, Object* prototype) { 3785 MaybeObject* Heap::AllocateJSProxy(Object* handler, Object* prototype) {
3728 // Allocate map. 3786 // Allocate map.
3729 // TODO(rossberg): Once we optimize proxies, think about a scheme to share 3787 // 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. 3788 // maps. Will probably depend on the identity of the handler object, too.
3731 Map* map; 3789 Map* map;
3732 MaybeObject* maybe_map_obj = AllocateMap(JS_PROXY_TYPE, JSProxy::kSize); 3790 MaybeObject* maybe_map_obj = AllocateMap(JS_PROXY_TYPE, JSProxy::kSize);
3733 if (!maybe_map_obj->To<Map>(&map)) return maybe_map_obj; 3791 if (!maybe_map_obj->To<Map>(&map)) return maybe_map_obj;
3734 map->set_prototype(prototype); 3792 map->set_prototype(prototype);
3735 3793
3736 // Allocate the proxy object. 3794 // Allocate the proxy object.
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after
4221 4279
4222 // Partially initialize the object. 4280 // Partially initialize the object.
4223 HeapObject::cast(result)->set_map_no_write_barrier(string_map()); 4281 HeapObject::cast(result)->set_map_no_write_barrier(string_map());
4224 String::cast(result)->set_length(length); 4282 String::cast(result)->set_length(length);
4225 String::cast(result)->set_hash_field(String::kEmptyHashField); 4283 String::cast(result)->set_hash_field(String::kEmptyHashField);
4226 ASSERT_EQ(size, HeapObject::cast(result)->Size()); 4284 ASSERT_EQ(size, HeapObject::cast(result)->Size());
4227 return result; 4285 return result;
4228 } 4286 }
4229 4287
4230 4288
4289 MaybeObject* Heap::AllocateJSArray(
4290 ElementsKind elements_kind,
4291 PretenureFlag pretenure) {
4292 Context* global_context = isolate()->context()->global_context();
4293 JSFunction* array_function = global_context->array_function();
4294 Map* map = array_function->initial_map();
4295 if (elements_kind == FAST_ELEMENTS || !FLAG_smi_only_arrays) {
4296 map = Map::cast(global_context->object_js_array_map());
4297 } else if (elements_kind == FAST_DOUBLE_ELEMENTS) {
4298 map = Map::cast(global_context->double_js_array_map());
4299 } else {
4300 ASSERT(elements_kind == FAST_SMI_ONLY_ELEMENTS);
4301 ASSERT(map == global_context->smi_js_array_map());
4302 }
4303
4304 return AllocateJSObjectFromMap(map, pretenure);
4305 }
4306
4307
4231 MaybeObject* Heap::AllocateEmptyFixedArray() { 4308 MaybeObject* Heap::AllocateEmptyFixedArray() {
4232 int size = FixedArray::SizeFor(0); 4309 int size = FixedArray::SizeFor(0);
4233 Object* result; 4310 Object* result;
4234 { MaybeObject* maybe_result = 4311 { MaybeObject* maybe_result =
4235 AllocateRaw(size, OLD_DATA_SPACE, OLD_DATA_SPACE); 4312 AllocateRaw(size, OLD_DATA_SPACE, OLD_DATA_SPACE);
4236 if (!maybe_result->ToObject(&result)) return maybe_result; 4313 if (!maybe_result->ToObject(&result)) return maybe_result;
4237 } 4314 }
4238 // Initialize the object. 4315 // Initialize the object.
4239 reinterpret_cast<FixedArray*>(result)->set_map_no_write_barrier( 4316 reinterpret_cast<FixedArray*>(result)->set_map_no_write_barrier(
4240 fixed_array_map()); 4317 fixed_array_map());
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
4411 reinterpret_cast<FixedDoubleArray*>(result)->set_length(0); 4488 reinterpret_cast<FixedDoubleArray*>(result)->set_length(0);
4412 return result; 4489 return result;
4413 } 4490 }
4414 4491
4415 4492
4416 MaybeObject* Heap::AllocateUninitializedFixedDoubleArray( 4493 MaybeObject* Heap::AllocateUninitializedFixedDoubleArray(
4417 int length, 4494 int length,
4418 PretenureFlag pretenure) { 4495 PretenureFlag pretenure) {
4419 if (length == 0) return empty_fixed_double_array(); 4496 if (length == 0) return empty_fixed_double_array();
4420 4497
4421 Object* obj; 4498 Object* elements_object;
4422 { MaybeObject* maybe_obj = AllocateRawFixedDoubleArray(length, pretenure); 4499 MaybeObject* maybe_obj = AllocateRawFixedDoubleArray(length, pretenure);
4423 if (!maybe_obj->ToObject(&obj)) return maybe_obj; 4500 if (!maybe_obj->ToObject(&elements_object)) return maybe_obj;
4424 } 4501 FixedDoubleArray* elements =
4502 reinterpret_cast<FixedDoubleArray*>(elements_object);
4425 4503
4426 reinterpret_cast<FixedDoubleArray*>(obj)->set_map_no_write_barrier( 4504 elements->set_map_no_write_barrier(fixed_double_array_map());
4427 fixed_double_array_map()); 4505 elements->set_length(length);
4428 FixedDoubleArray::cast(obj)->set_length(length); 4506 return elements;
4429 return obj;
4430 } 4507 }
4431 4508
4432 4509
4510 MaybeObject* Heap::AllocateFixedDoubleArrayWithHoles(
4511 int length,
4512 PretenureFlag pretenure) {
4513 if (length == 0) return empty_fixed_double_array();
4514
4515 Object* elements_object;
4516 MaybeObject* maybe_obj = AllocateRawFixedDoubleArray(length, pretenure);
4517 if (!maybe_obj->ToObject(&elements_object)) return maybe_obj;
4518 FixedDoubleArray* elements =
4519 reinterpret_cast<FixedDoubleArray*>(elements_object);
4520
4521 for (int i = 0; i < length; ++i) {
4522 elements->set_the_hole(i);
4523 }
4524
4525 elements->set_map_no_write_barrier(fixed_double_array_map());
4526 elements->set_length(length);
4527 return elements;
4528 }
4529
4530
4433 MaybeObject* Heap::AllocateRawFixedDoubleArray(int length, 4531 MaybeObject* Heap::AllocateRawFixedDoubleArray(int length,
4434 PretenureFlag pretenure) { 4532 PretenureFlag pretenure) {
4435 if (length < 0 || length > FixedDoubleArray::kMaxLength) { 4533 if (length < 0 || length > FixedDoubleArray::kMaxLength) {
4436 return Failure::OutOfMemoryException(); 4534 return Failure::OutOfMemoryException();
4437 } 4535 }
4438 4536
4439 AllocationSpace space = 4537 AllocationSpace space =
4440 (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE; 4538 (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE;
4441 int size = FixedDoubleArray::SizeFor(length); 4539 int size = FixedDoubleArray::SizeFor(length);
4442 if (space == NEW_SPACE && size > kMaxObjectSizeInNewSpace) { 4540 if (space == NEW_SPACE && size > kMaxObjectSizeInNewSpace) {
(...skipping 25 matching lines...) Expand all
4468 4566
4469 4567
4470 MaybeObject* Heap::AllocateGlobalContext() { 4568 MaybeObject* Heap::AllocateGlobalContext() {
4471 Object* result; 4569 Object* result;
4472 { MaybeObject* maybe_result = 4570 { MaybeObject* maybe_result =
4473 AllocateFixedArray(Context::GLOBAL_CONTEXT_SLOTS); 4571 AllocateFixedArray(Context::GLOBAL_CONTEXT_SLOTS);
4474 if (!maybe_result->ToObject(&result)) return maybe_result; 4572 if (!maybe_result->ToObject(&result)) return maybe_result;
4475 } 4573 }
4476 Context* context = reinterpret_cast<Context*>(result); 4574 Context* context = reinterpret_cast<Context*>(result);
4477 context->set_map_no_write_barrier(global_context_map()); 4575 context->set_map_no_write_barrier(global_context_map());
4576 context->set_smi_js_array_map(undefined_value());
4577 context->set_double_js_array_map(undefined_value());
4578 context->set_object_js_array_map(undefined_value());
4478 ASSERT(context->IsGlobalContext()); 4579 ASSERT(context->IsGlobalContext());
4479 ASSERT(result->IsContext()); 4580 ASSERT(result->IsContext());
4480 return result; 4581 return result;
4481 } 4582 }
4482 4583
4483 4584
4484 MaybeObject* Heap::AllocateFunctionContext(int length, JSFunction* function) { 4585 MaybeObject* Heap::AllocateFunctionContext(int length, JSFunction* function) {
4485 ASSERT(length >= Context::MIN_CONTEXT_SLOTS); 4586 ASSERT(length >= Context::MIN_CONTEXT_SLOTS);
4486 Object* result; 4587 Object* result;
4487 { MaybeObject* maybe_result = AllocateFixedArray(length); 4588 { MaybeObject* maybe_result = AllocateFixedArray(length);
(...skipping 2180 matching lines...) Expand 10 before | Expand all | Expand 10 after
6668 isolate_->heap()->store_buffer()->Compact(); 6769 isolate_->heap()->store_buffer()->Compact();
6669 isolate_->heap()->store_buffer()->Filter(MemoryChunk::ABOUT_TO_BE_FREED); 6770 isolate_->heap()->store_buffer()->Filter(MemoryChunk::ABOUT_TO_BE_FREED);
6670 for (chunk = chunks_queued_for_free_; chunk != NULL; chunk = next) { 6771 for (chunk = chunks_queued_for_free_; chunk != NULL; chunk = next) {
6671 next = chunk->next_chunk(); 6772 next = chunk->next_chunk();
6672 isolate_->memory_allocator()->Free(chunk); 6773 isolate_->memory_allocator()->Free(chunk);
6673 } 6774 }
6674 chunks_queued_for_free_ = NULL; 6775 chunks_queued_for_free_ = NULL;
6675 } 6776 }
6676 6777
6677 } } // namespace v8::internal 6778 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/heap.h ('k') | src/ia32/builtins-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698