Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Source/JavaScriptCore/heap/Heap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3005,6 +3005,13 @@ void Heap::collectIfNecessaryOrDefer(GCDeferralContext* deferralContext)
}
}

void Heap::performPendingDeferredGCWork()
{
ASSERT(hasPendingDeferredGCWork());
m_didDeferGCWork = false;
collectIfNecessaryOrDefer();
}

void Heap::decrementDeferralDepthAndGCIfNeededSlow()
{
// Can't do anything if we're still deferred.
Expand Down
7 changes: 7 additions & 0 deletions Source/JavaScriptCore/heap/Heap.h
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,13 @@ class Heap {

void collectIfNecessaryOrDefer(GCDeferralContext* = nullptr);

// A GC request raised while collection was deferred by DeferGCForAWhile (e.g. the extra-memory
// reports in ScriptExecutable::prepareForExecutionImpl) only sets m_didDeferGCWork; nothing acts on it
// until the next allocation slow path or ~DeferGC, which an embedder-driven loop may not reach for a
// long time. VM entry is a safe point to honor it.
bool hasPendingDeferredGCWork() const { return m_didDeferGCWork && !m_deferralDepth; }
JS_EXPORT_PRIVATE void performPendingDeferredGCWork();

void completeAllJITPlans();

// Note that:
Expand Down
1 change: 1 addition & 0 deletions Source/JavaScriptCore/runtime/OptionsList.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ bool hasCapacityToUseLargeGigacage();
v(Bool, testTheFTL, false, Normal, nullptr) \
v(Bool, verboseSanitizeStack, false, Normal, nullptr) \
v(Bool, useGenerationalGC, true, Normal, nullptr) \
v(Bool, usePollingDeferredGCWorkAtVMEntry, true, Normal, "Honor a GC request left pending by a DeferGCForAWhile scope when the VM is next entered, instead of waiting for the next allocation slow path or ~DeferGC."_s) \
v(Bool, useConcurrentGC, true, Normal, nullptr) \
v(Bool, collectContinuously, false, Normal, nullptr) \
v(Double, collectContinuouslyPeriodMS, 1, Normal, nullptr) \
Expand Down
2 changes: 2 additions & 0 deletions Source/JavaScriptCore/runtime/VMEntryScopeInlines.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ ALWAYS_INLINE VMEntryScope::VMEntryScope(VM& vm, JSGlobalObject* globalObject)
if (!vm.entryScope)
setUpSlow();
vm.clearLastException();
if (vm.heap.hasPendingDeferredGCWork() && Options::usePollingDeferredGCWorkAtVMEntry()) [[unlikely]]
vm.heap.performPendingDeferredGCWork();
}

ALWAYS_INLINE VMEntryScope::~VMEntryScope()
Expand Down
Loading