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

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

Issue 1371033002: [heap] Reland 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 2354 matching lines...) Expand 10 before | Expand all | Expand 10 after
2365 } 2365 }
2366 2366
2367 2367
2368 AllocationResult Heap::AllocateHeapNumber(double value, MutableMode mode, 2368 AllocationResult Heap::AllocateHeapNumber(double value, MutableMode mode,
2369 PretenureFlag pretenure) { 2369 PretenureFlag pretenure) {
2370 // Statically ensure that it is safe to allocate heap numbers in paged 2370 // Statically ensure that it is safe to allocate heap numbers in paged
2371 // spaces. 2371 // spaces.
2372 int size = HeapNumber::kSize; 2372 int size = HeapNumber::kSize;
2373 STATIC_ASSERT(HeapNumber::kSize <= Page::kMaxRegularHeapObjectSize); 2373 STATIC_ASSERT(HeapNumber::kSize <= Page::kMaxRegularHeapObjectSize);
2374 2374
2375 AllocationSpace space = SelectSpace(size, pretenure); 2375 AllocationSpace space = SelectSpace(pretenure);
2376 2376
2377 HeapObject* result = nullptr; 2377 HeapObject* result = nullptr;
2378 { 2378 {
2379 AllocationResult allocation = 2379 AllocationResult allocation =
2380 AllocateRaw(size, space, OLD_SPACE, kDoubleUnaligned); 2380 AllocateRaw(size, space, OLD_SPACE, kDoubleUnaligned);
2381 if (!allocation.To(&result)) return allocation; 2381 if (!allocation.To(&result)) return allocation;
2382 } 2382 }
2383 2383
2384 Map* map = mode == MUTABLE ? mutable_heap_number_map() : heap_number_map(); 2384 Map* map = mode == MUTABLE ? mutable_heap_number_map() : heap_number_map();
2385 HeapObject::cast(result)->set_map_no_write_barrier(map); 2385 HeapObject::cast(result)->set_map_no_write_barrier(map);
2386 HeapNumber::cast(result)->set_value(value); 2386 HeapNumber::cast(result)->set_value(value);
2387 return result; 2387 return result;
2388 } 2388 }
2389 2389
2390 #define SIMD_ALLOCATE_DEFINITION(TYPE, Type, type, lane_count, lane_type) \ 2390 #define SIMD_ALLOCATE_DEFINITION(TYPE, Type, type, lane_count, lane_type) \
2391 AllocationResult Heap::Allocate##Type(lane_type lanes[lane_count], \ 2391 AllocationResult Heap::Allocate##Type(lane_type lanes[lane_count], \
2392 PretenureFlag pretenure) { \ 2392 PretenureFlag pretenure) { \
2393 int size = Type::kSize; \ 2393 int size = Type::kSize; \
2394 STATIC_ASSERT(Type::kSize <= Page::kMaxRegularHeapObjectSize); \ 2394 STATIC_ASSERT(Type::kSize <= Page::kMaxRegularHeapObjectSize); \
2395 \ 2395 \
2396 AllocationSpace space = SelectSpace(size, pretenure); \ 2396 AllocationSpace space = SelectSpace(pretenure); \
2397 \ 2397 \
2398 HeapObject* result = nullptr; \ 2398 HeapObject* result = nullptr; \
2399 { \ 2399 { \
2400 AllocationResult allocation = \ 2400 AllocationResult allocation = \
2401 AllocateRaw(size, space, OLD_SPACE, kSimd128Unaligned); \ 2401 AllocateRaw(size, space, OLD_SPACE, kSimd128Unaligned); \
2402 if (!allocation.To(&result)) return allocation; \ 2402 if (!allocation.To(&result)) return allocation; \
2403 } \ 2403 } \
2404 \ 2404 \
2405 result->set_map_no_write_barrier(type##_map()); \ 2405 result->set_map_no_write_barrier(type##_map()); \
2406 Type* instance = Type::cast(result); \ 2406 Type* instance = Type::cast(result); \
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after
2924 result->set_foreign_address(address); 2924 result->set_foreign_address(address);
2925 return result; 2925 return result;
2926 } 2926 }
2927 2927
2928 2928
2929 AllocationResult Heap::AllocateByteArray(int length, PretenureFlag pretenure) { 2929 AllocationResult Heap::AllocateByteArray(int length, PretenureFlag pretenure) {
2930 if (length < 0 || length > ByteArray::kMaxLength) { 2930 if (length < 0 || length > ByteArray::kMaxLength) {
2931 v8::internal::Heap::FatalProcessOutOfMemory("invalid array length", true); 2931 v8::internal::Heap::FatalProcessOutOfMemory("invalid array length", true);
2932 } 2932 }
2933 int size = ByteArray::SizeFor(length); 2933 int size = ByteArray::SizeFor(length);
2934 AllocationSpace space = SelectSpace(size, pretenure); 2934 AllocationSpace space = SelectSpace(pretenure);
2935 HeapObject* result = nullptr; 2935 HeapObject* result = nullptr;
2936 { 2936 {
2937 AllocationResult allocation = AllocateRaw(size, space, OLD_SPACE); 2937 AllocationResult allocation = AllocateRaw(size, space, OLD_SPACE);
2938 if (!allocation.To(&result)) return allocation; 2938 if (!allocation.To(&result)) return allocation;
2939 } 2939 }
2940 2940
2941 result->set_map_no_write_barrier(byte_array_map()); 2941 result->set_map_no_write_barrier(byte_array_map());
2942 ByteArray::cast(result)->set_length(length); 2942 ByteArray::cast(result)->set_length(length);
2943 return result; 2943 return result;
2944 } 2944 }
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
3135 if (profiler->is_tracking_allocations()) { 3135 if (profiler->is_tracking_allocations()) {
3136 profiler->UpdateObjectSizeEvent(object->address(), object->Size()); 3136 profiler->UpdateObjectSizeEvent(object->address(), object->Size());
3137 } 3137 }
3138 } 3138 }
3139 3139
3140 3140
3141 AllocationResult Heap::AllocateFixedTypedArrayWithExternalPointer( 3141 AllocationResult Heap::AllocateFixedTypedArrayWithExternalPointer(
3142 int length, ExternalArrayType array_type, void* external_pointer, 3142 int length, ExternalArrayType array_type, void* external_pointer,
3143 PretenureFlag pretenure) { 3143 PretenureFlag pretenure) {
3144 int size = FixedTypedArrayBase::kHeaderSize; 3144 int size = FixedTypedArrayBase::kHeaderSize;
3145 AllocationSpace space = SelectSpace(size, pretenure); 3145 AllocationSpace space = SelectSpace(pretenure);
3146 HeapObject* result = nullptr; 3146 HeapObject* result = nullptr;
3147 { 3147 {
3148 AllocationResult allocation = AllocateRaw(size, space, OLD_SPACE); 3148 AllocationResult allocation = AllocateRaw(size, space, OLD_SPACE);
3149 if (!allocation.To(&result)) return allocation; 3149 if (!allocation.To(&result)) return allocation;
3150 } 3150 }
3151 3151
3152 result->set_map_no_write_barrier(MapForFixedTypedArray(array_type)); 3152 result->set_map_no_write_barrier(MapForFixedTypedArray(array_type));
3153 FixedTypedArrayBase* elements = FixedTypedArrayBase::cast(result); 3153 FixedTypedArrayBase* elements = FixedTypedArrayBase::cast(result);
3154 elements->set_base_pointer(Smi::FromInt(0), SKIP_WRITE_BARRIER); 3154 elements->set_base_pointer(Smi::FromInt(0), SKIP_WRITE_BARRIER);
3155 elements->set_external_pointer(external_pointer, SKIP_WRITE_BARRIER); 3155 elements->set_external_pointer(external_pointer, SKIP_WRITE_BARRIER);
(...skipping 23 matching lines...) Expand all
3179 3179
3180 AllocationResult Heap::AllocateFixedTypedArray(int length, 3180 AllocationResult Heap::AllocateFixedTypedArray(int length,
3181 ExternalArrayType array_type, 3181 ExternalArrayType array_type,
3182 bool initialize, 3182 bool initialize,
3183 PretenureFlag pretenure) { 3183 PretenureFlag pretenure) {
3184 int element_size; 3184 int element_size;
3185 ElementsKind elements_kind; 3185 ElementsKind elements_kind;
3186 ForFixedTypedArray(array_type, &element_size, &elements_kind); 3186 ForFixedTypedArray(array_type, &element_size, &elements_kind);
3187 int size = OBJECT_POINTER_ALIGN(length * element_size + 3187 int size = OBJECT_POINTER_ALIGN(length * element_size +
3188 FixedTypedArrayBase::kDataOffset); 3188 FixedTypedArrayBase::kDataOffset);
3189 AllocationSpace space = SelectSpace(size, pretenure); 3189 AllocationSpace space = SelectSpace(pretenure);
3190 3190
3191 HeapObject* object = nullptr; 3191 HeapObject* object = nullptr;
3192 AllocationResult allocation = AllocateRaw( 3192 AllocationResult allocation = AllocateRaw(
3193 size, space, OLD_SPACE, 3193 size, space, OLD_SPACE,
3194 array_type == kExternalFloat64Array ? kDoubleAligned : kWordAligned); 3194 array_type == kExternalFloat64Array ? kDoubleAligned : kWordAligned);
3195 if (!allocation.To(&object)) return allocation; 3195 if (!allocation.To(&object)) return allocation;
3196 3196
3197 object->set_map_no_write_barrier(MapForFixedTypedArray(array_type)); 3197 object->set_map_no_write_barrier(MapForFixedTypedArray(array_type));
3198 FixedTypedArrayBase* elements = FixedTypedArrayBase::cast(object); 3198 FixedTypedArrayBase* elements = FixedTypedArrayBase::cast(object);
3199 elements->set_base_pointer(elements, SKIP_WRITE_BARRIER); 3199 elements->set_base_pointer(elements, SKIP_WRITE_BARRIER);
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
3394 3394
3395 // Both types of global objects should be allocated using 3395 // Both types of global objects should be allocated using
3396 // AllocateGlobalObject to be properly initialized. 3396 // AllocateGlobalObject to be properly initialized.
3397 DCHECK(map->instance_type() != JS_GLOBAL_OBJECT_TYPE); 3397 DCHECK(map->instance_type() != JS_GLOBAL_OBJECT_TYPE);
3398 DCHECK(map->instance_type() != JS_BUILTINS_OBJECT_TYPE); 3398 DCHECK(map->instance_type() != JS_BUILTINS_OBJECT_TYPE);
3399 3399
3400 // Allocate the backing storage for the properties. 3400 // Allocate the backing storage for the properties.
3401 FixedArray* properties = empty_fixed_array(); 3401 FixedArray* properties = empty_fixed_array();
3402 3402
3403 // Allocate the JSObject. 3403 // Allocate the JSObject.
3404 int size = map->instance_size(); 3404 AllocationSpace space = SelectSpace(pretenure);
3405 AllocationSpace space = SelectSpace(size, pretenure);
3406 JSObject* js_obj = nullptr; 3405 JSObject* js_obj = nullptr;
3407 AllocationResult allocation = Allocate(map, space, allocation_site); 3406 AllocationResult allocation = Allocate(map, space, allocation_site);
3408 if (!allocation.To(&js_obj)) return allocation; 3407 if (!allocation.To(&js_obj)) return allocation;
3409 3408
3410 // Initialize the JSObject. 3409 // Initialize the JSObject.
3411 InitializeJSObjectFromMap(js_obj, properties, map); 3410 InitializeJSObjectFromMap(js_obj, properties, map);
3412 DCHECK(js_obj->HasFastElements() || js_obj->HasFixedTypedArrayElements()); 3411 DCHECK(js_obj->HasFastElements() || js_obj->HasFixedTypedArrayElements());
3413 return js_obj; 3412 return js_obj;
3414 } 3413 }
3415 3414
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
3596 3595
3597 DCHECK_LE(0, chars); 3596 DCHECK_LE(0, chars);
3598 DCHECK_GE(String::kMaxLength, chars); 3597 DCHECK_GE(String::kMaxLength, chars);
3599 if (is_one_byte) { 3598 if (is_one_byte) {
3600 map = one_byte_internalized_string_map(); 3599 map = one_byte_internalized_string_map();
3601 size = SeqOneByteString::SizeFor(chars); 3600 size = SeqOneByteString::SizeFor(chars);
3602 } else { 3601 } else {
3603 map = internalized_string_map(); 3602 map = internalized_string_map();
3604 size = SeqTwoByteString::SizeFor(chars); 3603 size = SeqTwoByteString::SizeFor(chars);
3605 } 3604 }
3606 AllocationSpace space = SelectSpace(size, TENURED);
3607 3605
3608 // Allocate string. 3606 // Allocate string.
3609 HeapObject* result = nullptr; 3607 HeapObject* result = nullptr;
3610 { 3608 {
3611 AllocationResult allocation = AllocateRaw(size, space, OLD_SPACE); 3609 AllocationResult allocation = AllocateRaw(size, OLD_SPACE, OLD_SPACE);
3612 if (!allocation.To(&result)) return allocation; 3610 if (!allocation.To(&result)) return allocation;
3613 } 3611 }
3614 3612
3615 result->set_map_no_write_barrier(map); 3613 result->set_map_no_write_barrier(map);
3616 // Set length and hash fields of the allocated string. 3614 // Set length and hash fields of the allocated string.
3617 String* answer = String::cast(result); 3615 String* answer = String::cast(result);
3618 answer->set_length(chars); 3616 answer->set_length(chars);
3619 answer->set_hash_field(hash_field); 3617 answer->set_hash_field(hash_field);
3620 3618
3621 DCHECK_EQ(size, answer->Size()); 3619 DCHECK_EQ(size, answer->Size());
(...skipping 17 matching lines...) Expand all
3639 template AllocationResult Heap::AllocateInternalizedStringImpl<false>( 3637 template AllocationResult Heap::AllocateInternalizedStringImpl<false>(
3640 Vector<const char>, int, uint32_t); 3638 Vector<const char>, int, uint32_t);
3641 3639
3642 3640
3643 AllocationResult Heap::AllocateRawOneByteString(int length, 3641 AllocationResult Heap::AllocateRawOneByteString(int length,
3644 PretenureFlag pretenure) { 3642 PretenureFlag pretenure) {
3645 DCHECK_LE(0, length); 3643 DCHECK_LE(0, length);
3646 DCHECK_GE(String::kMaxLength, length); 3644 DCHECK_GE(String::kMaxLength, length);
3647 int size = SeqOneByteString::SizeFor(length); 3645 int size = SeqOneByteString::SizeFor(length);
3648 DCHECK(size <= SeqOneByteString::kMaxSize); 3646 DCHECK(size <= SeqOneByteString::kMaxSize);
3649 AllocationSpace space = SelectSpace(size, pretenure); 3647 AllocationSpace space = SelectSpace(pretenure);
3650 3648
3651 HeapObject* result = nullptr; 3649 HeapObject* result = nullptr;
3652 { 3650 {
3653 AllocationResult allocation = AllocateRaw(size, space, OLD_SPACE); 3651 AllocationResult allocation = AllocateRaw(size, space, OLD_SPACE);
3654 if (!allocation.To(&result)) return allocation; 3652 if (!allocation.To(&result)) return allocation;
3655 } 3653 }
3656 3654
3657 // Partially initialize the object. 3655 // Partially initialize the object.
3658 result->set_map_no_write_barrier(one_byte_string_map()); 3656 result->set_map_no_write_barrier(one_byte_string_map());
3659 String::cast(result)->set_length(length); 3657 String::cast(result)->set_length(length);
3660 String::cast(result)->set_hash_field(String::kEmptyHashField); 3658 String::cast(result)->set_hash_field(String::kEmptyHashField);
3661 DCHECK_EQ(size, HeapObject::cast(result)->Size()); 3659 DCHECK_EQ(size, HeapObject::cast(result)->Size());
3662 3660
3663 return result; 3661 return result;
3664 } 3662 }
3665 3663
3666 3664
3667 AllocationResult Heap::AllocateRawTwoByteString(int length, 3665 AllocationResult Heap::AllocateRawTwoByteString(int length,
3668 PretenureFlag pretenure) { 3666 PretenureFlag pretenure) {
3669 DCHECK_LE(0, length); 3667 DCHECK_LE(0, length);
3670 DCHECK_GE(String::kMaxLength, length); 3668 DCHECK_GE(String::kMaxLength, length);
3671 int size = SeqTwoByteString::SizeFor(length); 3669 int size = SeqTwoByteString::SizeFor(length);
3672 DCHECK(size <= SeqTwoByteString::kMaxSize); 3670 DCHECK(size <= SeqTwoByteString::kMaxSize);
3673 AllocationSpace space = SelectSpace(size, pretenure); 3671 AllocationSpace space = SelectSpace(pretenure);
3674 3672
3675 HeapObject* result = nullptr; 3673 HeapObject* result = nullptr;
3676 { 3674 {
3677 AllocationResult allocation = AllocateRaw(size, space, OLD_SPACE); 3675 AllocationResult allocation = AllocateRaw(size, space, OLD_SPACE);
3678 if (!allocation.To(&result)) return allocation; 3676 if (!allocation.To(&result)) return allocation;
3679 } 3677 }
3680 3678
3681 // Partially initialize the object. 3679 // Partially initialize the object.
3682 result->set_map_no_write_barrier(string_map()); 3680 result->set_map_no_write_barrier(string_map());
3683 String::cast(result)->set_length(length); 3681 String::cast(result)->set_length(length);
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
3798 return obj; 3796 return obj;
3799 } 3797 }
3800 3798
3801 3799
3802 AllocationResult Heap::AllocateRawFixedArray(int length, 3800 AllocationResult Heap::AllocateRawFixedArray(int length,
3803 PretenureFlag pretenure) { 3801 PretenureFlag pretenure) {
3804 if (length < 0 || length > FixedArray::kMaxLength) { 3802 if (length < 0 || length > FixedArray::kMaxLength) {
3805 v8::internal::Heap::FatalProcessOutOfMemory("invalid array length", true); 3803 v8::internal::Heap::FatalProcessOutOfMemory("invalid array length", true);
3806 } 3804 }
3807 int size = FixedArray::SizeFor(length); 3805 int size = FixedArray::SizeFor(length);
3808 AllocationSpace space = SelectSpace(size, pretenure); 3806 AllocationSpace space = SelectSpace(pretenure);
3809 3807
3810 return AllocateRaw(size, space, OLD_SPACE); 3808 return AllocateRaw(size, space, OLD_SPACE);
3811 } 3809 }
3812 3810
3813 3811
3814 AllocationResult Heap::AllocateFixedArrayWithFiller(int length, 3812 AllocationResult Heap::AllocateFixedArrayWithFiller(int length,
3815 PretenureFlag pretenure, 3813 PretenureFlag pretenure,
3816 Object* filler) { 3814 Object* filler) {
3817 DCHECK(length >= 0); 3815 DCHECK(length >= 0);
3818 DCHECK(empty_fixed_array()->IsFixedArray()); 3816 DCHECK(empty_fixed_array()->IsFixedArray());
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
3867 } 3865 }
3868 3866
3869 3867
3870 AllocationResult Heap::AllocateRawFixedDoubleArray(int length, 3868 AllocationResult Heap::AllocateRawFixedDoubleArray(int length,
3871 PretenureFlag pretenure) { 3869 PretenureFlag pretenure) {
3872 if (length < 0 || length > FixedDoubleArray::kMaxLength) { 3870 if (length < 0 || length > FixedDoubleArray::kMaxLength) {
3873 v8::internal::Heap::FatalProcessOutOfMemory("invalid array length", 3871 v8::internal::Heap::FatalProcessOutOfMemory("invalid array length",
3874 kDoubleAligned); 3872 kDoubleAligned);
3875 } 3873 }
3876 int size = FixedDoubleArray::SizeFor(length); 3874 int size = FixedDoubleArray::SizeFor(length);
3877 AllocationSpace space = SelectSpace(size, pretenure); 3875 AllocationSpace space = SelectSpace(pretenure);
3878 3876
3879 HeapObject* object = nullptr; 3877 HeapObject* object = nullptr;
3880 { 3878 {
3881 AllocationResult allocation = 3879 AllocationResult allocation =
3882 AllocateRaw(size, space, OLD_SPACE, kDoubleAligned); 3880 AllocateRaw(size, space, OLD_SPACE, kDoubleAligned);
3883 if (!allocation.To(&object)) return allocation; 3881 if (!allocation.To(&object)) return allocation;
3884 } 3882 }
3885 3883
3886 return object; 3884 return object;
3887 } 3885 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
3924 case NAME##_TYPE: \ 3922 case NAME##_TYPE: \
3925 map = name##_map(); \ 3923 map = name##_map(); \
3926 break; 3924 break;
3927 STRUCT_LIST(MAKE_CASE) 3925 STRUCT_LIST(MAKE_CASE)
3928 #undef MAKE_CASE 3926 #undef MAKE_CASE
3929 default: 3927 default:
3930 UNREACHABLE(); 3928 UNREACHABLE();
3931 return exception(); 3929 return exception();
3932 } 3930 }
3933 int size = map->instance_size(); 3931 int size = map->instance_size();
3934 AllocationSpace space = SelectSpace(size, TENURED);
3935 Struct* result = nullptr; 3932 Struct* result = nullptr;
3936 { 3933 {
3937 AllocationResult allocation = Allocate(map, space); 3934 AllocationResult allocation = Allocate(map, OLD_SPACE);
3938 if (!allocation.To(&result)) return allocation; 3935 if (!allocation.To(&result)) return allocation;
3939 } 3936 }
3940 result->InitializeBody(size); 3937 result->InitializeBody(size);
3941 return result; 3938 return result;
3942 } 3939 }
3943 3940
3944 3941
3945 bool Heap::IsHeapIterable() { 3942 bool Heap::IsHeapIterable() {
3946 // TODO(hpayer): This function is not correct. Allocation folding in old 3943 // TODO(hpayer): This function is not correct. Allocation folding in old
3947 // space breaks the iterability. 3944 // space breaks the iterability.
(...skipping 2179 matching lines...) Expand 10 before | Expand all | Expand 10 after
6127 } 6124 }
6128 6125
6129 6126
6130 // static 6127 // static
6131 int Heap::GetStaticVisitorIdForMap(Map* map) { 6128 int Heap::GetStaticVisitorIdForMap(Map* map) {
6132 return StaticVisitorBase::GetVisitorId(map); 6129 return StaticVisitorBase::GetVisitorId(map);
6133 } 6130 }
6134 6131
6135 } // namespace internal 6132 } // namespace internal
6136 } // namespace v8 6133 } // 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