Skip to content

Commit 9d236ec

Browse files
committed
[JSC] Heaps that join global collections late adopt the others' marking version
https://bugs.webkit.org/show_bug.cgi?id=327777 rdar://190185283 Reviewed by Keith Miller. SlotVisitor caches one marking version for every heap it marks, but a heap that joins the global Collector after the others have had Full collections starts behind them. So at the start of each collection, before the versions advance, such a heap adopts the others' version. It has never been collected, so its blocks have no marks to lose. Doing this at Begin, with the mutators stopped, keeps the version from changing while the heap's mutator runs. This works while each heap is collected only locally or only globally, which is enough for developing global collections. If a heap can later be collected both ways, this will have to change, depending on which combinations of { Local, Global } x { Eden, Full } we end up supporting. No behavior change for local collections. * Source/JavaScriptCore/heap/Collector.cpp: (JSC::Collector::beginCollectionInEachHeap): (JSC::Collector::setUpVisitors): * Source/JavaScriptCore/heap/MarkedSpace.cpp: (JSC::MarkedSpace::adoptMarkingVersion): * Source/JavaScriptCore/heap/MarkedSpace.h: Canonical link: https://commits.webkit.org/324022@main
1 parent 189ce80 commit 9d236ec

3 files changed

Lines changed: 21 additions & 1 deletion

File tree

‎Source/JavaScriptCore/heap/Collector.cpp‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,15 @@ NEVER_INLINE bool Collector::runBeginPhase(GCConductor conn)
461461

462462
void Collector::beginCollectionInEachHeap(CollectionScope scope, MonotonicTime startTime)
463463
{
464+
HeapVersion markingVersion = m_heaps.first()->objectSpace().markingVersion();
464465
forEachHeap([&](Heap& heap) {
466+
// SlotVisitor caches one marking version and uses it for every heap, so they must all have the
467+
// same one. A heap that joined after the others have collected can take their version. That is
468+
// safe only because it has never been collected: all of its blocks are still at nullVersion,
469+
// which no heap's marking version ever equals.
470+
// Note: This will need to change if we ever have alternating local and global collections.
471+
if (heap.objectSpace().markingVersion() != markingVersion)
472+
heap.objectSpace().adoptMarkingVersion(markingVersion);
465473
heap.m_currentGCStartTime = startTime;
466474
if (!Options::seedOfVMRandomForFuzzer())
467475
heap.vm().random().setSeed(cryptographicallyRandomNumber<uint32_t>());
@@ -472,9 +480,10 @@ void Collector::beginCollectionInEachHeap(CollectionScope scope, MonotonicTime s
472480

473481
void Collector::setUpVisitors(CollectionScope scope)
474482
{
475-
HeapVersion markingVersion = heap().objectSpace().markingVersion();
483+
HeapVersion markingVersion = m_heaps.first()->objectSpace().markingVersion();
476484
bool isAnalyzingHeap = false;
477485
forEachHeap([&](Heap& heap) {
486+
ASSERT(heap.objectSpace().markingVersion() == markingVersion);
478487
if (heap.vm().isAnalyzingHeap())
479488
isAnalyzingHeap = true;
480489
});

‎Source/JavaScriptCore/heap/MarkedSpace.cpp‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,16 @@ void MarkedSpace::endMarking()
462462
m_isMarking = false;
463463
}
464464

465+
// For a space that has never been marked: each collection advances either the marking version or
466+
// the Eden version, so both are still initial, and every block is at nullVersion, which matches
467+
// neither the old version nor the new one, so no block's marks change meaning.
468+
void MarkedSpace::adoptMarkingVersion(HeapVersion version)
469+
{
470+
ASSERT(!m_isMarking);
471+
ASSERT(m_markingVersion == initialVersion && m_edenVersion == initialVersion);
472+
m_markingVersion = version;
473+
}
474+
465475
void MarkedSpace::willStartIterating()
466476
{
467477
ASSERT(!isIterating());

‎Source/JavaScriptCore/heap/MarkedSpace.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ class MarkedSpace {
143143

144144
void beginMarking();
145145
void endMarking();
146+
void adoptMarkingVersion(HeapVersion);
146147
void snapshotUnswept();
147148
void clearNewlyAllocated();
148149
void sweepBlocks();

0 commit comments

Comments
 (0)