<!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>[166142] 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/166142">166142</a></dd>
<dt>Author</dt> <dd>fpizlo@apple.com</dd>
<dt>Date</dt> <dd>2014-03-23 11:56:56 -0700 (Sun, 23 Mar 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Gotta grow the locals vectors if we are about to do SetLocals beyond the bytecode's numCalleeRegisters
https://bugs.webkit.org/show_bug.cgi?id=130650
&lt;rdar://problem/16122966&gt;

Reviewed by Michael Saboff.
        
Previously, it was only in the case of inlining that we would do SetLocal's beyond the
previously established numLocals limit. But then we added generalized op_call_varargs
handling, which results in us emitting SetLocals that didn't previously exist in the
bytecode.
        
This factors out the inliner's ensureLocals loop and calls it from op_call_varargs.

* dfg/DFGByteCodeParser.cpp:
(JSC::DFG::ByteCodeParser::ensureLocals):
(JSC::DFG::ByteCodeParser::handleInlining):
(JSC::DFG::ByteCodeParser::parseBlock):
(JSC::DFG::ByteCodeParser::parse):
* ftl/FTLOSRExitCompiler.cpp:
(JSC::FTL::compileStub): Make this do alignment correctly.
* runtime/Options.h:
* tests/stress/call-varargs-from-inlined-code.js: Added.
* tests/stress/call-varargs-from-inlined-code-with-odd-number-of-arguments.js: Added.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoredfgDFGByteCodeParsercpp">trunk/Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreftlFTLOSRExitCompilercpp">trunk/Source/JavaScriptCore/ftl/FTLOSRExitCompiler.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeOptionsh">trunk/Source/JavaScriptCore/runtime/Options.h</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoretestsstresscallvarargsfrominlinedcodewithoddnumberofargumentsjs">trunk/Source/JavaScriptCore/tests/stress/call-varargs-from-inlined-code-with-odd-number-of-arguments.js</a></li>
<li><a href="#trunkSourceJavaScriptCoretestsstresscallvarargsfrominlinedcodejs">trunk/Source/JavaScriptCore/tests/stress/call-varargs-from-inlined-code.js</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (166141 => 166142)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2014-03-23 17:32:13 UTC (rev 166141)
+++ trunk/Source/JavaScriptCore/ChangeLog        2014-03-23 18:56:56 UTC (rev 166142)
</span><span class="lines">@@ -1,3 +1,29 @@
</span><ins>+2014-03-23  Filip Pizlo  &lt;fpizlo@apple.com&gt;
+
+        Gotta grow the locals vectors if we are about to do SetLocals beyond the bytecode's numCalleeRegisters
+        https://bugs.webkit.org/show_bug.cgi?id=130650
+        &lt;rdar://problem/16122966&gt;
+
+        Reviewed by Michael Saboff.
+        
+        Previously, it was only in the case of inlining that we would do SetLocal's beyond the
+        previously established numLocals limit. But then we added generalized op_call_varargs
+        handling, which results in us emitting SetLocals that didn't previously exist in the
+        bytecode.
+        
+        This factors out the inliner's ensureLocals loop and calls it from op_call_varargs.
+
+        * dfg/DFGByteCodeParser.cpp:
+        (JSC::DFG::ByteCodeParser::ensureLocals):
+        (JSC::DFG::ByteCodeParser::handleInlining):
+        (JSC::DFG::ByteCodeParser::parseBlock):
+        (JSC::DFG::ByteCodeParser::parse):
+        * ftl/FTLOSRExitCompiler.cpp:
+        (JSC::FTL::compileStub): Make this do alignment correctly.
+        * runtime/Options.h:
+        * tests/stress/call-varargs-from-inlined-code.js: Added.
+        * tests/stress/call-varargs-from-inlined-code-with-odd-number-of-arguments.js: Added.
+
</ins><span class="cx"> 2014-03-22  Filip Pizlo  &lt;fpizlo@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Unreviewed, adjust sizes for ARM64.
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoredfgDFGByteCodeParsercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp (166141 => 166142)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp        2014-03-23 17:32:13 UTC (rev 166141)
+++ trunk/Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp        2014-03-23 18:56:56 UTC (rev 166142)
</span><span class="lines">@@ -156,6 +156,15 @@
</span><span class="cx"> 
</span><span class="cx">     // Just parse from m_currentIndex to the end of the current CodeBlock.
</span><span class="cx">     void parseCodeBlock();
</span><ins>+    
+    void ensureLocals(unsigned newNumLocals)
+    {
+        if (newNumLocals &lt;= m_numLocals)
+            return;
+        m_numLocals = newNumLocals;
+        for (size_t i = 0; i &lt; m_graph.numBlocks(); ++i)
+            m_graph.block(i)-&gt;ensureLocals(newNumLocals);
+    }
</ins><span class="cx"> 
</span><span class="cx">     // Helper for min and max.
</span><span class="cx">     bool handleMinMax(int resultOperand, NodeType op, int registerOffset, int argumentCountIncludingThis);
</span><span class="lines">@@ -1365,13 +1374,9 @@
</span><span class="cx">     
</span><span class="cx">     int inlineCallFrameStart = m_inlineStackTop-&gt;remapOperand(VirtualRegister(registerOffset)).offset() + JSStack::CallFrameHeaderSize;
</span><span class="cx">     
</span><del>-    // Make sure that we have enough locals.
-    unsigned newNumLocals = VirtualRegister(inlineCallFrameStart).toLocal() + 1 + JSStack::CallFrameHeaderSize + codeBlock-&gt;m_numCalleeRegisters;
-    if (newNumLocals &gt; m_numLocals) {
-        m_numLocals = newNumLocals;
-        for (size_t i = 0; i &lt; m_graph.numBlocks(); ++i)
-            m_graph.block(i)-&gt;ensureLocals(newNumLocals);
-    }
</del><ins>+    ensureLocals(
+        VirtualRegister(inlineCallFrameStart).toLocal() + 1 +
+        JSStack::CallFrameHeaderSize + codeBlock-&gt;m_numCalleeRegisters);
</ins><span class="cx">     
</span><span class="cx">     size_t argumentPositionStart = m_graph.m_argumentPositions.size();
</span><span class="cx"> 
</span><span class="lines">@@ -2127,6 +2132,9 @@
</span><span class="cx">         m_currentInstruction = currentInstruction; // Some methods want to use this, and we'd rather not thread it through calls.
</span><span class="cx">         OpcodeID opcodeID = interpreter-&gt;getOpcodeID(currentInstruction-&gt;u.opcode);
</span><span class="cx">         
</span><ins>+        if (Options::verboseDFGByteCodeParsing())
+            dataLog(&quot;    parsing &quot;, currentCodeOrigin(), &quot;\n&quot;);
+        
</ins><span class="cx">         if (m_graph.compilation()) {
</span><span class="cx">             addToGraph(CountExecution, OpInfo(m_graph.compilation()-&gt;executionCounterFor(
</span><span class="cx">                 Profiler::OriginStack(*m_vm-&gt;m_perBytecodeProfiler, m_codeBlock, currentCodeOrigin()))));
</span><span class="lines">@@ -2912,6 +2920,10 @@
</span><span class="cx">             registerOffset = -WTF::roundUpToMultipleOf(
</span><span class="cx">                 stackAlignmentRegisters(),
</span><span class="cx">                 -registerOffset);
</span><ins>+
+            ensureLocals(
+                m_inlineStackTop-&gt;remapOperand(
+                    VirtualRegister(registerOffset)).toLocal());
</ins><span class="cx">             
</span><span class="cx">             // The bytecode wouldn't have set up the arguments. But we'll do it and make it
</span><span class="cx">             // look like the bytecode had done it.
</span><span class="lines">@@ -3585,6 +3597,9 @@
</span><span class="cx">     // Set during construction.
</span><span class="cx">     ASSERT(!m_currentIndex);
</span><span class="cx">     
</span><ins>+    if (Options::verboseDFGByteCodeParsing())
+        dataLog(&quot;Parsing &quot;, *m_codeBlock, &quot;\n&quot;);
+    
</ins><span class="cx">     m_dfgCodeBlock = m_graph.m_plan.profiledDFGCodeBlock.get();
</span><span class="cx">     if (isFTL(m_graph.m_plan.mode) &amp;&amp; m_dfgCodeBlock) {
</span><span class="cx">         if (Options::enablePolyvariantCallInlining())
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreftlFTLOSRExitCompilercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ftl/FTLOSRExitCompiler.cpp (166141 => 166142)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ftl/FTLOSRExitCompiler.cpp        2014-03-23 17:32:13 UTC (rev 166141)
+++ trunk/Source/JavaScriptCore/ftl/FTLOSRExitCompiler.cpp        2014-03-23 18:56:56 UTC (rev 166142)
</span><span class="lines">@@ -77,8 +77,9 @@
</span><span class="cx"> 
</span><span class="cx">     saveAllRegisters(jit, registerScratch);
</span><span class="cx">     
</span><del>-    // Bring the stack back into a sane form.
</del><ins>+    // Bring the stack back into a sane form and assert that it's sane.
</ins><span class="cx">     jit.popToRestore(GPRInfo::regT0);
</span><ins>+    jit.checkStackPointerAlignment();
</ins><span class="cx">     
</span><span class="cx">     if (vm-&gt;m_perBytecodeProfiler &amp;&amp; codeBlock-&gt;jitCode()-&gt;dfgCommon()-&gt;compilation) {
</span><span class="cx">         Profiler::Database&amp; database = *vm-&gt;m_perBytecodeProfiler;
</span><span class="lines">@@ -259,12 +260,16 @@
</span><span class="cx">     arityIntact.link(&amp;jit);
</span><span class="cx"> 
</span><span class="cx">     // First set up SP so that our data doesn't get clobbered by signals.
</span><ins>+    unsigned conservativeStackDelta =
+        registerPreservationOffset() +
+        exit.m_values.numberOfLocals() * sizeof(Register) +
+        maxFrameExtentForSlowPathCall;
+    conservativeStackDelta = WTF::roundUpToMultipleOf(
+        stackAlignmentBytes(), conservativeStackDelta);
</ins><span class="cx">     jit.addPtr(
</span><del>-        MacroAssembler::TrustedImm32(
-            WTF::roundUpToMultipleOf(
-                stackAlignmentRegisters(),
-                -registerPreservationOffset() - exit.m_values.numberOfLocals() * sizeof(Register) - maxFrameExtentForSlowPathCall)),
</del><ins>+        MacroAssembler::TrustedImm32(-conservativeStackDelta),
</ins><span class="cx">         MacroAssembler::framePointerRegister, MacroAssembler::stackPointerRegister);
</span><ins>+    jit.checkStackPointerAlignment();
</ins><span class="cx">     
</span><span class="cx">     jit.subPtr(
</span><span class="cx">         MacroAssembler::TrustedImm32(registerPreservationOffset()),
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeOptionsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/Options.h (166141 => 166142)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/Options.h        2014-03-23 17:32:13 UTC (rev 166141)
+++ trunk/Source/JavaScriptCore/runtime/Options.h        2014-03-23 18:56:56 UTC (rev 166142)
</span><span class="lines">@@ -117,6 +117,7 @@
</span><span class="cx">     v(optionRange, bytecodeRangeToDFGCompile, 0) \
</span><span class="cx">     v(bool, dumpBytecodeAtDFGTime, false) \
</span><span class="cx">     v(bool, dumpGraphAtEachPhase, false) \
</span><ins>+    v(bool, verboseDFGByteCodeParsing, false) \
</ins><span class="cx">     v(bool, verboseCompilation, false) \
</span><span class="cx">     v(bool, verboseFTLCompilation, false) \
</span><span class="cx">     v(bool, logCompilationChanges, false) \
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoretestsstresscallvarargsfrominlinedcodewithoddnumberofargumentsjs"></a>
<div class="addfile"><h4>Added: trunk/Source/JavaScriptCore/tests/stress/call-varargs-from-inlined-code-with-odd-number-of-arguments.js (0 => 166142)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/tests/stress/call-varargs-from-inlined-code-with-odd-number-of-arguments.js                                (rev 0)
+++ trunk/Source/JavaScriptCore/tests/stress/call-varargs-from-inlined-code-with-odd-number-of-arguments.js        2014-03-23 18:56:56 UTC (rev 166142)
</span><span class="lines">@@ -0,0 +1,26 @@
</span><ins>+function foo(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y) {
+    return a * 2 + b * 3 + c * 5 + d * 7 + e * 11 + f * 13 + g * 17 + h * 19 + i * 23 + j * 29 + k * 31 + l * 37 + m * 41 + n * 43 + o * 47 + p * 53 + q * 59 + r * 61 + s * 67 + t * 71 + u * 73 + v * 79 + w * 83 + x * 89 + y * 97;
+}
+
+function bar() {
+    return foo.apply(this, arguments);
+}
+
+function baz(x) {
+    return bar(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25) + x;
+}
+
+noInline(baz);
+
+for (var i = 0; i &lt; 10000; ++i) {
+    var result = baz(0);
+    if (result != 21586 - 26 * 101)
+        throw &quot;Error: bad result: &quot; + result;
+}
+
+// Force recompilation.
+for (var i = 0; i &lt; 10000; ++i) {
+    var result = baz(2147483646);
+    if (result != 2147502606)
+        throw &quot;Error: bad result: &quot; + result;
+}
</ins></span></pre></div>
<a id="trunkSourceJavaScriptCoretestsstresscallvarargsfrominlinedcodejs"></a>
<div class="addfile"><h4>Added: trunk/Source/JavaScriptCore/tests/stress/call-varargs-from-inlined-code.js (0 => 166142)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/tests/stress/call-varargs-from-inlined-code.js                                (rev 0)
+++ trunk/Source/JavaScriptCore/tests/stress/call-varargs-from-inlined-code.js        2014-03-23 18:56:56 UTC (rev 166142)
</span><span class="lines">@@ -0,0 +1,26 @@
</span><ins>+function foo(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z) {
+    return a * 2 + b * 3 + c * 5 + d * 7 + e * 11 + f * 13 + g * 17 + h * 19 + i * 23 + j * 29 + k * 31 + l * 37 + m * 41 + n * 43 + o * 47 + p * 53 + q * 59 + r * 61 + s * 67 + t * 71 + u * 73 + v * 79 + w * 83 + x * 89 + y * 97 + z * 101;
+}
+
+function bar() {
+    return foo.apply(this, arguments);
+}
+
+function baz(x) {
+    return bar(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26) + x;
+}
+
+noInline(baz);
+
+for (var i = 0; i &lt; 10000; ++i) {
+    var result = baz(0);
+    if (result != 21586)
+        throw &quot;Error: bad result: &quot; + result;
+}
+
+// Force recompilation.
+for (var i = 0; i &lt; 10000; ++i) {
+    var result = baz(2147483646);
+    if (result != 2147505232)
+        throw &quot;Error: bad result: &quot; + result;
+}
</ins></span></pre>
</div>
</div>

</body>
</html>