[webkit-changes] [WebKit/WebKit] 58b937: [JSC] Add Concurrent Sweeping Locking
Keith Miller
noreply at github.com
Sun Jun 9 09:28:58 PDT 2024
Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: 58b937859832c12a4df62a2486ee23ccca6a5cb6
https://github.com/WebKit/WebKit/commit/58b937859832c12a4df62a2486ee23ccca6a5cb6
Author: Keith Miller <keith_miller at apple.com>
Date: 2024-06-09 (Sun, 09 Jun 2024)
Changed paths:
M Source/JavaScriptCore/heap/BlockDirectory.cpp
M Source/JavaScriptCore/heap/BlockDirectory.h
M Source/JavaScriptCore/heap/BlockDirectoryBits.h
M Source/JavaScriptCore/heap/BlockDirectoryInlines.h
M Source/JavaScriptCore/heap/HeapIterationScope.h
M Source/JavaScriptCore/heap/IncrementalSweeper.cpp
M Source/JavaScriptCore/heap/IsoCellSet.cpp
M Source/JavaScriptCore/heap/IsoCellSetInlines.h
M Source/JavaScriptCore/heap/LocalAllocator.cpp
M Source/JavaScriptCore/heap/MarkedBlock.cpp
M Source/JavaScriptCore/heap/MarkedBlock.h
M Source/JavaScriptCore/heap/MarkedBlockInlines.h
M Source/JavaScriptCore/heap/MarkedSpace.cpp
Log Message:
-----------
[JSC] Add Concurrent Sweeping Locking
https://bugs.webkit.org/show_bug.cgi?id=275085
rdar://problem/129194601
Reviewed by Yusuke Suzuki.
This patch updates the various parts needed for BlockDirectory to work with
concurrent sweeping.
To make sure the future sweeper thread and the mutator don't clobber each other this patch
adds a new bit to BlockDirectory that tracks when a MarkedBlock is "in use". Being in
use means that the MarkedBlock is actively being swept or allocated out of. Additionally,
we need to make sure that we don't see a tear when updating the BlockDirectory bits. This is done by
holding the BlockDirectory's bit vector lock when reading/writing the following bit fields:
1) empty
2) destructable
3) unswept
4) inUse
To help make the locking mechanism for BlockDirectoryBits more clear this patch adds support for
Clang's thread safety analysis tooling with some special tricks for reading/writing. Specifically,
this patch adds assertIsMutatorOrMutatorIsStopped that tells the thread safety analysis m_bitvectorLock
is acquired in as a shared lock (despite m_bitvectorLock being an exclusive lock) when reading from m_bits is
race-safe. The read-only accessors for m_bits take the "shared" lock so Clang is happy. For cases where
writing is race-free there is assertSweeperIsSuspended which "assert acquires" m_bitvectorLock and allows
access to the mutating accessors of m_bits.
Note, the concurrent sweeper doesn't sweep weak blocks because it's not thread safe to do so.
This is ok though because when the main thread goes to allocate out of a marked block it always does
another sweep to build the free list, which will clear these weak impls.
Lastly, this patch adds an assertion to HeapIterationScope that the current thread is holding the API
lock. It's expected the JS isn't running concurrently to HeapIterationScope so this shouldn't be an
issue.
* Source/JavaScriptCore/heap/BlockDirectory.cpp:
(JSC::BlockDirectory::findEmptyBlockToSteal):
(JSC::BlockDirectory::findBlockForAllocation):
(JSC::BlockDirectory::tryAllocateBlock):
(JSC::BlockDirectory::addBlock):
(JSC::BlockDirectory::removeBlock):
(JSC::BlockDirectory::stopAllocating):
(JSC::BlockDirectory::prepareForAllocation):
(JSC::BlockDirectory::stopAllocatingForGood):
(JSC::BlockDirectory::resumeAllocating):
(JSC::BlockDirectory::beginMarkingForFullCollection):
(JSC::BlockDirectory::endMarking):
(JSC::BlockDirectory::snapshotUnsweptForEdenCollection):
(JSC::BlockDirectory::snapshotUnsweptForFullCollection):
(JSC::BlockDirectory::findBlockToSweep):
(JSC::BlockDirectory::sweep):
(JSC::BlockDirectory::shrink):
(JSC::BlockDirectory::assertNoUnswept):
(JSC::BlockDirectory::didFinishUsingBlock):
(JSC::BlockDirectory::parallelNotEmptyBlockSource):
(JSC::BlockDirectory::dumpBits):
(JSC::BlockDirectory::assertIsMutatorOrMutatorIsStopped const):
(JSC::BlockDirectory::assertSweeperIsSuspended const):
* Source/JavaScriptCore/heap/BlockDirectory.h:
(JSC::BlockDirectory::WTF_ASSERTS_ACQUIRED_SHARED_LOCK):
(JSC::BlockDirectory::WTF_ASSERTS_ACQUIRED_LOCK):
(JSC::BlockDirectory::WTF_REQUIRES_LOCK):
(JSC::BlockDirectory::WTF_REQUIRES_SHARED_LOCK):
(JSC::BlockDirectory::findBlockToSweep):
(JSC::BlockDirectory::forEachBitVector): Deleted.
(JSC::BlockDirectory::forEachBitVectorWithName): Deleted.
* Source/JavaScriptCore/heap/BlockDirectoryBits.h:
* Source/JavaScriptCore/heap/BlockDirectoryInlines.h:
(JSC::BlockDirectory::forEachBlock):
(JSC::BlockDirectory::forEachNotEmptyBlock):
* Source/JavaScriptCore/heap/HeapIterationScope.h:
(JSC::HeapIterationScope::HeapIterationScope):
* Source/JavaScriptCore/heap/IncrementalSweeper.cpp:
(JSC::IncrementalSweeper::sweepNextBlock):
* Source/JavaScriptCore/heap/IsoCellSet.cpp:
(JSC::IsoCellSet::parallelNotEmptyMarkedBlockSource):
* Source/JavaScriptCore/heap/IsoCellSetInlines.h:
(JSC::IsoCellSet::forEachMarkedCell):
* Source/JavaScriptCore/heap/LocalAllocator.cpp:
(JSC::LocalAllocator::tryAllocateIn):
* Source/JavaScriptCore/heap/MarkedBlock.cpp:
(JSC::MarkedBlock::Handle::unsweepWithNoNewlyAllocated):
(JSC::MarkedBlock::Handle::stopAllocating):
(JSC::MarkedBlock::Handle::lastChanceToFinalize):
(JSC::MarkedBlock::Handle::resumeAllocating):
(JSC::MarkedBlock::aboutToMarkSlow):
(JSC::MarkedBlock::Handle::didConsumeFreeList):
(JSC::MarkedBlock::noteMarkedSlow):
(JSC::MarkedBlock::Handle::dumpState):
(JSC::MarkedBlock::Handle::sweep):
* Source/JavaScriptCore/heap/MarkedBlock.h:
* Source/JavaScriptCore/heap/MarkedBlockInlines.h:
(JSC::MarkedBlock::Handle::isAllocated):
(JSC::MarkedBlock::Handle::isLive):
(JSC::MarkedBlock::Handle::specializedSweep):
(JSC::MarkedBlock::Handle::isEmpty):
(JSC::MarkedBlock::Handle::setIsFreeListed): Deleted.
* Source/JavaScriptCore/heap/MarkedSpace.cpp:
(JSC::MarkedSpace::dumpBits):
* Source/JavaScriptCore/inspector/agents/InspectorDebuggerAgent.cpp:
(Inspector::InspectorDebuggerAgent::addSymbolicBreakpoint):
* Source/JavaScriptCore/llint/LLIntOffsetsExtractor.cpp:
* Source/WebCore/page/PerformanceLogging.cpp:
Canonical link: https://commits.webkit.org/279861@main
To unsubscribe from these emails, change your notification settings at https://github.com/WebKit/WebKit/settings/notifications
More information about the webkit-changes
mailing list