Interpreter::unwind() has no need for the bytecodeOffset
https://bugs.webkit.org/show_bug.cgi?id=121755
Reviewed by Oliver Hunt.
It was only using the bytecodeOffset for some debugger stuff, but the debugger could
just get the bytecodeOffset the same way the rest of the machinery does: by using the
CallFrame's location.
It turns out that a lot of really ugly code was in place just to supply this
bytecodeOffset. This patch kills most of that code, and allows us to kill even more
code in a future patch - though most likely that killage will involve further
refactorings as well, see https://bugs.webkit.org/show_bug.cgi?id=121734.
* dfg/DFGOperations.cpp:
* interpreter/CallFrame.cpp:
(JSC::CallFrame::bytecodeOffset):
(JSC::CallFrame::codeOrigin):
* interpreter/CallFrame.h:
* interpreter/Interpreter.cpp:
(JSC::Interpreter::unwind):
* interpreter/Interpreter.h:
* jit/JITExceptions.cpp:
(JSC::genericUnwind):
* jit/JITExceptions.h:
* jit/JITStubs.cpp:
(JSC::DEFINE_STUB_FUNCTION):
(JSC::cti_vm_handle_exception):
* llint/LLIntExceptions.cpp:
(JSC::LLInt::doThrow):
(JSC::LLInt::returnToThrow):
(JSC::LLInt::callToThrow):
* llint/LLIntExceptions.h:
* llint/LLIntSlowPaths.cpp:
(JSC::LLInt::LLINT_SLOW_PATH_DECL):
* runtime/CommonSlowPaths.cpp:
(JSC::SLOW_PATH_DECL):
* runtime/CommonSlowPathsExceptions.cpp:
(JSC::CommonSlowPaths::interpreterThrowInCaller):
* runtime/CommonSlowPathsExceptions.h:
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@156242 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/JavaScriptCore/interpreter/CallFrame.cpp b/Source/JavaScriptCore/interpreter/CallFrame.cpp
index f3156a0..5621b37 100644
--- a/Source/JavaScriptCore/interpreter/CallFrame.cpp
+++ b/Source/JavaScriptCore/interpreter/CallFrame.cpp
@@ -90,6 +90,31 @@
#endif // ENABLE(DFG_JIT)
+unsigned CallFrame::bytecodeOffset()
+{
+ if (!codeBlock())
+ return 0;
+#if ENABLE(DFG_JIT)
+ if (hasLocationAsCodeOriginIndex())
+ return bytecodeOffsetFromCodeOriginIndex();
+#endif
+ return locationAsBytecodeOffset();
+}
+
+CodeOrigin CallFrame::codeOrigin()
+{
+ if (!codeBlock())
+ return CodeOrigin(0);
+#if ENABLE(DFG_JIT)
+ if (hasLocationAsCodeOriginIndex()) {
+ unsigned index = locationAsCodeOriginIndex();
+ ASSERT(codeBlock()->canGetCodeOrigin(index));
+ return codeBlock()->codeOrigin(index);
+ }
+#endif
+ return CodeOrigin(locationAsBytecodeOffset());
+}
+
Register* CallFrame::frameExtentInternal()
{
CodeBlock* codeBlock = this->codeBlock();
diff --git a/Source/JavaScriptCore/interpreter/CallFrame.h b/Source/JavaScriptCore/interpreter/CallFrame.h
index e06e322..63a3d27 100644
--- a/Source/JavaScriptCore/interpreter/CallFrame.h
+++ b/Source/JavaScriptCore/interpreter/CallFrame.h
@@ -164,6 +164,17 @@
#if ENABLE(DFG_JIT)
unsigned bytecodeOffsetFromCodeOriginIndex();
#endif
+
+ // This will try to get you the bytecode offset, but you should be aware that
+ // this bytecode offset may be bogus in the presence of inlining. This will
+ // also return 0 if the call frame has no notion of bytecode offsets (for
+ // example if it's native code).
+ // https://bugs.webkit.org/show_bug.cgi?id=121754
+ unsigned bytecodeOffset();
+
+ // This will get you a CodeOrigin. It will always succeed. May return
+ // CodeOrigin(0) if we're in native code.
+ CodeOrigin codeOrigin();
Register* frameExtent()
{
diff --git a/Source/JavaScriptCore/interpreter/Interpreter.cpp b/Source/JavaScriptCore/interpreter/Interpreter.cpp
index 4208fe6..3209e8c 100644
--- a/Source/JavaScriptCore/interpreter/Interpreter.cpp
+++ b/Source/JavaScriptCore/interpreter/Interpreter.cpp
@@ -639,7 +639,7 @@
HandlerInfo*& m_handler;
};
-NEVER_INLINE HandlerInfo* Interpreter::unwind(CallFrame*& callFrame, JSValue& exceptionValue, unsigned bytecodeOffset)
+NEVER_INLINE HandlerInfo* Interpreter::unwind(CallFrame*& callFrame, JSValue& exceptionValue)
{
CodeBlock* codeBlock = callFrame->codeBlock();
bool isTermination = false;
@@ -662,6 +662,11 @@
// We need to clear the exception and the exception stack here in order to see if a new exception happens.
// Afterwards, the values are put back to continue processing this error.
ClearExceptionScope scope(&callFrame->vm());
+ // This code assumes that if the debugger is enabled then there is no inlining.
+ // If that assumption turns out to be false then we'll ignore the inlined call
+ // frames.
+ // https://bugs.webkit.org/show_bug.cgi?id=121754
+ unsigned bytecodeOffset = callFrame->bytecodeOffset();
int line = codeBlock->lineNumberForBytecodeOffset(bytecodeOffset);
int column = codeBlock->columnNumberForBytecodeOffset(bytecodeOffset);
DebuggerCallFrame debuggerCallFrame(callFrame, line, column, exceptionValue);
diff --git a/Source/JavaScriptCore/interpreter/Interpreter.h b/Source/JavaScriptCore/interpreter/Interpreter.h
index dc79f6d..36f4908 100644
--- a/Source/JavaScriptCore/interpreter/Interpreter.h
+++ b/Source/JavaScriptCore/interpreter/Interpreter.h
@@ -238,7 +238,7 @@
bool isInErrorHandlingMode() { return m_errorHandlingModeReentry; }
- NEVER_INLINE HandlerInfo* unwind(CallFrame*&, JSValue&, unsigned bytecodeOffset);
+ NEVER_INLINE HandlerInfo* unwind(CallFrame*&, JSValue&);
NEVER_INLINE void debug(CallFrame*, DebugHookID, int firstLine, int lastLine, int column);
JSString* stackTraceAsString(ExecState*, Vector<StackFrame>);