]>
git.saurik.com Git - apple/javascriptcore.git/blob - bytecode/CodeOrigin.cpp
2 * Copyright (C) 2012-2015 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.
27 #include "CodeOrigin.h"
29 #include "CallFrame.h"
30 #include "CodeBlock.h"
31 #include "Executable.h"
32 #include "JSCInlines.h"
36 unsigned CodeOrigin::inlineDepthForCallFrame(InlineCallFrame
* inlineCallFrame
)
39 for (InlineCallFrame
* current
= inlineCallFrame
; current
; current
= current
->caller
.inlineCallFrame
)
44 unsigned CodeOrigin::inlineDepth() const
46 return inlineDepthForCallFrame(inlineCallFrame
);
49 bool CodeOrigin::isApproximatelyEqualTo(const CodeOrigin
& other
) const
59 if (a
.isHashTableDeletedValue())
60 return b
.isHashTableDeletedValue();
61 if (b
.isHashTableDeletedValue())
68 if (a
.bytecodeIndex
!= b
.bytecodeIndex
)
71 if ((!!a
.inlineCallFrame
) != (!!b
.inlineCallFrame
))
74 if (!a
.inlineCallFrame
)
77 if (a
.inlineCallFrame
->executable
.get() != b
.inlineCallFrame
->executable
.get())
80 a
= a
.inlineCallFrame
->caller
;
81 b
= b
.inlineCallFrame
->caller
;
85 unsigned CodeOrigin::approximateHash() const
89 if (isHashTableDeletedValue())
93 CodeOrigin codeOrigin
= *this;
95 result
+= codeOrigin
.bytecodeIndex
;
97 if (!codeOrigin
.inlineCallFrame
)
100 result
+= WTF::PtrHash
<JSCell
*>::hash(codeOrigin
.inlineCallFrame
->executable
.get());
102 codeOrigin
= codeOrigin
.inlineCallFrame
->caller
;
106 Vector
<CodeOrigin
> CodeOrigin::inlineStack() const
108 Vector
<CodeOrigin
> result(inlineDepth());
109 result
.last() = *this;
110 unsigned index
= result
.size() - 2;
111 for (InlineCallFrame
* current
= inlineCallFrame
; current
; current
= current
->caller
.inlineCallFrame
)
112 result
[index
--] = current
->caller
;
113 RELEASE_ASSERT(!result
[0].inlineCallFrame
);
117 void CodeOrigin::dump(PrintStream
& out
) const
124 Vector
<CodeOrigin
> stack
= inlineStack();
125 for (unsigned i
= 0; i
< stack
.size(); ++i
) {
129 if (InlineCallFrame
* frame
= stack
[i
].inlineCallFrame
) {
130 out
.print(frame
->briefFunctionInformation(), ":<", RawPointer(frame
->executable
.get()), "> ");
131 if (frame
->isClosureCall
)
132 out
.print("(closure) ");
135 out
.print("bc#", stack
[i
].bytecodeIndex
);
139 void CodeOrigin::dumpInContext(PrintStream
& out
, DumpContext
*) const
144 JSFunction
* InlineCallFrame::calleeConstant() const
146 if (calleeRecovery
.isConstant())
147 return jsCast
<JSFunction
*>(calleeRecovery
.constant());
151 void InlineCallFrame::visitAggregate(SlotVisitor
& visitor
)
153 // FIXME: This is an antipattern for two reasons. References introduced by the DFG
154 // that aren't in the original CodeBlock being compiled should be weakly referenced.
155 // Inline call frames aren't in the original CodeBlock, so they qualify as weak. Also,
156 // those weak references should already be tracked in the DFG as weak FrozenValues. So,
157 // there is probably no need for this. We already have assertions that this should be
158 // unnecessary. Finally, just marking the executable and not anything else in the inline
159 // call frame is almost certainly insufficient for what this method thought it was going
161 // https://bugs.webkit.org/show_bug.cgi?id=146613
162 visitor
.append(&executable
);
165 JSFunction
* InlineCallFrame::calleeForCallFrame(ExecState
* exec
) const
167 return jsCast
<JSFunction
*>(calleeRecovery
.recover(exec
));
170 CodeBlockHash
InlineCallFrame::hash() const
172 return jsCast
<FunctionExecutable
*>(executable
.get())->codeBlockFor(
173 specializationKind())->hash();
176 CString
InlineCallFrame::hashAsStringIfPossible() const
178 return jsCast
<FunctionExecutable
*>(executable
.get())->codeBlockFor(
179 specializationKind())->hashAsStringIfPossible();
182 CString
InlineCallFrame::inferredName() const
184 return jsCast
<FunctionExecutable
*>(executable
.get())->inferredName().utf8();
187 CodeBlock
* InlineCallFrame::baselineCodeBlock() const
189 return jsCast
<FunctionExecutable
*>(executable
.get())->baselineCodeBlockFor(specializationKind());
192 void InlineCallFrame::dumpBriefFunctionInformation(PrintStream
& out
) const
194 out
.print(inferredName(), "#", hashAsStringIfPossible());
197 void InlineCallFrame::dumpInContext(PrintStream
& out
, DumpContext
* context
) const
199 out
.print(briefFunctionInformation(), ":<", RawPointer(executable
.get()));
200 if (executable
->isStrictMode())
201 out
.print(" (StrictMode)");
202 out
.print(", bc#", caller
.bytecodeIndex
, ", ", kind
);
204 out
.print(", closure call");
206 out
.print(", known callee: ", inContext(calleeRecovery
.constant(), context
));
207 out
.print(", numArgs+this = ", arguments
.size());
208 out
.print(", stackOffset = ", stackOffset
);
209 out
.print(" (", virtualRegisterForLocal(0), " maps to ", virtualRegisterForLocal(0) + stackOffset
, ")>");
212 void InlineCallFrame::dump(PrintStream
& out
) const
214 dumpInContext(out
, 0);
221 void printInternal(PrintStream
& out
, JSC::InlineCallFrame::Kind kind
)
224 case JSC::InlineCallFrame::Call
:
227 case JSC::InlineCallFrame::Construct
:
228 out
.print("Construct");
230 case JSC::InlineCallFrame::CallVarargs
:
231 out
.print("CallVarargs");
233 case JSC::InlineCallFrame::ConstructVarargs
:
234 out
.print("ConstructVarargs");
236 case JSC::InlineCallFrame::GetterCall
:
237 out
.print("GetterCall");
239 case JSC::InlineCallFrame::SetterCall
:
240 out
.print("SetterCall");
243 RELEASE_ASSERT_NOT_REACHED();