| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
| 8 #include "src/api.h" | 8 #include "src/api.h" |
| 9 #include "src/base/bits.h" | 9 #include "src/base/bits.h" |
| 10 #include "src/base/once.h" | 10 #include "src/base/once.h" |
| (...skipping 2704 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2715 reinterpret_cast<Map*>(result)->set_map(raw_unchecked_meta_map()); | 2715 reinterpret_cast<Map*>(result)->set_map(raw_unchecked_meta_map()); |
| 2716 reinterpret_cast<Map*>(result)->set_instance_type(instance_type); | 2716 reinterpret_cast<Map*>(result)->set_instance_type(instance_type); |
| 2717 reinterpret_cast<Map*>(result)->set_instance_size(instance_size); | 2717 reinterpret_cast<Map*>(result)->set_instance_size(instance_size); |
| 2718 // Initialize to only containing tagged fields. | 2718 // Initialize to only containing tagged fields. |
| 2719 reinterpret_cast<Map*>(result)->set_visitor_id( | 2719 reinterpret_cast<Map*>(result)->set_visitor_id( |
| 2720 StaticVisitorBase::GetVisitorId(instance_type, instance_size, false)); | 2720 StaticVisitorBase::GetVisitorId(instance_type, instance_size, false)); |
| 2721 if (FLAG_unbox_double_fields) { | 2721 if (FLAG_unbox_double_fields) { |
| 2722 reinterpret_cast<Map*>(result) | 2722 reinterpret_cast<Map*>(result) |
| 2723 ->set_layout_descriptor(LayoutDescriptor::FastPointerLayout()); | 2723 ->set_layout_descriptor(LayoutDescriptor::FastPointerLayout()); |
| 2724 } | 2724 } |
| 2725 reinterpret_cast<Map*>(result)->clear_unused(); |
| 2725 reinterpret_cast<Map*>(result)->set_inobject_properties(0); | 2726 reinterpret_cast<Map*>(result)->set_inobject_properties(0); |
| 2726 reinterpret_cast<Map*>(result)->set_pre_allocated_property_fields(0); | |
| 2727 reinterpret_cast<Map*>(result)->set_unused_property_fields(0); | 2727 reinterpret_cast<Map*>(result)->set_unused_property_fields(0); |
| 2728 reinterpret_cast<Map*>(result)->set_bit_field(0); | 2728 reinterpret_cast<Map*>(result)->set_bit_field(0); |
| 2729 reinterpret_cast<Map*>(result)->set_bit_field2(0); | 2729 reinterpret_cast<Map*>(result)->set_bit_field2(0); |
| 2730 int bit_field3 = Map::EnumLengthBits::encode(kInvalidEnumCacheSentinel) | | 2730 int bit_field3 = Map::EnumLengthBits::encode(kInvalidEnumCacheSentinel) | |
| 2731 Map::OwnsDescriptors::encode(true) | | 2731 Map::OwnsDescriptors::encode(true) | |
| 2732 Map::Counter::encode(Map::kRetainingCounterStart); | 2732 Map::Counter::encode(Map::kRetainingCounterStart); |
| 2733 reinterpret_cast<Map*>(result)->set_bit_field3(bit_field3); | 2733 reinterpret_cast<Map*>(result)->set_bit_field3(bit_field3); |
| 2734 reinterpret_cast<Map*>(result)->set_weak_cell_cache(Smi::FromInt(0)); | 2734 reinterpret_cast<Map*>(result)->set_weak_cell_cache(Smi::FromInt(0)); |
| 2735 return result; | 2735 return result; |
| 2736 } | 2736 } |
| 2737 | 2737 |
| 2738 | 2738 |
| 2739 AllocationResult Heap::AllocateMap(InstanceType instance_type, | 2739 AllocationResult Heap::AllocateMap(InstanceType instance_type, |
| 2740 int instance_size, | 2740 int instance_size, |
| 2741 ElementsKind elements_kind) { | 2741 ElementsKind elements_kind) { |
| 2742 HeapObject* result; | 2742 HeapObject* result; |
| 2743 AllocationResult allocation = AllocateRaw(Map::kSize, MAP_SPACE, MAP_SPACE); | 2743 AllocationResult allocation = AllocateRaw(Map::kSize, MAP_SPACE, MAP_SPACE); |
| 2744 if (!allocation.To(&result)) return allocation; | 2744 if (!allocation.To(&result)) return allocation; |
| 2745 | 2745 |
| 2746 result->set_map_no_write_barrier(meta_map()); | 2746 result->set_map_no_write_barrier(meta_map()); |
| 2747 Map* map = Map::cast(result); | 2747 Map* map = Map::cast(result); |
| 2748 map->set_instance_type(instance_type); | 2748 map->set_instance_type(instance_type); |
| 2749 map->set_prototype(null_value(), SKIP_WRITE_BARRIER); | 2749 map->set_prototype(null_value(), SKIP_WRITE_BARRIER); |
| 2750 map->set_constructor_or_backpointer(null_value(), SKIP_WRITE_BARRIER); | 2750 map->set_constructor_or_backpointer(null_value(), SKIP_WRITE_BARRIER); |
| 2751 map->set_instance_size(instance_size); | 2751 map->set_instance_size(instance_size); |
| 2752 map->clear_unused(); |
| 2752 map->set_inobject_properties(0); | 2753 map->set_inobject_properties(0); |
| 2753 map->set_pre_allocated_property_fields(0); | |
| 2754 map->set_code_cache(empty_fixed_array(), SKIP_WRITE_BARRIER); | 2754 map->set_code_cache(empty_fixed_array(), SKIP_WRITE_BARRIER); |
| 2755 map->set_dependent_code(DependentCode::cast(empty_fixed_array()), | 2755 map->set_dependent_code(DependentCode::cast(empty_fixed_array()), |
| 2756 SKIP_WRITE_BARRIER); | 2756 SKIP_WRITE_BARRIER); |
| 2757 map->set_weak_cell_cache(Smi::FromInt(0)); | 2757 map->set_weak_cell_cache(Smi::FromInt(0)); |
| 2758 map->set_raw_transitions(Smi::FromInt(0)); | 2758 map->set_raw_transitions(Smi::FromInt(0)); |
| 2759 map->set_unused_property_fields(0); | 2759 map->set_unused_property_fields(0); |
| 2760 map->set_instance_descriptors(empty_descriptor_array()); | 2760 map->set_instance_descriptors(empty_descriptor_array()); |
| 2761 if (FLAG_unbox_double_fields) { | 2761 if (FLAG_unbox_double_fields) { |
| 2762 map->set_layout_descriptor(LayoutDescriptor::FastPointerLayout()); | 2762 map->set_layout_descriptor(LayoutDescriptor::FastPointerLayout()); |
| 2763 } | 2763 } |
| (...skipping 1419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4183 DCHECK(obj->GetInternalFieldCount() == 0); | 4183 DCHECK(obj->GetInternalFieldCount() == 0); |
| 4184 filler = Heap::one_pointer_filler_map(); | 4184 filler = Heap::one_pointer_filler_map(); |
| 4185 } else { | 4185 } else { |
| 4186 filler = Heap::undefined_value(); | 4186 filler = Heap::undefined_value(); |
| 4187 } | 4187 } |
| 4188 obj->InitializeBody(map, Heap::undefined_value(), filler); | 4188 obj->InitializeBody(map, Heap::undefined_value(), filler); |
| 4189 } | 4189 } |
| 4190 | 4190 |
| 4191 | 4191 |
| 4192 AllocationResult Heap::AllocateJSObjectFromMap( | 4192 AllocationResult Heap::AllocateJSObjectFromMap( |
| 4193 Map* map, PretenureFlag pretenure, bool allocate_properties, | 4193 Map* map, PretenureFlag pretenure, AllocationSite* allocation_site) { |
| 4194 AllocationSite* allocation_site) { | |
| 4195 // JSFunctions should be allocated using AllocateFunction to be | 4194 // JSFunctions should be allocated using AllocateFunction to be |
| 4196 // properly initialized. | 4195 // properly initialized. |
| 4197 DCHECK(map->instance_type() != JS_FUNCTION_TYPE); | 4196 DCHECK(map->instance_type() != JS_FUNCTION_TYPE); |
| 4198 | 4197 |
| 4199 // Both types of global objects should be allocated using | 4198 // Both types of global objects should be allocated using |
| 4200 // AllocateGlobalObject to be properly initialized. | 4199 // AllocateGlobalObject to be properly initialized. |
| 4201 DCHECK(map->instance_type() != JS_GLOBAL_OBJECT_TYPE); | 4200 DCHECK(map->instance_type() != JS_GLOBAL_OBJECT_TYPE); |
| 4202 DCHECK(map->instance_type() != JS_BUILTINS_OBJECT_TYPE); | 4201 DCHECK(map->instance_type() != JS_BUILTINS_OBJECT_TYPE); |
| 4203 | 4202 |
| 4204 // Allocate the backing storage for the properties. | 4203 // Allocate the backing storage for the properties. |
| 4205 FixedArray* properties; | 4204 FixedArray* properties = empty_fixed_array(); |
| 4206 if (allocate_properties) { | |
| 4207 int prop_size = map->InitialPropertiesLength(); | |
| 4208 DCHECK(prop_size >= 0); | |
| 4209 { | |
| 4210 AllocationResult allocation = AllocateFixedArray(prop_size, pretenure); | |
| 4211 if (!allocation.To(&properties)) return allocation; | |
| 4212 } | |
| 4213 } else { | |
| 4214 properties = empty_fixed_array(); | |
| 4215 } | |
| 4216 | 4205 |
| 4217 // Allocate the JSObject. | 4206 // Allocate the JSObject. |
| 4218 int size = map->instance_size(); | 4207 int size = map->instance_size(); |
| 4219 AllocationSpace space = SelectSpace(size, pretenure); | 4208 AllocationSpace space = SelectSpace(size, pretenure); |
| 4220 JSObject* js_obj; | 4209 JSObject* js_obj; |
| 4221 AllocationResult allocation = Allocate(map, space, allocation_site); | 4210 AllocationResult allocation = Allocate(map, space, allocation_site); |
| 4222 if (!allocation.To(&js_obj)) return allocation; | 4211 if (!allocation.To(&js_obj)) return allocation; |
| 4223 | 4212 |
| 4224 // Initialize the JSObject. | 4213 // Initialize the JSObject. |
| 4225 InitializeJSObjectFromMap(js_obj, properties, map); | 4214 InitializeJSObjectFromMap(js_obj, properties, map); |
| 4226 DCHECK(js_obj->HasFastElements() || js_obj->HasExternalArrayElements() || | 4215 DCHECK(js_obj->HasFastElements() || js_obj->HasExternalArrayElements() || |
| 4227 js_obj->HasFixedTypedArrayElements()); | 4216 js_obj->HasFixedTypedArrayElements()); |
| 4228 return js_obj; | 4217 return js_obj; |
| 4229 } | 4218 } |
| 4230 | 4219 |
| 4231 | 4220 |
| 4232 AllocationResult Heap::AllocateJSObject(JSFunction* constructor, | 4221 AllocationResult Heap::AllocateJSObject(JSFunction* constructor, |
| 4233 PretenureFlag pretenure, | 4222 PretenureFlag pretenure, |
| 4234 AllocationSite* allocation_site) { | 4223 AllocationSite* allocation_site) { |
| 4235 DCHECK(constructor->has_initial_map()); | 4224 DCHECK(constructor->has_initial_map()); |
| 4236 | 4225 |
| 4237 // Allocate the object based on the constructors initial map. | 4226 // Allocate the object based on the constructors initial map. |
| 4238 AllocationResult allocation = AllocateJSObjectFromMap( | 4227 AllocationResult allocation = AllocateJSObjectFromMap( |
| 4239 constructor->initial_map(), pretenure, true, allocation_site); | 4228 constructor->initial_map(), pretenure, allocation_site); |
| 4240 #ifdef DEBUG | 4229 #ifdef DEBUG |
| 4241 // Make sure result is NOT a global object if valid. | 4230 // Make sure result is NOT a global object if valid. |
| 4242 HeapObject* obj; | 4231 HeapObject* obj; |
| 4243 DCHECK(!allocation.To(&obj) || !obj->IsGlobalObject()); | 4232 DCHECK(!allocation.To(&obj) || !obj->IsGlobalObject()); |
| 4244 #endif | 4233 #endif |
| 4245 return allocation; | 4234 return allocation; |
| 4246 } | 4235 } |
| 4247 | 4236 |
| 4248 | 4237 |
| 4249 AllocationResult Heap::CopyJSObject(JSObject* source, AllocationSite* site) { | 4238 AllocationResult Heap::CopyJSObject(JSObject* source, AllocationSite* site) { |
| (...skipping 2644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6894 *object_type = "CODE_TYPE"; \ | 6883 *object_type = "CODE_TYPE"; \ |
| 6895 *object_sub_type = "CODE_AGE/" #name; \ | 6884 *object_sub_type = "CODE_AGE/" #name; \ |
| 6896 return true; | 6885 return true; |
| 6897 CODE_AGE_LIST_COMPLETE(COMPARE_AND_RETURN_NAME) | 6886 CODE_AGE_LIST_COMPLETE(COMPARE_AND_RETURN_NAME) |
| 6898 #undef COMPARE_AND_RETURN_NAME | 6887 #undef COMPARE_AND_RETURN_NAME |
| 6899 } | 6888 } |
| 6900 return false; | 6889 return false; |
| 6901 } | 6890 } |
| 6902 } // namespace internal | 6891 } // namespace internal |
| 6903 } // namespace v8 | 6892 } // namespace v8 |
| OLD | NEW |