2 * Copyright (C) 2014, 2016 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
27 #include "DFGSafepoint.h"
32 #include "DFGScannable.h"
33 #include "DFGThreadData.h"
34 #include "JSCInlines.h"
36 namespace JSC { namespace DFG {
38 Safepoint::Result::~Result()
40 RELEASE_ASSERT(m_wasChecked);
43 bool Safepoint::Result::didGetCancelled()
46 return m_didGetCancelled;
49 Safepoint::Safepoint(Plan& plan, Result& result)
52 , m_didCallBegin(false)
55 RELEASE_ASSERT(result.m_wasChecked);
56 result.m_wasChecked = false;
57 result.m_didGetCancelled = false;
60 Safepoint::~Safepoint()
62 RELEASE_ASSERT(m_didCallBegin);
63 if (ThreadData* data = m_plan.threadData) {
64 RELEASE_ASSERT(data->m_safepoint == this);
65 data->m_rightToRun.lock();
66 data->m_safepoint = nullptr;
70 void Safepoint::add(Scannable* scannable)
72 RELEASE_ASSERT(!m_didCallBegin);
73 m_scannables.append(scannable);
76 void Safepoint::begin()
78 RELEASE_ASSERT(!m_didCallBegin);
79 m_didCallBegin = true;
80 if (ThreadData* data = m_plan.threadData) {
81 RELEASE_ASSERT(!data->m_safepoint);
82 data->m_safepoint = this;
83 data->m_rightToRun.unlock();
87 void Safepoint::checkLivenessAndVisitChildren(SlotVisitor& visitor)
89 RELEASE_ASSERT(m_didCallBegin);
91 if (m_result.m_didGetCancelled)
92 return; // We were cancelled during a previous GC!
94 if (!isKnownToBeLiveDuringGC())
97 for (unsigned i = m_scannables.size(); i--;)
98 m_scannables[i]->visitChildren(visitor);
101 bool Safepoint::isKnownToBeLiveDuringGC()
103 RELEASE_ASSERT(m_didCallBegin);
105 if (m_result.m_didGetCancelled)
106 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.
108 return m_plan.isKnownToBeLiveDuringGC();
111 void Safepoint::cancel()
113 RELEASE_ASSERT(m_didCallBegin);
114 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.
117 m_result.m_didGetCancelled = true;
121 VM* Safepoint::vm() const
126 } } // namespace JSC::DFG
128 #endif // ENABLE(DFG_JIT)