Commit bcf0c32d authored by Hannes Payer's avatar Hannes Payer Committed by Commit Bot

[heap] AllocateRawWithRetryOrFail is using AllocationType.

Bug: v8:8945
Change-Id: I2ee060c03496bbcb388d82fd05ecc61658047f98
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1503633Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Commit-Queue: Hannes Payer <hpayer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#60030}
parent cbc18b18
...@@ -132,8 +132,9 @@ void InitializeCode(Heap* heap, Handle<Code> code, int object_size, ...@@ -132,8 +132,9 @@ void InitializeCode(Heap* heap, Handle<Code> code, int object_size,
HeapObject Factory::AllocateRawWithImmortalMap(int size, HeapObject Factory::AllocateRawWithImmortalMap(int size,
PretenureFlag pretenure, Map map, PretenureFlag pretenure, Map map,
AllocationAlignment alignment) { AllocationAlignment alignment) {
HeapObject result = isolate()->heap()->AllocateRawWithRetryOrFail( AllocationType type = Heap::SelectType(Heap::SelectSpace(pretenure));
size, Heap::SelectSpace(pretenure), alignment); HeapObject result =
isolate()->heap()->AllocateRawWithRetryOrFail(size, type, alignment);
result->set_map_after_allocation(map, SKIP_WRITE_BARRIER); result->set_map_after_allocation(map, SKIP_WRITE_BARRIER);
return result; return result;
} }
...@@ -142,11 +143,11 @@ HeapObject Factory::AllocateRawWithAllocationSite( ...@@ -142,11 +143,11 @@ HeapObject Factory::AllocateRawWithAllocationSite(
Handle<Map> map, PretenureFlag pretenure, Handle<Map> map, PretenureFlag pretenure,
Handle<AllocationSite> allocation_site) { Handle<AllocationSite> allocation_site) {
DCHECK(map->instance_type() != MAP_TYPE); DCHECK(map->instance_type() != MAP_TYPE);
AllocationType type = Heap::SelectType(Heap::SelectSpace(pretenure));
int size = map->instance_size(); int size = map->instance_size();
if (!allocation_site.is_null()) size += AllocationMemento::kSize; if (!allocation_site.is_null()) size += AllocationMemento::kSize;
AllocationSpace space = Heap::SelectSpace(pretenure); AllocationSpace space = Heap::SelectSpace(pretenure);
HeapObject result = HeapObject result = isolate()->heap()->AllocateRawWithRetryOrFail(size, type);
isolate()->heap()->AllocateRawWithRetryOrFail(size, space);
WriteBarrierMode write_barrier_mode = WriteBarrierMode write_barrier_mode =
space == NEW_SPACE ? SKIP_WRITE_BARRIER : UPDATE_WRITE_BARRIER; space == NEW_SPACE ? SKIP_WRITE_BARRIER : UPDATE_WRITE_BARRIER;
result->set_map_after_allocation(*map, write_barrier_mode); result->set_map_after_allocation(*map, write_barrier_mode);
...@@ -169,9 +170,8 @@ void Factory::InitializeAllocationMemento(AllocationMemento memento, ...@@ -169,9 +170,8 @@ void Factory::InitializeAllocationMemento(AllocationMemento memento,
} }
HeapObject Factory::AllocateRawArray(int size, PretenureFlag pretenure) { HeapObject Factory::AllocateRawArray(int size, PretenureFlag pretenure) {
AllocationSpace space = Heap::SelectSpace(pretenure); AllocationType type = Heap::SelectType(Heap::SelectSpace(pretenure));
HeapObject result = HeapObject result = isolate()->heap()->AllocateRawWithRetryOrFail(size, type);
isolate()->heap()->AllocateRawWithRetryOrFail(size, space);
if (size > kMaxRegularHeapObjectSize && FLAG_use_marking_progress_bar) { if (size > kMaxRegularHeapObjectSize && FLAG_use_marking_progress_bar) {
MemoryChunk* chunk = MemoryChunk::FromHeapObject(result); MemoryChunk* chunk = MemoryChunk::FromHeapObject(result);
chunk->SetFlag<AccessMode::ATOMIC>(MemoryChunk::HAS_PROGRESS_BAR); chunk->SetFlag<AccessMode::ATOMIC>(MemoryChunk::HAS_PROGRESS_BAR);
...@@ -197,12 +197,12 @@ HeapObject Factory::AllocateRawWeakArrayList(int capacity, ...@@ -197,12 +197,12 @@ HeapObject Factory::AllocateRawWeakArrayList(int capacity,
HeapObject Factory::New(Handle<Map> map, PretenureFlag pretenure) { HeapObject Factory::New(Handle<Map> map, PretenureFlag pretenure) {
DCHECK(map->instance_type() != MAP_TYPE); DCHECK(map->instance_type() != MAP_TYPE);
int size = map->instance_size(); int size = map->instance_size();
AllocationSpace space = Heap::SelectSpace(pretenure); AllocationType type = Heap::SelectType(Heap::SelectSpace(pretenure));
HeapObject result = HeapObject result = isolate()->heap()->AllocateRawWithRetryOrFail(size, type);
isolate()->heap()->AllocateRawWithRetryOrFail(size, space);
// New space objects are allocated white. // New space objects are allocated white.
WriteBarrierMode write_barrier_mode = WriteBarrierMode write_barrier_mode = type == AllocationType::kYoung
space == NEW_SPACE ? SKIP_WRITE_BARRIER : UPDATE_WRITE_BARRIER; ? SKIP_WRITE_BARRIER
: UPDATE_WRITE_BARRIER;
result->set_map_after_allocation(*map, write_barrier_mode); result->set_map_after_allocation(*map, write_barrier_mode);
return result; return result;
} }
...@@ -211,7 +211,8 @@ Handle<HeapObject> Factory::NewFillerObject(int size, bool double_align, ...@@ -211,7 +211,8 @@ Handle<HeapObject> Factory::NewFillerObject(int size, bool double_align,
AllocationSpace space) { AllocationSpace space) {
AllocationAlignment alignment = double_align ? kDoubleAligned : kWordAligned; AllocationAlignment alignment = double_align ? kDoubleAligned : kWordAligned;
Heap* heap = isolate()->heap(); Heap* heap = isolate()->heap();
HeapObject result = heap->AllocateRawWithRetryOrFail(size, space, alignment); HeapObject result = heap->AllocateRawWithRetryOrFail(
size, Heap::SelectType(space), alignment);
#ifdef DEBUG #ifdef DEBUG
MemoryChunk* chunk = MemoryChunk::FromHeapObject(result); MemoryChunk* chunk = MemoryChunk::FromHeapObject(result);
DCHECK(chunk->owner()->identity() == space); DCHECK(chunk->owner()->identity() == space);
...@@ -1910,8 +1911,8 @@ Handle<DescriptorArray> Factory::NewDescriptorArray(int number_of_descriptors, ...@@ -1910,8 +1911,8 @@ Handle<DescriptorArray> Factory::NewDescriptorArray(int number_of_descriptors,
// Zero-length case must be handled outside. // Zero-length case must be handled outside.
DCHECK_LT(0, number_of_all_descriptors); DCHECK_LT(0, number_of_all_descriptors);
int size = DescriptorArray::SizeFor(number_of_all_descriptors); int size = DescriptorArray::SizeFor(number_of_all_descriptors);
AllocationSpace space = Heap::SelectSpace(pretenure); AllocationType type = Heap::SelectType(Heap::SelectSpace(pretenure));
HeapObject obj = isolate()->heap()->AllocateRawWithRetryOrFail(size, space); HeapObject obj = isolate()->heap()->AllocateRawWithRetryOrFail(size, type);
obj->set_map_after_allocation(*descriptor_array_map(), SKIP_WRITE_BARRIER); obj->set_map_after_allocation(*descriptor_array_map(), SKIP_WRITE_BARRIER);
DescriptorArray array = DescriptorArray::cast(obj); DescriptorArray array = DescriptorArray::cast(obj);
array->Initialize(*empty_enum_cache(), *undefined_value(), array->Initialize(*empty_enum_cache(), *undefined_value(),
...@@ -1961,8 +1962,8 @@ Handle<Map> Factory::NewMap(InstanceType type, int instance_size, ...@@ -1961,8 +1962,8 @@ Handle<Map> Factory::NewMap(InstanceType type, int instance_size,
!Map::CanHaveFastTransitionableElementsKind(type), !Map::CanHaveFastTransitionableElementsKind(type),
IsDictionaryElementsKind(elements_kind) || IsDictionaryElementsKind(elements_kind) ||
IsTerminalElementsKind(elements_kind)); IsTerminalElementsKind(elements_kind));
HeapObject result = HeapObject result = isolate()->heap()->AllocateRawWithRetryOrFail(
isolate()->heap()->AllocateRawWithRetryOrFail(Map::kSize, MAP_SPACE); Map::kSize, AllocationType::kMap);
result->set_map_after_allocation(*meta_map(), SKIP_WRITE_BARRIER); result->set_map_after_allocation(*meta_map(), SKIP_WRITE_BARRIER);
return handle(InitializeMap(Map::cast(result), type, instance_size, return handle(InitializeMap(Map::cast(result), type, instance_size,
elements_kind, inobject_properties), elements_kind, inobject_properties),
...@@ -2040,7 +2041,7 @@ Handle<JSObject> Factory::CopyJSObjectWithAllocationSite( ...@@ -2040,7 +2041,7 @@ Handle<JSObject> Factory::CopyJSObjectWithAllocationSite(
int adjusted_object_size = int adjusted_object_size =
site.is_null() ? object_size : object_size + AllocationMemento::kSize; site.is_null() ? object_size : object_size + AllocationMemento::kSize;
HeapObject raw_clone = isolate()->heap()->AllocateRawWithRetryOrFail( HeapObject raw_clone = isolate()->heap()->AllocateRawWithRetryOrFail(
adjusted_object_size, NEW_SPACE); adjusted_object_size, AllocationType::kYoung);
DCHECK(Heap::InYoungGeneration(raw_clone)); DCHECK(Heap::InYoungGeneration(raw_clone));
// Since we know the clone is allocated in new space, we can copy // Since we know the clone is allocated in new space, we can copy
...@@ -2731,7 +2732,7 @@ MaybeHandle<Code> Factory::TryNewCode( ...@@ -2731,7 +2732,7 @@ MaybeHandle<Code> Factory::TryNewCode(
Heap* heap = isolate()->heap(); Heap* heap = isolate()->heap();
CodePageCollectionMemoryModificationScope code_allocation(heap); CodePageCollectionMemoryModificationScope code_allocation(heap);
HeapObject result = HeapObject result =
heap->AllocateRawWithLightRetry(object_size, CODE_SPACE); heap->AllocateRawWithLightRetry(object_size, AllocationType::kCode);
// Return an empty handle if we cannot allocate the code object. // Return an empty handle if we cannot allocate the code object.
if (result.is_null()) return MaybeHandle<Code>(); if (result.is_null()) return MaybeHandle<Code>();
...@@ -2787,7 +2788,7 @@ Handle<Code> Factory::NewCode( ...@@ -2787,7 +2788,7 @@ Handle<Code> Factory::NewCode(
Heap* heap = isolate()->heap(); Heap* heap = isolate()->heap();
CodePageCollectionMemoryModificationScope code_allocation(heap); CodePageCollectionMemoryModificationScope code_allocation(heap);
HeapObject result = HeapObject result =
heap->AllocateRawWithRetryOrFail(object_size, CODE_SPACE); heap->AllocateRawWithRetryOrFail(object_size, AllocationType::kCode);
if (movability == kImmovable) { if (movability == kImmovable) {
result = heap->EnsureImmovableCode(result, object_size); result = heap->EnsureImmovableCode(result, object_size);
} }
...@@ -2872,7 +2873,8 @@ Handle<Code> Factory::CopyCode(Handle<Code> code) { ...@@ -2872,7 +2873,8 @@ Handle<Code> Factory::CopyCode(Handle<Code> code) {
{ {
int obj_size = code->Size(); int obj_size = code->Size();
CodePageCollectionMemoryModificationScope code_allocation(heap); CodePageCollectionMemoryModificationScope code_allocation(heap);
HeapObject result = heap->AllocateRawWithRetryOrFail(obj_size, CODE_SPACE); HeapObject result =
heap->AllocateRawWithRetryOrFail(obj_size, AllocationType::kCode);
// Copy code object. // Copy code object.
Address old_addr = code->address(); Address old_addr = code->address();
......
...@@ -4425,11 +4425,10 @@ HeapObject Heap::EnsureImmovableCode(HeapObject heap_object, int object_size) { ...@@ -4425,11 +4425,10 @@ HeapObject Heap::EnsureImmovableCode(HeapObject heap_object, int object_size) {
return heap_object; return heap_object;
} }
HeapObject Heap::AllocateRawWithLightRetry(int size, AllocationSpace space, HeapObject Heap::AllocateRawWithLightRetry(int size, AllocationType type,
AllocationAlignment alignment) { AllocationAlignment alignment) {
HeapObject result; HeapObject result;
AllocationResult alloc = AllocationResult alloc = AllocateRaw(size, type, alignment);
AllocateRaw(size, Heap::SelectType(space), alignment);
if (alloc.To(&result)) { if (alloc.To(&result)) {
DCHECK(result != ReadOnlyRoots(this).exception()); DCHECK(result != ReadOnlyRoots(this).exception());
return result; return result;
...@@ -4438,7 +4437,7 @@ HeapObject Heap::AllocateRawWithLightRetry(int size, AllocationSpace space, ...@@ -4438,7 +4437,7 @@ HeapObject Heap::AllocateRawWithLightRetry(int size, AllocationSpace space,
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
CollectGarbage(alloc.RetrySpace(), CollectGarbage(alloc.RetrySpace(),
GarbageCollectionReason::kAllocationFailure); GarbageCollectionReason::kAllocationFailure);
alloc = AllocateRaw(size, Heap::SelectType(space), alignment); alloc = AllocateRaw(size, type, alignment);
if (alloc.To(&result)) { if (alloc.To(&result)) {
DCHECK(result != ReadOnlyRoots(this).exception()); DCHECK(result != ReadOnlyRoots(this).exception());
return result; return result;
...@@ -4447,17 +4446,17 @@ HeapObject Heap::AllocateRawWithLightRetry(int size, AllocationSpace space, ...@@ -4447,17 +4446,17 @@ HeapObject Heap::AllocateRawWithLightRetry(int size, AllocationSpace space,
return HeapObject(); return HeapObject();
} }
HeapObject Heap::AllocateRawWithRetryOrFail(int size, AllocationSpace space, HeapObject Heap::AllocateRawWithRetryOrFail(int size, AllocationType type,
AllocationAlignment alignment) { AllocationAlignment alignment) {
AllocationResult alloc; AllocationResult alloc;
HeapObject result = AllocateRawWithLightRetry(size, space, alignment); HeapObject result = AllocateRawWithLightRetry(size, type, alignment);
if (!result.is_null()) return result; if (!result.is_null()) return result;
isolate()->counters()->gc_last_resort_from_handles()->Increment(); isolate()->counters()->gc_last_resort_from_handles()->Increment();
CollectAllAvailableGarbage(GarbageCollectionReason::kLastResort); CollectAllAvailableGarbage(GarbageCollectionReason::kLastResort);
{ {
AlwaysAllocateScope scope(isolate()); AlwaysAllocateScope scope(isolate());
alloc = AllocateRaw(size, Heap::SelectType(space), alignment); alloc = AllocateRaw(size, type, alignment);
} }
if (alloc.To(&result)) { if (alloc.To(&result)) {
DCHECK(result != ReadOnlyRoots(this).exception()); DCHECK(result != ReadOnlyRoots(this).exception());
......
...@@ -1714,23 +1714,23 @@ class Heap { ...@@ -1714,23 +1714,23 @@ class Heap {
int size_in_bytes, AllocationType type, int size_in_bytes, AllocationType type,
AllocationAlignment aligment = kWordAligned); AllocationAlignment aligment = kWordAligned);
// This method will try to perform an allocation of a given size in a given // This method will try to perform an allocation of a given size of a given
// space. If the allocation fails, a regular full garbage collection is // AllocationType. If the allocation fails, a regular full garbage collection
// triggered and the allocation is retried. This is performed multiple times. // is triggered and the allocation is retried. This is performed multiple
// If after that retry procedure the allocation still fails nullptr is // times. If after that retry procedure the allocation still fails nullptr is
// returned. // returned.
HeapObject AllocateRawWithLightRetry( HeapObject AllocateRawWithLightRetry(
int size, AllocationSpace space, int size, AllocationType type,
AllocationAlignment alignment = kWordAligned); AllocationAlignment alignment = kWordAligned);
// This method will try to perform an allocation of a given size in a given // This method will try to perform an allocation of a given size of a given
// space. If the allocation fails, a regular full garbage collection is // AllocationType. If the allocation fails, a regular full garbage collection
// triggered and the allocation is retried. This is performed multiple times. // is triggered and the allocation is retried. This is performed multiple
// If after that retry procedure the allocation still fails a "hammer" // times. If after that retry procedure the allocation still fails a "hammer"
// garbage collection is triggered which tries to significantly reduce memory. // garbage collection is triggered which tries to significantly reduce memory.
// If the allocation still fails after that a fatal error is thrown. // If the allocation still fails after that a fatal error is thrown.
HeapObject AllocateRawWithRetryOrFail( HeapObject AllocateRawWithRetryOrFail(
int size, AllocationSpace space, int size, AllocationType type,
AllocationAlignment alignment = kWordAligned); AllocationAlignment alignment = kWordAligned);
HeapObject AllocateRawCodeInLargeObjectSpace(int size); HeapObject AllocateRawCodeInLargeObjectSpace(int size);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment