<!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>[189928] trunk/Source</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/189928">189928</a></dd>
<dt>Author</dt> <dd>fpizlo@apple.com</dd>
<dt>Date</dt> <dd>2015-09-17 13:26:16 -0700 (Thu, 17 Sep 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>stress/exit-from-getter.js.ftl-eager occasionally traps in debug
https://bugs.webkit.org/show_bug.cgi?id=149096

Reviewed by Geoffrey Garen.

JS calls to getters/setters in get/put inline caches need to reset SP after the call, as our
calling convention requires.

* bytecode/PolymorphicAccess.cpp:
(JSC::AccessCase::generate): Fix the bug.
* ftl/FTLLink.cpp:
(JSC::FTL::link): Adds some verbiage about why the FTL stack offset logic is correct.
* tests/stress/getter-arity.js: Added. Other tests would flaky crash before the patch. This test instacrashes before the patch.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCorebytecodePolymorphicAccesscpp">trunk/Source/JavaScriptCore/bytecode/PolymorphicAccess.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreftlFTLLinkcpp">trunk/Source/JavaScriptCore/ftl/FTLLink.cpp</a></li>
<li><a href="#trunkSourceWTFbenchmarksLockSpeedTestcpp">trunk/Source/WTF/benchmarks/LockSpeedTest.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoretestsstressgetterarityjs">trunk/Source/JavaScriptCore/tests/stress/getter-arity.js</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (189927 => 189928)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2015-09-17 20:18:10 UTC (rev 189927)
+++ trunk/Source/JavaScriptCore/ChangeLog        2015-09-17 20:26:16 UTC (rev 189928)
</span><span class="lines">@@ -1,3 +1,19 @@
</span><ins>+2015-09-17  Filip Pizlo  &lt;fpizlo@apple.com&gt;
+
+        stress/exit-from-getter.js.ftl-eager occasionally traps in debug
+        https://bugs.webkit.org/show_bug.cgi?id=149096
+
+        Reviewed by Geoffrey Garen.
+
+        JS calls to getters/setters in get/put inline caches need to reset SP after the call, as our
+        calling convention requires.
+
+        * bytecode/PolymorphicAccess.cpp:
+        (JSC::AccessCase::generate): Fix the bug.
+        * ftl/FTLLink.cpp:
+        (JSC::FTL::link): Adds some verbiage about why the FTL stack offset logic is correct.
+        * tests/stress/getter-arity.js: Added. Other tests would flaky crash before the patch. This test instacrashes before the patch.
+
</ins><span class="cx"> 2015-09-17  Saam barati  &lt;sbarati@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Interpreter::unwind() shouldn't be responsible for filtering out uncatchable exceptions
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorebytecodePolymorphicAccesscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/bytecode/PolymorphicAccess.cpp (189927 => 189928)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/bytecode/PolymorphicAccess.cpp        2015-09-17 20:18:10 UTC (rev 189927)
+++ trunk/Source/JavaScriptCore/bytecode/PolymorphicAccess.cpp        2015-09-17 20:26:16 UTC (rev 189928)
</span><span class="lines">@@ -625,6 +625,11 @@
</span><span class="cx"> 
</span><span class="cx">                 done.link(&amp;jit);
</span><span class="cx"> 
</span><ins>+                jit.addPtr(
+                    CCallHelpers::TrustedImm32(
+                        jit.codeBlock()-&gt;stackPointerOffset() * sizeof(Register)),
+                    GPRInfo::callFrameRegister, CCallHelpers::stackPointerRegister);
+
</ins><span class="cx">                 state.callbacks.append(
</span><span class="cx">                     [=, &amp;vm] (LinkBuffer&amp; linkBuffer) {
</span><span class="cx">                         m_rareData-&gt;callLinkInfo-&gt;setCallLocations(
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreftlFTLLinkcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ftl/FTLLink.cpp (189927 => 189928)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ftl/FTLLink.cpp        2015-09-17 20:18:10 UTC (rev 189927)
+++ trunk/Source/JavaScriptCore/ftl/FTLLink.cpp        2015-09-17 20:26:16 UTC (rev 189928)
</span><span class="lines">@@ -52,7 +52,31 @@
</span><span class="cx">     
</span><span class="cx">     // LLVM will create its own jump tables as needed.
</span><span class="cx">     codeBlock-&gt;clearSwitchJumpTables();
</span><del>-    
</del><ins>+
+    // What LLVM's stackmaps call stackSizeForLocals and what we call frameRegisterCount have a simple
+    // relationship, though it's not obvious from reading the code. The easiest way to understand them
+    // is to look at stackOffset, i.e. what you have to add to FP to get SP. For LLVM that is just:
+    //
+    //     stackOffset == -state.jitCode-&gt;stackmaps.stackSizeForLocals()
+    //
+    // The way we define frameRegisterCount is that it satisfies this equality:
+    //
+    //     stackOffset == virtualRegisterForLocal(frameRegisterCount - 1).offset() * sizeof(Register)
+    //
+    // We can simplify this when we apply virtualRegisterForLocal():
+    //
+    //     stackOffset == (-1 - (frameRegisterCount - 1)) * sizeof(Register)
+    //     stackOffset == (-1 - frameRegisterCount + 1) * sizeof(Register)
+    //     stackOffset == -frameRegisterCount * sizeof(Register)
+    //
+    // Therefore we just have:
+    //
+    //     frameRegisterCount == -stackOffset / sizeof(Register)
+    //
+    // If we substitute what we have above, we get:
+    //
+    //     frameRegisterCount == -(-state.jitCode-&gt;stackmaps.stackSizeForLocals()) / sizeof(Register)
+    //     frameRegisterCount == state.jitCode-&gt;stackmaps.stackSizeForLocals() / sizeof(Register)
</ins><span class="cx">     state.jitCode-&gt;common.frameRegisterCount = state.jitCode-&gt;stackmaps.stackSizeForLocals() / sizeof(void*);
</span><span class="cx">     
</span><span class="cx">     state.jitCode-&gt;common.requiredRegisterCountForExit = graph.requiredRegisterCountForExit();
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoretestsstressgetterarityjs"></a>
<div class="addfile"><h4>Added: trunk/Source/JavaScriptCore/tests/stress/getter-arity.js (0 => 189928)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/tests/stress/getter-arity.js                                (rev 0)
+++ trunk/Source/JavaScriptCore/tests/stress/getter-arity.js        2015-09-17 20:26:16 UTC (rev 189928)
</span><span class="lines">@@ -0,0 +1,7 @@
</span><ins>+var o = {};
+o.__defineGetter__(&quot;f&quot;, function(a, b, c, d, e, f) { return 42; });
+for (var i = 0; i &lt; 10000; ++i) {
+    var result = o.f;
+    if (result != 42)
+        throw &quot;Error: bad result: &quot; + result;
+}
</ins></span></pre></div>
<a id="trunkSourceWTFbenchmarksLockSpeedTestcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/benchmarks/LockSpeedTest.cpp (189927 => 189928)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/benchmarks/LockSpeedTest.cpp        2015-09-17 20:18:10 UTC (rev 189927)
+++ trunk/Source/WTF/benchmarks/LockSpeedTest.cpp        2015-09-17 20:26:16 UTC (rev 189928)
</span><span class="lines">@@ -28,6 +28,7 @@
</span><span class="cx"> 
</span><span class="cx"> #include &quot;config.h&quot;
</span><span class="cx"> 
</span><ins>+#include &lt;thread&gt;
</ins><span class="cx"> #include &lt;unistd.h&gt;
</span><span class="cx"> #include &lt;wtf/CurrentTime.h&gt;
</span><span class="cx"> #include &lt;wtf/Lock.h&gt;
</span><span class="lines">@@ -67,15 +68,42 @@
</span><span class="cx">     Atomic&lt;unsigned&gt; m_lock;
</span><span class="cx"> };
</span><span class="cx"> 
</span><ins>+class ByteSpinLock {
+public:
+    ByteSpinLock()
+    {
+        m_lock.store(0, std::memory_order_relaxed);
+    }
+
+    void lock()
+    {
+        while (!m_lock.compareExchangeWeak(0, 1, std::memory_order_acquire))
+            std::this_thread::yield();
+    }
+
+    void unlock()
+    {
+        m_lock.store(0, std::memory_order_release);
+    }
+
+    bool isLocked() const
+    {
+        return m_lock.load(std::memory_order_acquire);
+    }
+
+private:
+    Atomic&lt;uint8_t&gt; m_lock;
+};
+
</ins><span class="cx"> unsigned numThreadGroups;
</span><span class="cx"> unsigned numThreadsPerGroup;
</span><del>-unsigned workPerCriticalSection;
</del><ins>+int workPerCriticalSection;
</ins><span class="cx"> unsigned numNoiseThreads;
</span><span class="cx"> unsigned numIterations;
</span><span class="cx">     
</span><span class="cx"> NO_RETURN void usage()
</span><span class="cx"> {
</span><del>-    printf(&quot;Usage: LockSpeedTest spinlock|wordlock|lock|mutex|all &lt;num thread groups&gt; &lt;num threads per group&gt; &lt;work per critical section&gt; &lt;num noise threads&gt; &lt;num iterations&gt;\n&quot;);
</del><ins>+    printf(&quot;Usage: LockSpeedTest spinlock|bytespinlock|wordlock|lock|mutex|all &lt;num thread groups&gt; &lt;num threads per group&gt; &lt;work per critical section&gt; &lt;num noise threads&gt; &lt;num iterations&gt;\n&quot;);
</ins><span class="cx">     exit(1);
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -110,9 +138,13 @@
</span><span class="cx">                 [threadGroupIndex, &amp;locks, &amp;words] () {
</span><span class="cx">                     for (unsigned i = numIterations; i--;) {
</span><span class="cx">                         locks[threadGroupIndex].lock();
</span><del>-                        for (unsigned j = workPerCriticalSection; j--;) {
-                            words[threadGroupIndex]++;
-                            words[threadGroupIndex] *= 1.01;
</del><ins>+                        if (workPerCriticalSection &lt; 0)
+                            sleep(-workPerCriticalSection);
+                        else {
+                            for (unsigned j = workPerCriticalSection; j--;) {
+                                words[threadGroupIndex]++;
+                                words[threadGroupIndex] *= 1.01;
+                            }
</ins><span class="cx">                         }
</span><span class="cx">                         locks[threadGroupIndex].unlock();
</span><span class="cx">                     }
</span><span class="lines">@@ -143,7 +175,7 @@
</span><span class="cx">     if (argc != 7
</span><span class="cx">         || sscanf(argv[2], &quot;%u&quot;, &amp;numThreadGroups) != 1
</span><span class="cx">         || sscanf(argv[3], &quot;%u&quot;, &amp;numThreadsPerGroup) != 1
</span><del>-        || sscanf(argv[4], &quot;%u&quot;, &amp;workPerCriticalSection) != 1
</del><ins>+        || sscanf(argv[4], &quot;%d&quot;, &amp;workPerCriticalSection) != 1
</ins><span class="cx">         || sscanf(argv[5], &quot;%u&quot;, &amp;numNoiseThreads) != 1
</span><span class="cx">         || sscanf(argv[6], &quot;%u&quot;, &amp;numIterations) != 1)
</span><span class="cx">         usage();
</span><span class="lines">@@ -153,6 +185,10 @@
</span><span class="cx">         runBenchmark&lt;SpinLock&gt;(&quot;SpinLock&quot;);
</span><span class="cx">         didRun = true;
</span><span class="cx">     }
</span><ins>+    if (!strcmp(argv[1], &quot;bytespinlock&quot;) || !strcmp(argv[1], &quot;all&quot;)) {
+        runBenchmark&lt;SpinLock&gt;(&quot;ByteSpinLock&quot;);
+        didRun = true;
+    }
</ins><span class="cx">     if (!strcmp(argv[1], &quot;wordlock&quot;) || !strcmp(argv[1], &quot;all&quot;)) {
</span><span class="cx">         runBenchmark&lt;WordLock&gt;(&quot;WTF WordLock&quot;);
</span><span class="cx">         didRun = true;
</span></span></pre>
</div>
</div>

</body>
</html>