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 2636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2647 reinterpret_cast<Map*>(result)->set_instance_type(instance_type); | 2647 reinterpret_cast<Map*>(result)->set_instance_type(instance_type); |
2648 reinterpret_cast<Map*>(result)->set_instance_size(instance_size); | 2648 reinterpret_cast<Map*>(result)->set_instance_size(instance_size); |
2649 // Initialize to only containing tagged fields. | 2649 // Initialize to only containing tagged fields. |
2650 reinterpret_cast<Map*>(result)->set_visitor_id( | 2650 reinterpret_cast<Map*>(result)->set_visitor_id( |
2651 StaticVisitorBase::GetVisitorId(instance_type, instance_size, false)); | 2651 StaticVisitorBase::GetVisitorId(instance_type, instance_size, false)); |
2652 if (FLAG_unbox_double_fields) { | 2652 if (FLAG_unbox_double_fields) { |
2653 reinterpret_cast<Map*>(result) | 2653 reinterpret_cast<Map*>(result) |
2654 ->set_layout_descriptor(LayoutDescriptor::FastPointerLayout()); | 2654 ->set_layout_descriptor(LayoutDescriptor::FastPointerLayout()); |
2655 } | 2655 } |
2656 reinterpret_cast<Map*>(result)->clear_unused(); | 2656 reinterpret_cast<Map*>(result)->clear_unused(); |
2657 reinterpret_cast<Map*>(result)->set_inobject_properties(0); | 2657 reinterpret_cast<Map*>(result) |
| 2658 ->set_inobject_properties_or_constructor_function_index(0); |
2658 reinterpret_cast<Map*>(result)->set_unused_property_fields(0); | 2659 reinterpret_cast<Map*>(result)->set_unused_property_fields(0); |
2659 reinterpret_cast<Map*>(result)->set_bit_field(0); | 2660 reinterpret_cast<Map*>(result)->set_bit_field(0); |
2660 reinterpret_cast<Map*>(result)->set_bit_field2(0); | 2661 reinterpret_cast<Map*>(result)->set_bit_field2(0); |
2661 int bit_field3 = Map::EnumLengthBits::encode(kInvalidEnumCacheSentinel) | | 2662 int bit_field3 = Map::EnumLengthBits::encode(kInvalidEnumCacheSentinel) | |
2662 Map::OwnsDescriptors::encode(true) | | 2663 Map::OwnsDescriptors::encode(true) | |
2663 Map::Counter::encode(Map::kRetainingCounterStart); | 2664 Map::Counter::encode(Map::kRetainingCounterStart); |
2664 reinterpret_cast<Map*>(result)->set_bit_field3(bit_field3); | 2665 reinterpret_cast<Map*>(result)->set_bit_field3(bit_field3); |
2665 reinterpret_cast<Map*>(result)->set_weak_cell_cache(Smi::FromInt(0)); | 2666 reinterpret_cast<Map*>(result)->set_weak_cell_cache(Smi::FromInt(0)); |
2666 return result; | 2667 return result; |
2667 } | 2668 } |
2668 | 2669 |
2669 | 2670 |
2670 AllocationResult Heap::AllocateMap(InstanceType instance_type, | 2671 AllocationResult Heap::AllocateMap(InstanceType instance_type, |
2671 int instance_size, | 2672 int instance_size, |
2672 ElementsKind elements_kind) { | 2673 ElementsKind elements_kind) { |
2673 HeapObject* result; | 2674 HeapObject* result; |
2674 AllocationResult allocation = AllocateRaw(Map::kSize, MAP_SPACE, MAP_SPACE); | 2675 AllocationResult allocation = AllocateRaw(Map::kSize, MAP_SPACE, MAP_SPACE); |
2675 if (!allocation.To(&result)) return allocation; | 2676 if (!allocation.To(&result)) return allocation; |
2676 | 2677 |
2677 result->set_map_no_write_barrier(meta_map()); | 2678 result->set_map_no_write_barrier(meta_map()); |
2678 Map* map = Map::cast(result); | 2679 Map* map = Map::cast(result); |
2679 map->set_instance_type(instance_type); | 2680 map->set_instance_type(instance_type); |
2680 map->set_prototype(null_value(), SKIP_WRITE_BARRIER); | 2681 map->set_prototype(null_value(), SKIP_WRITE_BARRIER); |
2681 map->set_constructor_or_backpointer(null_value(), SKIP_WRITE_BARRIER); | 2682 map->set_constructor_or_backpointer(null_value(), SKIP_WRITE_BARRIER); |
2682 map->set_instance_size(instance_size); | 2683 map->set_instance_size(instance_size); |
2683 map->clear_unused(); | 2684 map->clear_unused(); |
2684 map->set_inobject_properties(0); | 2685 map->set_inobject_properties_or_constructor_function_index(0); |
2685 map->set_code_cache(empty_fixed_array(), SKIP_WRITE_BARRIER); | 2686 map->set_code_cache(empty_fixed_array(), SKIP_WRITE_BARRIER); |
2686 map->set_dependent_code(DependentCode::cast(empty_fixed_array()), | 2687 map->set_dependent_code(DependentCode::cast(empty_fixed_array()), |
2687 SKIP_WRITE_BARRIER); | 2688 SKIP_WRITE_BARRIER); |
2688 map->set_weak_cell_cache(Smi::FromInt(0)); | 2689 map->set_weak_cell_cache(Smi::FromInt(0)); |
2689 map->set_raw_transitions(Smi::FromInt(0)); | 2690 map->set_raw_transitions(Smi::FromInt(0)); |
2690 map->set_unused_property_fields(0); | 2691 map->set_unused_property_fields(0); |
2691 map->set_instance_descriptors(empty_descriptor_array()); | 2692 map->set_instance_descriptors(empty_descriptor_array()); |
2692 if (FLAG_unbox_double_fields) { | 2693 if (FLAG_unbox_double_fields) { |
2693 map->set_layout_descriptor(LayoutDescriptor::FastPointerLayout()); | 2694 map->set_layout_descriptor(LayoutDescriptor::FastPointerLayout()); |
2694 } | 2695 } |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2863 #define ALLOCATE_MAP(instance_type, size, field_name) \ | 2864 #define ALLOCATE_MAP(instance_type, size, field_name) \ |
2864 { \ | 2865 { \ |
2865 Map* map; \ | 2866 Map* map; \ |
2866 if (!AllocateMap((instance_type), size).To(&map)) return false; \ | 2867 if (!AllocateMap((instance_type), size).To(&map)) return false; \ |
2867 set_##field_name##_map(map); \ | 2868 set_##field_name##_map(map); \ |
2868 } | 2869 } |
2869 | 2870 |
2870 #define ALLOCATE_VARSIZE_MAP(instance_type, field_name) \ | 2871 #define ALLOCATE_VARSIZE_MAP(instance_type, field_name) \ |
2871 ALLOCATE_MAP(instance_type, kVariableSizeSentinel, field_name) | 2872 ALLOCATE_MAP(instance_type, kVariableSizeSentinel, field_name) |
2872 | 2873 |
| 2874 #define ALLOCATE_PRIMITIVE_MAP(instance_type, size, field_name, \ |
| 2875 constructor_function_index) \ |
| 2876 { \ |
| 2877 ALLOCATE_MAP((instance_type), (size), field_name); \ |
| 2878 field_name##_map()->SetConstructorFunctionIndex( \ |
| 2879 (constructor_function_index)); \ |
| 2880 } |
| 2881 |
2873 ALLOCATE_VARSIZE_MAP(FIXED_ARRAY_TYPE, fixed_cow_array) | 2882 ALLOCATE_VARSIZE_MAP(FIXED_ARRAY_TYPE, fixed_cow_array) |
2874 DCHECK(fixed_array_map() != fixed_cow_array_map()); | 2883 DCHECK(fixed_array_map() != fixed_cow_array_map()); |
2875 | 2884 |
2876 ALLOCATE_VARSIZE_MAP(FIXED_ARRAY_TYPE, scope_info) | 2885 ALLOCATE_VARSIZE_MAP(FIXED_ARRAY_TYPE, scope_info) |
2877 ALLOCATE_MAP(HEAP_NUMBER_TYPE, HeapNumber::kSize, heap_number) | 2886 ALLOCATE_PRIMITIVE_MAP(HEAP_NUMBER_TYPE, HeapNumber::kSize, heap_number, |
| 2887 Context::NUMBER_FUNCTION_INDEX) |
2878 ALLOCATE_MAP(MUTABLE_HEAP_NUMBER_TYPE, HeapNumber::kSize, | 2888 ALLOCATE_MAP(MUTABLE_HEAP_NUMBER_TYPE, HeapNumber::kSize, |
2879 mutable_heap_number) | 2889 mutable_heap_number) |
2880 ALLOCATE_MAP(SYMBOL_TYPE, Symbol::kSize, symbol) | 2890 ALLOCATE_PRIMITIVE_MAP(SYMBOL_TYPE, Symbol::kSize, symbol, |
| 2891 Context::SYMBOL_FUNCTION_INDEX) |
2881 #define ALLOCATE_SIMD128_MAP(TYPE, Type, type, lane_count, lane_type) \ | 2892 #define ALLOCATE_SIMD128_MAP(TYPE, Type, type, lane_count, lane_type) \ |
2882 ALLOCATE_MAP(SIMD128_VALUE_TYPE, Type::kSize, type) | 2893 ALLOCATE_PRIMITIVE_MAP(SIMD128_VALUE_TYPE, Type::kSize, type, \ |
| 2894 Context::TYPE##_FUNCTION_INDEX) |
2883 SIMD128_TYPES(ALLOCATE_SIMD128_MAP) | 2895 SIMD128_TYPES(ALLOCATE_SIMD128_MAP) |
2884 #undef ALLOCATE_SIMD128_MAP | 2896 #undef ALLOCATE_SIMD128_MAP |
2885 ALLOCATE_MAP(FOREIGN_TYPE, Foreign::kSize, foreign) | 2897 ALLOCATE_MAP(FOREIGN_TYPE, Foreign::kSize, foreign) |
2886 | 2898 |
2887 ALLOCATE_MAP(ODDBALL_TYPE, Oddball::kSize, the_hole); | 2899 ALLOCATE_MAP(ODDBALL_TYPE, Oddball::kSize, the_hole); |
2888 ALLOCATE_MAP(ODDBALL_TYPE, Oddball::kSize, boolean); | 2900 ALLOCATE_PRIMITIVE_MAP(ODDBALL_TYPE, Oddball::kSize, boolean, |
| 2901 Context::BOOLEAN_FUNCTION_INDEX); |
2889 ALLOCATE_MAP(ODDBALL_TYPE, Oddball::kSize, uninitialized); | 2902 ALLOCATE_MAP(ODDBALL_TYPE, Oddball::kSize, uninitialized); |
2890 ALLOCATE_MAP(ODDBALL_TYPE, Oddball::kSize, arguments_marker); | 2903 ALLOCATE_MAP(ODDBALL_TYPE, Oddball::kSize, arguments_marker); |
2891 ALLOCATE_MAP(ODDBALL_TYPE, Oddball::kSize, no_interceptor_result_sentinel); | 2904 ALLOCATE_MAP(ODDBALL_TYPE, Oddball::kSize, no_interceptor_result_sentinel); |
2892 ALLOCATE_MAP(ODDBALL_TYPE, Oddball::kSize, exception); | 2905 ALLOCATE_MAP(ODDBALL_TYPE, Oddball::kSize, exception); |
2893 ALLOCATE_MAP(ODDBALL_TYPE, Oddball::kSize, termination_exception); | 2906 ALLOCATE_MAP(ODDBALL_TYPE, Oddball::kSize, termination_exception); |
2894 | 2907 |
2895 for (unsigned i = 0; i < arraysize(string_type_table); i++) { | 2908 for (unsigned i = 0; i < arraysize(string_type_table); i++) { |
2896 const StringTypeTable& entry = string_type_table[i]; | 2909 const StringTypeTable& entry = string_type_table[i]; |
2897 { | 2910 { |
2898 AllocationResult allocation = AllocateMap(entry.type, entry.size); | 2911 AllocationResult allocation = AllocateMap(entry.type, entry.size); |
2899 if (!allocation.To(&obj)) return false; | 2912 if (!allocation.To(&obj)) return false; |
2900 } | 2913 } |
| 2914 Map* map = Map::cast(obj); |
| 2915 map->SetConstructorFunctionIndex(Context::STRING_FUNCTION_INDEX); |
2901 // Mark cons string maps as unstable, because their objects can change | 2916 // Mark cons string maps as unstable, because their objects can change |
2902 // maps during GC. | 2917 // maps during GC. |
2903 Map* map = Map::cast(obj); | |
2904 if (StringShape(entry.type).IsCons()) map->mark_unstable(); | 2918 if (StringShape(entry.type).IsCons()) map->mark_unstable(); |
2905 roots_[entry.index] = map; | 2919 roots_[entry.index] = map; |
2906 } | 2920 } |
2907 | 2921 |
2908 { // Create a separate external one byte string map for native sources. | 2922 { // Create a separate external one byte string map for native sources. |
2909 AllocationResult allocation = AllocateMap(EXTERNAL_ONE_BYTE_STRING_TYPE, | 2923 AllocationResult allocation = AllocateMap(EXTERNAL_ONE_BYTE_STRING_TYPE, |
2910 ExternalOneByteString::kSize); | 2924 ExternalOneByteString::kSize); |
2911 if (!allocation.To(&obj)) return false; | 2925 if (!allocation.To(&obj)) return false; |
2912 set_native_source_string_map(Map::cast(obj)); | 2926 Map* map = Map::cast(obj); |
| 2927 map->SetConstructorFunctionIndex(Context::STRING_FUNCTION_INDEX); |
| 2928 set_native_source_string_map(map); |
2913 } | 2929 } |
2914 | 2930 |
2915 ALLOCATE_VARSIZE_MAP(FIXED_DOUBLE_ARRAY_TYPE, fixed_double_array) | 2931 ALLOCATE_VARSIZE_MAP(FIXED_DOUBLE_ARRAY_TYPE, fixed_double_array) |
2916 ALLOCATE_VARSIZE_MAP(BYTE_ARRAY_TYPE, byte_array) | 2932 ALLOCATE_VARSIZE_MAP(BYTE_ARRAY_TYPE, byte_array) |
2917 ALLOCATE_VARSIZE_MAP(BYTECODE_ARRAY_TYPE, bytecode_array) | 2933 ALLOCATE_VARSIZE_MAP(BYTECODE_ARRAY_TYPE, bytecode_array) |
2918 ALLOCATE_VARSIZE_MAP(FREE_SPACE_TYPE, free_space) | 2934 ALLOCATE_VARSIZE_MAP(FREE_SPACE_TYPE, free_space) |
2919 | 2935 |
2920 #define ALLOCATE_FIXED_TYPED_ARRAY_MAP(Type, type, TYPE, ctype, size) \ | 2936 #define ALLOCATE_FIXED_TYPED_ARRAY_MAP(Type, type, TYPE, ctype, size) \ |
2921 ALLOCATE_VARSIZE_MAP(FIXED_##TYPE##_ARRAY_TYPE, fixed_##type##_array) | 2937 ALLOCATE_VARSIZE_MAP(FIXED_##TYPE##_ARRAY_TYPE, fixed_##type##_array) |
2922 | 2938 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2956 native_context_map()->set_dictionary_map(true); | 2972 native_context_map()->set_dictionary_map(true); |
2957 native_context_map()->set_visitor_id( | 2973 native_context_map()->set_visitor_id( |
2958 StaticVisitorBase::kVisitNativeContext); | 2974 StaticVisitorBase::kVisitNativeContext); |
2959 | 2975 |
2960 ALLOCATE_MAP(SHARED_FUNCTION_INFO_TYPE, SharedFunctionInfo::kAlignedSize, | 2976 ALLOCATE_MAP(SHARED_FUNCTION_INFO_TYPE, SharedFunctionInfo::kAlignedSize, |
2961 shared_function_info) | 2977 shared_function_info) |
2962 | 2978 |
2963 ALLOCATE_MAP(JS_MESSAGE_OBJECT_TYPE, JSMessageObject::kSize, message_object) | 2979 ALLOCATE_MAP(JS_MESSAGE_OBJECT_TYPE, JSMessageObject::kSize, message_object) |
2964 ALLOCATE_MAP(JS_OBJECT_TYPE, JSObject::kHeaderSize + kPointerSize, external) | 2980 ALLOCATE_MAP(JS_OBJECT_TYPE, JSObject::kHeaderSize + kPointerSize, external) |
2965 external_map()->set_is_extensible(false); | 2981 external_map()->set_is_extensible(false); |
| 2982 #undef ALLOCATE_PRIMITIVE_MAP |
2966 #undef ALLOCATE_VARSIZE_MAP | 2983 #undef ALLOCATE_VARSIZE_MAP |
2967 #undef ALLOCATE_MAP | 2984 #undef ALLOCATE_MAP |
2968 } | 2985 } |
2969 | 2986 |
2970 { // Empty arrays | 2987 { // Empty arrays |
2971 { | 2988 { |
2972 ByteArray* byte_array; | 2989 ByteArray* byte_array; |
2973 if (!AllocateByteArray(0, TENURED).To(&byte_array)) return false; | 2990 if (!AllocateByteArray(0, TENURED).To(&byte_array)) return false; |
2974 set_empty_byte_array(byte_array); | 2991 set_empty_byte_array(byte_array); |
2975 | 2992 |
(...skipping 3926 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6902 *object_type = "CODE_TYPE"; \ | 6919 *object_type = "CODE_TYPE"; \ |
6903 *object_sub_type = "CODE_AGE/" #name; \ | 6920 *object_sub_type = "CODE_AGE/" #name; \ |
6904 return true; | 6921 return true; |
6905 CODE_AGE_LIST_COMPLETE(COMPARE_AND_RETURN_NAME) | 6922 CODE_AGE_LIST_COMPLETE(COMPARE_AND_RETURN_NAME) |
6906 #undef COMPARE_AND_RETURN_NAME | 6923 #undef COMPARE_AND_RETURN_NAME |
6907 } | 6924 } |
6908 return false; | 6925 return false; |
6909 } | 6926 } |
6910 } // namespace internal | 6927 } // namespace internal |
6911 } // namespace v8 | 6928 } // namespace v8 |
OLD | NEW |