<!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>[164069] trunk/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/164069">164069</a></dd>
<dt>Author</dt> <dd>msaboff@apple.com</dd>
<dt>Date</dt> <dd>2014-02-13 15:35:08 -0800 (Thu, 13 Feb 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Change FTL stack check to use VM's stackLimit
https://bugs.webkit.org/show_bug.cgi?id=128561

Reviewed by Filip Pizlo.

Changes FTL function entry to check the call frame register against the FTL
specific stack limit (VM::m_ftlStackLimit) and throw an exception if the
stack limit has been exceeded.  Updated the exception handling code to have
a second entry that will unroll the current frame to the caller, since that
is where the exception should be processed.

* ftl/FTLCompile.cpp:
(JSC::FTL::fixFunctionBasedOnStackMaps):
* ftl/FTLIntrinsicRepository.h:
* ftl/FTLLowerDFGToLLVM.cpp:
(JSC::FTL::LowerDFGToLLVM::lower):
* ftl/FTLState.h:
* runtime/VM.h:
(JSC::VM::addressOfFTLStackLimit):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoreftlFTLCompilecpp">trunk/Source/JavaScriptCore/ftl/FTLCompile.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreftlFTLIntrinsicRepositoryh">trunk/Source/JavaScriptCore/ftl/FTLIntrinsicRepository.h</a></li>
<li><a href="#trunkSourceJavaScriptCoreftlFTLLowerDFGToLLVMcpp">trunk/Source/JavaScriptCore/ftl/FTLLowerDFGToLLVM.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreftlFTLStateh">trunk/Source/JavaScriptCore/ftl/FTLState.h</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeVMh">trunk/Source/JavaScriptCore/runtime/VM.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (164068 => 164069)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2014-02-13 23:34:35 UTC (rev 164068)
+++ trunk/Source/JavaScriptCore/ChangeLog        2014-02-13 23:35:08 UTC (rev 164069)
</span><span class="lines">@@ -1,3 +1,25 @@
</span><ins>+2014-02-13  Michael Saboff  &lt;msaboff@apple.com&gt;
+
+        Change FTL stack check to use VM's stackLimit
+        https://bugs.webkit.org/show_bug.cgi?id=128561
+
+        Reviewed by Filip Pizlo.
+
+        Changes FTL function entry to check the call frame register against the FTL
+        specific stack limit (VM::m_ftlStackLimit) and throw an exception if the
+        stack limit has been exceeded.  Updated the exception handling code to have
+        a second entry that will unroll the current frame to the caller, since that
+        is where the exception should be processed.
+
+        * ftl/FTLCompile.cpp:
+        (JSC::FTL::fixFunctionBasedOnStackMaps):
+        * ftl/FTLIntrinsicRepository.h:
+        * ftl/FTLLowerDFGToLLVM.cpp:
+        (JSC::FTL::LowerDFGToLLVM::lower):
+        * ftl/FTLState.h:
+        * runtime/VM.h:
+        (JSC::VM::addressOfFTLStackLimit):
+
</ins><span class="cx"> 2014-02-13  Filip Pizlo  &lt;fpizlo@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         GetByIdStatus shouldn't call takesSlowPathInDFGForImpureProperty() for self accesses, and calling that method should never assert about anything
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreftlFTLCompilecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ftl/FTLCompile.cpp (164068 => 164069)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ftl/FTLCompile.cpp        2014-02-13 23:34:35 UTC (rev 164068)
+++ trunk/Source/JavaScriptCore/ftl/FTLCompile.cpp        2014-02-13 23:35:08 UTC (rev 164069)
</span><span class="lines">@@ -207,19 +207,27 @@
</span><span class="cx">             VirtualRegister(codeBlock-&gt;argumentsRegister().offset() + localsOffset));
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    MacroAssembler::Label stackOverflowException;
+
</ins><span class="cx">     {
</span><span class="cx">         CCallHelpers checkJIT(&amp;vm, codeBlock);
</span><span class="cx">         
</span><span class="cx">         // At this point it's perfectly fair to just blow away all state and restore the
</span><span class="cx">         // JS JIT view of the universe.
</span><ins>+        checkJIT.move(GPRInfo::callFrameRegister, GPRInfo::argumentGPR1);
+
+        MacroAssembler::Label exceptionContinueArg1Set = checkJIT.label();
</ins><span class="cx">         checkJIT.move(MacroAssembler::TrustedImm64(TagTypeNumber), GPRInfo::tagTypeNumberRegister);
</span><span class="cx">         checkJIT.move(MacroAssembler::TrustedImm64(TagMask), GPRInfo::tagMaskRegister);
</span><del>-        
</del><ins>+
</ins><span class="cx">         checkJIT.move(MacroAssembler::TrustedImmPtr(&amp;vm), GPRInfo::argumentGPR0);
</span><del>-        checkJIT.move(GPRInfo::callFrameRegister, GPRInfo::argumentGPR1);
</del><span class="cx">         MacroAssembler::Call call = checkJIT.call();
</span><span class="cx">         checkJIT.jumpToExceptionHandler();
</span><del>-        
</del><ins>+
+        stackOverflowException = checkJIT.label();
+        checkJIT.emitGetCallerFrameFromCallFrameHeaderPtr(GPRInfo::argumentGPR1);
+        checkJIT.jump(exceptionContinueArg1Set);
+
</ins><span class="cx">         OwnPtr&lt;LinkBuffer&gt; linkBuffer = adoptPtr(new LinkBuffer(
</span><span class="cx">             vm, &amp;checkJIT, codeBlock, JITCompilationMustSucceed));
</span><span class="cx">         linkBuffer-&gt;link(call, FunctionPtr(lookupExceptionHandler));
</span><span class="lines">@@ -412,6 +420,22 @@
</span><span class="cx">     }
</span><span class="cx">     
</span><span class="cx">     RepatchBuffer repatchBuffer(codeBlock);
</span><ins>+
+    iter = recordMap.find(state.handleStackOverflowExceptionStackmapID);
+    // It's sort of remotely possible that we won't have an in-band exception handling
+    // path, for some kinds of functions.
+    if (iter != recordMap.end()) {
+        for (unsigned i = iter-&gt;value.size(); i--;) {
+            StackMaps::Record&amp; record = iter-&gt;value[i];
+            
+            CodeLocationLabel source = CodeLocationLabel(
+                bitwise_cast&lt;char*&gt;(generatedFunction) + record.instructionOffset);
+
+            RELEASE_ASSERT(stackOverflowException.isSet());
+
+            repatchBuffer.replaceWithJump(source, state.finalizer-&gt;handleExceptionsLinkBuffer-&gt;locationOf(stackOverflowException));
+        }
+    }
</ins><span class="cx">     
</span><span class="cx">     iter = recordMap.find(state.handleExceptionStackmapID);
</span><span class="cx">     // It's sort of remotely possible that we won't have an in-band exception handling
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreftlFTLIntrinsicRepositoryh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ftl/FTLIntrinsicRepository.h (164068 => 164069)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ftl/FTLIntrinsicRepository.h        2014-02-13 23:34:35 UTC (rev 164068)
+++ trunk/Source/JavaScriptCore/ftl/FTLIntrinsicRepository.h        2014-02-13 23:35:08 UTC (rev 164069)
</span><span class="lines">@@ -86,6 +86,7 @@
</span><span class="cx">     macro(V_JITOperation_EOZD, functionType(voidType, intPtr, intPtr, int32, doubleType)) \
</span><span class="cx">     macro(V_JITOperation_EOZJ, functionType(voidType, intPtr, intPtr, int32, int64)) \
</span><span class="cx">     macro(V_JITOperation_EC, functionType(voidType, intPtr, intPtr)) \
</span><ins>+    macro(V_JITOperation_ECb, functionType(voidType, intPtr, intPtr)) \
</ins><span class="cx">     macro(V_JITOperation_EVws, functionType(voidType, intPtr, intPtr)) \
</span><span class="cx">     macro(Z_JITOperation_D, functionType(int32, doubleType))
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreftlFTLLowerDFGToLLVMcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ftl/FTLLowerDFGToLLVM.cpp (164068 => 164069)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ftl/FTLLowerDFGToLLVM.cpp        2014-02-13 23:34:35 UTC (rev 164068)
+++ trunk/Source/JavaScriptCore/ftl/FTLLowerDFGToLLVM.cpp        2014-02-13 23:35:08 UTC (rev 164069)
</span><span class="lines">@@ -52,10 +52,6 @@
</span><span class="cx"> 
</span><span class="cx"> static std::atomic&lt;int&gt; compileCounter;
</span><span class="cx"> 
</span><del>-// FIXME: Get rid of this and introduce a real stack check.
-// https://bugs.webkit.org/show_bug.cgi?id=125650
-static uintptr_t stackLimit;
-
</del><span class="cx"> // Using this instead of typeCheck() helps to reduce the load on LLVM, by creating
</span><span class="cx"> // significantly less dead code.
</span><span class="cx"> #define FTL_TYPE_CHECK(lowValue, highValue, typesPassedThrough, failCondition) do { \
</span><span class="lines">@@ -140,13 +136,16 @@
</span><span class="cx">         
</span><span class="cx">         m_out.storePtr(m_out.constIntPtr(codeBlock()), addressFor(JSStack::CodeBlock));
</span><span class="cx">         m_out.branch(
</span><del>-            m_out.below(m_callFrame, m_out.loadPtr(m_out.absolute(&amp;stackLimit))),
</del><ins>+            m_out.below(m_callFrame, m_out.loadPtr(m_out.absolute(vm().addressOfFTLStackLimit()))),
</ins><span class="cx">             stackOverflow, lowBlock(m_graph.block(0)));
</span><span class="cx">         
</span><span class="cx">         m_out.appendTo(stackOverflow, m_handleExceptions);
</span><del>-        // FIXME: Do a real stack check and throw the exception appropriately.
-        // https://bugs.webkit.org/show_bug.cgi?id=125650
-        m_out.crash();
</del><ins>+        vmCall(m_out.operation(operationThrowStackOverflowError), m_callFrame, m_out.constIntPtr(codeBlock()), NoExceptions);
+        m_ftlState.handleStackOverflowExceptionStackmapID = m_stackmapIDs++;
+        m_out.call(
+            m_out.stackmapIntrinsic(), m_out.constInt64(m_ftlState.handleStackOverflowExceptionStackmapID),
+            m_out.constInt32(MacroAssembler::maxJumpReplacementSize()));
+        m_out.unreachable();
</ins><span class="cx">         
</span><span class="cx">         m_out.appendTo(m_handleExceptions, lowBlock(m_graph.block(0)));
</span><span class="cx">         m_ftlState.handleExceptionStackmapID = m_stackmapIDs++;
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreftlFTLStateh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ftl/FTLState.h (164068 => 164069)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ftl/FTLState.h        2014-02-13 23:34:35 UTC (rev 164068)
+++ trunk/Source/JavaScriptCore/ftl/FTLState.h        2014-02-13 23:35:08 UTC (rev 164069)
</span><span class="lines">@@ -58,6 +58,7 @@
</span><span class="cx">     RefPtr&lt;JITCode&gt; jitCode;
</span><span class="cx">     GeneratedFunction generatedFunction;
</span><span class="cx">     JITFinalizer* finalizer;
</span><ins>+    unsigned handleStackOverflowExceptionStackmapID;
</ins><span class="cx">     unsigned handleExceptionStackmapID;
</span><span class="cx">     unsigned capturedStackmapID;
</span><span class="cx">     SegmentedVector&lt;GetByIdDescriptor&gt; getByIds;
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeVMh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/VM.h (164068 => 164069)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/VM.h        2014-02-13 23:34:35 UTC (rev 164068)
+++ trunk/Source/JavaScriptCore/runtime/VM.h        2014-02-13 23:35:08 UTC (rev 164069)
</span><span class="lines">@@ -383,6 +383,7 @@
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(FTL_JIT)
</span><span class="cx">         void updateFTLLargestStackSize(size_t);
</span><ins>+        void** addressOfFTLStackLimit() { return &amp;m_ftlStackLimit; }
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">         void** addressOfJSStackLimit() { return &amp;m_jsStackLimit; }
</span></span></pre>
</div>
</div>

</body>
</html>