2 * Copyright (C) 2011, 2012, 2013 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.
29 #include "CodeBlockHash.h"
30 #include "CodeSpecializationKind.h"
31 #include "ValueRecovery.h"
32 #include "WriteBarrier.h"
33 #include <wtf/BitVector.h>
34 #include <wtf/PrintStream.h>
35 #include <wtf/StdLibExtras.h>
36 #include <wtf/Vector.h>
40 struct InlineCallFrame
;
46 static const unsigned maximumBytecodeIndex
= (1u << 29) - 1;
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;
54 InlineCallFrame
* inlineCallFrame
;
57 : bytecodeIndex(maximumBytecodeIndex
)
58 , valueProfileOffset(0)
63 explicit CodeOrigin(unsigned bytecodeIndex
, InlineCallFrame
* inlineCallFrame
= 0, unsigned valueProfileOffset
= 0)
64 : bytecodeIndex(bytecodeIndex
)
65 , valueProfileOffset(valueProfileOffset
)
66 , inlineCallFrame(inlineCallFrame
)
68 RELEASE_ASSERT(bytecodeIndex
<= maximumBytecodeIndex
);
69 RELEASE_ASSERT(valueProfileOffset
< (1u << 3));
72 bool isSet() const { return bytecodeIndex
!= maximumBytecodeIndex
; }
74 unsigned bytecodeIndexForValueProfile() const
76 return bytecodeIndex
+ valueProfileOffset
;
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;
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;
87 unsigned stackOffset() const;
89 static unsigned inlineDepthForCallFrame(InlineCallFrame
*);
91 bool operator==(const CodeOrigin
& other
) const;
93 bool operator!=(const CodeOrigin
& other
) const { return !(*this == other
); }
95 // Get the inline stack. This is slow, and is intended for debugging only.
96 Vector
<CodeOrigin
> inlineStack() const;
98 void dump(PrintStream
&) const;
101 struct InlineCallFrame
{
102 Vector
<ValueRecovery
> arguments
;
103 WriteBarrier
<ExecutableBase
> executable
;
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.
106 BitVector capturedVars
; // Indexed by the machine call frame's variable numbering.
107 unsigned stackOffset
: 31;
110 CodeSpecializationKind
specializationKind() const { return specializationFromIsCall(isCall
); }
112 bool isClosureCall() const { return !callee
; }
114 // Get the callee given a machine call frame to which this InlineCallFrame belongs.
115 JSFunction
* calleeForCallFrame(ExecState
*) const;
117 String
inferredName() const;
118 CodeBlockHash
hash() const;
120 CodeBlock
* baselineCodeBlock() const;
122 void dumpBriefFunctionInformation(PrintStream
&) const;
123 void dump(PrintStream
&) const;
125 MAKE_PRINT_METHOD(InlineCallFrame
, dumpBriefFunctionInformation
, briefFunctionInformation
);
128 struct CodeOriginAtCallReturnOffset
{
129 CodeOrigin codeOrigin
;
130 unsigned callReturnOffset
;
133 inline unsigned CodeOrigin::stackOffset() const
135 if (!inlineCallFrame
)
138 return inlineCallFrame
->stackOffset
;
141 inline bool CodeOrigin::operator==(const CodeOrigin
& other
) const
143 return bytecodeIndex
== other
.bytecodeIndex
144 && inlineCallFrame
== other
.inlineCallFrame
;
147 inline unsigned getCallReturnOffsetForCodeOrigin(CodeOriginAtCallReturnOffset
* data
)
149 return data
->callReturnOffset
;
152 inline ExecutableBase
* CodeOrigin::codeOriginOwner() const
154 if (!inlineCallFrame
)
156 return inlineCallFrame
->executable
.get();
161 #endif // CodeOrigin_h