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

Side by Side Diff: src/heap.cc

Issue 211333002: Replace HeapNumber as doublebox with an explicit MutableHeapNumber. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: 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/heap-inl.h » ('j') | src/json-parser.h » ('J')
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 2838 matching lines...) Expand 10 before | Expand all | Expand 10 after
2849 } 2849 }
2850 2850
2851 #define ALLOCATE_VARSIZE_MAP(instance_type, field_name) \ 2851 #define ALLOCATE_VARSIZE_MAP(instance_type, field_name) \
2852 ALLOCATE_MAP(instance_type, kVariableSizeSentinel, field_name) 2852 ALLOCATE_MAP(instance_type, kVariableSizeSentinel, field_name)
2853 2853
2854 ALLOCATE_VARSIZE_MAP(FIXED_ARRAY_TYPE, fixed_cow_array) 2854 ALLOCATE_VARSIZE_MAP(FIXED_ARRAY_TYPE, fixed_cow_array)
2855 ASSERT(fixed_array_map() != fixed_cow_array_map()); 2855 ASSERT(fixed_array_map() != fixed_cow_array_map());
2856 2856
2857 ALLOCATE_VARSIZE_MAP(FIXED_ARRAY_TYPE, scope_info) 2857 ALLOCATE_VARSIZE_MAP(FIXED_ARRAY_TYPE, scope_info)
2858 ALLOCATE_MAP(HEAP_NUMBER_TYPE, HeapNumber::kSize, heap_number) 2858 ALLOCATE_MAP(HEAP_NUMBER_TYPE, HeapNumber::kSize, heap_number)
2859 ALLOCATE_MAP(
2860 MUTABLE_HEAP_NUMBER_TYPE, HeapNumber::kSize, mutable_heap_number)
2859 ALLOCATE_MAP(SYMBOL_TYPE, Symbol::kSize, symbol) 2861 ALLOCATE_MAP(SYMBOL_TYPE, Symbol::kSize, symbol)
2860 ALLOCATE_MAP(FOREIGN_TYPE, Foreign::kSize, foreign) 2862 ALLOCATE_MAP(FOREIGN_TYPE, Foreign::kSize, foreign)
2861 2863
2862 for (unsigned i = 0; i < ARRAY_SIZE(string_type_table); i++) { 2864 for (unsigned i = 0; i < ARRAY_SIZE(string_type_table); i++) {
2863 const StringTypeTable& entry = string_type_table[i]; 2865 const StringTypeTable& entry = string_type_table[i];
2864 { MaybeObject* maybe_obj = AllocateMap(entry.type, entry.size); 2866 { MaybeObject* maybe_obj = AllocateMap(entry.type, entry.size);
2865 if (!maybe_obj->ToObject(&obj)) return false; 2867 if (!maybe_obj->ToObject(&obj)) return false;
2866 } 2868 }
2867 roots_[entry.index] = Map::cast(obj); 2869 roots_[entry.index] = Map::cast(obj);
2868 } 2870 }
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
2959 } 2961 }
2960 2962
2961 TYPED_ARRAYS(ALLOCATE_EMPTY_FIXED_TYPED_ARRAY) 2963 TYPED_ARRAYS(ALLOCATE_EMPTY_FIXED_TYPED_ARRAY)
2962 #undef ALLOCATE_EMPTY_FIXED_TYPED_ARRAY 2964 #undef ALLOCATE_EMPTY_FIXED_TYPED_ARRAY
2963 } 2965 }
2964 ASSERT(!InNewSpace(empty_fixed_array())); 2966 ASSERT(!InNewSpace(empty_fixed_array()));
2965 return true; 2967 return true;
2966 } 2968 }
2967 2969
2968 2970
2969 MaybeObject* Heap::AllocateHeapNumber(double value, PretenureFlag pretenure) { 2971 MaybeObject* Heap::AllocateHeapNumber(double value,
2972 MutableMode mode,
2973 PretenureFlag pretenure) {
2970 // Statically ensure that it is safe to allocate heap numbers in paged 2974 // Statically ensure that it is safe to allocate heap numbers in paged
2971 // spaces. 2975 // spaces.
2972 int size = HeapNumber::kSize; 2976 int size = HeapNumber::kSize;
2973 STATIC_ASSERT(HeapNumber::kSize <= Page::kMaxRegularHeapObjectSize); 2977 STATIC_ASSERT(HeapNumber::kSize <= Page::kMaxRegularHeapObjectSize);
2974 2978
2975 AllocationSpace space = SelectSpace(size, OLD_DATA_SPACE, pretenure); 2979 AllocationSpace space = SelectSpace(size, OLD_DATA_SPACE, pretenure);
2976 2980
2977 Object* result; 2981 Object* result;
2978 { MaybeObject* maybe_result = AllocateRaw(size, space, OLD_DATA_SPACE); 2982 { MaybeObject* maybe_result = AllocateRaw(size, space, OLD_DATA_SPACE);
2979 if (!maybe_result->ToObject(&result)) return maybe_result; 2983 if (!maybe_result->ToObject(&result)) return maybe_result;
2980 } 2984 }
2981 2985
2982 HeapObject::cast(result)->set_map_no_write_barrier(heap_number_map()); 2986 Map* map = mode == MUTABLE ? mutable_heap_number_map() : heap_number_map();
2987 HeapObject::cast(result)->set_map_no_write_barrier(map);
2983 HeapNumber::cast(result)->set_value(value); 2988 HeapNumber::cast(result)->set_value(value);
2984 return result; 2989 return result;
2985 } 2990 }
2986 2991
2987 2992
2988 MaybeObject* Heap::AllocateCell(Object* value) { 2993 MaybeObject* Heap::AllocateCell(Object* value) {
2989 int size = Cell::kSize; 2994 int size = Cell::kSize;
2990 STATIC_ASSERT(Cell::kSize <= Page::kMaxRegularHeapObjectSize); 2995 STATIC_ASSERT(Cell::kSize <= Page::kMaxRegularHeapObjectSize);
2991 2996
2992 Object* result; 2997 Object* result;
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
3121 // To workaround the problem, make separate functions without inlining. 3126 // To workaround the problem, make separate functions without inlining.
3122 Heap::CreateJSEntryStub(); 3127 Heap::CreateJSEntryStub();
3123 Heap::CreateJSConstructEntryStub(); 3128 Heap::CreateJSConstructEntryStub();
3124 } 3129 }
3125 3130
3126 3131
3127 bool Heap::CreateInitialObjects() { 3132 bool Heap::CreateInitialObjects() {
3128 Object* obj; 3133 Object* obj;
3129 3134
3130 // The -0 value must be set before NumberFromDouble works. 3135 // The -0 value must be set before NumberFromDouble works.
3131 { MaybeObject* maybe_obj = AllocateHeapNumber(-0.0, TENURED); 3136 { MaybeObject* maybe_obj = AllocateHeapNumber(-0.0, IMMUTABLE, TENURED);
3132 if (!maybe_obj->ToObject(&obj)) return false; 3137 if (!maybe_obj->ToObject(&obj)) return false;
3133 } 3138 }
3134 set_minus_zero_value(HeapNumber::cast(obj)); 3139 set_minus_zero_value(HeapNumber::cast(obj));
3135 ASSERT(std::signbit(minus_zero_value()->Number()) != 0); 3140 ASSERT(std::signbit(minus_zero_value()->Number()) != 0);
3136 3141
3137 { MaybeObject* maybe_obj = AllocateHeapNumber(OS::nan_value(), TENURED); 3142 { MaybeObject* maybe_obj = AllocateHeapNumber(
3143 OS::nan_value(), IMMUTABLE, TENURED);
3138 if (!maybe_obj->ToObject(&obj)) return false; 3144 if (!maybe_obj->ToObject(&obj)) return false;
3139 } 3145 }
3140 set_nan_value(HeapNumber::cast(obj)); 3146 set_nan_value(HeapNumber::cast(obj));
3141 3147
3142 { MaybeObject* maybe_obj = AllocateHeapNumber(V8_INFINITY, TENURED); 3148 { MaybeObject* maybe_obj = AllocateHeapNumber(
3149 V8_INFINITY, IMMUTABLE, TENURED);
3143 if (!maybe_obj->ToObject(&obj)) return false; 3150 if (!maybe_obj->ToObject(&obj)) return false;
3144 } 3151 }
3145 set_infinity_value(HeapNumber::cast(obj)); 3152 set_infinity_value(HeapNumber::cast(obj));
3146 3153
3147 // The hole has not been created yet, but we want to put something 3154 // The hole has not been created yet, but we want to put something
3148 // predictable in the gaps in the string table, so lets make that Smi zero. 3155 // predictable in the gaps in the string table, so lets make that Smi zero.
3149 set_the_hole_value(reinterpret_cast<Oddball*>(Smi::FromInt(0))); 3156 set_the_hole_value(reinterpret_cast<Oddball*>(Smi::FromInt(0)));
3150 3157
3151 // Allocate initial string table. 3158 // Allocate initial string table.
3152 { MaybeObject* maybe_obj = 3159 { MaybeObject* maybe_obj =
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after
3814 return FixedTypedArrayBase::cast( 3821 return FixedTypedArrayBase::cast(
3815 roots_[RootIndexForEmptyFixedTypedArray(map->elements_kind())]); 3822 roots_[RootIndexForEmptyFixedTypedArray(map->elements_kind())]);
3816 } 3823 }
3817 3824
3818 3825
3819 MaybeObject* Heap::NumberFromDouble(double value, PretenureFlag pretenure) { 3826 MaybeObject* Heap::NumberFromDouble(double value, PretenureFlag pretenure) {
3820 // We need to distinguish the minus zero value and this cannot be 3827 // We need to distinguish the minus zero value and this cannot be
3821 // done after conversion to int. Doing this by comparing bit 3828 // done after conversion to int. Doing this by comparing bit
3822 // patterns is faster than using fpclassify() et al. 3829 // patterns is faster than using fpclassify() et al.
3823 if (IsMinusZero(value)) { 3830 if (IsMinusZero(value)) {
3824 return AllocateHeapNumber(-0.0, pretenure); 3831 return AllocateHeapNumber(-0.0, IMMUTABLE, pretenure);
3825 } 3832 }
3826 3833
3827 int int_value = FastD2I(value); 3834 int int_value = FastD2I(value);
3828 if (value == int_value && Smi::IsValid(int_value)) { 3835 if (value == int_value && Smi::IsValid(int_value)) {
3829 return Smi::FromInt(int_value); 3836 return Smi::FromInt(int_value);
3830 } 3837 }
3831 3838
3832 // Materialize the value in the heap. 3839 // Materialize the value in the heap.
3833 return AllocateHeapNumber(value, pretenure); 3840 return AllocateHeapNumber(value, IMMUTABLE, pretenure);
3834 } 3841 }
3835 3842
3836 3843
3837 MaybeObject* Heap::AllocateForeign(Address address, PretenureFlag pretenure) { 3844 MaybeObject* Heap::AllocateForeign(Address address, PretenureFlag pretenure) {
3838 // Statically ensure that it is safe to allocate foreigns in paged spaces. 3845 // Statically ensure that it is safe to allocate foreigns in paged spaces.
3839 STATIC_ASSERT(Foreign::kSize <= Page::kMaxRegularHeapObjectSize); 3846 STATIC_ASSERT(Foreign::kSize <= Page::kMaxRegularHeapObjectSize);
3840 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE; 3847 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE;
3841 Foreign* result; 3848 Foreign* result;
3842 MaybeObject* maybe_result = Allocate(foreign_map(), space); 3849 MaybeObject* maybe_result = Allocate(foreign_map(), space);
3843 if (!maybe_result->To(&result)) return maybe_result; 3850 if (!maybe_result->To(&result)) return maybe_result;
(...skipping 4023 matching lines...) Expand 10 before | Expand all | Expand 10 after
7867 static_cast<int>(object_sizes_last_time_[index])); 7874 static_cast<int>(object_sizes_last_time_[index]));
7868 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) 7875 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT)
7869 #undef ADJUST_LAST_TIME_OBJECT_COUNT 7876 #undef ADJUST_LAST_TIME_OBJECT_COUNT
7870 7877
7871 OS::MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); 7878 OS::MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_));
7872 OS::MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); 7879 OS::MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_));
7873 ClearObjectStats(); 7880 ClearObjectStats();
7874 } 7881 }
7875 7882
7876 } } // namespace v8::internal 7883 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/heap.h ('k') | src/heap-inl.h » ('j') | src/json-parser.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698