OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 1682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1693 StaticVisitorBase::GetVisitorId(instance_type, instance_size)); | 1693 StaticVisitorBase::GetVisitorId(instance_type, instance_size)); |
1694 reinterpret_cast<Map*>(result)->set_inobject_properties(0); | 1694 reinterpret_cast<Map*>(result)->set_inobject_properties(0); |
1695 reinterpret_cast<Map*>(result)->set_pre_allocated_property_fields(0); | 1695 reinterpret_cast<Map*>(result)->set_pre_allocated_property_fields(0); |
1696 reinterpret_cast<Map*>(result)->set_unused_property_fields(0); | 1696 reinterpret_cast<Map*>(result)->set_unused_property_fields(0); |
1697 reinterpret_cast<Map*>(result)->set_bit_field(0); | 1697 reinterpret_cast<Map*>(result)->set_bit_field(0); |
1698 reinterpret_cast<Map*>(result)->set_bit_field2(0); | 1698 reinterpret_cast<Map*>(result)->set_bit_field2(0); |
1699 return result; | 1699 return result; |
1700 } | 1700 } |
1701 | 1701 |
1702 | 1702 |
1703 MaybeObject* Heap::AllocateMap(InstanceType instance_type, int instance_size) { | 1703 MaybeObject* Heap::AllocateMap(InstanceType instance_type, |
| 1704 int instance_size, |
| 1705 ElementsKind elements_kind) { |
1704 Object* result; | 1706 Object* result; |
1705 { MaybeObject* maybe_result = AllocateRawMap(); | 1707 { MaybeObject* maybe_result = AllocateRawMap(); |
1706 if (!maybe_result->ToObject(&result)) return maybe_result; | 1708 if (!maybe_result->ToObject(&result)) return maybe_result; |
1707 } | 1709 } |
1708 | 1710 |
1709 Map* map = reinterpret_cast<Map*>(result); | 1711 Map* map = reinterpret_cast<Map*>(result); |
1710 map->set_map(meta_map()); | 1712 map->set_map(meta_map()); |
1711 map->set_instance_type(instance_type); | 1713 map->set_instance_type(instance_type); |
1712 map->set_visitor_id( | 1714 map->set_visitor_id( |
1713 StaticVisitorBase::GetVisitorId(instance_type, instance_size)); | 1715 StaticVisitorBase::GetVisitorId(instance_type, instance_size)); |
1714 map->set_prototype(null_value()); | 1716 map->set_prototype(null_value()); |
1715 map->set_constructor(null_value()); | 1717 map->set_constructor(null_value()); |
1716 map->set_instance_size(instance_size); | 1718 map->set_instance_size(instance_size); |
1717 map->set_inobject_properties(0); | 1719 map->set_inobject_properties(0); |
1718 map->set_pre_allocated_property_fields(0); | 1720 map->set_pre_allocated_property_fields(0); |
1719 map->init_instance_descriptors(); | 1721 map->init_instance_descriptors(); |
1720 map->set_code_cache(empty_fixed_array()); | 1722 map->set_code_cache(empty_fixed_array()); |
1721 map->set_prototype_transitions(empty_fixed_array()); | 1723 map->set_prototype_transitions(empty_fixed_array()); |
1722 map->set_unused_property_fields(0); | 1724 map->set_unused_property_fields(0); |
1723 map->set_bit_field(0); | 1725 map->set_bit_field(0); |
1724 map->set_bit_field2(1 << Map::kIsExtensible); | 1726 map->set_bit_field2(1 << Map::kIsExtensible); |
1725 map->set_elements_kind(FAST_ELEMENTS); | 1727 map->set_elements_kind(elements_kind); |
1726 | 1728 |
1727 // If the map object is aligned fill the padding area with Smi 0 objects. | 1729 // If the map object is aligned fill the padding area with Smi 0 objects. |
1728 if (Map::kPadStart < Map::kSize) { | 1730 if (Map::kPadStart < Map::kSize) { |
1729 memset(reinterpret_cast<byte*>(map) + Map::kPadStart - kHeapObjectTag, | 1731 memset(reinterpret_cast<byte*>(map) + Map::kPadStart - kHeapObjectTag, |
1730 0, | 1732 0, |
1731 Map::kSize - Map::kPadStart); | 1733 Map::kSize - Map::kPadStart); |
1732 } | 1734 } |
1733 return map; | 1735 return map; |
1734 } | 1736 } |
1735 | 1737 |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2105 return Oddball::cast(result)->Initialize(to_string, to_number, kind); | 2107 return Oddball::cast(result)->Initialize(to_string, to_number, kind); |
2106 } | 2108 } |
2107 | 2109 |
2108 | 2110 |
2109 bool Heap::CreateApiObjects() { | 2111 bool Heap::CreateApiObjects() { |
2110 Object* obj; | 2112 Object* obj; |
2111 | 2113 |
2112 { MaybeObject* maybe_obj = AllocateMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); | 2114 { MaybeObject* maybe_obj = AllocateMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); |
2113 if (!maybe_obj->ToObject(&obj)) return false; | 2115 if (!maybe_obj->ToObject(&obj)) return false; |
2114 } | 2116 } |
2115 set_neander_map(Map::cast(obj)); | 2117 // Don't use Smi-only elements optimizations for objects with the neander |
| 2118 // map. There are too many cases where element values are set directly with a |
| 2119 // bottleneck to trap the Smi-only -> fast elements transition, and there |
| 2120 // appears to be no benefit for optimize this case. |
| 2121 Map* new_neander_map = Map::cast(obj); |
| 2122 new_neander_map->set_elements_kind(FAST_ELEMENTS); |
| 2123 set_neander_map(new_neander_map); |
2116 | 2124 |
2117 { MaybeObject* maybe_obj = AllocateJSObjectFromMap(neander_map()); | 2125 { MaybeObject* maybe_obj = AllocateJSObjectFromMap(neander_map()); |
2118 if (!maybe_obj->ToObject(&obj)) return false; | 2126 if (!maybe_obj->ToObject(&obj)) return false; |
2119 } | 2127 } |
2120 Object* elements; | 2128 Object* elements; |
2121 { MaybeObject* maybe_elements = AllocateFixedArray(2); | 2129 { MaybeObject* maybe_elements = AllocateFixedArray(2); |
2122 if (!maybe_elements->ToObject(&elements)) return false; | 2130 if (!maybe_elements->ToObject(&elements)) return false; |
2123 } | 2131 } |
2124 FixedArray::cast(elements)->set(0, Smi::FromInt(0)); | 2132 FixedArray::cast(elements)->set(0, Smi::FromInt(0)); |
2125 JSObject::cast(obj)->set_elements(FixedArray::cast(elements)); | 2133 JSObject::cast(obj)->set_elements(FixedArray::cast(elements)); |
(...skipping 1361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3487 if (map->instance_size() > MaxObjectSizeInPagedSpace()) space = LO_SPACE; | 3495 if (map->instance_size() > MaxObjectSizeInPagedSpace()) space = LO_SPACE; |
3488 Object* obj; | 3496 Object* obj; |
3489 { MaybeObject* maybe_obj = Allocate(map, space); | 3497 { MaybeObject* maybe_obj = Allocate(map, space); |
3490 if (!maybe_obj->ToObject(&obj)) return maybe_obj; | 3498 if (!maybe_obj->ToObject(&obj)) return maybe_obj; |
3491 } | 3499 } |
3492 | 3500 |
3493 // Initialize the JSObject. | 3501 // Initialize the JSObject. |
3494 InitializeJSObjectFromMap(JSObject::cast(obj), | 3502 InitializeJSObjectFromMap(JSObject::cast(obj), |
3495 FixedArray::cast(properties), | 3503 FixedArray::cast(properties), |
3496 map); | 3504 map); |
3497 ASSERT(JSObject::cast(obj)->HasFastElements()); | 3505 ASSERT(JSObject::cast(obj)->HasFastSmiOnlyElements() || |
| 3506 JSObject::cast(obj)->HasFastElements()); |
3498 return obj; | 3507 return obj; |
3499 } | 3508 } |
3500 | 3509 |
3501 | 3510 |
3502 MaybeObject* Heap::AllocateJSObject(JSFunction* constructor, | 3511 MaybeObject* Heap::AllocateJSObject(JSFunction* constructor, |
3503 PretenureFlag pretenure) { | 3512 PretenureFlag pretenure) { |
3504 // Allocate the initial map if absent. | 3513 // Allocate the initial map if absent. |
3505 if (!constructor->has_initial_map()) { | 3514 if (!constructor->has_initial_map()) { |
3506 Object* initial_map; | 3515 Object* initial_map; |
3507 { MaybeObject* maybe_initial_map = AllocateInitialMap(constructor); | 3516 { MaybeObject* maybe_initial_map = AllocateInitialMap(constructor); |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3669 if (!maybe_clone->ToObject(&clone)) return maybe_clone; | 3678 if (!maybe_clone->ToObject(&clone)) return maybe_clone; |
3670 } | 3679 } |
3671 ASSERT(InNewSpace(clone)); | 3680 ASSERT(InNewSpace(clone)); |
3672 // Since we know the clone is allocated in new space, we can copy | 3681 // Since we know the clone is allocated in new space, we can copy |
3673 // the contents without worrying about updating the write barrier. | 3682 // the contents without worrying about updating the write barrier. |
3674 CopyBlock(HeapObject::cast(clone)->address(), | 3683 CopyBlock(HeapObject::cast(clone)->address(), |
3675 source->address(), | 3684 source->address(), |
3676 object_size); | 3685 object_size); |
3677 } | 3686 } |
3678 | 3687 |
| 3688 ASSERT(JSObject::cast(clone)->GetElementsKind() == source->GetElementsKind()); |
3679 FixedArrayBase* elements = FixedArrayBase::cast(source->elements()); | 3689 FixedArrayBase* elements = FixedArrayBase::cast(source->elements()); |
3680 FixedArray* properties = FixedArray::cast(source->properties()); | 3690 FixedArray* properties = FixedArray::cast(source->properties()); |
3681 // Update elements if necessary. | 3691 // Update elements if necessary. |
3682 if (elements->length() > 0) { | 3692 if (elements->length() > 0) { |
3683 Object* elem; | 3693 Object* elem; |
3684 { MaybeObject* maybe_elem; | 3694 { MaybeObject* maybe_elem; |
3685 if (elements->map() == fixed_cow_array_map()) { | 3695 if (elements->map() == fixed_cow_array_map()) { |
3686 maybe_elem = FixedArray::cast(elements); | 3696 maybe_elem = FixedArray::cast(elements); |
3687 } else if (source->HasFastDoubleElements()) { | 3697 } else if (source->HasFastDoubleElements()) { |
3688 maybe_elem = CopyFixedDoubleArray(FixedDoubleArray::cast(elements)); | 3698 maybe_elem = CopyFixedDoubleArray(FixedDoubleArray::cast(elements)); |
(...skipping 2658 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6347 } | 6357 } |
6348 isolate_->heap()->store_buffer()->Filter(MemoryChunk::ABOUT_TO_BE_FREED); | 6358 isolate_->heap()->store_buffer()->Filter(MemoryChunk::ABOUT_TO_BE_FREED); |
6349 for (chunk = chunks_queued_for_free_; chunk != NULL; chunk = next) { | 6359 for (chunk = chunks_queued_for_free_; chunk != NULL; chunk = next) { |
6350 next = chunk->next_chunk(); | 6360 next = chunk->next_chunk(); |
6351 isolate_->memory_allocator()->Free(chunk); | 6361 isolate_->memory_allocator()->Free(chunk); |
6352 } | 6362 } |
6353 chunks_queued_for_free_ = NULL; | 6363 chunks_queued_for_free_ = NULL; |
6354 } | 6364 } |
6355 | 6365 |
6356 } } // namespace v8::internal | 6366 } } // namespace v8::internal |
OLD | NEW |