2 * Copyright (C) 2014 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)
51 , m_didCallBegin(false)
54 RELEASE_ASSERT(result.m_wasChecked);
55 result.m_wasChecked = false;
56 result.m_didGetCancelled = false;
59 Safepoint::~Safepoint()
61 RELEASE_ASSERT(m_didCallBegin);
62 if (ThreadData* data = m_plan.threadData) {
63 RELEASE_ASSERT(data->m_safepoint == this);
64 data->m_rightToRun.lock();
65 data->m_safepoint = nullptr;
69 void Safepoint::add(Scannable* scannable)
71 RELEASE_ASSERT(!m_didCallBegin);
72 m_scannables.append(scannable);
75 void Safepoint::begin()
77 RELEASE_ASSERT(!m_didCallBegin);
78 m_didCallBegin = true;
79 if (ThreadData* data = m_plan.threadData) {
80 RELEASE_ASSERT(!data->m_safepoint);
81 data->m_safepoint = this;
82 data->m_rightToRun.unlock();
86 void Safepoint::checkLivenessAndVisitChildren(SlotVisitor& visitor)
88 RELEASE_ASSERT(m_didCallBegin);
90 if (m_result.m_didGetCancelled)
91 return; // We were cancelled during a previous GC!
93 if (!isKnownToBeLiveDuringGC())
96 for (unsigned i = m_scannables.size(); i--;)
97 m_scannables[i]->visitChildren(visitor);
100 bool Safepoint::isKnownToBeLiveDuringGC()
102 RELEASE_ASSERT(m_didCallBegin);
104 if (m_result.m_didGetCancelled)
105 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.
107 return m_plan.isKnownToBeLiveDuringGC();
110 void Safepoint::cancel()
112 RELEASE_ASSERT(m_didCallBegin);
113 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.
116 m_result.m_didGetCancelled = true;
119 VM& Safepoint::vm() const
124 } } // namespace JSC::DFG
126 #endif // ENABLE(DFG_JIT)