Skip to content

Commit 76ec268

Browse files
committed
[JSC] Collector should decide whether its thread marks during the concurrent phase
https://bugs.webkit.org/show_bug.cgi?id=329209 rdar://191179872 Reviewed by Keith Miller. SlotVisitor::drainInParallelPassively chose whether to mark on the collector thread or to leave the marking to the helpers, by looking at the mutator's world state. That is Collector policy and will need to be adjusted for global collections with multiple mutators, so move it to its only caller, Collector::runConcurrentPhase. Leave drainInParallelPassively only to donate and wait for termination, which is also the path that its name describes. This does not change behavior: the condition is the same, just negated, rewritten in the caller, except that it drops the worldIsStopped() test, which was always false. The collector thread enters the concurrent phase only after resuming the world, and with concurrent GC off a collection never enters this phase. Canonical link: https://commits.webkit.org/325058@main
1 parent a0639cf commit 76ec268

2 files changed

Lines changed: 12 additions & 13 deletions

File tree

‎Source/JavaScriptCore/heap/Collector.cpp‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,9 +604,18 @@ NEVER_INLINE bool Collector::runConcurrentPhase(GCConductor conn)
604604
return false;
605605
}
606606
case GCConductor::Collector: {
607+
unsigned worldState = heap().m_worldState.load();
608+
// FIXME: Heap access is only a proxy for whether the mutator's thread wants a core: a JSC API client drops
609+
// access with the JSLock and may then run native code. And the choice below holds until this drain returns,
610+
// even if the mutator takes or releases access meanwhile.
611+
bool mutatorIsRunningWithHeapAccess = (worldState & Heap::hasAccessBit) && !(worldState & Heap::mutatorWaitingBit);
607612
{
608613
ParallelModeEnabler enabler(visitor);
609-
visitor.drainInParallelPassively(m_scheduler->timeToStop());
614+
// If the mutator is running, don't compete for a core.
615+
if (Options::numberOfGCMarkers() > 1 && mutatorIsRunningWithHeapAccess)
616+
visitor.drainInParallelPassively(m_scheduler->timeToStop());
617+
else
618+
visitor.drainInParallel(m_scheduler->timeToStop());
610619
}
611620
return changePhase(conn, CollectorPhase::Reloop);
612621
} }

‎Source/JavaScriptCore/heap/SlotVisitor.cpp‎

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -724,18 +724,8 @@ SlotVisitor::SharedDrainResult SlotVisitor::drainInParallel(MonotonicTime timeou
724724
SlotVisitor::SharedDrainResult SlotVisitor::drainInParallelPassively(MonotonicTime timeout)
725725
{
726726
ASSERT(m_isInParallelMode);
727-
728-
ASSERT(Options::numberOfGCMarkers());
729-
730-
JSC::Heap& heap = m_collector.heap();
731-
if (Options::numberOfGCMarkers() == 1
732-
|| (heap.m_worldState.load() & Heap::mutatorWaitingBit)
733-
|| !heap.hasHeapAccess()
734-
|| heap.worldIsStopped()) {
735-
// This is an optimization over drainInParallel() when we have a concurrent mutator but
736-
// otherwise it is not profitable.
737-
return drainInParallel(timeout);
738-
}
727+
// This thread counts as one of the markers but does not mark here, so there must be at least one other.
728+
ASSERT(Options::numberOfGCMarkers() > 1);
739729

740730
Locker locker { collector().m_markingMutex };
741731
donateAll(locker);

0 commit comments

Comments
 (0)