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