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

Side by Side Diff: src/heap/heap.cc

Issue 1368103002: Revert of [heap] Move large object space selection into AllocateRaw. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 2 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
« no previous file with comments | « src/heap/heap.h ('k') | src/heap/heap-inl.h » ('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 // 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/heap/heap.h" 5 #include "src/heap/heap.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 2346 matching lines...) Expand 10 before | Expand all | Expand 10 after
2357 } 2357 }
2358 2358
2359 2359
2360 AllocationResult Heap::AllocateHeapNumber(double value, MutableMode mode, 2360 AllocationResult Heap::AllocateHeapNumber(double value, MutableMode mode,
2361 PretenureFlag pretenure) { 2361 PretenureFlag pretenure) {
2362 // Statically ensure that it is safe to allocate heap numbers in paged 2362 // Statically ensure that it is safe to allocate heap numbers in paged
2363 // spaces. 2363 // spaces.
2364 int size = HeapNumber::kSize; 2364 int size = HeapNumber::kSize;
2365 STATIC_ASSERT(HeapNumber::kSize <= Page::kMaxRegularHeapObjectSize); 2365 STATIC_ASSERT(HeapNumber::kSize <= Page::kMaxRegularHeapObjectSize);
2366 2366
2367 AllocationSpace space = SelectSpace(pretenure); 2367 AllocationSpace space = SelectSpace(size, pretenure);
2368 2368
2369 HeapObject* result = nullptr; 2369 HeapObject* result = nullptr;
2370 { 2370 {
2371 AllocationResult allocation = 2371 AllocationResult allocation =
2372 AllocateRaw(size, space, OLD_SPACE, kDoubleUnaligned); 2372 AllocateRaw(size, space, OLD_SPACE, kDoubleUnaligned);
2373 if (!allocation.To(&result)) return allocation; 2373 if (!allocation.To(&result)) return allocation;
2374 } 2374 }
2375 2375
2376 Map* map = mode == MUTABLE ? mutable_heap_number_map() : heap_number_map(); 2376 Map* map = mode == MUTABLE ? mutable_heap_number_map() : heap_number_map();
2377 HeapObject::cast(result)->set_map_no_write_barrier(map); 2377 HeapObject::cast(result)->set_map_no_write_barrier(map);
2378 HeapNumber::cast(result)->set_value(value); 2378 HeapNumber::cast(result)->set_value(value);
2379 return result; 2379 return result;
2380 } 2380 }
2381 2381
2382 #define SIMD_ALLOCATE_DEFINITION(TYPE, Type, type, lane_count, lane_type) \ 2382 #define SIMD_ALLOCATE_DEFINITION(TYPE, Type, type, lane_count, lane_type) \
2383 AllocationResult Heap::Allocate##Type(lane_type lanes[lane_count], \ 2383 AllocationResult Heap::Allocate##Type(lane_type lanes[lane_count], \
2384 PretenureFlag pretenure) { \ 2384 PretenureFlag pretenure) { \
2385 int size = Type::kSize; \ 2385 int size = Type::kSize; \
2386 STATIC_ASSERT(Type::kSize <= Page::kMaxRegularHeapObjectSize); \ 2386 STATIC_ASSERT(Type::kSize <= Page::kMaxRegularHeapObjectSize); \
2387 \ 2387 \
2388 AllocationSpace space = SelectSpace(pretenure); \ 2388 AllocationSpace space = SelectSpace(size, pretenure); \
2389 \ 2389 \
2390 HeapObject* result = nullptr; \ 2390 HeapObject* result = nullptr; \
2391 { \ 2391 { \
2392 AllocationResult allocation = \ 2392 AllocationResult allocation = \
2393 AllocateRaw(size, space, OLD_SPACE, kSimd128Unaligned); \ 2393 AllocateRaw(size, space, OLD_SPACE, kSimd128Unaligned); \
2394 if (!allocation.To(&result)) return allocation; \ 2394 if (!allocation.To(&result)) return allocation; \
2395 } \ 2395 } \
2396 \ 2396 \
2397 result->set_map_no_write_barrier(type##_map()); \ 2397 result->set_map_no_write_barrier(type##_map()); \
2398 Type* instance = Type::cast(result); \ 2398 Type* instance = Type::cast(result); \
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after
2916 result->set_foreign_address(address); 2916 result->set_foreign_address(address);
2917 return result; 2917 return result;
2918 } 2918 }
2919 2919
2920 2920
2921 AllocationResult Heap::AllocateByteArray(int length, PretenureFlag pretenure) { 2921 AllocationResult Heap::AllocateByteArray(int length, PretenureFlag pretenure) {
2922 if (length < 0 || length > ByteArray::kMaxLength) { 2922 if (length < 0 || length > ByteArray::kMaxLength) {
2923 v8::internal::Heap::FatalProcessOutOfMemory("invalid array length", true); 2923 v8::internal::Heap::FatalProcessOutOfMemory("invalid array length", true);
2924 } 2924 }
2925 int size = ByteArray::SizeFor(length); 2925 int size = ByteArray::SizeFor(length);
2926 AllocationSpace space = SelectSpace(pretenure); 2926 AllocationSpace space = SelectSpace(size, pretenure);
2927 HeapObject* result = nullptr; 2927 HeapObject* result = nullptr;
2928 { 2928 {
2929 AllocationResult allocation = AllocateRaw(size, space, OLD_SPACE); 2929 AllocationResult allocation = AllocateRaw(size, space, OLD_SPACE);
2930 if (!allocation.To(&result)) return allocation; 2930 if (!allocation.To(&result)) return allocation;
2931 } 2931 }
2932 2932
2933 result->set_map_no_write_barrier(byte_array_map()); 2933 result->set_map_no_write_barrier(byte_array_map());
2934 ByteArray::cast(result)->set_length(length); 2934 ByteArray::cast(result)->set_length(length);
2935 return result; 2935 return result;
2936 } 2936 }
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
3127 if (profiler->is_tracking_allocations()) { 3127 if (profiler->is_tracking_allocations()) {
3128 profiler->UpdateObjectSizeEvent(object->address(), object->Size()); 3128 profiler->UpdateObjectSizeEvent(object->address(), object->Size());
3129 } 3129 }
3130 } 3130 }
3131 3131
3132 3132
3133 AllocationResult Heap::AllocateFixedTypedArrayWithExternalPointer( 3133 AllocationResult Heap::AllocateFixedTypedArrayWithExternalPointer(
3134 int length, ExternalArrayType array_type, void* external_pointer, 3134 int length, ExternalArrayType array_type, void* external_pointer,
3135 PretenureFlag pretenure) { 3135 PretenureFlag pretenure) {
3136 int size = FixedTypedArrayBase::kHeaderSize; 3136 int size = FixedTypedArrayBase::kHeaderSize;
3137 AllocationSpace space = SelectSpace(pretenure); 3137 AllocationSpace space = SelectSpace(size, pretenure);
3138 HeapObject* result = nullptr; 3138 HeapObject* result = nullptr;
3139 { 3139 {
3140 AllocationResult allocation = AllocateRaw(size, space, OLD_SPACE); 3140 AllocationResult allocation = AllocateRaw(size, space, OLD_SPACE);
3141 if (!allocation.To(&result)) return allocation; 3141 if (!allocation.To(&result)) return allocation;
3142 } 3142 }
3143 3143
3144 result->set_map_no_write_barrier(MapForFixedTypedArray(array_type)); 3144 result->set_map_no_write_barrier(MapForFixedTypedArray(array_type));
3145 FixedTypedArrayBase* elements = FixedTypedArrayBase::cast(result); 3145 FixedTypedArrayBase* elements = FixedTypedArrayBase::cast(result);
3146 elements->set_base_pointer(Smi::FromInt(0), SKIP_WRITE_BARRIER); 3146 elements->set_base_pointer(Smi::FromInt(0), SKIP_WRITE_BARRIER);
3147 elements->set_external_pointer(external_pointer, SKIP_WRITE_BARRIER); 3147 elements->set_external_pointer(external_pointer, SKIP_WRITE_BARRIER);
(...skipping 23 matching lines...) Expand all
3171 3171
3172 AllocationResult Heap::AllocateFixedTypedArray(int length, 3172 AllocationResult Heap::AllocateFixedTypedArray(int length,
3173 ExternalArrayType array_type, 3173 ExternalArrayType array_type,
3174 bool initialize, 3174 bool initialize,
3175 PretenureFlag pretenure) { 3175 PretenureFlag pretenure) {
3176 int element_size; 3176 int element_size;
3177 ElementsKind elements_kind; 3177 ElementsKind elements_kind;
3178 ForFixedTypedArray(array_type, &element_size, &elements_kind); 3178 ForFixedTypedArray(array_type, &element_size, &elements_kind);
3179 int size = OBJECT_POINTER_ALIGN(length * element_size + 3179 int size = OBJECT_POINTER_ALIGN(length * element_size +
3180 FixedTypedArrayBase::kDataOffset); 3180 FixedTypedArrayBase::kDataOffset);
3181 AllocationSpace space = SelectSpace(pretenure); 3181 AllocationSpace space = SelectSpace(size, pretenure);
3182 3182
3183 HeapObject* object = nullptr; 3183 HeapObject* object = nullptr;
3184 AllocationResult allocation = AllocateRaw( 3184 AllocationResult allocation = AllocateRaw(
3185 size, space, OLD_SPACE, 3185 size, space, OLD_SPACE,
3186 array_type == kExternalFloat64Array ? kDoubleAligned : kWordAligned); 3186 array_type == kExternalFloat64Array ? kDoubleAligned : kWordAligned);
3187 if (!allocation.To(&object)) return allocation; 3187 if (!allocation.To(&object)) return allocation;
3188 3188
3189 object->set_map_no_write_barrier(MapForFixedTypedArray(array_type)); 3189 object->set_map_no_write_barrier(MapForFixedTypedArray(array_type));
3190 FixedTypedArrayBase* elements = FixedTypedArrayBase::cast(object); 3190 FixedTypedArrayBase* elements = FixedTypedArrayBase::cast(object);
3191 elements->set_base_pointer(elements, SKIP_WRITE_BARRIER); 3191 elements->set_base_pointer(elements, SKIP_WRITE_BARRIER);
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
3386 3386
3387 // Both types of global objects should be allocated using 3387 // Both types of global objects should be allocated using
3388 // AllocateGlobalObject to be properly initialized. 3388 // AllocateGlobalObject to be properly initialized.
3389 DCHECK(map->instance_type() != JS_GLOBAL_OBJECT_TYPE); 3389 DCHECK(map->instance_type() != JS_GLOBAL_OBJECT_TYPE);
3390 DCHECK(map->instance_type() != JS_BUILTINS_OBJECT_TYPE); 3390 DCHECK(map->instance_type() != JS_BUILTINS_OBJECT_TYPE);
3391 3391
3392 // Allocate the backing storage for the properties. 3392 // Allocate the backing storage for the properties.
3393 FixedArray* properties = empty_fixed_array(); 3393 FixedArray* properties = empty_fixed_array();
3394 3394
3395 // Allocate the JSObject. 3395 // Allocate the JSObject.
3396 AllocationSpace space = SelectSpace(pretenure); 3396 int size = map->instance_size();
3397 AllocationSpace space = SelectSpace(size, pretenure);
3397 JSObject* js_obj = nullptr; 3398 JSObject* js_obj = nullptr;
3398 AllocationResult allocation = Allocate(map, space, allocation_site); 3399 AllocationResult allocation = Allocate(map, space, allocation_site);
3399 if (!allocation.To(&js_obj)) return allocation; 3400 if (!allocation.To(&js_obj)) return allocation;
3400 3401
3401 // Initialize the JSObject. 3402 // Initialize the JSObject.
3402 InitializeJSObjectFromMap(js_obj, properties, map); 3403 InitializeJSObjectFromMap(js_obj, properties, map);
3403 DCHECK(js_obj->HasFastElements() || js_obj->HasFixedTypedArrayElements()); 3404 DCHECK(js_obj->HasFastElements() || js_obj->HasFixedTypedArrayElements());
3404 return js_obj; 3405 return js_obj;
3405 } 3406 }
3406 3407
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
3587 3588
3588 DCHECK_LE(0, chars); 3589 DCHECK_LE(0, chars);
3589 DCHECK_GE(String::kMaxLength, chars); 3590 DCHECK_GE(String::kMaxLength, chars);
3590 if (is_one_byte) { 3591 if (is_one_byte) {
3591 map = one_byte_internalized_string_map(); 3592 map = one_byte_internalized_string_map();
3592 size = SeqOneByteString::SizeFor(chars); 3593 size = SeqOneByteString::SizeFor(chars);
3593 } else { 3594 } else {
3594 map = internalized_string_map(); 3595 map = internalized_string_map();
3595 size = SeqTwoByteString::SizeFor(chars); 3596 size = SeqTwoByteString::SizeFor(chars);
3596 } 3597 }
3598 AllocationSpace space = SelectSpace(size, TENURED);
3597 3599
3598 // Allocate string. 3600 // Allocate string.
3599 HeapObject* result = nullptr; 3601 HeapObject* result = nullptr;
3600 { 3602 {
3601 AllocationResult allocation = AllocateRaw(size, OLD_SPACE, OLD_SPACE); 3603 AllocationResult allocation = AllocateRaw(size, space, OLD_SPACE);
3602 if (!allocation.To(&result)) return allocation; 3604 if (!allocation.To(&result)) return allocation;
3603 } 3605 }
3604 3606
3605 result->set_map_no_write_barrier(map); 3607 result->set_map_no_write_barrier(map);
3606 // Set length and hash fields of the allocated string. 3608 // Set length and hash fields of the allocated string.
3607 String* answer = String::cast(result); 3609 String* answer = String::cast(result);
3608 answer->set_length(chars); 3610 answer->set_length(chars);
3609 answer->set_hash_field(hash_field); 3611 answer->set_hash_field(hash_field);
3610 3612
3611 DCHECK_EQ(size, answer->Size()); 3613 DCHECK_EQ(size, answer->Size());
(...skipping 17 matching lines...) Expand all
3629 template AllocationResult Heap::AllocateInternalizedStringImpl<false>( 3631 template AllocationResult Heap::AllocateInternalizedStringImpl<false>(
3630 Vector<const char>, int, uint32_t); 3632 Vector<const char>, int, uint32_t);
3631 3633
3632 3634
3633 AllocationResult Heap::AllocateRawOneByteString(int length, 3635 AllocationResult Heap::AllocateRawOneByteString(int length,
3634 PretenureFlag pretenure) { 3636 PretenureFlag pretenure) {
3635 DCHECK_LE(0, length); 3637 DCHECK_LE(0, length);
3636 DCHECK_GE(String::kMaxLength, length); 3638 DCHECK_GE(String::kMaxLength, length);
3637 int size = SeqOneByteString::SizeFor(length); 3639 int size = SeqOneByteString::SizeFor(length);
3638 DCHECK(size <= SeqOneByteString::kMaxSize); 3640 DCHECK(size <= SeqOneByteString::kMaxSize);
3639 AllocationSpace space = SelectSpace(pretenure); 3641 AllocationSpace space = SelectSpace(size, pretenure);
3640 3642
3641 HeapObject* result = nullptr; 3643 HeapObject* result = nullptr;
3642 { 3644 {
3643 AllocationResult allocation = AllocateRaw(size, space, OLD_SPACE); 3645 AllocationResult allocation = AllocateRaw(size, space, OLD_SPACE);
3644 if (!allocation.To(&result)) return allocation; 3646 if (!allocation.To(&result)) return allocation;
3645 } 3647 }
3646 3648
3647 // Partially initialize the object. 3649 // Partially initialize the object.
3648 result->set_map_no_write_barrier(one_byte_string_map()); 3650 result->set_map_no_write_barrier(one_byte_string_map());
3649 String::cast(result)->set_length(length); 3651 String::cast(result)->set_length(length);
3650 String::cast(result)->set_hash_field(String::kEmptyHashField); 3652 String::cast(result)->set_hash_field(String::kEmptyHashField);
3651 DCHECK_EQ(size, HeapObject::cast(result)->Size()); 3653 DCHECK_EQ(size, HeapObject::cast(result)->Size());
3652 3654
3653 return result; 3655 return result;
3654 } 3656 }
3655 3657
3656 3658
3657 AllocationResult Heap::AllocateRawTwoByteString(int length, 3659 AllocationResult Heap::AllocateRawTwoByteString(int length,
3658 PretenureFlag pretenure) { 3660 PretenureFlag pretenure) {
3659 DCHECK_LE(0, length); 3661 DCHECK_LE(0, length);
3660 DCHECK_GE(String::kMaxLength, length); 3662 DCHECK_GE(String::kMaxLength, length);
3661 int size = SeqTwoByteString::SizeFor(length); 3663 int size = SeqTwoByteString::SizeFor(length);
3662 DCHECK(size <= SeqTwoByteString::kMaxSize); 3664 DCHECK(size <= SeqTwoByteString::kMaxSize);
3663 AllocationSpace space = SelectSpace(pretenure); 3665 AllocationSpace space = SelectSpace(size, pretenure);
3664 3666
3665 HeapObject* result = nullptr; 3667 HeapObject* result = nullptr;
3666 { 3668 {
3667 AllocationResult allocation = AllocateRaw(size, space, OLD_SPACE); 3669 AllocationResult allocation = AllocateRaw(size, space, OLD_SPACE);
3668 if (!allocation.To(&result)) return allocation; 3670 if (!allocation.To(&result)) return allocation;
3669 } 3671 }
3670 3672
3671 // Partially initialize the object. 3673 // Partially initialize the object.
3672 result->set_map_no_write_barrier(string_map()); 3674 result->set_map_no_write_barrier(string_map());
3673 String::cast(result)->set_length(length); 3675 String::cast(result)->set_length(length);
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
3788 return obj; 3790 return obj;
3789 } 3791 }
3790 3792
3791 3793
3792 AllocationResult Heap::AllocateRawFixedArray(int length, 3794 AllocationResult Heap::AllocateRawFixedArray(int length,
3793 PretenureFlag pretenure) { 3795 PretenureFlag pretenure) {
3794 if (length < 0 || length > FixedArray::kMaxLength) { 3796 if (length < 0 || length > FixedArray::kMaxLength) {
3795 v8::internal::Heap::FatalProcessOutOfMemory("invalid array length", true); 3797 v8::internal::Heap::FatalProcessOutOfMemory("invalid array length", true);
3796 } 3798 }
3797 int size = FixedArray::SizeFor(length); 3799 int size = FixedArray::SizeFor(length);
3798 AllocationSpace space = SelectSpace(pretenure); 3800 AllocationSpace space = SelectSpace(size, pretenure);
3799 3801
3800 return AllocateRaw(size, space, OLD_SPACE); 3802 return AllocateRaw(size, space, OLD_SPACE);
3801 } 3803 }
3802 3804
3803 3805
3804 AllocationResult Heap::AllocateFixedArrayWithFiller(int length, 3806 AllocationResult Heap::AllocateFixedArrayWithFiller(int length,
3805 PretenureFlag pretenure, 3807 PretenureFlag pretenure,
3806 Object* filler) { 3808 Object* filler) {
3807 DCHECK(length >= 0); 3809 DCHECK(length >= 0);
3808 DCHECK(empty_fixed_array()->IsFixedArray()); 3810 DCHECK(empty_fixed_array()->IsFixedArray());
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
3857 } 3859 }
3858 3860
3859 3861
3860 AllocationResult Heap::AllocateRawFixedDoubleArray(int length, 3862 AllocationResult Heap::AllocateRawFixedDoubleArray(int length,
3861 PretenureFlag pretenure) { 3863 PretenureFlag pretenure) {
3862 if (length < 0 || length > FixedDoubleArray::kMaxLength) { 3864 if (length < 0 || length > FixedDoubleArray::kMaxLength) {
3863 v8::internal::Heap::FatalProcessOutOfMemory("invalid array length", 3865 v8::internal::Heap::FatalProcessOutOfMemory("invalid array length",
3864 kDoubleAligned); 3866 kDoubleAligned);
3865 } 3867 }
3866 int size = FixedDoubleArray::SizeFor(length); 3868 int size = FixedDoubleArray::SizeFor(length);
3867 AllocationSpace space = SelectSpace(pretenure); 3869 AllocationSpace space = SelectSpace(size, pretenure);
3868 3870
3869 HeapObject* object = nullptr; 3871 HeapObject* object = nullptr;
3870 { 3872 {
3871 AllocationResult allocation = 3873 AllocationResult allocation =
3872 AllocateRaw(size, space, OLD_SPACE, kDoubleAligned); 3874 AllocateRaw(size, space, OLD_SPACE, kDoubleAligned);
3873 if (!allocation.To(&object)) return allocation; 3875 if (!allocation.To(&object)) return allocation;
3874 } 3876 }
3875 3877
3876 return object; 3878 return object;
3877 } 3879 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
3914 case NAME##_TYPE: \ 3916 case NAME##_TYPE: \
3915 map = name##_map(); \ 3917 map = name##_map(); \
3916 break; 3918 break;
3917 STRUCT_LIST(MAKE_CASE) 3919 STRUCT_LIST(MAKE_CASE)
3918 #undef MAKE_CASE 3920 #undef MAKE_CASE
3919 default: 3921 default:
3920 UNREACHABLE(); 3922 UNREACHABLE();
3921 return exception(); 3923 return exception();
3922 } 3924 }
3923 int size = map->instance_size(); 3925 int size = map->instance_size();
3926 AllocationSpace space = SelectSpace(size, TENURED);
3924 Struct* result = nullptr; 3927 Struct* result = nullptr;
3925 { 3928 {
3926 AllocationResult allocation = Allocate(map, OLD_SPACE); 3929 AllocationResult allocation = Allocate(map, space);
3927 if (!allocation.To(&result)) return allocation; 3930 if (!allocation.To(&result)) return allocation;
3928 } 3931 }
3929 result->InitializeBody(size); 3932 result->InitializeBody(size);
3930 return result; 3933 return result;
3931 } 3934 }
3932 3935
3933 3936
3934 bool Heap::IsHeapIterable() { 3937 bool Heap::IsHeapIterable() {
3935 // TODO(hpayer): This function is not correct. Allocation folding in old 3938 // TODO(hpayer): This function is not correct. Allocation folding in old
3936 // space breaks the iterability. 3939 // space breaks the iterability.
(...skipping 2165 matching lines...) Expand 10 before | Expand all | Expand 10 after
6102 } 6105 }
6103 6106
6104 6107
6105 // static 6108 // static
6106 int Heap::GetStaticVisitorIdForMap(Map* map) { 6109 int Heap::GetStaticVisitorIdForMap(Map* map) {
6107 return StaticVisitorBase::GetVisitorId(map); 6110 return StaticVisitorBase::GetVisitorId(map);
6108 } 6111 }
6109 6112
6110 } // namespace internal 6113 } // namespace internal
6111 } // namespace v8 6114 } // namespace v8
OLDNEW
« no previous file with comments | « src/heap/heap.h ('k') | src/heap/heap-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698