You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 4294ae2
Browse filesBrowse the repository at this point in the historyBrowse files
[JSC] Rebuild assertIsMutatorOrMutatorIsStopped on the GC protocol's roles
https://bugs.webkit.org/show_bug.cgi?id=330335
rdar://191952601
Reviewed by Keith Miller.
BlockDirectory's bit vectors are guarded by m_bitvectorLock, a reader-writer
lock. Reading or writing a single bit takes only its shared side, mutate(), and
only resizing the vectors takes its exclusive side, grow(). Some callers skip
even mutate(), in places where no other thread can resize the vectors. That
relies on two invariants:
- One thread at a time has access to the heap, and only that thread resizes
the vectors, in addBlock() and removeBlock().
- While the world is stopped, no thread acts as the access holder: a thread
with access can act only as the conductor, which does not allocate. So
nothing resizes the vectors.
So the access holder may read and write single bits without taking mutate(),
and so may the conductor and its marking helpers while the world is stopped.
Only part of the first invariant was checked: access is a single bit, which
acquireAccessSlow() release-asserts is clear, and addBlock() asserted the API
lock, a stand-in for access. removeBlock() and the unlocked readers relied on
assertIsMutatorOrMutatorIsStopped(), which accepted any thread while the world
was stopped, including compiler threads, so the second invariant was not checked
at all. With the world running, if no thread owned the API lock, it accepted any
thread as long as some thread had access, which is the normal state for WebKit's
main thread and workers.
Replace it with checks of the roles:
- assertIsAccessHolder() now also requires the world to be running, so
addBlock() and removeBlock(), which assert it, fail if anything resizes the
vectors during a stopped phase.
- assertIsExclusiveAccessHolder() also requires that no other thread has
access, using a debug-only count of threads with access, and grants the
access capability exclusively. Code that relies on a single mutator calls
it: LocalAllocator::tryAllocateIn(), MarkedSpace::freeBlock() and the
unlocked bit accesses. Later changes will mark the rest of the code that
assumes a single mutator the same way.
- BlockDirectory::assertMayAccessBitsUnlocked() accepts the exclusive access
holder, or the conductor or a marking helper while the world is stopped.
- Heap::assertIsExclusiveAccessHolderOrConductorWithWorldStopped() covers
MarkedBlock::Handle::sweep(), which the conductor also runs when it resumes
allocation.
A concurrent sweeper thread, which BlockDirectory's inUse claims prepare for,
holds none of these roles, so it must take mutate(). If it ever frees blocks
itself, removeBlock()'s assert fails, since the first invariant would no longer
hold.
Canonical link: https://commits.webkit.org/325970@main
0 commit comments