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

Side by Side Diff: src/heap.cc

Issue 227473002: Use distinct maps for oddballs with special handling in the type system. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Put kInternal last. Created 6 years, 8 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/ic.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 2739 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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, arguments_marker);
2873 ALLOCATE_MAP(ODDBALL_TYPE, Oddball::kSize, no_interceptor_result_sentinel);
2874 ALLOCATE_MAP(ODDBALL_TYPE, Oddball::kSize, termination_exception);
2875
2862 for (unsigned i = 0; i < ARRAY_SIZE(string_type_table); i++) { 2876 for (unsigned i = 0; i < ARRAY_SIZE(string_type_table); i++) {
2863 const StringTypeTable& entry = string_type_table[i]; 2877 const StringTypeTable& entry = string_type_table[i];
2864 { MaybeObject* maybe_obj = AllocateMap(entry.type, entry.size); 2878 { MaybeObject* maybe_obj = AllocateMap(entry.type, entry.size);
2865 if (!maybe_obj->ToObject(&obj)) return false; 2879 if (!maybe_obj->ToObject(&obj)) return false;
2866 } 2880 }
2867 roots_[entry.index] = Map::cast(obj); 2881 roots_[entry.index] = Map::cast(obj);
2868 } 2882 }
2869 2883
2870 ALLOCATE_VARSIZE_MAP(STRING_TYPE, undetectable_string) 2884 ALLOCATE_VARSIZE_MAP(STRING_TYPE, undetectable_string)
2871 undetectable_string_map()->set_is_undetectable(); 2885 undetectable_string_map()->set_is_undetectable();
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
3035 if (!maybe_result->To(&site)) return maybe_result; 3049 if (!maybe_result->To(&site)) return maybe_result;
3036 site->Initialize(); 3050 site->Initialize();
3037 3051
3038 // Link the site 3052 // Link the site
3039 site->set_weak_next(allocation_sites_list()); 3053 site->set_weak_next(allocation_sites_list());
3040 set_allocation_sites_list(site); 3054 set_allocation_sites_list(site);
3041 return site; 3055 return site;
3042 } 3056 }
3043 3057
3044 3058
3045 MaybeObject* Heap::CreateOddball(const char* to_string, 3059 MaybeObject* Heap::CreateOddball(Map* map,
3060 const char* to_string,
3046 Object* to_number, 3061 Object* to_number,
3047 byte kind) { 3062 byte kind) {
3048 Object* result; 3063 Object* result;
3049 { MaybeObject* maybe_result = Allocate(oddball_map(), OLD_POINTER_SPACE); 3064 { MaybeObject* maybe_result = Allocate(map, OLD_POINTER_SPACE);
3050 if (!maybe_result->ToObject(&result)) return maybe_result; 3065 if (!maybe_result->ToObject(&result)) return maybe_result;
3051 } 3066 }
3052 return Oddball::cast(result)->Initialize(this, to_string, to_number, kind); 3067 return Oddball::cast(result)->Initialize(this, to_string, to_number, kind);
3053 } 3068 }
3054 3069
3055 3070
3056 bool Heap::CreateApiObjects() { 3071 bool Heap::CreateApiObjects() {
3057 Object* obj; 3072 Object* obj;
3058 3073
3059 { MaybeObject* maybe_obj = AllocateMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); 3074 { MaybeObject* maybe_obj = AllocateMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
3164 Oddball::kUndefined); 3179 Oddball::kUndefined);
3165 if (!maybe_obj->ToObject(&obj)) return false; 3180 if (!maybe_obj->ToObject(&obj)) return false;
3166 } 3181 }
3167 3182
3168 // Initialize the null_value. 3183 // Initialize the null_value.
3169 { MaybeObject* maybe_obj = null_value()->Initialize( 3184 { MaybeObject* maybe_obj = null_value()->Initialize(
3170 this, "null", Smi::FromInt(0), Oddball::kNull); 3185 this, "null", Smi::FromInt(0), Oddball::kNull);
3171 if (!maybe_obj->ToObject(&obj)) return false; 3186 if (!maybe_obj->ToObject(&obj)) return false;
3172 } 3187 }
3173 3188
3174 { MaybeObject* maybe_obj = CreateOddball("true", 3189 { MaybeObject* maybe_obj = CreateOddball(boolean_map(),
3190 "true",
3175 Smi::FromInt(1), 3191 Smi::FromInt(1),
3176 Oddball::kTrue); 3192 Oddball::kTrue);
3177 if (!maybe_obj->ToObject(&obj)) return false; 3193 if (!maybe_obj->ToObject(&obj)) return false;
3178 } 3194 }
3179 set_true_value(Oddball::cast(obj)); 3195 set_true_value(Oddball::cast(obj));
3180 3196
3181 { MaybeObject* maybe_obj = CreateOddball("false", 3197 { MaybeObject* maybe_obj = CreateOddball(boolean_map(),
3198 "false",
3182 Smi::FromInt(0), 3199 Smi::FromInt(0),
3183 Oddball::kFalse); 3200 Oddball::kFalse);
3184 if (!maybe_obj->ToObject(&obj)) return false; 3201 if (!maybe_obj->ToObject(&obj)) return false;
3185 } 3202 }
3186 set_false_value(Oddball::cast(obj)); 3203 set_false_value(Oddball::cast(obj));
3187 3204
3188 { MaybeObject* maybe_obj = CreateOddball("hole", 3205 { MaybeObject* maybe_obj = CreateOddball(the_hole_map(),
3206 "hole",
3189 Smi::FromInt(-1), 3207 Smi::FromInt(-1),
3190 Oddball::kTheHole); 3208 Oddball::kTheHole);
3191 if (!maybe_obj->ToObject(&obj)) return false; 3209 if (!maybe_obj->ToObject(&obj)) return false;
3192 } 3210 }
3193 set_the_hole_value(Oddball::cast(obj)); 3211 set_the_hole_value(Oddball::cast(obj));
3194 3212
3195 { MaybeObject* maybe_obj = CreateOddball("uninitialized", 3213 { MaybeObject* maybe_obj = CreateOddball(uninitialized_map(),
3214 "uninitialized",
3196 Smi::FromInt(-1), 3215 Smi::FromInt(-1),
3197 Oddball::kUninitialized); 3216 Oddball::kUninitialized);
3198 if (!maybe_obj->ToObject(&obj)) return false; 3217 if (!maybe_obj->ToObject(&obj)) return false;
3199 } 3218 }
3200 set_uninitialized_value(Oddball::cast(obj)); 3219 set_uninitialized_value(Oddball::cast(obj));
3201 3220
3202 { MaybeObject* maybe_obj = CreateOddball("arguments_marker", 3221 { MaybeObject* maybe_obj = CreateOddball(arguments_marker_map(),
3222 "arguments_marker",
3203 Smi::FromInt(-4), 3223 Smi::FromInt(-4),
3204 Oddball::kArgumentMarker); 3224 Oddball::kArgumentMarker);
3205 if (!maybe_obj->ToObject(&obj)) return false; 3225 if (!maybe_obj->ToObject(&obj)) return false;
3206 } 3226 }
3207 set_arguments_marker(Oddball::cast(obj)); 3227 set_arguments_marker(Oddball::cast(obj));
3208 3228
3209 { MaybeObject* maybe_obj = CreateOddball("no_interceptor_result_sentinel", 3229 { MaybeObject* maybe_obj = CreateOddball(no_interceptor_result_sentinel_map(),
3230 "no_interceptor_result_sentinel",
3210 Smi::FromInt(-2), 3231 Smi::FromInt(-2),
3211 Oddball::kOther); 3232 Oddball::kOther);
3212 if (!maybe_obj->ToObject(&obj)) return false; 3233 if (!maybe_obj->ToObject(&obj)) return false;
3213 } 3234 }
3214 set_no_interceptor_result_sentinel(obj); 3235 set_no_interceptor_result_sentinel(Oddball::cast(obj));
3215 3236
3216 { MaybeObject* maybe_obj = CreateOddball("termination_exception", 3237 { MaybeObject* maybe_obj = CreateOddball(termination_exception_map(),
3238 "termination_exception",
3217 Smi::FromInt(-3), 3239 Smi::FromInt(-3),
3218 Oddball::kOther); 3240 Oddball::kOther);
3219 if (!maybe_obj->ToObject(&obj)) return false; 3241 if (!maybe_obj->ToObject(&obj)) return false;
3220 } 3242 }
3221 set_termination_exception(obj); 3243 set_termination_exception(Oddball::cast(obj));
3222 3244
3223 for (unsigned i = 0; i < ARRAY_SIZE(constant_string_table); i++) { 3245 for (unsigned i = 0; i < ARRAY_SIZE(constant_string_table); i++) {
3224 { MaybeObject* maybe_obj = 3246 { MaybeObject* maybe_obj =
3225 InternalizeUtf8String(constant_string_table[i].contents); 3247 InternalizeUtf8String(constant_string_table[i].contents);
3226 if (!maybe_obj->ToObject(&obj)) return false; 3248 if (!maybe_obj->ToObject(&obj)) return false;
3227 } 3249 }
3228 roots_[constant_string_table[i].index] = String::cast(obj); 3250 roots_[constant_string_table[i].index] = String::cast(obj);
3229 } 3251 }
3230 3252
3231 // Allocate the hidden string which is used to identify the hidden properties 3253 // Allocate the hidden string which is used to identify the hidden properties
(...skipping 4633 matching lines...) Expand 10 before | Expand all | Expand 10 after
7865 static_cast<int>(object_sizes_last_time_[index])); 7887 static_cast<int>(object_sizes_last_time_[index]));
7866 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) 7888 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT)
7867 #undef ADJUST_LAST_TIME_OBJECT_COUNT 7889 #undef ADJUST_LAST_TIME_OBJECT_COUNT
7868 7890
7869 OS::MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); 7891 OS::MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_));
7870 OS::MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); 7892 OS::MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_));
7871 ClearObjectStats(); 7893 ClearObjectStats();
7872 } 7894 }
7873 7895
7874 } } // namespace v8::internal 7896 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/heap.h ('k') | src/ic.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698