Skip to content

Commit d39ac42

Browse files
committed
[JSC] Replace three unreachable collection epilogue calls with asserts
https://bugs.webkit.org/show_bug.cgi?id=329110 rdar://191115102 Reviewed by Keith Miller. End sets the epilogue bit while the mutator is either stopped or running the collection itself: - If the mutator is stopped, it has no heap access. Its next acquireAccess() takes the slow path because the bit is set, and acquireAccessSlow runs the epilogue as soon as it has access. - If the mutator is running the collection, it runs the epilogue in finishChangingPhase when it resumes the world, before it returns from the collection. Either way, the epilogue runs before the mutator does anything else with heap access, so stopIfNecessarySlow and releaseAccessSlow never find the bit set. Assert that instead of calling handleNeedCollectionEpilogue(), and remove the stale comment saying the epilogue sometimes can't run there. stopIfNecessarySlow(unsigned) then always returns false, so make it void. Canonical link: https://commits.webkit.org/324942@main
1 parent 0da0fd6 commit d39ac42

2 files changed

Lines changed: 18 additions & 25 deletions

File tree

‎Source/JavaScriptCore/heap/Heap.cpp‎

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,37 +1451,33 @@ void Heap::stopIfNecessarySlow()
14511451
if constexpr (validateDFGDoesGC)
14521452
vm().verifyCanGC();
14531453

1454-
while (stopIfNecessarySlow(m_worldState.load())) { }
1455-
1456-
RELEASE_ASSERT(m_worldState.load() & hasAccessBit);
1457-
RELEASE_ASSERT(!(m_worldState.load() & stoppedBit));
1458-
1459-
handleNeedCollectionEpilogue();
1454+
stopIfNecessarySlow(m_worldState.load());
14601455
m_mutatorDidRun = true;
14611456
}
14621457

1463-
bool Heap::stopIfNecessarySlow(unsigned oldState)
1458+
void Heap::stopIfNecessarySlow(unsigned oldState)
14641459
{
14651460
if constexpr (validateDFGDoesGC)
14661461
vm().verifyCanGC();
14671462

1468-
RELEASE_ASSERT(oldState & hasAccessBit);
1469-
RELEASE_ASSERT(!(oldState & stoppedBit));
1470-
1471-
// It's possible for us to wake up with the epilogue already requested but the world not yet
1472-
// resumed. If that happens, we can't run the epilogue yet.
1473-
if (handleNeedCollectionEpilogue(oldState))
1474-
return true;
1463+
RELEASE_ASSERT(oldState & hasAccessBit, oldState);
1464+
RELEASE_ASSERT(!(oldState & stoppedBit), oldState);
1465+
RELEASE_ASSERT(!(oldState & needCollectionEpilogueBit), oldState);
14751466

14761467
// FIXME: When entering the concurrent phase, we could arrange for this branch not to fire, and then
14771468
// have the SlotVisitor do things to the m_worldState to make this branch fire again. That would
14781469
// prevent us from polling this so much. Ideally, stopIfNecessary would ignore the mutatorHasConnBit
14791470
// and there would be some other bit indicating whether we were in some GC phase other than the
14801471
// NotRunning or Concurrent ones.
1481-
if (oldState & mutatorHasConnBit)
1472+
if (oldState & mutatorHasConnBit) {
14821473
collectInMutatorThread();
1483-
1484-
return false;
1474+
1475+
// Conducting leaves the mutator with heap access, and resuming the world ran any epilogue.
1476+
unsigned state = m_worldState.load();
1477+
RELEASE_ASSERT(state & hasAccessBit, state);
1478+
RELEASE_ASSERT(!(state & stoppedBit), state);
1479+
RELEASE_ASSERT(!(state & needCollectionEpilogueBit), state);
1480+
}
14851481
}
14861482

14871483
NEVER_INLINE void Heap::collectInMutatorThread()
@@ -1510,9 +1506,8 @@ void Heap::waitForCollector(NOESCAPE const Func& func)
15101506

15111507
// If we're in a stop-the-world scenario, we need to wait for that even if done is true.
15121508
unsigned oldState = m_worldState.load();
1513-
if (stopIfNecessarySlow(oldState))
1514-
continue;
1515-
1509+
stopIfNecessarySlow(oldState);
1510+
15161511
m_mutatorDidRun = true;
15171512
// FIXME: We wouldn't need this if stopIfNecessarySlow() had a mode where it knew to just
15181513
// do the collection.
@@ -1564,12 +1559,10 @@ void Heap::releaseAccessSlow()
15641559
RELEASE_ASSERT(oldState & hasAccessBit, oldState);
15651560
RELEASE_ASSERT(!(oldState & stoppedBit), oldState);
15661561
RELEASE_ASSERT(!(oldState & mutatorWaitingBit), oldState);
1562+
RELEASE_ASSERT(!(oldState & needCollectionEpilogueBit), oldState);
15671563

1568-
if (handleNeedCollectionEpilogue(oldState))
1569-
continue;
1570-
15711564
unsigned newState = oldState & ~(hasAccessBit | mutatorHasConnBit);
1572-
1565+
15731566
if ((oldState & mutatorHasConnBit)
15741567
&& m_collector->m_nextPhase != m_collector->m_currentPhase) {
15751568
// This means that the collector thread had given us the conn so that we would do something

‎Source/JavaScriptCore/heap/Heap.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ class Heap {
676676
void resumeTheMutator();
677677

678678
JS_EXPORT_PRIVATE void stopIfNecessarySlow();
679-
bool stopIfNecessarySlow(unsigned extraStateBits);
679+
void stopIfNecessarySlow(unsigned extraStateBits);
680680

681681
template<typename Func>
682682
void waitForCollector(NOESCAPE const Func&);

0 commit comments

Comments
 (0)