]>
Commit | Line | Data |
---|---|---|
6fe7ccc8 | 1 | /* |
ed1e77d3 | 2 | * Copyright (C) 2011-2015 Apple Inc. All rights reserved. |
6fe7ccc8 A |
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 CodeOrigin_h | |
27 | #define CodeOrigin_h | |
28 | ||
93a37866 A |
29 | #include "CodeBlockHash.h" |
30 | #include "CodeSpecializationKind.h" | |
6fe7ccc8 A |
31 | #include "ValueRecovery.h" |
32 | #include "WriteBarrier.h" | |
93a37866 | 33 | #include <wtf/BitVector.h> |
81345200 | 34 | #include <wtf/HashMap.h> |
93a37866 | 35 | #include <wtf/PrintStream.h> |
6fe7ccc8 A |
36 | #include <wtf/StdLibExtras.h> |
37 | #include <wtf/Vector.h> | |
38 | ||
39 | namespace JSC { | |
40 | ||
41 | struct InlineCallFrame; | |
93a37866 | 42 | class ExecState; |
81345200 | 43 | class ScriptExecutable; |
6fe7ccc8 A |
44 | class JSFunction; |
45 | ||
46 | struct CodeOrigin { | |
81345200 | 47 | static const unsigned invalidBytecodeIndex = UINT_MAX; |
93a37866 | 48 | |
81345200 A |
49 | // Bytecode offset that you'd use to re-execute this instruction, and the |
50 | // bytecode index of the bytecode instruction that produces some result that | |
51 | // you're interested in (used for mapping Nodes whose values you're using | |
52 | // to bytecode instructions that have the appropriate value profile). | |
53 | unsigned bytecodeIndex; | |
6fe7ccc8 A |
54 | |
55 | InlineCallFrame* inlineCallFrame; | |
56 | ||
57 | CodeOrigin() | |
81345200 | 58 | : bytecodeIndex(invalidBytecodeIndex) |
6fe7ccc8 A |
59 | , inlineCallFrame(0) |
60 | { | |
61 | } | |
62 | ||
81345200 A |
63 | CodeOrigin(WTF::HashTableDeletedValueType) |
64 | : bytecodeIndex(invalidBytecodeIndex) | |
65 | , inlineCallFrame(deletedMarker()) | |
66 | { | |
67 | } | |
68 | ||
69 | explicit CodeOrigin(unsigned bytecodeIndex, InlineCallFrame* inlineCallFrame = 0) | |
6fe7ccc8 | 70 | : bytecodeIndex(bytecodeIndex) |
6fe7ccc8 A |
71 | , inlineCallFrame(inlineCallFrame) |
72 | { | |
81345200 | 73 | ASSERT(bytecodeIndex < invalidBytecodeIndex); |
6fe7ccc8 A |
74 | } |
75 | ||
81345200 A |
76 | bool isSet() const { return bytecodeIndex != invalidBytecodeIndex; } |
77 | bool operator!() const { return !isSet(); } | |
6fe7ccc8 | 78 | |
81345200 | 79 | bool isHashTableDeletedValue() const |
6fe7ccc8 | 80 | { |
81345200 | 81 | return bytecodeIndex == invalidBytecodeIndex && !!inlineCallFrame; |
6fe7ccc8 A |
82 | } |
83 | ||
84 | // The inline depth is the depth of the inline stack, so 1 = not inlined, | |
85 | // 2 = inlined one deep, etc. | |
86 | unsigned inlineDepth() const; | |
87 | ||
88 | // If the code origin corresponds to inlined code, gives you the heap object that | |
89 | // would have owned the code if it had not been inlined. Otherwise returns 0. | |
81345200 | 90 | ScriptExecutable* codeOriginOwner() const; |
6fe7ccc8 | 91 | |
81345200 | 92 | int stackOffset() const; |
93a37866 | 93 | |
6fe7ccc8 A |
94 | static unsigned inlineDepthForCallFrame(InlineCallFrame*); |
95 | ||
81345200 | 96 | unsigned hash() const; |
6fe7ccc8 | 97 | bool operator==(const CodeOrigin& other) const; |
6fe7ccc8 A |
98 | bool operator!=(const CodeOrigin& other) const { return !(*this == other); } |
99 | ||
81345200 A |
100 | // This checks if the two code origins correspond to the same stack trace snippets, |
101 | // but ignore whether the InlineCallFrame's are identical. | |
102 | bool isApproximatelyEqualTo(const CodeOrigin& other) const; | |
103 | ||
104 | unsigned approximateHash() const; | |
105 | ||
6fe7ccc8 A |
106 | // Get the inline stack. This is slow, and is intended for debugging only. |
107 | Vector<CodeOrigin> inlineStack() const; | |
93a37866 A |
108 | |
109 | void dump(PrintStream&) const; | |
81345200 A |
110 | void dumpInContext(PrintStream&, DumpContext*) const; |
111 | ||
112 | private: | |
113 | static InlineCallFrame* deletedMarker() | |
114 | { | |
115 | return bitwise_cast<InlineCallFrame*>(static_cast<uintptr_t>(1)); | |
116 | } | |
6fe7ccc8 A |
117 | }; |
118 | ||
119 | struct InlineCallFrame { | |
ed1e77d3 A |
120 | enum Kind { |
121 | Call, | |
122 | Construct, | |
123 | CallVarargs, | |
124 | ConstructVarargs, | |
125 | ||
126 | // For these, the stackOffset incorporates the argument count plus the true return PC | |
127 | // slot. | |
128 | GetterCall, | |
129 | SetterCall | |
130 | }; | |
131 | ||
132 | static Kind kindFor(CodeSpecializationKind kind) | |
133 | { | |
134 | switch (kind) { | |
135 | case CodeForCall: | |
136 | return Call; | |
137 | case CodeForConstruct: | |
138 | return Construct; | |
139 | } | |
140 | RELEASE_ASSERT_NOT_REACHED(); | |
141 | return Call; | |
142 | } | |
143 | ||
144 | static Kind varargsKindFor(CodeSpecializationKind kind) | |
145 | { | |
146 | switch (kind) { | |
147 | case CodeForCall: | |
148 | return CallVarargs; | |
149 | case CodeForConstruct: | |
150 | return ConstructVarargs; | |
151 | } | |
152 | RELEASE_ASSERT_NOT_REACHED(); | |
153 | return Call; | |
154 | } | |
155 | ||
156 | static CodeSpecializationKind specializationKindFor(Kind kind) | |
157 | { | |
158 | switch (kind) { | |
159 | case Call: | |
160 | case CallVarargs: | |
161 | case GetterCall: | |
162 | case SetterCall: | |
163 | return CodeForCall; | |
164 | case Construct: | |
165 | case ConstructVarargs: | |
166 | return CodeForConstruct; | |
167 | } | |
168 | RELEASE_ASSERT_NOT_REACHED(); | |
169 | return CodeForCall; | |
170 | } | |
171 | ||
172 | static bool isVarargs(Kind kind) | |
173 | { | |
174 | switch (kind) { | |
175 | case CallVarargs: | |
176 | case ConstructVarargs: | |
177 | return true; | |
178 | default: | |
179 | return false; | |
180 | } | |
181 | } | |
182 | bool isVarargs() const | |
183 | { | |
184 | return isVarargs(static_cast<Kind>(kind)); | |
185 | } | |
186 | ||
81345200 A |
187 | Vector<ValueRecovery> arguments; // Includes 'this'. |
188 | WriteBarrier<ScriptExecutable> executable; | |
189 | ValueRecovery calleeRecovery; | |
6fe7ccc8 | 190 | CodeOrigin caller; |
ed1e77d3 A |
191 | |
192 | signed stackOffset : 28; | |
193 | unsigned kind : 3; // real type is Kind | |
81345200 | 194 | bool isClosureCall : 1; // If false then we know that callee/scope are constants and the DFG won't treat them as variables, i.e. they have to be recovered manually. |
ed1e77d3 | 195 | VirtualRegister argumentCountRegister; // Only set when we inline a varargs call. |
81345200 A |
196 | |
197 | // There is really no good notion of a "default" set of values for | |
198 | // InlineCallFrame's fields. This constructor is here just to reduce confusion if | |
199 | // we forgot to initialize explicitly. | |
200 | InlineCallFrame() | |
201 | : stackOffset(0) | |
ed1e77d3 | 202 | , kind(Call) |
81345200 A |
203 | , isClosureCall(false) |
204 | { | |
205 | } | |
93a37866 | 206 | |
ed1e77d3 | 207 | CodeSpecializationKind specializationKind() const { return specializationKindFor(static_cast<Kind>(kind)); } |
81345200 | 208 | |
ed1e77d3 A |
209 | JSFunction* calleeConstant() const; |
210 | void visitAggregate(SlotVisitor&); | |
93a37866 A |
211 | |
212 | // Get the callee given a machine call frame to which this InlineCallFrame belongs. | |
213 | JSFunction* calleeForCallFrame(ExecState*) const; | |
214 | ||
81345200 | 215 | CString inferredName() const; |
93a37866 | 216 | CodeBlockHash hash() const; |
81345200 | 217 | CString hashAsStringIfPossible() const; |
93a37866 A |
218 | |
219 | CodeBlock* baselineCodeBlock() const; | |
220 | ||
ed1e77d3 A |
221 | void setStackOffset(signed offset) |
222 | { | |
223 | stackOffset = offset; | |
224 | RELEASE_ASSERT(static_cast<signed>(stackOffset) == offset); | |
225 | } | |
226 | ||
81345200 A |
227 | ptrdiff_t callerFrameOffset() const { return stackOffset * sizeof(Register) + CallFrame::callerFrameOffset(); } |
228 | ptrdiff_t returnPCOffset() const { return stackOffset * sizeof(Register) + CallFrame::returnPCOffset(); } | |
229 | ||
93a37866 A |
230 | void dumpBriefFunctionInformation(PrintStream&) const; |
231 | void dump(PrintStream&) const; | |
81345200 | 232 | void dumpInContext(PrintStream&, DumpContext*) const; |
93a37866 A |
233 | |
234 | MAKE_PRINT_METHOD(InlineCallFrame, dumpBriefFunctionInformation, briefFunctionInformation); | |
6fe7ccc8 A |
235 | }; |
236 | ||
81345200 | 237 | inline int CodeOrigin::stackOffset() const |
6fe7ccc8 | 238 | { |
93a37866 A |
239 | if (!inlineCallFrame) |
240 | return 0; | |
241 | ||
242 | return inlineCallFrame->stackOffset; | |
6fe7ccc8 A |
243 | } |
244 | ||
81345200 A |
245 | inline unsigned CodeOrigin::hash() const |
246 | { | |
247 | return WTF::IntHash<unsigned>::hash(bytecodeIndex) + | |
248 | WTF::PtrHash<InlineCallFrame*>::hash(inlineCallFrame); | |
249 | } | |
250 | ||
6fe7ccc8 A |
251 | inline bool CodeOrigin::operator==(const CodeOrigin& other) const |
252 | { | |
253 | return bytecodeIndex == other.bytecodeIndex | |
254 | && inlineCallFrame == other.inlineCallFrame; | |
255 | } | |
256 | ||
81345200 | 257 | inline ScriptExecutable* CodeOrigin::codeOriginOwner() const |
6fe7ccc8 A |
258 | { |
259 | if (!inlineCallFrame) | |
260 | return 0; | |
261 | return inlineCallFrame->executable.get(); | |
262 | } | |
263 | ||
81345200 A |
264 | struct CodeOriginHash { |
265 | static unsigned hash(const CodeOrigin& key) { return key.hash(); } | |
266 | static bool equal(const CodeOrigin& a, const CodeOrigin& b) { return a == b; } | |
267 | static const bool safeToCompareToEmptyOrDeleted = true; | |
268 | }; | |
269 | ||
270 | struct CodeOriginApproximateHash { | |
271 | static unsigned hash(const CodeOrigin& key) { return key.approximateHash(); } | |
272 | static bool equal(const CodeOrigin& a, const CodeOrigin& b) { return a.isApproximatelyEqualTo(b); } | |
273 | static const bool safeToCompareToEmptyOrDeleted = true; | |
274 | }; | |
275 | ||
6fe7ccc8 A |
276 | } // namespace JSC |
277 | ||
81345200 A |
278 | namespace WTF { |
279 | ||
ed1e77d3 A |
280 | void printInternal(PrintStream&, JSC::InlineCallFrame::Kind); |
281 | ||
81345200 A |
282 | template<typename T> struct DefaultHash; |
283 | template<> struct DefaultHash<JSC::CodeOrigin> { | |
284 | typedef JSC::CodeOriginHash Hash; | |
285 | }; | |
286 | ||
287 | template<typename T> struct HashTraits; | |
288 | template<> struct HashTraits<JSC::CodeOrigin> : SimpleClassHashTraits<JSC::CodeOrigin> { | |
289 | static const bool emptyValueIsZero = false; | |
290 | }; | |
291 | ||
292 | } // namespace WTF | |
293 | ||
6fe7ccc8 A |
294 | #endif // CodeOrigin_h |
295 |