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 847b1d1
Browse filesBrowse the repository at this point in the historyBrowse files
[JSC] BlockDirectory's bits should be guarded by a mutate-grow lock
https://bugs.webkit.org/show_bug.cgi?id=325474
rdar://188567814
Reviewed by Yusuke Suzuki and Dan Hecht.
BlockDirectory's bits have relied on the mutator being the only thread that allocates from or
sweeps a directory's blocks, so most mutator-side reads and writes went unlocked and
m_bitvectorLock mainly guarded the few places where other threads touch the bits. That
assumption stands in the way of sweeping concurrently with the mutator, and of a global GC
with multiple mutators allocating from the same directory. This patch starts making those
cases possible. m_bitvectorLock is now a MutateGrowLock, which is a thin renaming of
WTF::ReadWriteLock. Per-block bit updates take the shared mutate() side, and only operations
that resize or restructure the bit vectors (addBlock, removeBlock) take the exclusive grow()
side. A block's inUse bit acts as a per-block lock, claimInUse() is the acquire and
releaseInUse() release it. This could be error-prone so a Clang thread safety analysis tracks
ownership of the claimed block through a new BlockOwnership capability. Right now the
capability model only ASSERTs that some thread is holding the inUse bit but if there bugs
in the future we can add proper thread id tracking.
Because shared holders can write different bits of the same word at the same time, every
per-bit accessor is a relaxed atomic operation. This is generally safe because of the inUse
ownership mechanism. Bulk vector rewrites stay plain and still require the exclusive lock.
Additionally, many of the cursors need to be turned into a new VersionedField. VersionedField
is largely ported from libpas with a more C++ style interface. It works by attaching a version
number to the contents of the field. The field supports moving in either direction, however,
it's only possible to move one way without failure.
IsoCellSet used to borrow the directory's lock to keep its per-block bits and its
blocks-with-bits vector in sync. That no longer fits. addBlock and removeBlock now call into
IsoCellSet while already holding grow(). IsoCellSet::add() runs on marker threads and needs
mutual exclusion that the shared side doesn't provide. Taking grow() there would stall
allocation and sweeping for a structure the directory doesn't own. IsoCellSet now has its own
lock for installing, dropping and resizing those bits. To avoid deadlocking, a thread can't
take the m_bitvectorLock after taking the IsoCellSet lock. In the future we may end up
with a MutateGrowLock in IsoCellSets too.
BlockDirectory::sweep() is also renamed sweepAll() to distinguish it from per-block sweeping,
as a drive by change.
Tests:
JSC Covered by existing tests. No behavior change.
Tools/TestWebKitAPI/Tests/WTF/VersionedField.cpp
Canonical link: https://commits.webkit.org/323819@main
macro(live, Live) /* The set of block indices that have actual blocks. */\
39
-
macro(empty, Empty) /* The set of all blocks that have no live objects and are not free listed. */ \
40
-
macro(allocated, Allocated) /* The set of all blocks that are full of live objects. */\
41
-
macro(canAllocate, CanAllocate) /* The set of all blocks are live and not retired (i.e. are more than minMarkedBlockUtilization full). Note: This also implies they wouldn't be allocated. */ \
42
-
macro(destructible, Destructible) /* The set of all blocks that may have destructors to run. */\
43
-
macro(eden, Eden) /* The set of all blocks that have new objects since the last GC. */\
44
-
macro(unswept, Unswept) /* The set of all blocks that could be swept by the incremental sweeper. */\
45
-
macro(inUse, InUse) /* This tells us if a block is currently being allocated from or swept. This acts like a lock bit. */\
43
+
macro(live, Live, BlockOwned) /* The set of block indices that have actual blocks. */\
44
+
macro(empty, Empty, BlockOwned) /* The set of all blocks that have no live objects and are not free listed. */ \
45
+
macro(allocated, Allocated, BlockOwned) /* The set of all blocks that are full of live objects. */\
46
+
macro(canAllocate, CanAllocate, BlockOwned) /* The set of all blocks are live and not retired (i.e. are more than minMarkedBlockUtilization full). Note: This also implies they wouldn't be allocated. */ \
47
+
macro(destructible, Destructible, BlockOwned) /* The set of all blocks that may have destructors to run. */\
48
+
macro(eden, Eden, BlockOwned) /* The set of all blocks that have new objects since the last GC. */\
49
+
macro(unswept, Unswept, BlockOwned) /* The set of all blocks that could be swept by the incremental sweeper. */\
50
+
macro(inUse, InUse, Unowned) /* This tells us if a block is currently being allocated from or swept. This acts like a lock bit. */\
46
51
\
47
-
/* These are computed during marking. */\
48
-
macro(markingNotEmpty, MarkingNotEmpty) /* The set of all blocks that are not empty. */ \
49
-
macro(markingRetired, MarkingRetired) /* The set of all blocks that are retired. */
52
+
/* These are computed during marking, by any marker thread. */\
53
+
macro(markingNotEmpty, MarkingNotEmpty, Unowned) /* The set of all blocks that are not empty. */ \
54
+
macro(markingRetired, MarkingRetired, Unowned) /* The set of all blocks that are retired. */
0 commit comments