[heap] InvokeSecondPassPhantomCallbacks() before selecting garbage collector.

InvokeSecondPassPhantomCallbacks() may allocate which may result in a different GC selection.

Bug: v8:12503
Change-Id: I936634f9b819bc160749e058cbee8fb1c555f376
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3386800
Reviewed-by: Michael Lippautz <mlippautz@chromium.org>
Commit-Queue: Hannes Payer <hpayer@chromium.org>
Cr-Commit-Position: refs/heads/main@{#78619}
This commit is contained in:
Hannes Payer 2022-01-14 10:30:28 +01:00 committed by V8 LUCI CQ
parent 2984052ae8
commit 0b3b2cb33a

View File

@ -1672,6 +1672,10 @@ bool Heap::CollectGarbage(AllocationSpace space,
CHECK(always_allocate());
FatalProcessOutOfMemory("GC during deserialization");
}
// Ensure that all pending phantom callbacks are invoked.
isolate()->global_handles()->InvokeSecondPassPhantomCallbacks();
const char* collector_reason = nullptr;
GarbageCollector collector = SelectGarbageCollector(space, &collector_reason);
is_current_gc_forced_ = gc_callback_flags & v8::kGCCallbackFlagForced ||
@ -1690,9 +1694,6 @@ bool Heap::CollectGarbage(AllocationSpace space,
->global_handles()
->CleanupOnStackReferencesBelowCurrentStackPosition();
// Ensure that all pending phantom callbacks are invoked.
isolate()->global_handles()->InvokeSecondPassPhantomCallbacks();
// The VM is in the GC state until exiting this function.
VMState<GC> state(isolate());