source: webkit/trunk/Source/JavaScriptCore/jit/JITSafepoint.cpp

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

Drop UncheckedCondition / UncheckedLock
https://bugs.webkit.org/show_bug.cgi?id=226432

Reviewed by Darin Adler.

Source/JavaScriptCore:

Drop one remaining use of UncheckedLock in favor of Lock.

  • jit/JITSafepoint.cpp:
  • jit/JITWorklistThread.h:

Source/WTF:

Drop UncheckedCondition / UncheckedLock now that the whole codebase has been ported to
Condition / Lock, which support Clang thread safety analysis.

  • wtf/Condition.h:
  • wtf/Forward.h:
  • wtf/Lock.cpp:

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

  • wtf/Lock.h:

(WTF::assertIsHeld):
(WTF::WTF_ASSERTS_ACQUIRED_LOCK):

File size: 4.3 KB
Line 
1/*
2 * Copyright (C) 2014-2021 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#include "JITSafepoint.h"
28
29#if ENABLE(JIT)
30
31#include "JITPlan.h"
32#include "JITScannable.h"
33#include "JITWorklistThread.h"
34#include "SlotVisitor.h"
35
36namespace JSC {
37
38Safepoint::Result::~Result()
39{
40 RELEASE_ASSERT(m_wasChecked);
41}
42
43bool Safepoint::Result::didGetCancelled()
44{
45 m_wasChecked = true;
46 return m_didGetCancelled;
47}
48
49Safepoint::Safepoint(JITPlan& plan, Result& result)
50 : m_vm(plan.vm())
51 , m_plan(plan)
52 , m_didCallBegin(false)
53 , m_result(result)
54{
55 RELEASE_ASSERT(result.m_wasChecked);
56 result.m_wasChecked = false;
57 result.m_didGetCancelled = false;
58}
59
60Safepoint::~Safepoint()
61{
62 RELEASE_ASSERT(m_didCallBegin);
63 if (JITWorklistThread* thread = m_plan.thread()) {
64 RELEASE_ASSERT(thread->m_safepoint == this);
65 thread->m_rightToRun.lock();
66 thread->m_safepoint = nullptr;
67 }
68}
69
70void Safepoint::add(Scannable* scannable)
71{
72 RELEASE_ASSERT(!m_didCallBegin);
73 m_scannables.append(scannable);
74}
75
76void Safepoint::begin() WTF_IGNORES_THREAD_SAFETY_ANALYSIS
77{
78 RELEASE_ASSERT(!m_didCallBegin);
79 m_didCallBegin = true;
80 if (JITWorklistThread* data = m_plan.thread()) {
81 RELEASE_ASSERT(!data->m_safepoint);
82 data->m_safepoint = this;
83 data->m_rightToRun.unlockFairly();
84 }
85}
86
87template<typename Visitor>
88void Safepoint::checkLivenessAndVisitChildren(Visitor& visitor)
89{
90 RELEASE_ASSERT(m_didCallBegin);
91
92 if (m_result.m_didGetCancelled)
93 return; // We were cancelled during a previous GC!
94
95 if (!isKnownToBeLiveDuringGC(visitor))
96 return;
97
98 for (unsigned i = m_scannables.size(); i--;)
99 m_scannables[i]->visitChildren(visitor);
100}
101
102template void Safepoint::checkLivenessAndVisitChildren(AbstractSlotVisitor&);
103template void Safepoint::checkLivenessAndVisitChildren(SlotVisitor&);
104
105template<typename Visitor>
106bool Safepoint::isKnownToBeLiveDuringGC(Visitor& visitor)
107{
108 RELEASE_ASSERT(m_didCallBegin);
109
110 if (m_result.m_didGetCancelled)
111 return true; // We were cancelled during a previous GC, so let's not mess with it this time around - pretend it's live and move on.
112
113 return m_plan.isKnownToBeLiveDuringGC(visitor);
114}
115
116template bool Safepoint::isKnownToBeLiveDuringGC(AbstractSlotVisitor&);
117template bool Safepoint::isKnownToBeLiveDuringGC(SlotVisitor&);
118
119bool Safepoint::isKnownToBeLiveAfterGC()
120{
121 RELEASE_ASSERT(m_didCallBegin);
122
123 if (m_result.m_didGetCancelled)
124 return true; // We were cancelled during a previous GC, so let's not mess with it this time around - pretend it's live and move on.
125
126 return m_plan.isKnownToBeLiveAfterGC();
127}
128
129void Safepoint::cancel()
130{
131 RELEASE_ASSERT(m_didCallBegin);
132 RELEASE_ASSERT(!m_result.m_didGetCancelled); // We cannot get cancelled twice because subsequent GCs will think that we're alive and they will not do anything to us.
133
134 RELEASE_ASSERT(m_plan.stage() == JITPlanStage::Canceled);
135 m_result.m_didGetCancelled = true;
136 m_vm = nullptr;
137}
138
139VM* Safepoint::vm() const
140{
141 return m_vm;
142}
143
144} // namespace JSC
145
146#endif // ENABLE(JIT)
147
Note: See TracBrowser for help on using the repository browser.