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 5edecbf
Browse filesBrowse the repository at this point in the historyBrowse files
https://bugs.webkit.org/show_bug.cgi?id=329377
rdar://191259964
Reviewed by Dan Hecht.
Lets a WeakSet's dead handles be finalized off the mutator, one sweeper at a time, while the mutator
keeps allocating and clearing Weak<> handles without a lock.
1 WeakBlock's free list is now one Atomic<uint64_t>, with a bit per weak atom that is set while the
atom is free. The header's weak atoms are never set. Only the mutator clears (allocates) bits, so
taking a cell is one exchangeAnd with no retry loop; any thread frees with one fetch_or, and
exactly one free sees the block become empty.
2 A sweep starts finalizing a Dead slot with a CAS of its state bits from Dead to Finalized, and
clear() takes a Dead slot with an exchange, so each dead handle is finalized at most once and a
cleared handle's finalizer never runs. Because a mutator clear() of a Dead slot does not decrement
m_deadCount, m_deadCount is now an upper bound that sweep() resets to 0 when done.
3 In order to avoid racing with the mutator, WeakImpl::tryFinalize() copies the weak value and
context out of the slot before its CAS marks the impl Finalized (returning an empty
WeakImplSnapshot if the CAS fails). This allows a finalized impl to be cleared and reused by the
mutator while the finalizer itself is still running.
4 WeakHandleOwner::finalize() returns a FinalizeResult (KeepImpl or DeallocateImpl). An owner that
wants the impl freed returns DeallocateImpl instead of clearing it from inside the finalizer, so
the sweep frees it. This removes the need for `WeakImpl::asWeakImpl(JSValue*)`, which doesn't fit
with concurrent finalizing in (3) where the handle wraps a stack copy of the WeakImpl.
5 Only the mutator unlinks blocks from a WeakSet. WeakSet::finalizeDeadHandles() is the part of
sweep() that may run off the mutator, and releaseBlocks() hands back the blocks it emptied on the
mutator. Heap::weakBlockLock() guards m_blocks and iteration targets.
6 WeakSet::lastChanceToFinalize() now repeats markLiveHandlesDead() and sweep() until no live
handles remain, so handles allocated by a finalizer during VM teardown are finalized too.
This change does not permit clearing other WeakImpls while finalizing off the mutator (a finalizer
may still clear other handles when running on the mutator). It's possible this API is too
restrictive and we'll want to support concurrent clearing, assuming it's perf neutral.
Concurrent allocation seems to be a regression in the naive implementation (adding a lock around the
WeakSet). If we ever want to support that we'll likely need a LocalAllocator like system.
Canonical link: https://commits.webkit.org/325371@main
0 commit comments