<!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>[160746] 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/160746">160746</a></dd>
<dt>Author</dt> <dd>msaboff@apple.com</dd>
<dt>Date</dt> <dd>2013-12-17 19:45:57 -0800 (Tue, 17 Dec 2013)</dd>
</dl>

<h3>Log Message</h3>
<pre>CStack Branch: Fix varargs calls to work on C stack
https://bugs.webkit.org/show_bug.cgi?id=125903

Reviewed by Filip Pizlo.

Fixed up the stack pointer after the sizeAndAllocFrameForVarargs() has been called in both the 
LLInt and baseline JIT code.  Adjusted the callee frame calculations in sizeAndAllocFrameForVarargs()
and compileLoadVarargs() to create aligned callee frames.

* interpreter/Interpreter.cpp:
(JSC::sizeAndAllocFrameForVarargs):
* jit/JIT.cpp:
(JSC::JIT::privateCompile):
* jit/JITCall.cpp:
(JSC::JIT::compileLoadVarargs):
* llint/LowLevelInterpreter.asm:</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="#branchesjsCStackSourceJavaScriptCorejitJITcpp">branches/jsCStack/Source/JavaScriptCore/jit/JIT.cpp</a></li>
<li><a href="#branchesjsCStackSourceJavaScriptCorejitJITCallcpp">branches/jsCStack/Source/JavaScriptCore/jit/JITCall.cpp</a></li>
<li><a href="#branchesjsCStackSourceJavaScriptCorellintLowLevelInterpreterasm">branches/jsCStack/Source/JavaScriptCore/llint/LowLevelInterpreter.asm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchesjsCStackSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: branches/jsCStack/Source/JavaScriptCore/ChangeLog (160745 => 160746)</h4>
<pre class="diff"><span>
<span class="info">--- branches/jsCStack/Source/JavaScriptCore/ChangeLog        2013-12-18 03:38:14 UTC (rev 160745)
+++ branches/jsCStack/Source/JavaScriptCore/ChangeLog        2013-12-18 03:45:57 UTC (rev 160746)
</span><span class="lines">@@ -1,3 +1,22 @@
</span><ins>+2013-12-17  Michael Saboff  &lt;msaboff@apple.com&gt;
+
+        CStack Branch: Fix varargs calls to work on C stack
+        https://bugs.webkit.org/show_bug.cgi?id=125903
+
+        Reviewed by Filip Pizlo.
+
+        Fixed up the stack pointer after the sizeAndAllocFrameForVarargs() has been called in both the 
+        LLInt and baseline JIT code.  Adjusted the callee frame calculations in sizeAndAllocFrameForVarargs()
+        and compileLoadVarargs() to create aligned callee frames.
+
+        * interpreter/Interpreter.cpp:
+        (JSC::sizeAndAllocFrameForVarargs):
+        * jit/JIT.cpp:
+        (JSC::JIT::privateCompile):
+        * jit/JITCall.cpp:
+        (JSC::JIT::compileLoadVarargs):
+        * llint/LowLevelInterpreter.asm:
+
</ins><span class="cx"> 2013-12-17  Mark Lam  &lt;mark.lam@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         frameRegisterCount() should include maxFrameExtentForSlowPathCall.
</span></span></pre></div>
<a id="branchesjsCStackSourceJavaScriptCoreinterpreterInterpretercpp"></a>
<div class="modfile"><h4>Modified: branches/jsCStack/Source/JavaScriptCore/interpreter/Interpreter.cpp (160745 => 160746)</h4>
<pre class="diff"><span>
<span class="info">--- branches/jsCStack/Source/JavaScriptCore/interpreter/Interpreter.cpp        2013-12-18 03:38:14 UTC (rev 160745)
+++ branches/jsCStack/Source/JavaScriptCore/interpreter/Interpreter.cpp        2013-12-18 03:45:57 UTC (rev 160746)
</span><span class="lines">@@ -65,6 +65,7 @@
</span><span class="cx"> #include &quot;RegExpPrototype.h&quot;
</span><span class="cx"> #include &quot;Register.h&quot;
</span><span class="cx"> #include &quot;SamplingTool.h&quot;
</span><ins>+#include &quot;StackAlignment.h&quot;
</ins><span class="cx"> #include &quot;StackVisitor.h&quot;
</span><span class="cx"> #include &quot;StrictEvalActivation.h&quot;
</span><span class="cx"> #include &quot;StrongInlines.h&quot;
</span><span class="lines">@@ -74,6 +75,7 @@
</span><span class="cx"> #include &lt;limits.h&gt;
</span><span class="cx"> #include &lt;stdio.h&gt;
</span><span class="cx"> #include &lt;wtf/StackStats.h&gt;
</span><ins>+#include &lt;wtf/StdLibExtras.h&gt;
</ins><span class="cx"> #include &lt;wtf/StringPrintStream.h&gt;
</span><span class="cx"> #include &lt;wtf/Threading.h&gt;
</span><span class="cx"> #include &lt;wtf/WTFThreadData.h&gt;
</span><span class="lines">@@ -156,7 +158,8 @@
</span><span class="cx"> {
</span><span class="cx">     if (!arguments) { // f.apply(x, arguments), with arguments unmodified.
</span><span class="cx">         unsigned argumentCountIncludingThis = callFrame-&gt;argumentCountIncludingThis();
</span><del>-        CallFrame* newCallFrame = CallFrame::create(callFrame-&gt;registers() + firstFreeRegister - argumentCountIncludingThis - JSStack::CallFrameHeaderSize - 1);
</del><ins>+        unsigned paddedCalleeFrameOffset = WTF::roundUpToMultipleOf(stackAlignmentRegisters(), -firstFreeRegister + argumentCountIncludingThis + JSStack::CallFrameHeaderSize + 1);
+        CallFrame* newCallFrame = CallFrame::create(callFrame-&gt;registers() - paddedCalleeFrameOffset);
</ins><span class="cx">         if (argumentCountIncludingThis &gt; Arguments::MaxArguments + 1 || !stack-&gt;grow(newCallFrame-&gt;registers())) {
</span><span class="cx">             callFrame-&gt;vm().throwException(callFrame, createStackOverflowError(callFrame));
</span><span class="cx">             return 0;
</span><span class="lines">@@ -165,7 +168,9 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     if (arguments.isUndefinedOrNull()) {
</span><del>-        CallFrame* newCallFrame = CallFrame::create(callFrame-&gt;registers() + firstFreeRegister - 1 - JSStack::CallFrameHeaderSize - 1);
</del><ins>+        unsigned argumentCountIncludingThis = 1;
+        unsigned paddedCalleeFrameOffset = WTF::roundUpToMultipleOf(stackAlignmentRegisters(),  -firstFreeRegister + argumentCountIncludingThis + JSStack::CallFrameHeaderSize + 1);
+        CallFrame* newCallFrame = CallFrame::create(callFrame-&gt;registers() - paddedCalleeFrameOffset);
</ins><span class="cx">         if (!stack-&gt;grow(newCallFrame-&gt;registers())) {
</span><span class="cx">             callFrame-&gt;vm().throwException(callFrame, createStackOverflowError(callFrame));
</span><span class="cx">             return 0;
</span><span class="lines">@@ -181,7 +186,8 @@
</span><span class="cx">     if (asObject(arguments)-&gt;classInfo() == Arguments::info()) {
</span><span class="cx">         Arguments* argsObject = asArguments(arguments);
</span><span class="cx">         unsigned argCount = argsObject-&gt;length(callFrame);
</span><del>-        CallFrame* newCallFrame = CallFrame::create(callFrame-&gt;registers() + firstFreeRegister - CallFrame::offsetFor(argCount + 1));
</del><ins>+        unsigned paddedCalleeFrameOffset = WTF::roundUpToMultipleOf(stackAlignmentRegisters(), -firstFreeRegister + CallFrame::offsetFor(argCount + 1));
+        CallFrame* newCallFrame = CallFrame::create(callFrame-&gt;registers() - paddedCalleeFrameOffset);
</ins><span class="cx">         if (argCount &gt; Arguments::MaxArguments || !stack-&gt;grow(newCallFrame-&gt;registers())) {
</span><span class="cx">             callFrame-&gt;vm().throwException(callFrame, createStackOverflowError(callFrame));
</span><span class="cx">             return 0;
</span><span class="lines">@@ -192,7 +198,8 @@
</span><span class="cx">     if (isJSArray(arguments)) {
</span><span class="cx">         JSArray* array = asArray(arguments);
</span><span class="cx">         unsigned argCount = array-&gt;length();
</span><del>-        CallFrame* newCallFrame = CallFrame::create(callFrame-&gt;registers() + firstFreeRegister - CallFrame::offsetFor(argCount + 1));
</del><ins>+        unsigned paddedCalleeFrameOffset = WTF::roundUpToMultipleOf(stackAlignmentRegisters(), -firstFreeRegister + CallFrame::offsetFor(argCount + 1));
+        CallFrame* newCallFrame = CallFrame::create(callFrame-&gt;registers() - paddedCalleeFrameOffset);
</ins><span class="cx">         if (argCount &gt; Arguments::MaxArguments || !stack-&gt;grow(newCallFrame-&gt;registers())) {
</span><span class="cx">             callFrame-&gt;vm().throwException(callFrame, createStackOverflowError(callFrame));
</span><span class="cx">             return 0;
</span><span class="lines">@@ -202,7 +209,8 @@
</span><span class="cx"> 
</span><span class="cx">     JSObject* argObject = asObject(arguments);
</span><span class="cx">     unsigned argCount = argObject-&gt;get(callFrame, callFrame-&gt;propertyNames().length).toUInt32(callFrame);
</span><del>-    CallFrame* newCallFrame = CallFrame::create(callFrame-&gt;registers() + firstFreeRegister - CallFrame::offsetFor(argCount + 1));
</del><ins>+    unsigned paddedCalleeFrameOffset = WTF::roundUpToMultipleOf(stackAlignmentRegisters(), -firstFreeRegister + CallFrame::offsetFor(argCount + 1));
+    CallFrame* newCallFrame = CallFrame::create(callFrame-&gt;registers() - paddedCalleeFrameOffset);
</ins><span class="cx">     if (argCount &gt; Arguments::MaxArguments || !stack-&gt;grow(newCallFrame-&gt;registers())) {
</span><span class="cx">         callFrame-&gt;vm().throwException(callFrame,  createStackOverflowError(callFrame));
</span><span class="cx">         return 0;
</span></span></pre></div>
<a id="branchesjsCStackSourceJavaScriptCorejitJITcpp"></a>
<div class="modfile"><h4>Modified: branches/jsCStack/Source/JavaScriptCore/jit/JIT.cpp (160745 => 160746)</h4>
<pre class="diff"><span>
<span class="info">--- branches/jsCStack/Source/JavaScriptCore/jit/JIT.cpp        2013-12-18 03:38:14 UTC (rev 160745)
+++ branches/jsCStack/Source/JavaScriptCore/jit/JIT.cpp        2013-12-18 03:45:57 UTC (rev 160746)
</span><span class="lines">@@ -547,7 +547,7 @@
</span><span class="cx">     Label functionBody = label();
</span><span class="cx"> 
</span><span class="cx">     checkStackPointerAlignment();
</span><del>-    addPtr(TrustedImm32(-frameRegisterCountFor(m_codeBlock) * sizeof(Register)), callFrameRegister, stackPointerRegister);
</del><ins>+    addPtr(TrustedImm32(-frameRegisterCountFor(m_codeBlock) * sizeof(Register) - maxFrameExtentForSlowPathCall), callFrameRegister, stackPointerRegister);
</ins><span class="cx">     checkStackPointerAlignment();
</span><span class="cx"> 
</span><span class="cx">     privateCompileMainPass();
</span></span></pre></div>
<a id="branchesjsCStackSourceJavaScriptCorejitJITCallcpp"></a>
<div class="modfile"><h4>Modified: branches/jsCStack/Source/JavaScriptCore/jit/JITCall.cpp (160745 => 160746)</h4>
<pre class="diff"><span>
<span class="info">--- branches/jsCStack/Source/JavaScriptCore/jit/JITCall.cpp        2013-12-18 03:38:14 UTC (rev 160745)
+++ branches/jsCStack/Source/JavaScriptCore/jit/JITCall.cpp        2013-12-18 03:45:57 UTC (rev 160746)
</span><span class="lines">@@ -39,6 +39,7 @@
</span><span class="cx"> #include &quot;RepatchBuffer.h&quot;
</span><span class="cx"> #include &quot;ResultType.h&quot;
</span><span class="cx"> #include &quot;SamplingTool.h&quot;
</span><ins>+#include &quot;StackAlignment.h&quot;
</ins><span class="cx"> #include &quot;ThunkGenerators.h&quot;
</span><span class="cx"> #include &lt;wtf/StringPrintStream.h&gt;
</span><span class="cx"> 
</span><span class="lines">@@ -71,10 +72,14 @@
</span><span class="cx">         emitGetFromCallFrameHeader32(JSStack::ArgumentCount, regT0);
</span><span class="cx">         slowCase.append(branch32(Above, regT0, TrustedImm32(Arguments::MaxArguments + 1)));
</span><span class="cx">         // regT0: argumentCountIncludingThis
</span><ins>+        move(regT0, regT1);
+        add64(TrustedImm32(-firstFreeRegister + JSStack::CallFrameHeaderSize), regT1);
+        // regT1 now has the required frame size in Register units
+        // Round regT1 to next multiple of stackAlignmentRegisters()
+        add64(TrustedImm32(stackAlignmentRegisters() - 1), regT1);
+        and64(TrustedImm32(~(stackAlignmentRegisters() - 1)), regT1);
</ins><span class="cx"> 
</span><del>-        move(regT0, regT1);
</del><span class="cx">         neg64(regT1);
</span><del>-        add64(TrustedImm32(firstFreeRegister - JSStack::CallFrameHeaderSize), regT1);
</del><span class="cx">         lshift64(TrustedImm32(3), regT1);
</span><span class="cx">         addPtr(callFrameRegister, regT1);
</span><span class="cx">         // regT1: newCallFrame
</span><span class="lines">@@ -106,6 +111,7 @@
</span><span class="cx"> 
</span><span class="cx">     emitGetVirtualRegister(arguments, regT1);
</span><span class="cx">     callOperation(operationSizeAndAllocFrameForVarargs, regT1, firstFreeRegister);
</span><ins>+    move(returnValueGPR, stackPointerRegister);
</ins><span class="cx">     emitGetVirtualRegister(thisValue, regT1);
</span><span class="cx">     emitGetVirtualRegister(arguments, regT2);
</span><span class="cx">     callOperation(operationLoadVarargs, returnValueGPR, regT1, regT2);
</span></span></pre></div>
<a id="branchesjsCStackSourceJavaScriptCorellintLowLevelInterpreterasm"></a>
<div class="modfile"><h4>Modified: branches/jsCStack/Source/JavaScriptCore/llint/LowLevelInterpreter.asm (160745 => 160746)</h4>
<pre class="diff"><span>
<span class="info">--- branches/jsCStack/Source/JavaScriptCore/llint/LowLevelInterpreter.asm        2013-12-18 03:38:14 UTC (rev 160745)
+++ branches/jsCStack/Source/JavaScriptCore/llint/LowLevelInterpreter.asm        2013-12-18 03:45:57 UTC (rev 160746)
</span><span class="lines">@@ -798,6 +798,10 @@
</span><span class="cx">     traceExecution()
</span><span class="cx">     callSlowPath(_llint_slow_path_size_and_alloc_frame_for_varargs)
</span><span class="cx">     branchIfException(_llint_throw_from_slow_path_trampoline)
</span><ins>+    loadp CodeBlock[cfr], t0
+    loadp CodeBlock::m_vm[t0], t0
+    loadp VM::newCallFrameReturnValue[t0], t0
+    move t0, sp
</ins><span class="cx">     slowPathForCall(_llint_slow_path_call_varargs)
</span><span class="cx"> 
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>