- Revision
- 151285
- Author
- [email protected]
- Date
- 2013-06-06 13:29:03 -0700 (Thu, 06 Jun 2013)
Log Message
CallFrame::trueCallFrame() should populate the bytecodeOffset field
when reifying inlined frames..
https://bugs.webkit.org/show_bug.cgi?id=117209.
Reviewed by Geoffrey Garen.
When reifying an inlined frame, we fill in its CodeBlock, and
bytecodeOffset. We also set the InlinedFrame bit in the location field.
This is needed in order to iterate the stack correctly. Here's why:
Let's say we have the following stack trace:
X calls A inlines B inlines C calls D
Based on the above scenario,
1. D's callerFrame points to A (not C).
2. A has a codeOriginIndex that points to C.
When iterating the stack (from D back towards X), we will encounter A
twice:
t1. when trying to find C as D's caller.
This is the time when we reify B and C using the
codeOriginIndex in A, and return C as the caller frame of D.
t2. when getting's the reified B's caller.
This time, we don't run the reification process, and
just take A as the caller frame of B.
To discern which treatment of the DFG frame (i.e. A) we need to apply,
we check if the callee is an inlined frame:
If callee is NOT an inlined frame (e.g. frame D), apply treatment t1.
If callee is an inlined frame (e.g. frame B), apply treatment t2.
Why not just reify A by replacing its codeOriginIndex with A's
bytecodeOffset?
We can't do this because D's callerFrame pointer still points to A, and
needs to remain that way because we did not deopt A. It remains a DFG
frame which inlined B and C.
If we replace the codeOriginIndex in A with A's bytecodeOffset, we will
only get to iterate the stack correctly once. If we try to iterate the
stack a second time, we will not have the information from the
codeOriginIndex to tell us that D's caller is actually the inlined C,
and not A.
To recap, when reifying frames for stack iteration purposes, the DFG
frame needs to hold on to its codeOriginIndex. This in turn means the
DFG frame will need to be treated in 2 possible ways, and we need to
know if a callee frame is an inlined frame in order to choose the
correct treatment for the DFG frame.
Other changes:
- Simplified Interpreter::getCallerInfo().
- Removed CodeBlock::codeOriginForReturn() and supporting code
which is now unneeded.
- Moved CallFrame location bit encoding from the CodeOrigin to the
new CallFrame::Location class.
- Explicitly tagged inlined frames. This is necessary in order to
iterate the stack correctly as explained above.
* bytecode/CodeBlock.cpp:
* bytecode/CodeBlock.h:
(JSC::CodeBlock::codeOrigins):
(CodeBlock):
(JSC::CodeBlock::codeOrigin):
(RareData):
* bytecode/CodeOrigin.h:
(CodeOrigin):
* dfg/DFGJITCompiler.cpp:
(JSC::DFG::JITCompiler::link):
* dfg/DFGJITCompiler.h:
(JSC::DFG::JITCompiler::beginCall):
* interpreter/CallFrame.cpp:
(JSC::CallFrame::trueCallFrame):
(JSC::CallFrame::trueCallerFrame):
(JSC::CallFrame::bytecodeOffsetFromCodeOriginIndex):
* interpreter/CallFrame.h:
(Location):
(ExecState):
(JSC::ExecState::trueCallerFrame):
(JSC::ExecState::callerFrameNoFlags):
* interpreter/CallFrameInlines.h:
(JSC::CallFrame::Location::encode):
(JSC::CallFrame::Location::decode):
(JSC::CallFrame::Location::isBytecodeOffset):
(JSC::CallFrame::Location::isCodeOriginIndex):
(JSC::CallFrame::Location::isInlinedFrame):
(JSC::CallFrame::isInlinedFrame):
(JSC::CallFrame::setIsInlinedFrame):
(JSC::CallFrame::hasLocationAsBytecodeOffset):
(JSC::CallFrame::hasLocationAsCodeOriginIndex):
(JSC::CallFrame::locationAsBytecodeOffset):
(JSC::CallFrame::setLocationAsBytecodeOffset):
(JSC::CallFrame::locationAsCodeOriginIndex):
* interpreter/Interpreter.cpp:
(JSC::getCallerInfo):
(JSC::Interpreter::getStackTrace):
(JSC::Interpreter::findFunctionCallFrameFromVMCode):
* runtime/Arguments.cpp:
(JSC::Arguments::tearOff):
Modified Paths
Diff
Modified: branches/dfgFourthTier/Source/_javascript_Core/ChangeLog (151284 => 151285)
--- branches/dfgFourthTier/Source/_javascript_Core/ChangeLog 2013-06-06 19:58:30 UTC (rev 151284)
+++ branches/dfgFourthTier/Source/_javascript_Core/ChangeLog 2013-06-06 20:29:03 UTC (rev 151285)
@@ -1,3 +1,108 @@
+2013-06-06 Mark Lam <[email protected]>
+
+ CallFrame::trueCallFrame() should populate the bytecodeOffset field
+ when reifying inlined frames..
+ https://bugs.webkit.org/show_bug.cgi?id=117209.
+
+ Reviewed by Geoffrey Garen.
+
+ When reifying an inlined frame, we fill in its CodeBlock, and
+ bytecodeOffset. We also set the InlinedFrame bit in the location field.
+ This is needed in order to iterate the stack correctly. Here's why:
+
+ Let's say we have the following stack trace:
+ X calls A inlines B inlines C calls D
+
+ Based on the above scenario,
+ 1. D's callerFrame points to A (not C).
+ 2. A has a codeOriginIndex that points to C.
+
+ When iterating the stack (from D back towards X), we will encounter A
+ twice:
+
+ t1. when trying to find C as D's caller.
+ This is the time when we reify B and C using the
+ codeOriginIndex in A, and return C as the caller frame of D.
+
+ t2. when getting's the reified B's caller.
+ This time, we don't run the reification process, and
+ just take A as the caller frame of B.
+
+ To discern which treatment of the DFG frame (i.e. A) we need to apply,
+ we check if the callee is an inlined frame:
+
+ If callee is NOT an inlined frame (e.g. frame D), apply treatment t1.
+ If callee is an inlined frame (e.g. frame B), apply treatment t2.
+
+ Why not just reify A by replacing its codeOriginIndex with A's
+ bytecodeOffset?
+
+ We can't do this because D's callerFrame pointer still points to A, and
+ needs to remain that way because we did not deopt A. It remains a DFG
+ frame which inlined B and C.
+
+ If we replace the codeOriginIndex in A with A's bytecodeOffset, we will
+ only get to iterate the stack correctly once. If we try to iterate the
+ stack a second time, we will not have the information from the
+ codeOriginIndex to tell us that D's caller is actually the inlined C,
+ and not A.
+
+ To recap, when reifying frames for stack iteration purposes, the DFG
+ frame needs to hold on to its codeOriginIndex. This in turn means the
+ DFG frame will need to be treated in 2 possible ways, and we need to
+ know if a callee frame is an inlined frame in order to choose the
+ correct treatment for the DFG frame.
+
+ Other changes:
+ - Simplified Interpreter::getCallerInfo().
+ - Removed CodeBlock::codeOriginForReturn() and supporting code
+ which is now unneeded.
+ - Moved CallFrame location bit encoding from the CodeOrigin to the
+ new CallFrame::Location class.
+ - Explicitly tagged inlined frames. This is necessary in order to
+ iterate the stack correctly as explained above.
+
+ * bytecode/CodeBlock.cpp:
+ * bytecode/CodeBlock.h:
+ (JSC::CodeBlock::codeOrigins):
+ (CodeBlock):
+ (JSC::CodeBlock::codeOrigin):
+ (RareData):
+ * bytecode/CodeOrigin.h:
+ (CodeOrigin):
+ * dfg/DFGJITCompiler.cpp:
+ (JSC::DFG::JITCompiler::link):
+ * dfg/DFGJITCompiler.h:
+ (JSC::DFG::JITCompiler::beginCall):
+ * interpreter/CallFrame.cpp:
+ (JSC::CallFrame::trueCallFrame):
+ (JSC::CallFrame::trueCallerFrame):
+ (JSC::CallFrame::bytecodeOffsetFromCodeOriginIndex):
+ * interpreter/CallFrame.h:
+ (Location):
+ (ExecState):
+ (JSC::ExecState::trueCallerFrame):
+ (JSC::ExecState::callerFrameNoFlags):
+ * interpreter/CallFrameInlines.h:
+ (JSC::CallFrame::Location::encode):
+ (JSC::CallFrame::Location::decode):
+ (JSC::CallFrame::Location::isBytecodeOffset):
+ (JSC::CallFrame::Location::isCodeOriginIndex):
+ (JSC::CallFrame::Location::isInlinedFrame):
+ (JSC::CallFrame::isInlinedFrame):
+ (JSC::CallFrame::setIsInlinedFrame):
+ (JSC::CallFrame::hasLocationAsBytecodeOffset):
+ (JSC::CallFrame::hasLocationAsCodeOriginIndex):
+ (JSC::CallFrame::locationAsBytecodeOffset):
+ (JSC::CallFrame::setLocationAsBytecodeOffset):
+ (JSC::CallFrame::locationAsCodeOriginIndex):
+ * interpreter/Interpreter.cpp:
+ (JSC::getCallerInfo):
+ (JSC::Interpreter::getStackTrace):
+ (JSC::Interpreter::findFunctionCallFrameFromVMCode):
+ * runtime/Arguments.cpp:
+ (JSC::Arguments::tearOff):
+
2013-06-05 Filip Pizlo <[email protected]>
DFG CFA shouldn't filter ArrayModes with ALL_NON_ARRAY_ARRAY_MODES if the speculated type is not SpecArray
Modified: branches/dfgFourthTier/Source/_javascript_Core/bytecode/CodeBlock.cpp (151284 => 151285)
--- branches/dfgFourthTier/Source/_javascript_Core/bytecode/CodeBlock.cpp 2013-06-06 19:58:30 UTC (rev 151284)
+++ branches/dfgFourthTier/Source/_javascript_Core/bytecode/CodeBlock.cpp 2013-06-06 20:29:03 UTC (rev 151285)
@@ -2808,33 +2808,6 @@
#endif
}
-#if ENABLE(DFG_JIT)
-bool CodeBlock::codeOriginForReturn(ReturnAddressPtr returnAddress, CodeOrigin& codeOrigin)
-{
- if (!hasCodeOrigins())
- return false;
-
- if (!jitCode()->contains(returnAddress.value())) {
- ClosureCallStubRoutine* stub = findClosureCallForReturnPC(returnAddress);
- ASSERT(stub);
- if (!stub)
- return false;
- codeOrigin = stub->codeOrigin();
- return true;
- }
-
- unsigned offset = jitCode()->offsetOf(returnAddress.value());
- CodeOriginAtCallReturnOffset* entry =
- tryBinarySearch<CodeOriginAtCallReturnOffset, unsigned>(
- codeOrigins(), codeOrigins().size(), offset,
- getCallReturnOffsetForCodeOrigin);
- if (!entry)
- return false;
- codeOrigin = entry->codeOrigin;
- return true;
-}
-#endif // ENABLE(DFG_JIT)
-
void CodeBlock::clearEvalCache()
{
if (!!m_alternative)
Modified: branches/dfgFourthTier/Source/_javascript_Core/bytecode/CodeBlock.h (151284 => 151285)
--- branches/dfgFourthTier/Source/_javascript_Core/bytecode/CodeBlock.h 2013-06-06 19:58:30 UTC (rev 151284)
+++ branches/dfgFourthTier/Source/_javascript_Core/bytecode/CodeBlock.h 2013-06-06 20:29:03 UTC (rev 151285)
@@ -588,7 +588,7 @@
return m_rareData->m_inlineCallFrames;
}
- Vector<CodeOriginAtCallReturnOffset, 0, UnsafeVectorOverflow>& codeOrigins()
+ Vector<CodeOrigin, 0, UnsafeVectorOverflow>& codeOrigins()
{
createRareDataIfNecessary();
return m_rareData->m_codeOrigins;
@@ -600,8 +600,6 @@
return m_rareData && !!m_rareData->m_codeOrigins.size();
}
- bool codeOriginForReturn(ReturnAddressPtr, CodeOrigin&);
-
bool canGetCodeOrigin(unsigned index)
{
if (!m_rareData)
@@ -612,7 +610,7 @@
CodeOrigin codeOrigin(unsigned index)
{
RELEASE_ASSERT(m_rareData);
- return m_rareData->m_codeOrigins[index].codeOrigin;
+ return m_rareData->m_codeOrigins[index];
}
bool addFrequentExitSite(const DFG::FrequentExitSite& site)
@@ -1102,7 +1100,7 @@
#endif
#if ENABLE(DFG_JIT)
SegmentedVector<InlineCallFrame, 4> m_inlineCallFrames;
- Vector<CodeOriginAtCallReturnOffset, 0, UnsafeVectorOverflow> m_codeOrigins;
+ Vector<CodeOrigin, 0, UnsafeVectorOverflow> m_codeOrigins;
#endif
};
#if COMPILER(MSVC)
@@ -1247,15 +1245,6 @@
return this[index];
}
-#if ENABLE(DFG_JIT)
-inline bool ExecState::isInlineCallFrame()
-{
- if (LIKELY(!codeBlock() || !JITCode::isOptimizingJIT(codeBlock()->jitType())))
- return false;
- return isInlineCallFrameSlow();
-}
-#endif
-
inline JSValue ExecState::argumentAfterCapture(size_t argument)
{
if (argument >= argumentCount())
Modified: branches/dfgFourthTier/Source/_javascript_Core/bytecode/CodeOrigin.h (151284 => 151285)
--- branches/dfgFourthTier/Source/_javascript_Core/bytecode/CodeOrigin.h 2013-06-06 19:58:30 UTC (rev 151284)
+++ branches/dfgFourthTier/Source/_javascript_Core/bytecode/CodeOrigin.h 2013-06-06 20:29:03 UTC (rev 151285)
@@ -88,21 +88,6 @@
Vector<CodeOrigin> inlineStack() const;
void dump(PrintStream&) const;
-
- static inline bool isHandle(uint32_t bits) { return !!(bits & handleFlag); }
- static inline uint32_t encodeHandle(uint32_t bits)
- {
- ASSERT(!isHandle(bits));
- return bits | handleFlag;
- }
- static inline uint32_t decodeHandle(uint32_t bits)
- {
- ASSERT(isHandle(bits));
- return bits & ~handleFlag;
- }
-
-private:
- static const uint32_t handleFlag = (1 << 31);
};
struct InlineCallFrame {
@@ -132,11 +117,6 @@
MAKE_PRINT_METHOD(InlineCallFrame, dumpBriefFunctionInformation, briefFunctionInformation);
};
-struct CodeOriginAtCallReturnOffset {
- CodeOrigin codeOrigin;
- unsigned callReturnOffset;
-};
-
inline unsigned CodeOrigin::stackOffset() const
{
if (!inlineCallFrame)
@@ -151,11 +131,6 @@
&& inlineCallFrame == other.inlineCallFrame;
}
-inline unsigned getCallReturnOffsetForCodeOrigin(CodeOriginAtCallReturnOffset* data)
-{
- return data->callReturnOffset;
-}
-
inline ScriptExecutable* CodeOrigin::codeOriginOwner() const
{
if (!inlineCallFrame)
Modified: branches/dfgFourthTier/Source/_javascript_Core/dfg/DFGJITCompiler.cpp (151284 => 151285)
--- branches/dfgFourthTier/Source/_javascript_Core/dfg/DFGJITCompiler.cpp 2013-06-06 19:58:30 UTC (rev 151284)
+++ branches/dfgFourthTier/Source/_javascript_Core/dfg/DFGJITCompiler.cpp 2013-06-06 20:29:03 UTC (rev 151285)
@@ -170,14 +170,12 @@
m_codeBlock->callReturnIndexVector().append(CallReturnOffsetToBytecodeOffset(returnAddressOffset, exceptionInfo));
}
- Vector<CodeOriginAtCallReturnOffset, 0, UnsafeVectorOverflow>& codeOrigins = m_codeBlock->codeOrigins();
+ Vector<CodeOrigin, 0, UnsafeVectorOverflow>& codeOrigins = m_codeBlock->codeOrigins();
codeOrigins.resize(m_exceptionChecks.size());
for (unsigned i = 0; i < m_exceptionChecks.size(); ++i) {
CallExceptionRecord& record = m_exceptionChecks[i];
- unsigned returnAddressOffset = linkBuffer.returnAddressOffset(m_exceptionChecks[i].m_call);
- codeOrigins[i].codeOrigin = record.m_codeOrigin;
- codeOrigins[i].callReturnOffset = returnAddressOffset;
+ codeOrigins[i] = record.m_codeOrigin;
}
m_codeBlock->setNumberOfStructureStubInfos(m_propertyAccesses.size());
Modified: branches/dfgFourthTier/Source/_javascript_Core/dfg/DFGJITCompiler.h (151284 => 151285)
--- branches/dfgFourthTier/Source/_javascript_Core/dfg/DFGJITCompiler.h 2013-06-06 19:58:30 UTC (rev 151284)
+++ branches/dfgFourthTier/Source/_javascript_Core/dfg/DFGJITCompiler.h 2013-06-06 20:29:03 UTC (rev 151285)
@@ -28,6 +28,7 @@
#if ENABLE(DFG_JIT)
+#include "CallFrameInlines.h"
#include "CodeBlock.h"
#include "DFGCCallHelpers.h"
#include "DFGDisassembler.h"
@@ -313,8 +314,8 @@
void beginCall(CodeOrigin codeOrigin, CallBeginToken& token)
{
unsigned index = m_exceptionChecks.size();
- unsigned handle = CodeOrigin::encodeHandle(index);
- store32(TrustedImm32(handle), tagFor(static_cast<VirtualRegister>(JSStack::ArgumentCount)));
+ unsigned locationBits = CallFrame::Location::encode(CallFrame::Location::CodeOriginIndex, index);
+ store32(TrustedImm32(locationBits), tagFor(static_cast<VirtualRegister>(JSStack::ArgumentCount)));
token.set(codeOrigin, index);
}
Modified: branches/dfgFourthTier/Source/_javascript_Core/interpreter/CallFrame.cpp (151284 => 151285)
--- branches/dfgFourthTier/Source/_javascript_Core/interpreter/CallFrame.cpp 2013-06-06 19:58:30 UTC (rev 151284)
+++ branches/dfgFourthTier/Source/_javascript_Core/interpreter/CallFrame.cpp 2013-06-06 20:29:03 UTC (rev 151285)
@@ -68,21 +68,10 @@
#endif
#if ENABLE(DFG_JIT)
-bool CallFrame::isInlineCallFrameSlow()
+CallFrame* CallFrame::trueCallFrame()
{
- if (!callee())
- return false;
- JSCell* calleeAsFunctionCell = getJSFunction(callee());
- if (!calleeAsFunctionCell)
- return false;
- JSFunction* calleeAsFunction = jsCast<JSFunction*>(calleeAsFunctionCell);
- return calleeAsFunction->executable() != codeBlock()->ownerExecutable();
-}
-
-CallFrame* CallFrame::trueCallFrame(AbstractPC pc)
-{
// Am I an inline call frame? If so, we're done.
- if (isInlineCallFrame())
+ if (isInlinedFrame())
return this;
// If I don't have a code block, then I'm not DFG code, so I'm the true call frame.
@@ -95,47 +84,23 @@
if (!machineCodeBlock->hasCodeOrigins())
return this;
- // At this point the PC must be due either to the DFG, or it must be unset.
- ASSERT(pc.hasJITReturnAddress() || !pc);
-
// Try to determine the CodeOrigin. If we don't have a pc set then the only way
// that this makes sense is if the CodeOrigin index was set in the call frame.
- // FIXME: Note that you will see "Not currently in inlined code" comments below.
- // Currently, we do not record code origins for code that is not inlined, because
- // the only thing that we use code origins for is determining the inline stack.
- // But in the future, we'll want to use this same functionality (having a code
- // origin mapping for any calls out of JIT code) to determine the PC at any point
- // in the stack even if not in inlined code. When that happens, the code below
- // will have to change the way it detects the presence of inlining: it will always
- // get a code origin, but sometimes, that code origin will not have an inline call
- // frame. In that case, this method should bail and return this.
CodeOrigin codeOrigin;
- if (pc.isSet()) {
- ReturnAddressPtr currentReturnPC = pc.jitReturnAddress();
-
- bool hasCodeOrigin = machineCodeBlock->codeOriginForReturn(currentReturnPC, codeOrigin);
- ASSERT(hasCodeOrigin);
- if (!hasCodeOrigin) {
- // In release builds, if we find ourselves in a situation where the return PC doesn't
- // correspond to a valid CodeOrigin, we return zero instead of continuing. Some of
- // the callers of trueCallFrame() will be able to recover and do conservative things,
- // while others will crash.
- return 0;
- }
- } else {
- unsigned index = locationAsCodeOriginIndex();
- ASSERT(machineCodeBlock->canGetCodeOrigin(index));
- if (!machineCodeBlock->canGetCodeOrigin(index)) {
- // See above. In release builds, we try to protect ourselves from crashing even
- // though stack walking will be goofed up.
- return 0;
- }
- codeOrigin = machineCodeBlock->codeOrigin(index);
+ unsigned index = locationAsCodeOriginIndex();
+ ASSERT(machineCodeBlock->canGetCodeOrigin(index));
+ if (!machineCodeBlock->canGetCodeOrigin(index)) {
+ // See above. In release builds, we try to protect ourselves from crashing even
+ // though stack walking will be goofed up.
+ return 0;
}
+ codeOrigin = machineCodeBlock->codeOrigin(index);
if (!codeOrigin.inlineCallFrame)
return this; // Not currently in inlined code.
-
+
+ CodeOrigin innerMostCodeOrigin = codeOrigin;
+
for (InlineCallFrame* inlineCallFrame = codeOrigin.inlineCallFrame; inlineCallFrame;) {
InlineCallFrame* nextInlineCallFrame = inlineCallFrame->caller.inlineCallFrame;
@@ -144,7 +109,7 @@
JSFunction* calleeAsFunction = inlineCallFrame->callee.get();
// Fill in the inlinedCaller
- inlinedCaller->setCodeBlock(machineCodeBlock);
+ inlinedCaller->setCodeBlock(inlineCallFrame->baselineCodeBlock());
if (calleeAsFunction)
inlinedCaller->setScope(calleeAsFunction->scope());
if (nextInlineCallFrame)
@@ -154,19 +119,23 @@
inlinedCaller->setInlineCallFrame(inlineCallFrame);
inlinedCaller->setArgumentCountIncludingThis(inlineCallFrame->arguments.size());
+ inlinedCaller->setLocationAsBytecodeOffset(codeOrigin.bytecodeIndex);
+ inlinedCaller->setIsInlinedFrame();
if (calleeAsFunction)
inlinedCaller->setCallee(calleeAsFunction);
+ codeOrigin = inlineCallFrame->caller;
inlineCallFrame = nextInlineCallFrame;
}
- return this + codeOrigin.inlineCallFrame->stackOffset;
+ return this + innerMostCodeOrigin.inlineCallFrame->stackOffset;
}
CallFrame* CallFrame::trueCallerFrame()
{
+ CallFrame* callerFrame = this->callerFrame()->removeHostCallFrameFlag();
if (!codeBlock())
- return callerFrame()->removeHostCallFrameFlag();
+ return callerFrame;
// this -> The callee; this is either an inlined callee in which case it already has
// a pointer to the true caller. Otherwise it contains current PC in the machine
@@ -176,33 +145,43 @@
// more frames above the true caller due to inlining.
// Am I an inline call frame? If so, we're done.
- if (isInlineCallFrame())
- return callerFrame()->removeHostCallFrameFlag();
+ if (isInlinedFrame())
+ return callerFrame;
// I am a machine call frame, so the question is: is my caller a machine call frame
// that has inlines or a machine call frame that doesn't?
- CallFrame* machineCaller = callerFrame()->removeHostCallFrameFlag();
- if (!machineCaller)
+ if (!callerFrame)
return 0;
- ASSERT(!machineCaller->isInlineCallFrame());
+
+ if (!callerFrame->codeBlock())
+ return callerFrame;
+ ASSERT(!callerFrame->isInlinedFrame());
- // Figure out how we want to get the current code location.
- if (!hasReturnPC() || returnAddressIsInCtiTrampoline(returnPC()))
- return machineCaller->trueCallFrameFromVMCode()->removeHostCallFrameFlag();
-
- return machineCaller->trueCallFrame(returnPC())->removeHostCallFrameFlag();
+ return callerFrame->trueCallFrame()->removeHostCallFrameFlag();
}
-CodeBlock* CallFrame::someCodeBlockForPossiblyInlinedCode()
+unsigned CallFrame::bytecodeOffsetFromCodeOriginIndex()
{
- if (!isInlineCallFrame())
- return codeBlock();
-
- return jsCast<FunctionExecutable*>(inlineCallFrame()->executable.get())->baselineCodeBlockFor(
- inlineCallFrame()->isCall ? CodeForCall : CodeForConstruct);
+ ASSERT(hasLocationAsCodeOriginIndex());
+ CodeBlock* codeBlock = this->codeBlock();
+ ASSERT(codeBlock);
+
+ CodeOrigin codeOrigin;
+ unsigned index = locationAsCodeOriginIndex();
+ ASSERT(codeBlock->canGetCodeOrigin(index));
+ codeOrigin = codeBlock->codeOrigin(index);
+
+ for (InlineCallFrame* inlineCallFrame = codeOrigin.inlineCallFrame; inlineCallFrame;) {
+ if (inlineCallFrame->baselineCodeBlock() == codeBlock)
+ return codeOrigin.bytecodeIndex;
+
+ codeOrigin = inlineCallFrame->caller;
+ inlineCallFrame = codeOrigin.inlineCallFrame;
+ }
+ return codeOrigin.bytecodeIndex;
}
-#endif
+#endif // ENABLE(DFG_JIT)
Register* CallFrame::frameExtentInternal()
{
Modified: branches/dfgFourthTier/Source/_javascript_Core/interpreter/CallFrame.h (151284 => 151285)
--- branches/dfgFourthTier/Source/_javascript_Core/interpreter/CallFrame.h 2013-06-06 19:58:30 UTC (rev 151284)
+++ branches/dfgFourthTier/Source/_javascript_Core/interpreter/CallFrame.h 2013-06-06 20:29:03 UTC (rev 151285)
@@ -114,6 +114,29 @@
#endif
AbstractPC abstractReturnPC(VM& vm) { return AbstractPC(vm, this); }
+ class Location {
+ public:
+ enum Type {
+ BytecodeOffset = 0,
+ CodeOriginIndex = (1 << 0),
+ IsInlinedCode = (1 << 1),
+ };
+
+ static inline uint32_t encode(Type, uint32_t bits);
+ static inline uint32_t decode(uint32_t bits);
+ static inline bool isBytecodeOffset(uint32_t bits);
+ static inline bool isCodeOriginIndex(uint32_t bits);
+ static inline bool isInlinedCode(uint32_t bits);
+
+ private:
+ static const uint32_t s_mask = 0x3;
+ static const uint32_t s_shift = 30;
+ static const uint32_t s_shiftedMask = s_mask << s_shift;
+ };
+
+ bool isInlinedFrame() const;
+ void setIsInlinedFrame();
+
bool hasLocationAsBytecodeOffset() const;
bool hasLocationAsCodeOriginIndex() const;
@@ -124,6 +147,8 @@
void setLocationAsRawBits(unsigned);
void setLocationAsBytecodeOffset(unsigned);
+ unsigned bytecodeOffsetFromCodeOriginIndex();
+
Register* frameExtent()
{
if (!codeBlock())
@@ -137,7 +162,7 @@
InlineCallFrame* inlineCallFrame() const { return this[JSStack::ReturnPC].asInlineCallFrame(); }
#else
// This will never be called if !ENABLE(DFG_JIT) since all calls should be guarded by
- // isInlineCallFrame(). But to make it easier to write code without having a bunch of
+ // isInlinedFrame(). But to make it easier to write code without having a bunch of
// #if's, we make a dummy implementation available anyway.
InlineCallFrame* inlineCallFrame() const
{
@@ -231,39 +256,21 @@
void setReturnPC(void* value) { static_cast<Register*>(this)[JSStack::ReturnPC] = (Instruction*)value; }
#if ENABLE(DFG_JIT)
- bool isInlineCallFrame();
-
void setInlineCallFrame(InlineCallFrame* inlineCallFrame) { static_cast<Register*>(this)[JSStack::ReturnPC] = inlineCallFrame; }
-
+
// Call this to get the semantically correct JS CallFrame* for the
// currently executing function.
- CallFrame* trueCallFrame(AbstractPC);
-
+ CallFrame* trueCallFrame();
+
// Call this to get the semantically correct JS CallFrame* corresponding
// to the caller. This resolves issues surrounding inlining and the
// HostCallFrameFlag stuff.
CallFrame* trueCallerFrame();
-
- CodeBlock* someCodeBlockForPossiblyInlinedCode();
#else
- bool isInlineCallFrame() { return false; }
-
CallFrame* trueCallFrame(AbstractPC) { return this; }
CallFrame* trueCallerFrame() { return callerFrame()->removeHostCallFrameFlag(); }
-
- CodeBlock* someCodeBlockForPossiblyInlinedCode() { return codeBlock(); }
#endif
CallFrame* callerFrameNoFlags() { return callerFrame()->removeHostCallFrameFlag(); }
-
- // Call this to get the true call frame (accounted for inlining and any
- // other optimizations), when you have entered into VM code through one
- // of the "blessed" entrypoints (JITStubs or DFGOperations). This means
- // that if you're pretty much anywhere in the VM you can safely call this;
- // though if you were to magically get an ExecState* by, say, interrupting
- // a thread that is running JS code and brutishly scraped the call frame
- // register, calling this method would probably lead to horrible things
- // happening.
- CallFrame* trueCallFrameFromVMCode() { return trueCallFrame(AbstractPC()); }
private:
static const intptr_t HostCallFrameFlag = 1;
@@ -273,9 +280,6 @@
#ifndef NDEBUG
JSStack* stack();
#endif
-#if ENABLE(DFG_JIT)
- bool isInlineCallFrameSlow();
-#endif
ExecState();
~ExecState();
Modified: branches/dfgFourthTier/Source/_javascript_Core/interpreter/CallFrameInlines.h (151284 => 151285)
--- branches/dfgFourthTier/Source/_javascript_Core/interpreter/CallFrameInlines.h 2013-06-06 19:58:30 UTC (rev 151284)
+++ branches/dfgFourthTier/Source/_javascript_Core/interpreter/CallFrameInlines.h 2013-06-06 20:29:03 UTC (rev 151285)
@@ -27,18 +27,59 @@
#define CallFrameInlines_h
#include "CallFrame.h"
-#include "CodeOrigin.h"
namespace JSC {
+inline uint32_t CallFrame::Location::encode(CallFrame::Location::Type type, uint32_t bits)
+{
+ ASSERT(!(bits & s_shiftedMask));
+ ASSERT(!(type & ~s_mask));
+ return bits | (type << s_shift);
+}
+
+inline uint32_t CallFrame::Location::decode(uint32_t bits)
+{
+ return bits & ~s_shiftedMask;
+}
+
+inline bool CallFrame::Location::isBytecodeOffset(uint32_t bits)
+{
+ return !isCodeOriginIndex(bits);
+}
+
+inline bool CallFrame::Location::isCodeOriginIndex(uint32_t bits)
+{
+ Type type = static_cast<Type>(bits >> s_shift);
+ return !!(type & CodeOriginIndex);
+}
+
+inline bool CallFrame::Location::isInlinedCode(uint32_t bits)
+{
+ Type type = static_cast<Type>(bits >> s_shift);
+ return !!(type & IsInlinedCode);
+}
+
+inline bool CallFrame::isInlinedFrame() const
+{
+ return Location::isInlinedCode(locationAsRawBits());
+}
+
+inline void CallFrame::setIsInlinedFrame()
+{
+ ASSERT(codeBlock());
+ uint32_t bits = Location::encode(Location::IsInlinedCode, locationAsRawBits());
+ setLocationAsRawBits(bits);
+ ASSERT(isInlinedFrame());
+}
+
inline bool CallFrame::hasLocationAsBytecodeOffset() const
{
- return !CodeOrigin::isHandle(locationAsRawBits());
+ return Location::isBytecodeOffset(locationAsRawBits());
}
inline bool CallFrame::hasLocationAsCodeOriginIndex() const
{
- return CodeOrigin::isHandle(locationAsRawBits());
+ return Location::isCodeOriginIndex(locationAsRawBits());
}
inline unsigned CallFrame::locationAsRawBits() const
@@ -56,13 +97,13 @@
{
ASSERT(hasLocationAsBytecodeOffset());
ASSERT(codeBlock());
- return locationAsRawBits();
+ return Location::decode(locationAsRawBits());
}
inline void CallFrame::setLocationAsBytecodeOffset(unsigned offset)
{
ASSERT(codeBlock());
- setLocationAsRawBits(offset);
+ setLocationAsRawBits(Location::encode(Location::BytecodeOffset, offset));
ASSERT(hasLocationAsBytecodeOffset());
}
#endif // USE(JSVALUE64)
@@ -71,7 +112,7 @@
{
ASSERT(hasLocationAsCodeOriginIndex());
ASSERT(codeBlock());
- return CodeOrigin::decodeHandle(locationAsRawBits());
+ return Location::decode(locationAsRawBits());
}
} // namespace JSC
Modified: branches/dfgFourthTier/Source/_javascript_Core/interpreter/Interpreter.cpp (151284 => 151285)
--- branches/dfgFourthTier/Source/_javascript_Core/interpreter/Interpreter.cpp 2013-06-06 19:58:30 UTC (rev 151284)
+++ branches/dfgFourthTier/Source/_javascript_Core/interpreter/Interpreter.cpp 2013-06-06 20:29:03 UTC (rev 151285)
@@ -586,7 +586,6 @@
bytecodeOffset = 0;
ASSERT(!callFrame->hasHostCallFrameFlag());
CallFrame* trueCallerFrame = callFrame->trueCallerFrame();
- bool wasCalledByHost = callFrame->callerFrame()->hasHostCallFrameFlag();
ASSERT(!trueCallerFrame->hasHostCallFrameFlag());
if (trueCallerFrame == CallFrame::noCaller() || !trueCallerFrame || !trueCallerFrame->codeBlock()) {
@@ -595,60 +594,11 @@
}
CodeBlock* callerCodeBlock = trueCallerFrame->codeBlock();
-
- if (!callFrame->hasReturnPC())
- wasCalledByHost = true;
+ if (trueCallerFrame->hasLocationAsCodeOriginIndex())
+ bytecodeOffset = trueCallerFrame->bytecodeOffsetFromCodeOriginIndex();
+ else
+ bytecodeOffset = trueCallerFrame->locationAsBytecodeOffset();
- if (wasCalledByHost) {
-#if ENABLE(DFG_JIT)
- if (callerCodeBlock && JITCode::isOptimizingJIT(callerCodeBlock->jitType())) {
- unsigned codeOriginIndex = callFrame->callerFrame()->removeHostCallFrameFlag()->locationAsCodeOriginIndex();
- CodeOrigin origin = callerCodeBlock->codeOrigin(codeOriginIndex);
- bytecodeOffset = origin.bytecodeIndex;
- if (InlineCallFrame* inlineCallFrame = origin.inlineCallFrame)
- callerCodeBlock = inlineCallFrame->baselineCodeBlock();
- } else
-#endif
- bytecodeOffset = trueCallerFrame->locationAsBytecodeOffset();
- } else {
-#if ENABLE(DFG_JIT)
- if (callFrame->isInlineCallFrame()) {
- InlineCallFrame* icf = callFrame->inlineCallFrame();
- bytecodeOffset = icf->caller.bytecodeIndex;
- if (InlineCallFrame* parentCallFrame = icf->caller.inlineCallFrame) {
- FunctionExecutable* executable = static_cast<FunctionExecutable*>(parentCallFrame->executable.get());
- CodeBlock* newCodeBlock = executable->baselineCodeBlockFor(parentCallFrame->isCall ? CodeForCall : CodeForConstruct);
- ASSERT(newCodeBlock);
- ASSERT(newCodeBlock->instructionCount() > bytecodeOffset);
- callerCodeBlock = newCodeBlock;
- }
- } else if (callerCodeBlock && JITCode::isOptimizingJIT(callerCodeBlock->jitType())) {
- CodeOrigin origin;
- if (!callerCodeBlock->codeOriginForReturn(callFrame->returnPC(), origin)) {
- // This should not be possible, but we're seeing cases where it does happen
- // CallFrame already has robustness against bogus stack walks, so
- // we'll extend that to here as well.
- ASSERT_NOT_REACHED();
- caller = 0;
- return 0;
- }
- bytecodeOffset = origin.bytecodeIndex;
- if (InlineCallFrame* icf = origin.inlineCallFrame) {
- FunctionExecutable* executable = static_cast<FunctionExecutable*>(icf->executable.get());
- CodeBlock* newCodeBlock = executable->baselineCodeBlockFor(icf->isCall ? CodeForCall : CodeForConstruct);
- ASSERT(newCodeBlock);
- ASSERT(newCodeBlock->instructionCount() > bytecodeOffset);
- callerCodeBlock = newCodeBlock;
- }
- } else
-#endif
- {
- RELEASE_ASSERT(callerCodeBlock);
- bytecodeOffset = callerCodeBlock->bytecodeOffset(trueCallerFrame, callFrame->returnPC());
- }
- }
-
- RELEASE_ASSERT(callerCodeBlock);
caller = callerCodeBlock;
return trueCallerFrame;
}
@@ -724,7 +674,7 @@
if (!callFrame || callFrame == CallFrame::noCaller())
return;
unsigned bytecodeOffset = getBytecodeOffsetForCallFrame(callFrame);
- callFrame = callFrame->trueCallFrameFromVMCode();
+ callFrame = callFrame->trueCallFrame();
if (!callFrame)
return;
CodeBlock* callerCodeBlock = callFrame->codeBlock();
@@ -1471,7 +1421,7 @@
CallFrame* Interpreter::findFunctionCallFrameFromVMCode(CallFrame* callFrame, JSFunction* function)
{
- for (CallFrame* candidate = callFrame->trueCallFrameFromVMCode(); candidate; candidate = candidate->trueCallerFrame()) {
+ for (CallFrame* candidate = callFrame->trueCallFrame(); candidate; candidate = candidate->trueCallerFrame()) {
if (candidate->callee() == function)
return candidate;
}
Modified: branches/dfgFourthTier/Source/_javascript_Core/runtime/Arguments.cpp (151284 => 151285)
--- branches/dfgFourthTier/Source/_javascript_Core/runtime/Arguments.cpp 2013-06-06 19:58:30 UTC (rev 151284)
+++ branches/dfgFourthTier/Source/_javascript_Core/runtime/Arguments.cpp 2013-06-06 20:29:03 UTC (rev 151285)
@@ -25,6 +25,7 @@
#include "config.h"
#include "Arguments.h"
+#include "CallFrameInlines.h"
#include "JSActivation.h"
#include "JSFunction.h"
#include "JSGlobalObject.h"
@@ -354,7 +355,7 @@
}
}
- if (!callFrame->isInlineCallFrame()) {
+ if (!callFrame->isInlinedFrame()) {
for (size_t i = 0; i < m_numArguments; ++i)
trySetArgument(callFrame->vm(), i, callFrame->argumentAfterCapture(i));
return;