Skip to content

Commit 321cdfc

Browse files
committed
Use UncheckedLock even less in JavaScriptCore
https://bugs.webkit.org/show_bug.cgi?id=226278 Reviewed by Darin Adler. Use UncheckedLock even less in JavaScriptCore as it is being phased out in favor of Lock, which supports Clang thread safety analysis. * heap/BlockDirectory.h: (JSC::BlockDirectory::WTF_RETURNS_LOCK): * heap/CodeBlockSet.h: (JSC::CodeBlockSet::WTF_RETURNS_LOCK): * heap/Heap.h: * heap/MarkedSpace.h: (JSC::MarkedSpace::directoryLock): * heap/MarkingConstraintSolver.h: * heap/SlotVisitor.cpp: (JSC::SlotVisitor::donateKnownParallel): * heap/SlotVisitor.h: * jit/JITWorklist.cpp: * jit/JITWorklist.h: * jsc.cpp: * profiler/ProfilerDatabase.h: * runtime/DeferredWorkTimer.h: * runtime/VMTraps.cpp: (JSC::VMTraps::invalidateCodeBlocksOnStack): * runtime/VMTraps.h: * tools/FunctionOverrides.cpp: (JSC::FunctionOverrides::FunctionOverrides): (JSC::FunctionOverrides::reinstallOverrides): (JSC::FunctionOverrides::parseOverridesInFile): * tools/FunctionOverrides.h: (JSC::FunctionOverrides::WTF_REQUIRES_LOCK): * tools/VMInspector.cpp: (JSC::ensureIsSafeToLock): (JSC::VMInspector::codeBlockForMachinePC): * wasm/WasmBBQPlan.cpp: (JSC::Wasm::BBQPlan::work): (JSC::Wasm::BBQPlan::compileFunction): (JSC::Wasm::BBQPlan::didCompleteCompilation): * wasm/WasmBBQPlan.h: * wasm/WasmEntryPlan.cpp: (JSC::Wasm::EntryPlan::parseAndValidateModule): (JSC::Wasm::EntryPlan::prepare): (JSC::Wasm::EntryPlan::ThreadCountHolder::~ThreadCountHolder): (JSC::Wasm::EntryPlan::complete): * wasm/WasmEntryPlan.h: (JSC::Wasm::EntryPlan::tryReserveCapacity): * wasm/WasmLLIntPlan.cpp: (JSC::Wasm::LLIntPlan::compileFunction): (JSC::Wasm::LLIntPlan::didCompleteCompilation): (JSC::Wasm::LLIntPlan::completeInStreaming): (JSC::Wasm::LLIntPlan::didFailInStreaming): * wasm/WasmLLIntPlan.h: * wasm/WasmOMGForOSREntryPlan.cpp: (JSC::Wasm::OMGForOSREntryPlan::work): * wasm/WasmOMGForOSREntryPlan.h: * wasm/WasmOMGPlan.cpp: (JSC::Wasm::OMGPlan::work): * wasm/WasmOMGPlan.h: * wasm/WasmPlan.cpp: (JSC::Wasm::Plan::runCompletionTasks): (JSC::Wasm::Plan::tryRemoveContextAndCancelIfLast): (JSC::Wasm::Plan::fail): * wasm/WasmPlan.h: * wasm/WasmStreamingCompiler.cpp: (JSC::Wasm::StreamingCompiler::didCompileFunction): (JSC::Wasm::StreamingCompiler::completeIfNecessary): (JSC::Wasm::StreamingCompiler::didComplete): (JSC::Wasm::StreamingCompiler::finalize): * wasm/WasmStreamingCompiler.h: * wasm/WasmStreamingPlan.cpp: (JSC::Wasm::StreamingPlan::work): * wasm/WasmStreamingPlan.h: * wasm/WasmThunks.h: Canonical link: https://commits.webkit.org/238168@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@278093 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 67c8a6b commit 321cdfc

35 files changed

Lines changed: 187 additions & 93 deletions

‎Source/JavaScriptCore/ChangeLog‎

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,81 @@
1+
2021-05-26 Chris Dumez <cdumez@apple.com>
2+
3+
Use UncheckedLock even less in JavaScriptCore
4+
https://bugs.webkit.org/show_bug.cgi?id=226278
5+
6+
Reviewed by Darin Adler.
7+
8+
Use UncheckedLock even less in JavaScriptCore as it is being phased out in
9+
favor of Lock, which supports Clang thread safety analysis.
10+
11+
* heap/BlockDirectory.h:
12+
(JSC::BlockDirectory::WTF_RETURNS_LOCK):
13+
* heap/CodeBlockSet.h:
14+
(JSC::CodeBlockSet::WTF_RETURNS_LOCK):
15+
* heap/Heap.h:
16+
* heap/MarkedSpace.h:
17+
(JSC::MarkedSpace::directoryLock):
18+
* heap/MarkingConstraintSolver.h:
19+
* heap/SlotVisitor.cpp:
20+
(JSC::SlotVisitor::donateKnownParallel):
21+
* heap/SlotVisitor.h:
22+
* jit/JITWorklist.cpp:
23+
* jit/JITWorklist.h:
24+
* jsc.cpp:
25+
* profiler/ProfilerDatabase.h:
26+
* runtime/DeferredWorkTimer.h:
27+
* runtime/VMTraps.cpp:
28+
(JSC::VMTraps::invalidateCodeBlocksOnStack):
29+
* runtime/VMTraps.h:
30+
* tools/FunctionOverrides.cpp:
31+
(JSC::FunctionOverrides::FunctionOverrides):
32+
(JSC::FunctionOverrides::reinstallOverrides):
33+
(JSC::FunctionOverrides::parseOverridesInFile):
34+
* tools/FunctionOverrides.h:
35+
(JSC::FunctionOverrides::WTF_REQUIRES_LOCK):
36+
* tools/VMInspector.cpp:
37+
(JSC::ensureIsSafeToLock):
38+
(JSC::VMInspector::codeBlockForMachinePC):
39+
* wasm/WasmBBQPlan.cpp:
40+
(JSC::Wasm::BBQPlan::work):
41+
(JSC::Wasm::BBQPlan::compileFunction):
42+
(JSC::Wasm::BBQPlan::didCompleteCompilation):
43+
* wasm/WasmBBQPlan.h:
44+
* wasm/WasmEntryPlan.cpp:
45+
(JSC::Wasm::EntryPlan::parseAndValidateModule):
46+
(JSC::Wasm::EntryPlan::prepare):
47+
(JSC::Wasm::EntryPlan::ThreadCountHolder::~ThreadCountHolder):
48+
(JSC::Wasm::EntryPlan::complete):
49+
* wasm/WasmEntryPlan.h:
50+
(JSC::Wasm::EntryPlan::tryReserveCapacity):
51+
* wasm/WasmLLIntPlan.cpp:
52+
(JSC::Wasm::LLIntPlan::compileFunction):
53+
(JSC::Wasm::LLIntPlan::didCompleteCompilation):
54+
(JSC::Wasm::LLIntPlan::completeInStreaming):
55+
(JSC::Wasm::LLIntPlan::didFailInStreaming):
56+
* wasm/WasmLLIntPlan.h:
57+
* wasm/WasmOMGForOSREntryPlan.cpp:
58+
(JSC::Wasm::OMGForOSREntryPlan::work):
59+
* wasm/WasmOMGForOSREntryPlan.h:
60+
* wasm/WasmOMGPlan.cpp:
61+
(JSC::Wasm::OMGPlan::work):
62+
* wasm/WasmOMGPlan.h:
63+
* wasm/WasmPlan.cpp:
64+
(JSC::Wasm::Plan::runCompletionTasks):
65+
(JSC::Wasm::Plan::tryRemoveContextAndCancelIfLast):
66+
(JSC::Wasm::Plan::fail):
67+
* wasm/WasmPlan.h:
68+
* wasm/WasmStreamingCompiler.cpp:
69+
(JSC::Wasm::StreamingCompiler::didCompileFunction):
70+
(JSC::Wasm::StreamingCompiler::completeIfNecessary):
71+
(JSC::Wasm::StreamingCompiler::didComplete):
72+
(JSC::Wasm::StreamingCompiler::finalize):
73+
* wasm/WasmStreamingCompiler.h:
74+
* wasm/WasmStreamingPlan.cpp:
75+
(JSC::Wasm::StreamingPlan::work):
76+
* wasm/WasmStreamingPlan.h:
77+
* wasm/WasmThunks.h:
78+
179
2021-05-26 Chris Dumez <cdumez@apple.com>
280

381
Stop using UncheckedLock in WTF::AutomaticThread

‎Source/JavaScriptCore/heap/BlockDirectory.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class BlockDirectory {
9393

9494
void updatePercentageOfPagedOutPages(WTF::SimpleStats&);
9595

96-
UncheckedLock& bitvectorLock() { return m_bitvectorLock; }
96+
Lock& bitvectorLock() WTF_RETURNS_LOCK(m_bitvectorLock) { return m_bitvectorLock; }
9797

9898
#define BLOCK_DIRECTORY_BIT_ACCESSORS(lowerBitName, capitalBitName) \
9999
bool is ## capitalBitName(const AbstractLocker&, size_t index) const { return m_bits.is ## capitalBitName(index); } \
@@ -155,7 +155,7 @@ class BlockDirectory {
155155
// Mutator uses this to guard resizing the bitvectors. Those things in the GC that may run
156156
// concurrently to the mutator must lock this when accessing the bitvectors.
157157
BlockDirectoryBits m_bits;
158-
UncheckedLock m_bitvectorLock;
158+
Lock m_bitvectorLock;
159159
Lock m_localAllocatorsLock;
160160
CellAttributes m_attributes;
161161

‎Source/JavaScriptCore/heap/CodeBlockSet.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class CodeBlockSet {
5454
void clearCurrentlyExecuting();
5555

5656
bool contains(const AbstractLocker&, void* candidateCodeBlock);
57-
UncheckedLock& getLock() { return m_lock; }
57+
Lock& getLock() WTF_RETURNS_LOCK(m_lock) { return m_lock; }
5858

5959
// This is expected to run only when we're not adding to the set for now. If
6060
// this needs to run concurrently in the future, we'll need to lock around this.
@@ -78,7 +78,7 @@ class CodeBlockSet {
7878
private:
7979
HashSet<CodeBlock*> m_codeBlocks;
8080
HashSet<CodeBlock*> m_currentlyExecuting;
81-
UncheckedLock m_lock;
81+
Lock m_lock;
8282
};
8383

8484
} // namespace JSC

‎Source/JavaScriptCore/heap/Heap.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -716,8 +716,8 @@ class Heap {
716716
Atomic<unsigned> m_worldState;
717717
bool m_worldIsStopped { false };
718718
Lock m_visitRaceLock;
719-
UncheckedLock m_markingMutex;
720-
UncheckedCondition m_markingConditionVariable;
719+
Lock m_markingMutex;
720+
Condition m_markingConditionVariable;
721721

722722
MonotonicTime m_beforeGC;
723723
MonotonicTime m_afterGC;

‎Source/JavaScriptCore/heap/MarkedSpace.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ class MarkedSpace {
168168

169169
BlockDirectory* firstDirectory() const { return m_directories.first(); }
170170

171-
UncheckedLock& directoryLock() { return m_directoryLock; }
171+
Lock& directoryLock() { return m_directoryLock; }
172172
void addBlockDirectory(const AbstractLocker&, BlockDirectory*);
173173

174174
// When this is true it means that we have flipped but the mark bits haven't converged yet.
@@ -214,7 +214,7 @@ class MarkedSpace {
214214
HeapVersion m_newlyAllocatedVersion { initialVersion };
215215
bool m_isIterating { false };
216216
bool m_isMarking { false };
217-
UncheckedLock m_directoryLock;
217+
Lock m_directoryLock;
218218
MarkedBlockSet m_blocks;
219219

220220
SentinelLinkedList<WeakSet, BasicRawSentinelNode<WeakSet>> m_activeWeakSets;

‎Source/JavaScriptCore/heap/MarkingConstraintSolver.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ class MarkingConstraintSolver {
9595
BitVector m_executed;
9696
Deque<TaskWithConstraint, 32> m_toExecuteInParallel;
9797
Vector<unsigned, 32> m_toExecuteSequentially;
98-
UncheckedLock m_lock;
99-
UncheckedCondition m_condition;
98+
Lock m_lock;
99+
Condition m_condition;
100100
bool m_pickNextIsStillActive { true };
101101
unsigned m_numThreadsThatMayProduceWork { 0 };
102102
Vector<VisitCounter, 16> m_visitCounters;

‎Source/JavaScriptCore/heap/SlotVisitor.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,9 +436,9 @@ void SlotVisitor::donateKnownParallel(MarkStackArray& from, MarkStackArray& to)
436436

437437
// If we're contending on the lock, be conservative and assume that another
438438
// thread is already donating.
439-
std::unique_lock<UncheckedLock> lock(m_heap.m_markingMutex, std::try_to_lock);
440-
if (!lock.owns_lock())
439+
if (!m_heap.m_markingMutex.tryLock())
441440
return;
441+
Locker locker { AdoptLock, m_heap.m_markingMutex };
442442

443443
// Otherwise, assume that a thread will go idle soon, and donate.
444444
from.donateSomeCellsTo(to);

‎Source/JavaScriptCore/heap/SlotVisitor.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ class SlotVisitor final : public AbstractSlotVisitor {
161161

162162
bool mutatorIsStopped() const final { return m_mutatorIsStopped; }
163163

164-
UncheckedLock& rightToRun() { return m_rightToRun; }
164+
Lock& rightToRun() WTF_RETURNS_LOCK(m_rightToRun) { return m_rightToRun; }
165165

166166
void updateMutatorIsStopped(const AbstractLocker&);
167167
void updateMutatorIsStopped();
@@ -232,7 +232,7 @@ class SlotVisitor final : public AbstractSlotVisitor {
232232
bool m_mutatorIsStopped { false };
233233
bool m_canOptimizeForStoppedMutator { false };
234234
bool m_isInParallelMode { false };
235-
UncheckedLock m_rightToRun;
235+
Lock m_rightToRun;
236236

237237
// Put padding here to mitigate false sharing between multiple SlotVisitors.
238238
char padding[64];

‎Source/JavaScriptCore/jit/JITWorklist.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,14 @@ size_t JITWorklist::queueLength(const AbstractLocker&) const
109109
return queueLength;
110110
}
111111

112-
void JITWorklist::suspendAllThreads()
112+
void JITWorklist::suspendAllThreads() WTF_IGNORES_THREAD_SAFETY_ANALYSIS
113113
{
114114
m_suspensionLock.lock();
115115
for (unsigned i = m_threads.size(); i--;)
116116
m_threads[i]->m_rightToRun.lock();
117117
}
118118

119-
void JITWorklist::resumeAllThreads()
119+
void JITWorklist::resumeAllThreads() WTF_IGNORES_THREAD_SAFETY_ANALYSIS
120120
{
121121
for (unsigned i = m_threads.size(); i--;)
122122
m_threads[i]->m_rightToRun.unlock();

‎Source/JavaScriptCore/jit/JITWorklist.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class JITWorklist {
118118
// be completed.
119119
Vector<RefPtr<JITPlan>, 16> m_readyPlans;
120120

121-
UncheckedLock m_suspensionLock;
121+
Lock m_suspensionLock;
122122
Box<Lock> m_lock;
123123

124124
Ref<AutomaticThreadCondition> m_planEnqueued;

0 commit comments

Comments
 (0)