Commit b7d9672a authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Trigger GC two times before reporting OOM

The first GC will collect dead JSArrayBuffers, but the release of the
underlying JSArrayBuffer::Allocations might be delayed. Hence, a second
GC might be needed.

R=ulan@chromium.org

Bug: v8:7621
Change-Id: Iee714f05cb939bb084d064be6d31dfbab32ff4ba
Reviewed-on: https://chromium-review.googlesource.com/995533
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#52357}
parent 58b503c2
...@@ -33,13 +33,17 @@ void* TryAllocateBackingStore(WasmMemoryTracker* memory_tracker, Heap* heap, ...@@ -33,13 +33,17 @@ void* TryAllocateBackingStore(WasmMemoryTracker* memory_tracker, Heap* heap,
// Let the WasmMemoryTracker know we are going to reserve a bunch of // Let the WasmMemoryTracker know we are going to reserve a bunch of
// address space. // address space.
if (!memory_tracker->ReserveAddressSpace(*allocation_length)) { // Try up to three times; getting rid of dead JSArrayBuffer allocations might
// If we fail the first time, collect garbage and retry. // require two GCs.
// TODO(gc): Fix this to only require one GC (crbug.com/v8/7621).
for (int trial = 0;; ++trial) {
if (memory_tracker->ReserveAddressSpace(*allocation_length)) break;
// Collect garbage and retry.
heap->MemoryPressureNotification(MemoryPressureLevel::kCritical, true); heap->MemoryPressureNotification(MemoryPressureLevel::kCritical, true);
if (!memory_tracker->ReserveAddressSpace(*allocation_length)) { // After first and second GC: retry.
// If we are over the address space limit, fail. if (trial < 2) continue;
return nullptr; // We are over the address space limit. Fail.
} return nullptr;
} }
// The Reserve makes the whole region inaccessible by default. // The Reserve makes the whole region inaccessible by default.
......
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