source: webkit/trunk/Source/JavaScriptCore/dynbench.cpp@ 277943

Last change on this file since 277943 was 277943, checked in by Chris Dumez, 4 years ago

Make CheckedLock the default Lock
https://bugs.webkit.org/show_bug.cgi?id=226157

Reviewed by Darin Adler.

Make CheckedLock the default Lock so that we get more benefits from Clang
Thread Safety Analysis. Note that CheckedLock 100% relies on the existing
Source/JavaScriptCore:

Lock implementation and merely adds the clang anotations for thread
safety.

That this patch does is:

  1. Rename the Lock class to UncheckedLock
  2. Rename the CheckedLock class to Lock
  3. Rename the Condition class to UncheckedCondition
  4. Rename the CheckedCondition class to Condition
  5. Update the types of certain variables from Lock / Condition to UncheckedLock / UncheckedCondition if I got a build failure. Build failures are usually caused by the following facts:
    • Locker<CheckedLock> doesn't subclass AbstractLocker which a lot of JSC code passes as argument
    • Locker<CheckedLock> has no move constructor
    • Locker<CheckedLock> cannot be constructed from a lock pointer, only a reference

For now, CheckedLock and CheckedCondition remain as aliases to Lock and
Condition, in their respective CheckedLock.h / CheckedCondition.h headers.
I will drop them in a follow-up to reduce patch size.

I will also follow-up to try and get rid of as much usage of UncheckedLock
and UncheckedCondition as possible. I did not try very hard in this patch
to reduce patch size.

  • assembler/testmasm.cpp:
  • dfg/DFGCommon.cpp:
  • dfg/DFGThreadData.h:
  • dfg/DFGWorklist.cpp:

(JSC::DFG::Worklist::Worklist):

  • dfg/DFGWorklist.h:
  • dynbench.cpp:
  • heap/BlockDirectory.h:

(JSC::BlockDirectory::bitvectorLock):

  • heap/CodeBlockSet.h:

(JSC::CodeBlockSet::getLock):

  • heap/Heap.cpp:

(JSC::Heap::Heap):

  • heap/Heap.h:
  • heap/MarkedSpace.h:

(JSC::MarkedSpace::directoryLock):

  • heap/MarkingConstraintSolver.h:
  • heap/SlotVisitor.cpp:

(JSC::SlotVisitor::donateKnownParallel):

  • heap/SlotVisitor.h:
  • jit/ExecutableAllocator.cpp:

(JSC::ExecutableAllocator::getLock const):
(JSC::dumpJITMemory):

  • jit/ExecutableAllocator.h:

(JSC::ExecutableAllocatorBase::getLock const):

  • jit/JITWorklist.cpp:

(JSC::JITWorklist::JITWorklist):

  • jit/JITWorklist.h:
  • jsc.cpp:
  • profiler/ProfilerDatabase.h:
  • runtime/ConcurrentJSLock.h:
  • runtime/DeferredWorkTimer.h:
  • runtime/JSLock.h:
  • runtime/SamplingProfiler.cpp:

(JSC::FrameWalker::FrameWalker):
(JSC::CFrameWalker::CFrameWalker):
(JSC::SamplingProfiler::takeSample):

  • runtime/SamplingProfiler.h:

(JSC::SamplingProfiler::getLock):

  • runtime/VM.h:
  • runtime/VMTraps.cpp:

(JSC::VMTraps::invalidateCodeBlocksOnStack):
(JSC::VMTraps::VMTraps):

  • runtime/VMTraps.h:
  • tools/FunctionOverrides.h:
  • tools/VMInspector.cpp:

(JSC::ensureIsSafeToLock):

  • tools/VMInspector.h:

(JSC::VMInspector::getLock):

  • wasm/WasmCalleeRegistry.h:

(JSC::Wasm::CalleeRegistry::getLock):

  • wasm/WasmPlan.h:
  • wasm/WasmStreamingCompiler.h:
  • wasm/WasmThunks.h:
  • wasm/WasmWorklist.cpp:

(JSC::Wasm::Worklist::Worklist):

  • wasm/WasmWorklist.h:

Source/WebCore:

Lock implementation and merely adds the clang anotations for thread
safety.

That this patch does is:

  1. Rename the Lock class to UncheckedLock
  2. Rename the CheckedLock class to Lock
  3. Rename the Condition class to UncheckedCondition
  4. Rename the CheckedCondition class to Condition
  5. Update the types of certain variables from Lock / Condition to UncheckedLock / UncheckedCondition if I got a build failure. Build failures are usually caused by the following facts:
    • Locker<CheckedLock> doesn't subclass AbstractLocker which a lot of JSC code passes as argument
    • Locker<CheckedLock> has no move constructor
    • Locker<CheckedLock> cannot be constructed from a lock pointer, only a reference

For now, CheckedLock and CheckedCondition remain as aliases to Lock and
Condition, in their respective CheckedLock.h / CheckedCondition.h headers.
I will drop them in a follow-up to reduce patch size.

I will also follow-up to try and get rid of as much usage of UncheckedLock
and UncheckedCondition as possible. I did not try very hard in this patch
to reduce patch size.

  • Modules/indexeddb/server/IDBServer.cpp:
  • Modules/webaudio/MediaElementAudioSourceNode.h:
  • Modules/webdatabase/OriginLock.cpp:
  • bindings/js/JSDOMGlobalObject.h:
  • dom/Node.cpp:
  • html/HTMLMediaElement.cpp:

(WebCore::HTMLMediaElement::createMediaPlayer):

  • html/canvas/WebGLContextGroup.cpp:

(WebCore::WebGLContextGroup::objectGraphLockForAContext):

  • html/canvas/WebGLContextGroup.h:
  • html/canvas/WebGLContextObject.cpp:

(WebCore::WebGLContextObject::objectGraphLockForContext):

  • html/canvas/WebGLContextObject.h:
  • html/canvas/WebGLObject.h:
  • html/canvas/WebGLRenderingContextBase.cpp:

(WebCore::WebGLRenderingContextBase::objectGraphLock):

  • html/canvas/WebGLRenderingContextBase.h:
  • html/canvas/WebGLSharedObject.cpp:

(WebCore::WebGLSharedObject::objectGraphLockForContext):

  • html/canvas/WebGLSharedObject.h:
  • page/scrolling/mac/ScrollingTreeMac.h:
  • platform/audio/ReverbConvolver.cpp:

(WebCore::ReverbConvolver::backgroundThreadEntry):

  • platform/graphics/ShadowBlur.cpp:

(WebCore::ScratchBuffer::lock):
(WebCore::ShadowBlur::drawRectShadowWithTiling):
(WebCore::ShadowBlur::drawInsetShadowWithTiling):

  • platform/graphics/gstreamer/VideoSinkGStreamer.cpp:
  • platform/graphics/gstreamer/eme/WebKitCommonEncryptionDecryptorGStreamer.cpp:

Source/WebKit:

Lock implementation and merely adds the clang anotations for thread
safety.

That this patch does is:

  1. Rename the Lock class to UncheckedLock
  2. Rename the CheckedLock class to Lock
  3. Rename the Condition class to UncheckedCondition
  4. Rename the CheckedCondition class to Condition
  5. Update the types of certain variables from Lock / Condition to UncheckedLock / UncheckedCondition if I got a build failure. Build failures are usually caused by the following facts:
    • Locker<CheckedLock> doesn't subclass AbstractLocker which a lot of JSC code passes as argument
    • Locker<CheckedLock> has no move constructor
    • Locker<CheckedLock> cannot be constructed from a lock pointer, only a reference

For now, CheckedLock and CheckedCondition remain as aliases to Lock and
Condition, in their respective CheckedLock.h / CheckedCondition.h headers.
I will drop them in a follow-up to reduce patch size.

I will also follow-up to try and get rid of as much usage of UncheckedLock
and UncheckedCondition as possible. I did not try very hard in this patch
to reduce patch size.

  • GPUProcess/graphics/RemoteGraphicsContextGL.cpp:

(WebKit::RemoteGraphicsContextGL::paintPixelBufferToImageBuffer):

  • NetworkProcess/IndexedDB/WebIDBServer.cpp:
  • UIProcess/API/glib/IconDatabase.h:
  • UIProcess/mac/WKPrintingView.mm:

(-[WKPrintingView knowsPageRange:]):

Source/WTF:

Lock implementation and merely adds the clang anotations for thread
safety.

That this patch does is:

  1. Rename the Lock class to UncheckedLock
  2. Rename the CheckedLock class to Lock
  3. Rename the Condition class to UncheckedCondition
  4. Rename the CheckedCondition class to Condition
  5. Update the types of certain variables from Lock / Condition to UncheckedLock / UncheckedCondition if I got a build failure. Build failures are usually caused by the following facts:
    • Locker<CheckedLock> doesn't subclass AbstractLocker which a lot of JSC code passes as argument
    • Locker<CheckedLock> has no move constructor
    • Locker<CheckedLock> cannot be constructed from a lock pointer, only a reference

For now, CheckedLock and CheckedCondition remain as aliases to Lock and
Condition, in their respective CheckedLock.h / CheckedCondition.h headers.
I will drop them in a follow-up to reduce patch size.

I will also follow-up to try and get rid of as much usage of UncheckedLock
and UncheckedCondition as possible. I did not try very hard in this patch
to reduce patch size.

  • wtf/AutomaticThread.cpp:

(WTF::AutomaticThreadCondition::wait):
(WTF::AutomaticThreadCondition::waitFor):
(WTF::AutomaticThread::AutomaticThread):

  • wtf/AutomaticThread.h:
  • wtf/CheckedCondition.h:
  • wtf/CheckedLock.h:
  • wtf/Condition.h:
  • wtf/Lock.cpp:

(WTF::UncheckedLock::lockSlow):
(WTF::UncheckedLock::unlockSlow):
(WTF::UncheckedLock::unlockFairlySlow):
(WTF::UncheckedLock::safepointSlow):

  • wtf/Lock.h:

(WTF::WTF_ASSERTS_ACQUIRED_LOCK):

  • wtf/MetaAllocator.cpp:

(WTF::MetaAllocator::release):
(WTF::MetaAllocator::MetaAllocator):
(WTF::MetaAllocator::allocate):
(WTF::MetaAllocator::currentStatistics):

  • wtf/MetaAllocator.h:
  • wtf/ParallelHelperPool.cpp:

(WTF::ParallelHelperPool::ParallelHelperPool):

  • wtf/ParallelHelperPool.h:
  • wtf/RecursiveLockAdapter.h:
  • wtf/WorkerPool.cpp:

(WTF::WorkerPool::WorkerPool):

  • wtf/WorkerPool.h:

Tools:

Lock implementation and merely adds the clang anotations for thread
safety.

That this patch does is:

  1. Rename the Lock class to UncheckedLock
  2. Rename the CheckedLock class to Lock
  3. Rename the Condition class to UncheckedCondition
  4. Rename the CheckedCondition class to Condition
  5. Update the types of certain variables from Lock / Condition to UncheckedLock / UncheckedCondition if I got a build failure. Build failures are usually caused by the following facts:
    • Locker<CheckedLock> doesn't subclass AbstractLocker which a lot of JSC code passes as argument
    • Locker<CheckedLock> has no move constructor
    • Locker<CheckedLock> cannot be constructed from a lock pointer, only a reference

For now, CheckedLock and CheckedCondition remain as aliases to Lock and
Condition, in their respective CheckedLock.h / CheckedCondition.h headers.
I will drop them in a follow-up to reduce patch size.

I will also follow-up to try and get rid of as much usage of UncheckedLock
and UncheckedCondition as possible. I did not try very hard in this patch
to reduce patch size.

  • TestWebKitAPI/Tests/WTF/CheckedConditionTest.cpp:
  • TestWebKitAPI/Tests/WTF/Condition.cpp:
  • TestWebKitAPI/Tests/WTF/MetaAllocator.cpp:
  • WebKitTestRunner/InjectedBundle/AccessibilityController.cpp:

(WTR::AXThread::createThreadIfNeeded):

File size: 9.2 KB
Line 
1/*
2 * Copyright (C) 2015-2019 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#include "config.h"
27
28#include "Identifier.h"
29#include "InitializeThreading.h"
30#include "JSCInlines.h"
31#include "JSCJSValue.h"
32#include "JSGlobalObject.h"
33#include "JSLock.h"
34#include "JSObject.h"
35#include "VM.h"
36#include <wtf/MainThread.h>
37#include <wtf/text/StringCommon.h>
38
39using namespace JSC;
40
41namespace {
42
43UncheckedLock crashLock;
44const char* nameFilter;
45unsigned requestedIterationCount;
46
47#define CHECK(x) do { \
48 if (!!(x)) \
49 break; \
50 crashLock.lock(); \
51 WTFReportAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, #x); \
52 CRASH(); \
53 } while (false)
54
55template<typename Callback>
56NEVER_INLINE void benchmarkImpl(const char* name, unsigned iterationCount, const Callback& callback)
57{
58 if (nameFilter && WTF::findIgnoringASCIICaseWithoutLength(name, nameFilter) == WTF::notFound)
59 return;
60
61 if (requestedIterationCount)
62 iterationCount = requestedIterationCount;
63
64 MonotonicTime before = MonotonicTime::now();
65 callback(iterationCount);
66 MonotonicTime after = MonotonicTime::now();
67 dataLog(name, ": ", (after - before).milliseconds(), " ms.\n");
68}
69
70} // anonymous namespace
71
72int main(int argc, char** argv)
73{
74 if (argc >= 2) {
75 if (argv[1][0] == '-') {
76 dataLog("Usage: dynbench [<filter> [<iteration count>]]\n");
77 return 1;
78 }
79
80 nameFilter = argv[1];
81
82 if (argc >= 3) {
83 if (sscanf(argv[2], "%u", &requestedIterationCount) != 1) {
84 dataLog("Could not parse iteration count ", argv[2], "\n");
85 return 1;
86 }
87 }
88 }
89
90 WTF::initializeMainThread();
91 JSC::initialize();
92
93 VM& vm = VM::create(LargeHeap).leakRef();
94 {
95 JSLockHolder locker(vm);
96
97 JSGlobalObject* globalObject =
98 JSGlobalObject::create(vm, JSGlobalObject::createStructure(vm, jsNull()));
99
100 Identifier identF = Identifier::fromString(vm, "f");
101 Identifier identG = Identifier::fromString(vm, "g");
102
103 Structure* objectStructure =
104 JSFinalObject::createStructure(vm, globalObject, globalObject->objectPrototype(), 2);
105
106 // Non-strict dynamic get by id:
107 JSValue object = JSFinalObject::create(vm, objectStructure);
108 {
109 PutPropertySlot slot(object, false, PutPropertySlot::PutById);
110 object.putInline(globalObject, identF, jsNumber(42), slot);
111 }
112 {
113 PutPropertySlot slot(object, false, PutPropertySlot::PutById);
114 object.putInline(globalObject, identG, jsNumber(43), slot);
115 }
116 benchmarkImpl(
117 "Non Strict Dynamic Get By Id",
118 1000000,
119 [&] (unsigned iterationCount) {
120 for (unsigned i = iterationCount; i--;) {
121 JSValue result = object.get(globalObject, identF);
122 CHECK(result == jsNumber(42));
123 result = object.get(globalObject, identG);
124 CHECK(result == jsNumber(43));
125 }
126 });
127
128 // Non-strict dynamic put by id replace:
129 object = JSFinalObject::create(vm, objectStructure);
130 {
131 PutPropertySlot slot(object, false, PutPropertySlot::PutById);
132 object.putInline(globalObject, identF, jsNumber(42), slot);
133 }
134 {
135 PutPropertySlot slot(object, false, PutPropertySlot::PutById);
136 object.putInline(globalObject, identG, jsNumber(43), slot);
137 }
138 benchmarkImpl(
139 "Non Strict Dynamic Put By Id Replace",
140 1000000,
141 [&] (unsigned iterationCount) {
142 for (unsigned i = iterationCount; i--;) {
143 {
144 PutPropertySlot slot(object, false, PutPropertySlot::PutById);
145 object.putInline(globalObject, identF, jsNumber(i), slot);
146 }
147 {
148 PutPropertySlot slot(object, false, PutPropertySlot::PutById);
149 object.putInline(globalObject, identG, jsNumber(i), slot);
150 }
151 }
152 });
153
154 // Non-strict dynamic put by id transition with object allocation:
155 benchmarkImpl(
156 "Non Strict Dynamic Allocation and Put By Id Transition",
157 1000000,
158 [&] (unsigned iterationCount) {
159 for (unsigned i = iterationCount; i--;) {
160 JSValue object = JSFinalObject::create(vm, objectStructure);
161 {
162 PutPropertySlot slot(object, false, PutPropertySlot::PutById);
163 object.putInline(globalObject, identF, jsNumber(i), slot);
164 }
165 {
166 PutPropertySlot slot(object, false, PutPropertySlot::PutById);
167 object.putInline(globalObject, identG, jsNumber(i), slot);
168 }
169 }
170 });
171
172 // Non-strict dynamic get by id with dynamic store context:
173 object = JSFinalObject::create(vm, objectStructure);
174 {
175 PutPropertySlot slot(object, false);
176 object.putInline(globalObject, identF, jsNumber(42), slot);
177 }
178 {
179 PutPropertySlot slot(object, false);
180 object.putInline(globalObject, identG, jsNumber(43), slot);
181 }
182 benchmarkImpl(
183 "Non Strict Dynamic Get By Id With Dynamic Store Context",
184 1000000,
185 [&] (unsigned iterationCount) {
186 for (unsigned i = iterationCount; i--;) {
187 JSValue result = object.get(globalObject, identF);
188 CHECK(result == jsNumber(42));
189 result = object.get(globalObject, identG);
190 CHECK(result == jsNumber(43));
191 }
192 });
193
194 // Non-strict dynamic put by id replace with dynamic store context:
195 object = JSFinalObject::create(vm, objectStructure);
196 {
197 PutPropertySlot slot(object, false);
198 object.putInline(globalObject, identF, jsNumber(42), slot);
199 }
200 {
201 PutPropertySlot slot(object, false);
202 object.putInline(globalObject, identG, jsNumber(43), slot);
203 }
204 benchmarkImpl(
205 "Non Strict Dynamic Put By Id Replace With Dynamic Store Context",
206 1000000,
207 [&] (unsigned iterationCount) {
208 for (unsigned i = iterationCount; i--;) {
209 {
210 PutPropertySlot slot(object, false);
211 object.putInline(globalObject, identF, jsNumber(i), slot);
212 }
213 {
214 PutPropertySlot slot(object, false);
215 object.putInline(globalObject, identG, jsNumber(i), slot);
216 }
217 }
218 });
219
220 // Non-strict dynamic put by id transition with object allocation with dynamic store context:
221 benchmarkImpl(
222 "Non Strict Dynamic Allocation and Put By Id Transition With Dynamic Store Context",
223 1000000,
224 [&] (unsigned iterationCount) {
225 for (unsigned i = iterationCount; i--;) {
226 JSValue object = JSFinalObject::create(vm, objectStructure);
227 {
228 PutPropertySlot slot(object, false);
229 object.putInline(globalObject, identF, jsNumber(i), slot);
230 }
231 {
232 PutPropertySlot slot(object, false);
233 object.putInline(globalObject, identG, jsNumber(i), slot);
234 }
235 }
236 });
237 }
238
239 crashLock.lock();
240 return 0;
241}
242
Note: See TracBrowser for help on using the repository browser.