<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[160656] branches/jsCStack/Source/JavaScriptCore</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/160656">160656</a></dd>
<dt>Author</dt> <dd>mark.lam@apple.com</dd>
<dt>Date</dt> <dd>2013-12-16 12:46:39 -0800 (Mon, 16 Dec 2013)</dd>
</dl>
<h3>Log Message</h3>
<pre>Fix exception handling for the baseline JIT.
https://bugs.webkit.org/show_bug.cgi?id=125736.
Reviewed by Geoffrey Garen.
* interpreter/Interpreter.cpp:
(JSC::unwindCallFrame):
Removed some unneeded code.
1. Removed use of the oldCodeBlock variable which is only a copy of
the codeBlock variable. There is no longer any reason to use a copy.
Just use codeBlock directly instead.
2. There's no need to set VM::topCallFrame. The UnwindFunctor
automatically updates the incoming callFrame pointer reference to
the frame that should be catching / handling the exception, and that
is adequate for what we need.
* jit/JITOpcodes.cpp:
(JSC::JIT::emit_op_catch):
- Restored sp.
* jit/JITOpcodes32_64.cpp:
(JSC::JIT::privateCompileCTINativeCall):
(JSC::JIT::emit_op_catch):
* jit/ThunkGenerators.cpp:
(JSC::nativeForGenerator):
Fixed 2 issues:
1. After returning from a native / host function, the thunk did not pop
the native / host frame before executing exception handling code.
This resulted in the VM trying to "unwind" the native / host frame
which is not possible, and crashes ensue.
2. After returning from a native / host function and discovering the
need to handle an exception, the thunk was wrongly popping a
non-existant return address off the stack. This caused the
callerFrame pointer of the current frame to be popped off the stack,
and havoc ensues.
* llint/LowLevelInterpreter32_64.asm:
- Updated to match exception handling code in LowLevelInterpreter64.asm.
* runtime/VM.h:
- Removed dead code.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#branchesjsCStackSourceJavaScriptCoreChangeLog">branches/jsCStack/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#branchesjsCStackSourceJavaScriptCoreinterpreterInterpretercpp">branches/jsCStack/Source/JavaScriptCore/interpreter/Interpreter.cpp</a></li>
<li><a href="#branchesjsCStackSourceJavaScriptCorejitJITOpcodescpp">branches/jsCStack/Source/JavaScriptCore/jit/JITOpcodes.cpp</a></li>
<li><a href="#branchesjsCStackSourceJavaScriptCorejitJITOpcodes32_64cpp">branches/jsCStack/Source/JavaScriptCore/jit/JITOpcodes32_64.cpp</a></li>
<li><a href="#branchesjsCStackSourceJavaScriptCorejitThunkGeneratorscpp">branches/jsCStack/Source/JavaScriptCore/jit/ThunkGenerators.cpp</a></li>
<li><a href="#branchesjsCStackSourceJavaScriptCorellintLowLevelInterpreter32_64asm">branches/jsCStack/Source/JavaScriptCore/llint/LowLevelInterpreter32_64.asm</a></li>
<li><a href="#branchesjsCStackSourceJavaScriptCoreruntimeVMh">branches/jsCStack/Source/JavaScriptCore/runtime/VM.h</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchesjsCStackSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: branches/jsCStack/Source/JavaScriptCore/ChangeLog (160655 => 160656)</h4>
<pre class="diff"><span>
<span class="info">--- branches/jsCStack/Source/JavaScriptCore/ChangeLog        2013-12-16 20:44:01 UTC (rev 160655)
+++ branches/jsCStack/Source/JavaScriptCore/ChangeLog        2013-12-16 20:46:39 UTC (rev 160656)
</span><span class="lines">@@ -1,3 +1,47 @@
</span><ins>+2013-12-14 Mark Lam <mark.lam@apple.com>
+
+ Fix exception handling for the baseline JIT.
+ https://bugs.webkit.org/show_bug.cgi?id=125736.
+
+ Reviewed by Geoffrey Garen.
+
+ * interpreter/Interpreter.cpp:
+ (JSC::unwindCallFrame):
+ Removed some unneeded code.
+ 1. Removed use of the oldCodeBlock variable which is only a copy of
+ the codeBlock variable. There is no longer any reason to use a copy.
+ Just use codeBlock directly instead.
+ 2. There's no need to set VM::topCallFrame. The UnwindFunctor
+ automatically updates the incoming callFrame pointer reference to
+ the frame that should be catching / handling the exception, and that
+ is adequate for what we need.
+
+ * jit/JITOpcodes.cpp:
+ (JSC::JIT::emit_op_catch):
+ - Restored sp.
+
+ * jit/JITOpcodes32_64.cpp:
+ (JSC::JIT::privateCompileCTINativeCall):
+ (JSC::JIT::emit_op_catch):
+ * jit/ThunkGenerators.cpp:
+ (JSC::nativeForGenerator):
+ Fixed 2 issues:
+ 1. After returning from a native / host function, the thunk did not pop
+ the native / host frame before executing exception handling code.
+ This resulted in the VM trying to "unwind" the native / host frame
+ which is not possible, and crashes ensue.
+ 2. After returning from a native / host function and discovering the
+ need to handle an exception, the thunk was wrongly popping a
+ non-existant return address off the stack. This caused the
+ callerFrame pointer of the current frame to be popped off the stack,
+ and havoc ensues.
+
+ * llint/LowLevelInterpreter32_64.asm:
+ - Updated to match exception handling code in LowLevelInterpreter64.asm.
+
+ * runtime/VM.h:
+ - Removed dead code.
+
</ins><span class="cx"> 2013-12-14 Filip Pizlo <fpizlo@apple.com>
</span><span class="cx">
</span><span class="cx"> FTL should *really* know when things are flushed
</span></span></pre></div>
<a id="branchesjsCStackSourceJavaScriptCoreinterpreterInterpretercpp"></a>
<div class="modfile"><h4>Modified: branches/jsCStack/Source/JavaScriptCore/interpreter/Interpreter.cpp (160655 => 160656)</h4>
<pre class="diff"><span>
<span class="info">--- branches/jsCStack/Source/JavaScriptCore/interpreter/Interpreter.cpp        2013-12-16 20:44:01 UTC (rev 160655)
+++ branches/jsCStack/Source/JavaScriptCore/interpreter/Interpreter.cpp        2013-12-16 20:46:39 UTC (rev 160656)
</span><span class="lines">@@ -421,7 +421,6 @@
</span><span class="cx"> {
</span><span class="cx"> CallFrame* callFrame = visitor->callFrame();
</span><span class="cx"> CodeBlock* codeBlock = visitor->codeBlock();
</span><del>- CodeBlock* oldCodeBlock = codeBlock;
</del><span class="cx"> JSScope* scope = callFrame->scope();
</span><span class="cx">
</span><span class="cx"> if (Debugger* debugger = callFrame->vmEntryGlobalObject()->debugger()) {
</span><span class="lines">@@ -432,16 +431,16 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> JSValue activation;
</span><del>- if (oldCodeBlock->codeType() == FunctionCode && oldCodeBlock->needsActivation()) {
</del><ins>+ if (codeBlock->codeType() == FunctionCode && codeBlock->needsActivation()) {
</ins><span class="cx"> #if ENABLE(DFG_JIT)
</span><span class="cx"> RELEASE_ASSERT(!visitor->isInlinedFrame());
</span><span class="cx"> #endif
</span><del>- activation = callFrame->uncheckedR(oldCodeBlock->activationRegister().offset()).jsValue();
</del><ins>+ activation = callFrame->uncheckedR(codeBlock->activationRegister().offset()).jsValue();
</ins><span class="cx"> if (activation)
</span><span class="cx"> jsCast<JSActivation*>(activation)->tearOff(*scope->vm());
</span><span class="cx"> }
</span><span class="cx">
</span><del>- if (oldCodeBlock->codeType() == FunctionCode && oldCodeBlock->usesArguments()) {
</del><ins>+ if (codeBlock->codeType() == FunctionCode && codeBlock->usesArguments()) {
</ins><span class="cx"> if (Arguments* arguments = visitor->existingArguments()) {
</span><span class="cx"> if (activation)
</span><span class="cx"> arguments->didTearOffActivation(callFrame, jsCast<JSActivation*>(activation));
</span><span class="lines">@@ -455,14 +454,7 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> CallFrame* callerFrame = callFrame->callerFrame();
</span><del>- if (callerFrame->isVMEntrySentinel()) {
- if (callerFrame->vmEntrySentinelCallerFrame())
- callFrame->vm().topCallFrame = callerFrame->vmEntrySentinelCallerFrame();
- else
- callFrame->vm().topCallFrame = callFrame; // _handleUncaughtException will pop the frame off.
- return false;
- }
- return true;
</del><ins>+ return !callerFrame->isVMEntrySentinel();
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> static StackFrameCodeType getStackFrameCodeType(StackVisitor& visitor)
</span></span></pre></div>
<a id="branchesjsCStackSourceJavaScriptCorejitJITOpcodescpp"></a>
<div class="modfile"><h4>Modified: branches/jsCStack/Source/JavaScriptCore/jit/JITOpcodes.cpp (160655 => 160656)</h4>
<pre class="diff"><span>
<span class="info">--- branches/jsCStack/Source/JavaScriptCore/jit/JITOpcodes.cpp        2013-12-16 20:44:01 UTC (rev 160655)
+++ branches/jsCStack/Source/JavaScriptCore/jit/JITOpcodes.cpp        2013-12-16 20:46:39 UTC (rev 160656)
</span><span class="lines">@@ -38,6 +38,7 @@
</span><span class="cx"> #include "JSFunction.h"
</span><span class="cx"> #include "JSPropertyNameIterator.h"
</span><span class="cx"> #include "LinkBuffer.h"
</span><ins>+#include "MaxFrameExtentForSlowPathCall.h"
</ins><span class="cx"> #include "SlowPathCall.h"
</span><span class="cx"> #include "VirtualRegister.h"
</span><span class="cx">
</span><span class="lines">@@ -635,6 +636,11 @@
</span><span class="cx"> {
</span><span class="cx"> move(TrustedImmPtr(m_vm), regT3);
</span><span class="cx"> load64(Address(regT3, VM::callFrameForThrowOffset()), callFrameRegister);
</span><ins>+
+ size_t frameExtent = JIT::frameRegisterCountFor(codeBlock()) * sizeof(Register) + maxFrameExtentForSlowPathCall;
+ ASSERT(frameExtent == WTF::roundUpToMultipleOf(stackAlignmentBytes(), frameExtent));
+ addPtr(TrustedImm32(-frameExtent), callFrameRegister, stackPointerRegister);
+
</ins><span class="cx"> load64(Address(regT3, VM::exceptionOffset()), regT0);
</span><span class="cx"> store64(TrustedImm64(JSValue::encode(JSValue())), Address(regT3, VM::exceptionOffset()));
</span><span class="cx"> emitPutVirtualRegister(currentInstruction[1].u.operand);
</span></span></pre></div>
<a id="branchesjsCStackSourceJavaScriptCorejitJITOpcodes32_64cpp"></a>
<div class="modfile"><h4>Modified: branches/jsCStack/Source/JavaScriptCore/jit/JITOpcodes32_64.cpp (160655 => 160656)</h4>
<pre class="diff"><span>
<span class="info">--- branches/jsCStack/Source/JavaScriptCore/jit/JITOpcodes32_64.cpp        2013-12-16 20:44:01 UTC (rev 160655)
+++ branches/jsCStack/Source/JavaScriptCore/jit/JITOpcodes32_64.cpp        2013-12-16 20:46:39 UTC (rev 160656)
</span><span class="lines">@@ -39,6 +39,7 @@
</span><span class="cx"> #include "JSPropertyNameIterator.h"
</span><span class="cx"> #include "JSVariableObject.h"
</span><span class="cx"> #include "LinkBuffer.h"
</span><ins>+#include "MaxFrameExtentForSlowPathCall.h"
</ins><span class="cx"> #include "SlowPathCall.h"
</span><span class="cx"> #include "VirtualRegister.h"
</span><span class="cx">
</span><span class="lines">@@ -119,11 +120,6 @@
</span><span class="cx"> // Handle an exception
</span><span class="cx"> sawException.link(this);
</span><span class="cx">
</span><del>- // Grab the return address.
- preserveReturnAddressAfterCall(regT1);
-
- move(TrustedImmPtr(&vm->exceptionLocation), regT2);
- storePtr(regT1, regT2);
</del><span class="cx"> storePtr(callFrameRegister, &m_vm->topCallFrame);
</span><span class="cx">
</span><span class="cx"> #if CPU(X86)
</span><span class="lines">@@ -927,6 +923,11 @@
</span><span class="cx"> move(TrustedImmPtr(m_vm), regT3);
</span><span class="cx"> // operationThrow returns the callFrame for the handler.
</span><span class="cx"> load32(Address(regT3, VM::callFrameForThrowOffset()), callFrameRegister);
</span><ins>+
+ size_t frameExtent = JIT::frameRegisterCountFor(codeBlock()) * sizeof(Register) + maxFrameExtentForSlowPathCall;
+ ASSERT(frameExtent == WTF::roundUpToMultipleOf(stackAlignmentBytes(), frameExtent));
+ addPtr(TrustedImm32(-frameExtent), callFrameRegister, stackPointerRegister);
+
</ins><span class="cx"> // Now store the exception returned by operationThrow.
</span><span class="cx"> load32(Address(regT3, VM::exceptionOffset() + OBJECT_OFFSETOF(JSValue, u.asBits.payload)), regT0);
</span><span class="cx"> load32(Address(regT3, VM::exceptionOffset() + OBJECT_OFFSETOF(JSValue, u.asBits.tag)), regT1);
</span></span></pre></div>
<a id="branchesjsCStackSourceJavaScriptCorejitThunkGeneratorscpp"></a>
<div class="modfile"><h4>Modified: branches/jsCStack/Source/JavaScriptCore/jit/ThunkGenerators.cpp (160655 => 160656)</h4>
<pre class="diff"><span>
<span class="info">--- branches/jsCStack/Source/JavaScriptCore/jit/ThunkGenerators.cpp        2013-12-16 20:44:01 UTC (rev 160655)
+++ branches/jsCStack/Source/JavaScriptCore/jit/ThunkGenerators.cpp        2013-12-16 20:46:39 UTC (rev 160656)
</span><span class="lines">@@ -367,6 +367,8 @@
</span><span class="cx"> breakpoint();
</span><span class="cx"> #endif
</span><span class="cx">
</span><ins>+ jit.emitFunctionEpilogue();
+
</ins><span class="cx"> // Check for an exception
</span><span class="cx"> #if USE(JSVALUE64)
</span><span class="cx"> jit.load64(vm->addressOfException(), JSInterfaceJIT::regT2);
</span><span class="lines">@@ -379,18 +381,11 @@
</span><span class="cx"> #endif
</span><span class="cx">
</span><span class="cx"> // Return.
</span><del>- jit.emitFunctionEpilogue();
</del><span class="cx"> jit.ret();
</span><span class="cx">
</span><span class="cx"> // Handle an exception
</span><span class="cx"> exceptionHandler.link(&jit);
</span><span class="cx">
</span><del>- // Grab the return address.
- jit.preserveReturnAddressAfterCall(JSInterfaceJIT::regT1);
-
- jit.move(JSInterfaceJIT::TrustedImmPtr(&vm->exceptionLocation), JSInterfaceJIT::regT2);
- jit.storePtr(JSInterfaceJIT::regT1, JSInterfaceJIT::regT2);
-
</del><span class="cx"> jit.storePtr(JSInterfaceJIT::callFrameRegister, &vm->topCallFrame);
</span><span class="cx">
</span><span class="cx"> #if CPU(X86) && USE(JSVALUE32_64)
</span></span></pre></div>
<a id="branchesjsCStackSourceJavaScriptCorellintLowLevelInterpreter32_64asm"></a>
<div class="modfile"><h4>Modified: branches/jsCStack/Source/JavaScriptCore/llint/LowLevelInterpreter32_64.asm (160655 => 160656)</h4>
<pre class="diff"><span>
<span class="info">--- branches/jsCStack/Source/JavaScriptCore/llint/LowLevelInterpreter32_64.asm        2013-12-16 20:44:01 UTC (rev 160655)
+++ branches/jsCStack/Source/JavaScriptCore/llint/LowLevelInterpreter32_64.asm        2013-12-16 20:46:39 UTC (rev 160656)
</span><span class="lines">@@ -344,7 +344,7 @@
</span><span class="cx"> end
</span><span class="cx">
</span><span class="cx"> _handleUncaughtException:
</span><del>- loadp ScopeChain[cfr], t3
</del><ins>+ loadp ScopeChain + PayloadOffset[cfr], t3
</ins><span class="cx"> andp MarkedBlockMask, t3
</span><span class="cx"> loadp MarkedBlock::m_weakSet + WeakSet::m_vm[t3], t3
</span><span class="cx"> loadp VM::callFrameForThrow[t3], cfr
</span><span class="lines">@@ -352,10 +352,10 @@
</span><span class="cx"> # So far, we've unwound the stack to the frame just below the sentinel frame.
</span><span class="cx"> # We need to pop to the sentinel frame and do the necessary clean up for
</span><span class="cx"> # returning to the caller C frame.
</span><del>- loadp CallerFrame[cfr], cfr
</del><ins>+ loadp CallerFrame + PayloadOffset[cfr], cfr
</ins><span class="cx">
</span><del>- loadp Callee[cfr], t3 # VM.topCallFrame
- loadp ScopeChain[cfr], t6
</del><ins>+ loadp Callee + PayloadOffset[cfr], t3 # VM.topCallFrame
+ loadp ScopeChain + PayloadOffset[cfr], t6
</ins><span class="cx"> storep t6, [t3]
</span><span class="cx">
</span><span class="cx"> callToJavaScriptEpilogue()
</span><span class="lines">@@ -2002,10 +2002,12 @@
</span><span class="cx"> # the interpreter's throw trampoline (see _llint_throw_trampoline).
</span><span class="cx"> # The throwing code must have known that we were throwing to the interpreter,
</span><span class="cx"> # and have set VM::targetInterpreterPCForThrow.
</span><del>- loadp ScopeChain[cfr], t3
</del><ins>+ loadp ScopeChain + PayloadOffset[cfr], t3
</ins><span class="cx"> andp MarkedBlockMask, t3
</span><span class="cx"> loadp MarkedBlock::m_weakSet + WeakSet::m_vm[t3], t3
</span><span class="cx"> loadp VM::callFrameForThrow[t3], cfr
</span><ins>+ restoreStackPointerAfterCall()
+
</ins><span class="cx"> loadi VM::targetInterpreterPCForThrow[t3], PC
</span><span class="cx"> loadi VM::m_exception + PayloadOffset[t3], t0
</span><span class="cx"> loadi VM::m_exception + TagOffset[t3], t1
</span></span></pre></div>
<a id="branchesjsCStackSourceJavaScriptCoreruntimeVMh"></a>
<div class="modfile"><h4>Modified: branches/jsCStack/Source/JavaScriptCore/runtime/VM.h (160655 => 160656)</h4>
<pre class="diff"><span>
<span class="info">--- branches/jsCStack/Source/JavaScriptCore/runtime/VM.h        2013-12-16 20:44:01 UTC (rev 160655)
+++ branches/jsCStack/Source/JavaScriptCore/runtime/VM.h        2013-12-16 20:46:39 UTC (rev 160656)
</span><span class="lines">@@ -381,7 +381,6 @@
</span><span class="cx"> const ClassInfo* const jsArrayClassInfo;
</span><span class="cx"> const ClassInfo* const jsFinalObjectClassInfo;
</span><span class="cx">
</span><del>- ReturnAddressPtr exceptionLocation;
</del><span class="cx"> JSValue hostCallReturnValue;
</span><span class="cx"> ExecState* newCallFrameReturnValue;
</span><span class="cx"> ExecState* callFrameForThrow;
</span></span></pre>
</div>
</div>
</body>
</html>