| Index: Source/platform/heap/ThreadState.cpp
|
| diff --git a/Source/platform/heap/ThreadState.cpp b/Source/platform/heap/ThreadState.cpp
|
| index b2f2f607b8ffa5946229c83e6d037e7788824978..e0f6759ee27b2503ccb34e92f6b90c40bba24e56 100644
|
| --- a/Source/platform/heap/ThreadState.cpp
|
| +++ b/Source/platform/heap/ThreadState.cpp
|
| @@ -671,6 +671,9 @@ bool ThreadState::shouldSchedulePreciseGC()
|
| // These heuristics affect performance significantly.
|
| bool ThreadState::shouldForceConservativeGC()
|
| {
|
| + if (Heap::isUrgentGCRequested())
|
| + return true;
|
| +
|
| size_t newSize = Heap::allocatedObjectSize();
|
| if (newSize >= 300 * 1024 * 1024) {
|
| // If we consume too much memory, trigger a conservative GC
|
| @@ -696,13 +699,21 @@ void ThreadState::scheduleGCIfNeeded()
|
| checkThread();
|
| // Allocation is allowed during sweeping, but those allocations should not
|
| // trigger nested GCs
|
| - if (isSweepingInProgress())
|
| - return;
|
| + if (isSweepingInProgress()) {
|
| + if (!Heap::isUrgentGCRequested() || !isSweepingScheduled())
|
| + return;
|
| + // Urgent GC requested with only a GC scheduled; fall through
|
| + // and have it be serviced by a conservative GC.
|
| + }
|
| ASSERT(!sweepForbidden());
|
|
|
| - if (shouldForceConservativeGC())
|
| - Heap::collectGarbage(ThreadState::HeapPointersOnStack, ThreadState::GCWithoutSweep);
|
| - else if (shouldSchedulePreciseGC())
|
| + if (shouldForceConservativeGC()) {
|
| + // If GC is deemed urgent, eagerly sweep and finalize any external allocations right away.
|
| + GCType gcType = Heap::isUrgentGCRequested() ? GCWithSweep : GCWithoutSweep;
|
| + Heap::collectGarbage(HeapPointersOnStack, gcType);
|
| + return;
|
| + }
|
| + if (shouldSchedulePreciseGC())
|
| schedulePreciseGC();
|
| else if (shouldScheduleIdleGC())
|
| scheduleIdleGC();
|
|
|