]> git.saurik.com Git - apple/javascriptcore.git/blob - dfg/DFGSafepoint.cpp
JavaScriptCore-7600.1.4.9.tar.gz
[apple/javascriptcore.git] / dfg / DFGSafepoint.cpp
1 /*
2 * Copyright (C) 2014 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 "DFGSafepoint.h"
28
29 #if ENABLE(DFG_JIT)
30
31 #include "DFGPlan.h"
32 #include "DFGScannable.h"
33 #include "DFGThreadData.h"
34 #include "JSCInlines.h"
35
36 namespace JSC { namespace DFG {
37
38 Safepoint::Result::~Result()
39 {
40 RELEASE_ASSERT(m_wasChecked);
41 }
42
43 bool Safepoint::Result::didGetCancelled()
44 {
45 m_wasChecked = true;
46 return m_didGetCancelled;
47 }
48
49 Safepoint::Safepoint(Plan& plan, Result& result)
50 : m_plan(plan)
51 , m_didCallBegin(false)
52 , m_result(result)
53 {
54 RELEASE_ASSERT(result.m_wasChecked);
55 result.m_wasChecked = false;
56 result.m_didGetCancelled = false;
57 }
58
59 Safepoint::~Safepoint()
60 {
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;
66 }
67 }
68
69 void Safepoint::add(Scannable* scannable)
70 {
71 RELEASE_ASSERT(!m_didCallBegin);
72 m_scannables.append(scannable);
73 }
74
75 void Safepoint::begin()
76 {
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();
83 }
84 }
85
86 void Safepoint::checkLivenessAndVisitChildren(SlotVisitor& visitor)
87 {
88 RELEASE_ASSERT(m_didCallBegin);
89
90 if (m_result.m_didGetCancelled)
91 return; // We were cancelled during a previous GC!
92
93 if (!isKnownToBeLiveDuringGC())
94 return;
95
96 for (unsigned i = m_scannables.size(); i--;)
97 m_scannables[i]->visitChildren(visitor);
98 }
99
100 bool Safepoint::isKnownToBeLiveDuringGC()
101 {
102 RELEASE_ASSERT(m_didCallBegin);
103
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.
106
107 return m_plan.isKnownToBeLiveDuringGC();
108 }
109
110 void Safepoint::cancel()
111 {
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.
114
115 m_plan.cancel();
116 m_result.m_didGetCancelled = true;
117 }
118
119 VM& Safepoint::vm() const
120 {
121 return m_plan.vm;
122 }
123
124 } } // namespace JSC::DFG
125
126 #endif // ENABLE(DFG_JIT)
127