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 2739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2750 bool Heap::CreateInitialMaps() { | 2750 bool Heap::CreateInitialMaps() { |
2751 Object* obj; | 2751 Object* obj; |
2752 { MaybeObject* maybe_obj = AllocatePartialMap(MAP_TYPE, Map::kSize); | 2752 { MaybeObject* maybe_obj = AllocatePartialMap(MAP_TYPE, Map::kSize); |
2753 if (!maybe_obj->ToObject(&obj)) return false; | 2753 if (!maybe_obj->ToObject(&obj)) return false; |
2754 } | 2754 } |
2755 // Map::cast cannot be used due to uninitialized map field. | 2755 // Map::cast cannot be used due to uninitialized map field. |
2756 Map* new_meta_map = reinterpret_cast<Map*>(obj); | 2756 Map* new_meta_map = reinterpret_cast<Map*>(obj); |
2757 set_meta_map(new_meta_map); | 2757 set_meta_map(new_meta_map); |
2758 new_meta_map->set_map(new_meta_map); | 2758 new_meta_map->set_map(new_meta_map); |
2759 | 2759 |
2760 { MaybeObject* maybe_obj = | 2760 { // Partial map allocation |
2761 AllocatePartialMap(FIXED_ARRAY_TYPE, kVariableSizeSentinel); | 2761 #define ALLOCATE_PARTIAL_MAP(instance_type, size, field_name) \ |
2762 if (!maybe_obj->ToObject(&obj)) return false; | 2762 { Map* map; \ |
| 2763 if (!AllocatePartialMap((instance_type), (size))->To(&map)) return false;\ |
| 2764 set_##field_name##_map(map); \ |
| 2765 } |
| 2766 |
| 2767 ALLOCATE_PARTIAL_MAP(FIXED_ARRAY_TYPE, kVariableSizeSentinel, fixed_array); |
| 2768 ALLOCATE_PARTIAL_MAP(ODDBALL_TYPE, Oddball::kSize, undefined); |
| 2769 ALLOCATE_PARTIAL_MAP(ODDBALL_TYPE, Oddball::kSize, null); |
| 2770 ALLOCATE_PARTIAL_MAP(CONSTANT_POOL_ARRAY_TYPE, kVariableSizeSentinel, |
| 2771 constant_pool_array); |
| 2772 |
| 2773 #undef ALLOCATE_PARTIAL_MAP |
2763 } | 2774 } |
2764 set_fixed_array_map(Map::cast(obj)); | |
2765 | |
2766 { MaybeObject* maybe_obj = AllocatePartialMap(ODDBALL_TYPE, Oddball::kSize); | |
2767 if (!maybe_obj->ToObject(&obj)) return false; | |
2768 } | |
2769 set_oddball_map(Map::cast(obj)); | |
2770 | |
2771 { MaybeObject* maybe_obj = | |
2772 AllocatePartialMap(CONSTANT_POOL_ARRAY_TYPE, kVariableSizeSentinel); | |
2773 if (!maybe_obj->ToObject(&obj)) return false; | |
2774 } | |
2775 set_constant_pool_array_map(Map::cast(obj)); | |
2776 | 2775 |
2777 // Allocate the empty array. | 2776 // Allocate the empty array. |
2778 { MaybeObject* maybe_obj = AllocateEmptyFixedArray(); | 2777 { MaybeObject* maybe_obj = AllocateEmptyFixedArray(); |
2779 if (!maybe_obj->ToObject(&obj)) return false; | 2778 if (!maybe_obj->ToObject(&obj)) return false; |
2780 } | 2779 } |
2781 set_empty_fixed_array(FixedArray::cast(obj)); | 2780 set_empty_fixed_array(FixedArray::cast(obj)); |
2782 | 2781 |
2783 { MaybeObject* maybe_obj = Allocate(oddball_map(), OLD_POINTER_SPACE); | 2782 { MaybeObject* maybe_obj = Allocate(null_map(), OLD_POINTER_SPACE); |
2784 if (!maybe_obj->ToObject(&obj)) return false; | 2783 if (!maybe_obj->ToObject(&obj)) return false; |
2785 } | 2784 } |
2786 set_null_value(Oddball::cast(obj)); | 2785 set_null_value(Oddball::cast(obj)); |
2787 Oddball::cast(obj)->set_kind(Oddball::kNull); | 2786 Oddball::cast(obj)->set_kind(Oddball::kNull); |
2788 | 2787 |
2789 { MaybeObject* maybe_obj = Allocate(oddball_map(), OLD_POINTER_SPACE); | 2788 { MaybeObject* maybe_obj = Allocate(undefined_map(), OLD_POINTER_SPACE); |
2790 if (!maybe_obj->ToObject(&obj)) return false; | 2789 if (!maybe_obj->ToObject(&obj)) return false; |
2791 } | 2790 } |
2792 set_undefined_value(Oddball::cast(obj)); | 2791 set_undefined_value(Oddball::cast(obj)); |
2793 Oddball::cast(obj)->set_kind(Oddball::kUndefined); | 2792 Oddball::cast(obj)->set_kind(Oddball::kUndefined); |
2794 ASSERT(!InNewSpace(undefined_value())); | 2793 ASSERT(!InNewSpace(undefined_value())); |
2795 | 2794 |
2796 // Allocate the empty descriptor array. | 2795 // Allocate the empty descriptor array. |
2797 { MaybeObject* maybe_obj = AllocateEmptyFixedArray(); | 2796 { MaybeObject* maybe_obj = AllocateEmptyFixedArray(); |
2798 if (!maybe_obj->ToObject(&obj)) return false; | 2797 if (!maybe_obj->ToObject(&obj)) return false; |
2799 } | 2798 } |
(...skipping 10 matching lines...) Expand all Loading... |
2810 meta_map()->set_dependent_code(DependentCode::cast(empty_fixed_array())); | 2809 meta_map()->set_dependent_code(DependentCode::cast(empty_fixed_array())); |
2811 meta_map()->init_back_pointer(undefined_value()); | 2810 meta_map()->init_back_pointer(undefined_value()); |
2812 meta_map()->set_instance_descriptors(empty_descriptor_array()); | 2811 meta_map()->set_instance_descriptors(empty_descriptor_array()); |
2813 | 2812 |
2814 fixed_array_map()->set_code_cache(empty_fixed_array()); | 2813 fixed_array_map()->set_code_cache(empty_fixed_array()); |
2815 fixed_array_map()->set_dependent_code( | 2814 fixed_array_map()->set_dependent_code( |
2816 DependentCode::cast(empty_fixed_array())); | 2815 DependentCode::cast(empty_fixed_array())); |
2817 fixed_array_map()->init_back_pointer(undefined_value()); | 2816 fixed_array_map()->init_back_pointer(undefined_value()); |
2818 fixed_array_map()->set_instance_descriptors(empty_descriptor_array()); | 2817 fixed_array_map()->set_instance_descriptors(empty_descriptor_array()); |
2819 | 2818 |
2820 oddball_map()->set_code_cache(empty_fixed_array()); | 2819 undefined_map()->set_code_cache(empty_fixed_array()); |
2821 oddball_map()->set_dependent_code(DependentCode::cast(empty_fixed_array())); | 2820 undefined_map()->set_dependent_code(DependentCode::cast(empty_fixed_array())); |
2822 oddball_map()->init_back_pointer(undefined_value()); | 2821 undefined_map()->init_back_pointer(undefined_value()); |
2823 oddball_map()->set_instance_descriptors(empty_descriptor_array()); | 2822 undefined_map()->set_instance_descriptors(empty_descriptor_array()); |
| 2823 |
| 2824 null_map()->set_code_cache(empty_fixed_array()); |
| 2825 null_map()->set_dependent_code(DependentCode::cast(empty_fixed_array())); |
| 2826 null_map()->init_back_pointer(undefined_value()); |
| 2827 null_map()->set_instance_descriptors(empty_descriptor_array()); |
2824 | 2828 |
2825 constant_pool_array_map()->set_code_cache(empty_fixed_array()); | 2829 constant_pool_array_map()->set_code_cache(empty_fixed_array()); |
2826 constant_pool_array_map()->set_dependent_code( | 2830 constant_pool_array_map()->set_dependent_code( |
2827 DependentCode::cast(empty_fixed_array())); | 2831 DependentCode::cast(empty_fixed_array())); |
2828 constant_pool_array_map()->init_back_pointer(undefined_value()); | 2832 constant_pool_array_map()->init_back_pointer(undefined_value()); |
2829 constant_pool_array_map()->set_instance_descriptors(empty_descriptor_array()); | 2833 constant_pool_array_map()->set_instance_descriptors(empty_descriptor_array()); |
2830 | 2834 |
2831 // Fix prototype object for existing maps. | 2835 // Fix prototype object for existing maps. |
2832 meta_map()->set_prototype(null_value()); | 2836 meta_map()->set_prototype(null_value()); |
2833 meta_map()->set_constructor(null_value()); | 2837 meta_map()->set_constructor(null_value()); |
2834 | 2838 |
2835 fixed_array_map()->set_prototype(null_value()); | 2839 fixed_array_map()->set_prototype(null_value()); |
2836 fixed_array_map()->set_constructor(null_value()); | 2840 fixed_array_map()->set_constructor(null_value()); |
2837 | 2841 |
2838 oddball_map()->set_prototype(null_value()); | 2842 undefined_map()->set_prototype(null_value()); |
2839 oddball_map()->set_constructor(null_value()); | 2843 undefined_map()->set_constructor(null_value()); |
| 2844 |
| 2845 null_map()->set_prototype(null_value()); |
| 2846 null_map()->set_constructor(null_value()); |
2840 | 2847 |
2841 constant_pool_array_map()->set_prototype(null_value()); | 2848 constant_pool_array_map()->set_prototype(null_value()); |
2842 constant_pool_array_map()->set_constructor(null_value()); | 2849 constant_pool_array_map()->set_constructor(null_value()); |
2843 | 2850 |
2844 { // Map allocation | 2851 { // Map allocation |
2845 #define ALLOCATE_MAP(instance_type, size, field_name) \ | 2852 #define ALLOCATE_MAP(instance_type, size, field_name) \ |
2846 { Map* map; \ | 2853 { Map* map; \ |
2847 if (!AllocateMap((instance_type), size)->To(&map)) return false; \ | 2854 if (!AllocateMap((instance_type), size)->To(&map)) return false; \ |
2848 set_##field_name##_map(map); \ | 2855 set_##field_name##_map(map); \ |
2849 } | 2856 } |
2850 | 2857 |
2851 #define ALLOCATE_VARSIZE_MAP(instance_type, field_name) \ | 2858 #define ALLOCATE_VARSIZE_MAP(instance_type, field_name) \ |
2852 ALLOCATE_MAP(instance_type, kVariableSizeSentinel, field_name) | 2859 ALLOCATE_MAP(instance_type, kVariableSizeSentinel, field_name) |
2853 | 2860 |
2854 ALLOCATE_VARSIZE_MAP(FIXED_ARRAY_TYPE, fixed_cow_array) | 2861 ALLOCATE_VARSIZE_MAP(FIXED_ARRAY_TYPE, fixed_cow_array) |
2855 ASSERT(fixed_array_map() != fixed_cow_array_map()); | 2862 ASSERT(fixed_array_map() != fixed_cow_array_map()); |
2856 | 2863 |
2857 ALLOCATE_VARSIZE_MAP(FIXED_ARRAY_TYPE, scope_info) | 2864 ALLOCATE_VARSIZE_MAP(FIXED_ARRAY_TYPE, scope_info) |
2858 ALLOCATE_MAP(HEAP_NUMBER_TYPE, HeapNumber::kSize, heap_number) | 2865 ALLOCATE_MAP(HEAP_NUMBER_TYPE, HeapNumber::kSize, heap_number) |
2859 ALLOCATE_MAP(SYMBOL_TYPE, Symbol::kSize, symbol) | 2866 ALLOCATE_MAP(SYMBOL_TYPE, Symbol::kSize, symbol) |
2860 ALLOCATE_MAP(FOREIGN_TYPE, Foreign::kSize, foreign) | 2867 ALLOCATE_MAP(FOREIGN_TYPE, Foreign::kSize, foreign) |
2861 | 2868 |
| 2869 ALLOCATE_MAP(ODDBALL_TYPE, Oddball::kSize, the_hole); |
| 2870 ALLOCATE_MAP(ODDBALL_TYPE, Oddball::kSize, boolean); |
| 2871 ALLOCATE_MAP(ODDBALL_TYPE, Oddball::kSize, uninitialized); |
| 2872 ALLOCATE_MAP(ODDBALL_TYPE, Oddball::kSize, oddball); |
| 2873 |
2862 for (unsigned i = 0; i < ARRAY_SIZE(string_type_table); i++) { | 2874 for (unsigned i = 0; i < ARRAY_SIZE(string_type_table); i++) { |
2863 const StringTypeTable& entry = string_type_table[i]; | 2875 const StringTypeTable& entry = string_type_table[i]; |
2864 { MaybeObject* maybe_obj = AllocateMap(entry.type, entry.size); | 2876 { MaybeObject* maybe_obj = AllocateMap(entry.type, entry.size); |
2865 if (!maybe_obj->ToObject(&obj)) return false; | 2877 if (!maybe_obj->ToObject(&obj)) return false; |
2866 } | 2878 } |
2867 roots_[entry.index] = Map::cast(obj); | 2879 roots_[entry.index] = Map::cast(obj); |
2868 } | 2880 } |
2869 | 2881 |
2870 ALLOCATE_VARSIZE_MAP(STRING_TYPE, undetectable_string) | 2882 ALLOCATE_VARSIZE_MAP(STRING_TYPE, undetectable_string) |
2871 undetectable_string_map()->set_is_undetectable(); | 2883 undetectable_string_map()->set_is_undetectable(); |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3035 if (!maybe_result->To(&site)) return maybe_result; | 3047 if (!maybe_result->To(&site)) return maybe_result; |
3036 site->Initialize(); | 3048 site->Initialize(); |
3037 | 3049 |
3038 // Link the site | 3050 // Link the site |
3039 site->set_weak_next(allocation_sites_list()); | 3051 site->set_weak_next(allocation_sites_list()); |
3040 set_allocation_sites_list(site); | 3052 set_allocation_sites_list(site); |
3041 return site; | 3053 return site; |
3042 } | 3054 } |
3043 | 3055 |
3044 | 3056 |
3045 MaybeObject* Heap::CreateOddball(const char* to_string, | 3057 MaybeObject* Heap::CreateOddball(Map* map, |
| 3058 const char* to_string, |
3046 Object* to_number, | 3059 Object* to_number, |
3047 byte kind) { | 3060 byte kind) { |
3048 Object* result; | 3061 Object* result; |
3049 { MaybeObject* maybe_result = Allocate(oddball_map(), OLD_POINTER_SPACE); | 3062 { MaybeObject* maybe_result = Allocate(map, OLD_POINTER_SPACE); |
3050 if (!maybe_result->ToObject(&result)) return maybe_result; | 3063 if (!maybe_result->ToObject(&result)) return maybe_result; |
3051 } | 3064 } |
3052 return Oddball::cast(result)->Initialize(this, to_string, to_number, kind); | 3065 return Oddball::cast(result)->Initialize(this, to_string, to_number, kind); |
3053 } | 3066 } |
3054 | 3067 |
3055 | 3068 |
3056 bool Heap::CreateApiObjects() { | 3069 bool Heap::CreateApiObjects() { |
3057 Object* obj; | 3070 Object* obj; |
3058 | 3071 |
3059 { MaybeObject* maybe_obj = AllocateMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); | 3072 { MaybeObject* maybe_obj = AllocateMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3164 Oddball::kUndefined); | 3177 Oddball::kUndefined); |
3165 if (!maybe_obj->ToObject(&obj)) return false; | 3178 if (!maybe_obj->ToObject(&obj)) return false; |
3166 } | 3179 } |
3167 | 3180 |
3168 // Initialize the null_value. | 3181 // Initialize the null_value. |
3169 { MaybeObject* maybe_obj = null_value()->Initialize( | 3182 { MaybeObject* maybe_obj = null_value()->Initialize( |
3170 this, "null", Smi::FromInt(0), Oddball::kNull); | 3183 this, "null", Smi::FromInt(0), Oddball::kNull); |
3171 if (!maybe_obj->ToObject(&obj)) return false; | 3184 if (!maybe_obj->ToObject(&obj)) return false; |
3172 } | 3185 } |
3173 | 3186 |
3174 { MaybeObject* maybe_obj = CreateOddball("true", | 3187 { MaybeObject* maybe_obj = CreateOddball(boolean_map(), |
| 3188 "true", |
3175 Smi::FromInt(1), | 3189 Smi::FromInt(1), |
3176 Oddball::kTrue); | 3190 Oddball::kTrue); |
3177 if (!maybe_obj->ToObject(&obj)) return false; | 3191 if (!maybe_obj->ToObject(&obj)) return false; |
3178 } | 3192 } |
3179 set_true_value(Oddball::cast(obj)); | 3193 set_true_value(Oddball::cast(obj)); |
3180 | 3194 |
3181 { MaybeObject* maybe_obj = CreateOddball("false", | 3195 { MaybeObject* maybe_obj = CreateOddball(boolean_map(), |
| 3196 "false", |
3182 Smi::FromInt(0), | 3197 Smi::FromInt(0), |
3183 Oddball::kFalse); | 3198 Oddball::kFalse); |
3184 if (!maybe_obj->ToObject(&obj)) return false; | 3199 if (!maybe_obj->ToObject(&obj)) return false; |
3185 } | 3200 } |
3186 set_false_value(Oddball::cast(obj)); | 3201 set_false_value(Oddball::cast(obj)); |
3187 | 3202 |
3188 { MaybeObject* maybe_obj = CreateOddball("hole", | 3203 { MaybeObject* maybe_obj = CreateOddball(the_hole_map(), |
| 3204 "hole", |
3189 Smi::FromInt(-1), | 3205 Smi::FromInt(-1), |
3190 Oddball::kTheHole); | 3206 Oddball::kTheHole); |
3191 if (!maybe_obj->ToObject(&obj)) return false; | 3207 if (!maybe_obj->ToObject(&obj)) return false; |
3192 } | 3208 } |
3193 set_the_hole_value(Oddball::cast(obj)); | 3209 set_the_hole_value(Oddball::cast(obj)); |
3194 | 3210 |
3195 { MaybeObject* maybe_obj = CreateOddball("uninitialized", | 3211 { MaybeObject* maybe_obj = CreateOddball(uninitialized_map(), |
| 3212 "uninitialized", |
3196 Smi::FromInt(-1), | 3213 Smi::FromInt(-1), |
3197 Oddball::kUninitialized); | 3214 Oddball::kUninitialized); |
3198 if (!maybe_obj->ToObject(&obj)) return false; | 3215 if (!maybe_obj->ToObject(&obj)) return false; |
3199 } | 3216 } |
3200 set_uninitialized_value(Oddball::cast(obj)); | 3217 set_uninitialized_value(Oddball::cast(obj)); |
3201 | 3218 |
3202 { MaybeObject* maybe_obj = CreateOddball("arguments_marker", | 3219 { MaybeObject* maybe_obj = CreateOddball(oddball_map(), |
| 3220 "arguments_marker", |
3203 Smi::FromInt(-4), | 3221 Smi::FromInt(-4), |
3204 Oddball::kArgumentMarker); | 3222 Oddball::kArgumentMarker); |
3205 if (!maybe_obj->ToObject(&obj)) return false; | 3223 if (!maybe_obj->ToObject(&obj)) return false; |
3206 } | 3224 } |
3207 set_arguments_marker(Oddball::cast(obj)); | 3225 set_arguments_marker(Oddball::cast(obj)); |
3208 | 3226 |
3209 { MaybeObject* maybe_obj = CreateOddball("no_interceptor_result_sentinel", | 3227 { MaybeObject* maybe_obj = CreateOddball(oddball_map(), |
| 3228 "no_interceptor_result_sentinel", |
3210 Smi::FromInt(-2), | 3229 Smi::FromInt(-2), |
3211 Oddball::kOther); | 3230 Oddball::kOther); |
3212 if (!maybe_obj->ToObject(&obj)) return false; | 3231 if (!maybe_obj->ToObject(&obj)) return false; |
3213 } | 3232 } |
3214 set_no_interceptor_result_sentinel(obj); | 3233 set_no_interceptor_result_sentinel(Oddball::cast(obj)); |
3215 | 3234 |
3216 { MaybeObject* maybe_obj = CreateOddball("termination_exception", | 3235 { MaybeObject* maybe_obj = CreateOddball(oddball_map(), |
| 3236 "termination_exception", |
3217 Smi::FromInt(-3), | 3237 Smi::FromInt(-3), |
3218 Oddball::kOther); | 3238 Oddball::kOther); |
3219 if (!maybe_obj->ToObject(&obj)) return false; | 3239 if (!maybe_obj->ToObject(&obj)) return false; |
3220 } | 3240 } |
3221 set_termination_exception(obj); | 3241 set_termination_exception(Oddball::cast(obj)); |
3222 | 3242 |
3223 for (unsigned i = 0; i < ARRAY_SIZE(constant_string_table); i++) { | 3243 for (unsigned i = 0; i < ARRAY_SIZE(constant_string_table); i++) { |
3224 { MaybeObject* maybe_obj = | 3244 { MaybeObject* maybe_obj = |
3225 InternalizeUtf8String(constant_string_table[i].contents); | 3245 InternalizeUtf8String(constant_string_table[i].contents); |
3226 if (!maybe_obj->ToObject(&obj)) return false; | 3246 if (!maybe_obj->ToObject(&obj)) return false; |
3227 } | 3247 } |
3228 roots_[constant_string_table[i].index] = String::cast(obj); | 3248 roots_[constant_string_table[i].index] = String::cast(obj); |
3229 } | 3249 } |
3230 | 3250 |
3231 // Allocate the hidden string which is used to identify the hidden properties | 3251 // Allocate the hidden string which is used to identify the hidden properties |
(...skipping 4633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7865 static_cast<int>(object_sizes_last_time_[index])); | 7885 static_cast<int>(object_sizes_last_time_[index])); |
7866 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) | 7886 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) |
7867 #undef ADJUST_LAST_TIME_OBJECT_COUNT | 7887 #undef ADJUST_LAST_TIME_OBJECT_COUNT |
7868 | 7888 |
7869 OS::MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); | 7889 OS::MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); |
7870 OS::MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); | 7890 OS::MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); |
7871 ClearObjectStats(); | 7891 ClearObjectStats(); |
7872 } | 7892 } |
7873 | 7893 |
7874 } } // namespace v8::internal | 7894 } } // namespace v8::internal |
OLD | NEW |