]>
Commit | Line | Data |
---|---|---|
6fe7ccc8 | 1 | /* |
93a37866 | 2 | * Copyright (C) 2011, 2012, 2013 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 A |
33 | #include <wtf/BitVector.h> |
34 | #include <wtf/PrintStream.h> | |
6fe7ccc8 A |
35 | #include <wtf/StdLibExtras.h> |
36 | #include <wtf/Vector.h> | |
37 | ||
38 | namespace JSC { | |
39 | ||
40 | struct InlineCallFrame; | |
93a37866 | 41 | class ExecState; |
6fe7ccc8 A |
42 | class ExecutableBase; |
43 | class JSFunction; | |
44 | ||
45 | struct CodeOrigin { | |
93a37866 A |
46 | static const unsigned maximumBytecodeIndex = (1u << 29) - 1; |
47 | ||
6fe7ccc8 A |
48 | // Bytecode offset that you'd use to re-execute this instruction. |
49 | unsigned bytecodeIndex : 29; | |
50 | // Bytecode offset corresponding to the opcode that gives the result (needed to handle | |
51 | // op_call/op_call_put_result and op_method_check/op_get_by_id). | |
52 | unsigned valueProfileOffset : 3; | |
53 | ||
54 | InlineCallFrame* inlineCallFrame; | |
55 | ||
56 | CodeOrigin() | |
93a37866 | 57 | : bytecodeIndex(maximumBytecodeIndex) |
6fe7ccc8 A |
58 | , valueProfileOffset(0) |
59 | , inlineCallFrame(0) | |
60 | { | |
61 | } | |
62 | ||
63 | explicit CodeOrigin(unsigned bytecodeIndex, InlineCallFrame* inlineCallFrame = 0, unsigned valueProfileOffset = 0) | |
64 | : bytecodeIndex(bytecodeIndex) | |
65 | , valueProfileOffset(valueProfileOffset) | |
66 | , inlineCallFrame(inlineCallFrame) | |
67 | { | |
93a37866 A |
68 | RELEASE_ASSERT(bytecodeIndex <= maximumBytecodeIndex); |
69 | RELEASE_ASSERT(valueProfileOffset < (1u << 3)); | |
6fe7ccc8 A |
70 | } |
71 | ||
93a37866 | 72 | bool isSet() const { return bytecodeIndex != maximumBytecodeIndex; } |
6fe7ccc8 A |
73 | |
74 | unsigned bytecodeIndexForValueProfile() const | |
75 | { | |
76 | return bytecodeIndex + valueProfileOffset; | |
77 | } | |
78 | ||
79 | // The inline depth is the depth of the inline stack, so 1 = not inlined, | |
80 | // 2 = inlined one deep, etc. | |
81 | unsigned inlineDepth() const; | |
82 | ||
83 | // If the code origin corresponds to inlined code, gives you the heap object that | |
84 | // would have owned the code if it had not been inlined. Otherwise returns 0. | |
85 | ExecutableBase* codeOriginOwner() const; | |
86 | ||
93a37866 A |
87 | unsigned stackOffset() const; |
88 | ||
6fe7ccc8 A |
89 | static unsigned inlineDepthForCallFrame(InlineCallFrame*); |
90 | ||
91 | bool operator==(const CodeOrigin& other) const; | |
92 | ||
93 | bool operator!=(const CodeOrigin& other) const { return !(*this == other); } | |
94 | ||
95 | // Get the inline stack. This is slow, and is intended for debugging only. | |
96 | Vector<CodeOrigin> inlineStack() const; | |
93a37866 A |
97 | |
98 | void dump(PrintStream&) const; | |
6fe7ccc8 A |
99 | }; |
100 | ||
101 | struct InlineCallFrame { | |
102 | Vector<ValueRecovery> arguments; | |
103 | WriteBarrier<ExecutableBase> executable; | |
93a37866 | 104 | WriteBarrier<JSFunction> callee; // This may be null, indicating that this is a closure call and that the JSFunction and JSScope are already on the stack. |
6fe7ccc8 | 105 | CodeOrigin caller; |
93a37866 | 106 | BitVector capturedVars; // Indexed by the machine call frame's variable numbering. |
6fe7ccc8 A |
107 | unsigned stackOffset : 31; |
108 | bool isCall : 1; | |
93a37866 A |
109 | |
110 | CodeSpecializationKind specializationKind() const { return specializationFromIsCall(isCall); } | |
111 | ||
112 | bool isClosureCall() const { return !callee; } | |
113 | ||
114 | // Get the callee given a machine call frame to which this InlineCallFrame belongs. | |
115 | JSFunction* calleeForCallFrame(ExecState*) const; | |
116 | ||
117 | String inferredName() const; | |
118 | CodeBlockHash hash() const; | |
119 | ||
120 | CodeBlock* baselineCodeBlock() const; | |
121 | ||
122 | void dumpBriefFunctionInformation(PrintStream&) const; | |
123 | void dump(PrintStream&) const; | |
124 | ||
125 | MAKE_PRINT_METHOD(InlineCallFrame, dumpBriefFunctionInformation, briefFunctionInformation); | |
6fe7ccc8 A |
126 | }; |
127 | ||
128 | struct CodeOriginAtCallReturnOffset { | |
129 | CodeOrigin codeOrigin; | |
130 | unsigned callReturnOffset; | |
131 | }; | |
132 | ||
93a37866 | 133 | inline unsigned CodeOrigin::stackOffset() const |
6fe7ccc8 | 134 | { |
93a37866 A |
135 | if (!inlineCallFrame) |
136 | return 0; | |
137 | ||
138 | return inlineCallFrame->stackOffset; | |
6fe7ccc8 A |
139 | } |
140 | ||
6fe7ccc8 A |
141 | inline bool CodeOrigin::operator==(const CodeOrigin& other) const |
142 | { | |
143 | return bytecodeIndex == other.bytecodeIndex | |
144 | && inlineCallFrame == other.inlineCallFrame; | |
145 | } | |
146 | ||
6fe7ccc8 A |
147 | inline unsigned getCallReturnOffsetForCodeOrigin(CodeOriginAtCallReturnOffset* data) |
148 | { | |
149 | return data->callReturnOffset; | |
150 | } | |
151 | ||
152 | inline ExecutableBase* CodeOrigin::codeOriginOwner() const | |
153 | { | |
154 | if (!inlineCallFrame) | |
155 | return 0; | |
156 | return inlineCallFrame->executable.get(); | |
157 | } | |
158 | ||
159 | } // namespace JSC | |
160 | ||
161 | #endif // CodeOrigin_h | |
162 |