]> git.saurik.com Git - apple/javascriptcore.git/blame_incremental - jit/JITCode.h
JavaScriptCore-7600.1.4.15.12.tar.gz
[apple/javascriptcore.git] / jit / JITCode.h
... / ...
CommitLineData
1/*
2 * Copyright (C) 2008, 2012, 2013 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#ifndef JITCode_h
27#define JITCode_h
28
29#include "ArityCheckMode.h"
30#include "CallFrame.h"
31#include "Disassembler.h"
32#include "JITStubs.h"
33#include "JSCJSValue.h"
34#include "LegacyProfiler.h"
35#include "MacroAssemblerCodeRef.h"
36#include "RegisterPreservationMode.h"
37
38namespace JSC {
39
40namespace DFG {
41class CommonData;
42class JITCode;
43}
44namespace FTL {
45class ForOSREntryJITCode;
46class JITCode;
47}
48
49struct ProtoCallFrame;
50class VM;
51
52class JITCode : public ThreadSafeRefCounted<JITCode> {
53public:
54 typedef MacroAssemblerCodeRef CodeRef;
55 typedef MacroAssemblerCodePtr CodePtr;
56
57 enum JITType : uint8_t {
58 None,
59 HostCallThunk,
60 InterpreterThunk,
61 BaselineJIT,
62 DFGJIT,
63 FTLJIT
64 };
65
66 static JITType bottomTierJIT()
67 {
68 return BaselineJIT;
69 }
70
71 static JITType topTierJIT()
72 {
73 return FTLJIT;
74 }
75
76 static JITType nextTierJIT(JITType jitType)
77 {
78 switch (jitType) {
79 case BaselineJIT:
80 return DFGJIT;
81 case DFGJIT:
82 return FTLJIT;
83 default:
84 RELEASE_ASSERT_NOT_REACHED();
85 return None;
86 }
87 }
88
89 static bool isExecutableScript(JITType jitType)
90 {
91 switch (jitType) {
92 case None:
93 case HostCallThunk:
94 return false;
95 default:
96 return true;
97 }
98 }
99
100 static bool couldBeInterpreted(JITType jitType)
101 {
102 switch (jitType) {
103 case InterpreterThunk:
104 case BaselineJIT:
105 return true;
106 default:
107 return false;
108 }
109 }
110
111 static bool isJIT(JITType jitType)
112 {
113 switch (jitType) {
114 case BaselineJIT:
115 case DFGJIT:
116 case FTLJIT:
117 return true;
118 default:
119 return false;
120 }
121 }
122
123 static bool isLowerTier(JITType expectedLower, JITType expectedHigher)
124 {
125 RELEASE_ASSERT(isExecutableScript(expectedLower));
126 RELEASE_ASSERT(isExecutableScript(expectedHigher));
127 return expectedLower < expectedHigher;
128 }
129
130 static bool isHigherTier(JITType expectedHigher, JITType expectedLower)
131 {
132 return isLowerTier(expectedLower, expectedHigher);
133 }
134
135 static bool isLowerOrSameTier(JITType expectedLower, JITType expectedHigher)
136 {
137 return !isHigherTier(expectedLower, expectedHigher);
138 }
139
140 static bool isHigherOrSameTier(JITType expectedHigher, JITType expectedLower)
141 {
142 return isLowerOrSameTier(expectedLower, expectedHigher);
143 }
144
145 static bool isOptimizingJIT(JITType jitType)
146 {
147 return jitType == DFGJIT || jitType == FTLJIT;
148 }
149
150 static bool isBaselineCode(JITType jitType)
151 {
152 return jitType == InterpreterThunk || jitType == BaselineJIT;
153 }
154
155protected:
156 JITCode(JITType);
157
158public:
159 virtual ~JITCode();
160
161 JITType jitType() const
162 {
163 return m_jitType;
164 }
165
166 template<typename PointerType>
167 static JITType jitTypeFor(PointerType jitCode)
168 {
169 if (!jitCode)
170 return None;
171 return jitCode->jitType();
172 }
173
174 virtual CodePtr addressForCall(VM&, ExecutableBase*, ArityCheckMode, RegisterPreservationMode) = 0;
175 virtual void* executableAddressAtOffset(size_t offset) = 0;
176 void* executableAddress() { return executableAddressAtOffset(0); }
177 virtual void* dataAddressAtOffset(size_t offset) = 0;
178 virtual unsigned offsetOf(void* pointerIntoCode) = 0;
179
180 virtual DFG::CommonData* dfgCommon();
181 virtual DFG::JITCode* dfg();
182 virtual FTL::JITCode* ftl();
183 virtual FTL::ForOSREntryJITCode* ftlForOSREntry();
184
185 JSValue execute(VM*, ProtoCallFrame*);
186
187 void* start() { return dataAddressAtOffset(0); }
188 virtual size_t size() = 0;
189 void* end() { return reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(start()) + size()); }
190
191 virtual bool contains(void*) = 0;
192
193private:
194 JITType m_jitType;
195};
196
197class JITCodeWithCodeRef : public JITCode {
198protected:
199 JITCodeWithCodeRef(JITType);
200 JITCodeWithCodeRef(CodeRef, JITType);
201
202public:
203 virtual ~JITCodeWithCodeRef();
204
205 virtual void* executableAddressAtOffset(size_t offset) override;
206 virtual void* dataAddressAtOffset(size_t offset) override;
207 virtual unsigned offsetOf(void* pointerIntoCode) override;
208 virtual size_t size() override;
209 virtual bool contains(void*) override;
210
211protected:
212 CodeRef m_ref;
213};
214
215class DirectJITCode : public JITCodeWithCodeRef {
216public:
217 DirectJITCode(JITType);
218 DirectJITCode(CodeRef, CodePtr withArityCheck, JITType);
219 virtual ~DirectJITCode();
220
221 void initializeCodeRef(CodeRef, CodePtr withArityCheck);
222
223 virtual CodePtr addressForCall(VM&, ExecutableBase*, ArityCheckMode, RegisterPreservationMode) override;
224
225private:
226 struct RegisterPreservationWrappers {
227 CodeRef withoutArityCheck;
228 CodeRef withArityCheck;
229 };
230
231 RegisterPreservationWrappers* ensureWrappers();
232
233 CodePtr m_withArityCheck;
234
235 std::unique_ptr<RegisterPreservationWrappers> m_wrappers;
236};
237
238class NativeJITCode : public JITCodeWithCodeRef {
239public:
240 NativeJITCode(JITType);
241 NativeJITCode(CodeRef, JITType);
242 virtual ~NativeJITCode();
243
244 void initializeCodeRef(CodeRef);
245
246 virtual CodePtr addressForCall(VM&, ExecutableBase*, ArityCheckMode, RegisterPreservationMode) override;
247};
248
249} // namespace JSC
250
251namespace WTF {
252
253class PrintStream;
254void printInternal(PrintStream&, JSC::JITCode::JITType);
255
256} // namespace WTF
257
258#endif