<!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>[169145] 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/169145">169145</a></dd>
<dt>Author</dt> <dd>fpizlo@apple.com</dd>
<dt>Date</dt> <dd>2014-05-20 20:49:16 -0700 (Tue, 20 May 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>DFG prediction propagation should agree with fixup phase over the return type of GetByVal
https://bugs.webkit.org/show_bug.cgi?id=133134

Reviewed by Mark Hahnenberg.
        
Make prediction propagator use ArrayMode refinement to decide the return type.
        
Also introduce a heap prediction intrinsic that allows us to test weird corner cases
like this. The only way we'll see a mismatch like this in the real world is probably
through a gnarly race condition.

* dfg/DFGByteCodeParser.cpp:
(JSC::DFG::ByteCodeParser::handleIntrinsic):
* dfg/DFGNode.h:
(JSC::DFG::Node::setHeapPrediction):
* dfg/DFGPredictionPropagationPhase.cpp:
(JSC::DFG::PredictionPropagationPhase::propagate):
* jsc.cpp:
(GlobalObject::finishCreation):
(functionFalse1):
(functionFalse2):
(functionUndefined1):
(functionUndefined2):
(functionFalse): Deleted.
(functionOtherFalse): Deleted.
(functionUndefined): Deleted.
* runtime/Intrinsic.h:
* tests/stress/get-by-val-double-predicted-int.js: Added.
(foo):</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="#trunkSourceJavaScriptCoredfgDFGNodeh">trunk/Source/JavaScriptCore/dfg/DFGNode.h</a></li>
<li><a href="#trunkSourceJavaScriptCoredfgDFGPredictionPropagationPhasecpp">trunk/Source/JavaScriptCore/dfg/DFGPredictionPropagationPhase.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCorejsccpp">trunk/Source/JavaScriptCore/jsc.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeIntrinsich">trunk/Source/JavaScriptCore/runtime/Intrinsic.h</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoretestsstressgetbyvaldoublepredictedintjs">trunk/Source/JavaScriptCore/tests/stress/get-by-val-double-predicted-int.js</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (169144 => 169145)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2014-05-21 01:55:59 UTC (rev 169144)
+++ trunk/Source/JavaScriptCore/ChangeLog        2014-05-21 03:49:16 UTC (rev 169145)
</span><span class="lines">@@ -1,3 +1,35 @@
</span><ins>+2014-05-20  Filip Pizlo  &lt;fpizlo@apple.com&gt;
+
+        DFG prediction propagation should agree with fixup phase over the return type of GetByVal
+        https://bugs.webkit.org/show_bug.cgi?id=133134
+
+        Reviewed by Mark Hahnenberg.
+        
+        Make prediction propagator use ArrayMode refinement to decide the return type.
+        
+        Also introduce a heap prediction intrinsic that allows us to test weird corner cases
+        like this. The only way we'll see a mismatch like this in the real world is probably
+        through a gnarly race condition.
+
+        * dfg/DFGByteCodeParser.cpp:
+        (JSC::DFG::ByteCodeParser::handleIntrinsic):
+        * dfg/DFGNode.h:
+        (JSC::DFG::Node::setHeapPrediction):
+        * dfg/DFGPredictionPropagationPhase.cpp:
+        (JSC::DFG::PredictionPropagationPhase::propagate):
+        * jsc.cpp:
+        (GlobalObject::finishCreation):
+        (functionFalse1):
+        (functionFalse2):
+        (functionUndefined1):
+        (functionUndefined2):
+        (functionFalse): Deleted.
+        (functionOtherFalse): Deleted.
+        (functionUndefined): Deleted.
+        * runtime/Intrinsic.h:
+        * tests/stress/get-by-val-double-predicted-int.js: Added.
+        (foo):
+
</ins><span class="cx"> 2014-05-20  Mark Hahnenberg  &lt;mhahnenberg@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Watchdog timer should be lazily allocated
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoredfgDFGByteCodeParsercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp (169144 => 169145)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp        2014-05-21 01:55:59 UTC (rev 169144)
+++ trunk/Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp        2014-05-21 03:49:16 UTC (rev 169145)
</span><span class="lines">@@ -1737,6 +1737,16 @@
</span><span class="cx">         return true;
</span><span class="cx">     }
</span><span class="cx">         
</span><ins>+    case SetInt32HeapPredictionIntrinsic: {
+        for (int i = 1; i &lt; argumentCountIncludingThis; ++i) {
+            Node* node = get(virtualRegisterForArgument(i, registerOffset));
+            if (node-&gt;hasHeapPrediction())
+                node-&gt;setHeapPrediction(SpecInt32);
+        }
+        set(VirtualRegister(resultOperand), constantUndefined());
+        return true;
+    }
+        
</ins><span class="cx">     default:
</span><span class="cx">         return false;
</span><span class="cx">     }
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoredfgDFGNodeh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/dfg/DFGNode.h (169144 => 169145)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/dfg/DFGNode.h        2014-05-21 01:55:59 UTC (rev 169144)
+++ trunk/Source/JavaScriptCore/dfg/DFGNode.h        2014-05-21 03:49:16 UTC (rev 169145)
</span><span class="lines">@@ -1031,6 +1031,12 @@
</span><span class="cx">         return mergeSpeculation(m_opInfo2, prediction);
</span><span class="cx">     }
</span><span class="cx">     
</span><ins>+    void setHeapPrediction(SpeculatedType prediction)
+    {
+        ASSERT(hasHeapPrediction());
+        m_opInfo2 = prediction;
+    }
+    
</ins><span class="cx">     bool hasFunction()
</span><span class="cx">     {
</span><span class="cx">         switch (op()) {
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoredfgDFGPredictionPropagationPhasecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/dfg/DFGPredictionPropagationPhase.cpp (169144 => 169145)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/dfg/DFGPredictionPropagationPhase.cpp        2014-05-21 01:55:59 UTC (rev 169144)
+++ trunk/Source/JavaScriptCore/dfg/DFGPredictionPropagationPhase.cpp        2014-05-21 03:49:16 UTC (rev 169145)
</span><span class="lines">@@ -369,19 +369,36 @@
</span><span class="cx">         case GetByVal: {
</span><span class="cx">             if (!node-&gt;child1()-&gt;prediction())
</span><span class="cx">                 break;
</span><del>-            if (!node-&gt;getHeapPrediction())
</del><ins>+            
+            ArrayMode arrayMode = node-&gt;arrayMode().refine(
+                m_graph, node,
+                node-&gt;child1()-&gt;prediction(),
+                node-&gt;child2()-&gt;prediction(),
+                SpecNone, node-&gt;flags());
+            
+            switch (arrayMode.type()) {
+            case Array::Double:
+                if (arrayMode.isOutOfBounds())
+                    changed |= mergePrediction(node-&gt;getHeapPrediction() | SpecDoubleReal);
+                else
+                    changed |= mergePrediction(SpecDoubleReal);
</ins><span class="cx">                 break;
</span><del>-            
-            if (node-&gt;child1()-&gt;shouldSpeculateFloat32Array()
-                || node-&gt;child1()-&gt;shouldSpeculateFloat64Array())
</del><ins>+            case Array::Float32Array:
+            case Array::Float64Array:
</ins><span class="cx">                 changed |= mergePrediction(SpecFullDouble);
</span><del>-            else if (node-&gt;child1()-&gt;shouldSpeculateUint32Array()) {
</del><ins>+                break;
+            case Array::Uint32Array:
</ins><span class="cx">                 if (isInt32Speculation(node-&gt;getHeapPrediction()))
</span><span class="cx">                     changed |= mergePrediction(SpecInt32);
</span><ins>+                else if (enableInt52())
+                    changed |= mergePrediction(SpecMachineInt);
</ins><span class="cx">                 else
</span><del>-                    changed |= mergePrediction(SpecInt52);
-            } else
</del><ins>+                    changed |= mergePrediction(SpecInt32 | SpecInt52AsDouble);
+                break;
+            default:
</ins><span class="cx">                 changed |= mergePrediction(node-&gt;getHeapPrediction());
</span><ins>+                break;
+            }
</ins><span class="cx">             break;
</span><span class="cx">         }
</span><span class="cx">             
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorejsccpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/jsc.cpp (169144 => 169145)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/jsc.cpp        2014-05-21 01:55:59 UTC (rev 169144)
+++ trunk/Source/JavaScriptCore/jsc.cpp        2014-05-21 03:49:16 UTC (rev 169145)
</span><span class="lines">@@ -333,9 +333,10 @@
</span><span class="cx"> static EncodedJSValue JSC_HOST_CALL functionReoptimizationRetryCount(ExecState*);
</span><span class="cx"> static EncodedJSValue JSC_HOST_CALL functionTransferArrayBuffer(ExecState*);
</span><span class="cx"> static NO_RETURN_WITH_VALUE EncodedJSValue JSC_HOST_CALL functionQuit(ExecState*);
</span><del>-static EncodedJSValue JSC_HOST_CALL functionFalse(ExecState*);
-static EncodedJSValue JSC_HOST_CALL functionOtherFalse(ExecState*); // Need a separate function to break hash-consing of native executables.
-static EncodedJSValue JSC_HOST_CALL functionUndefined(ExecState*);
</del><ins>+static EncodedJSValue JSC_HOST_CALL functionFalse1(ExecState*);
+static EncodedJSValue JSC_HOST_CALL functionFalse2(ExecState*);
+static EncodedJSValue JSC_HOST_CALL functionUndefined1(ExecState*);
+static EncodedJSValue JSC_HOST_CALL functionUndefined2(ExecState*);
</ins><span class="cx"> static EncodedJSValue JSC_HOST_CALL functionEffectful42(ExecState*);
</span><span class="cx"> static EncodedJSValue JSC_HOST_CALL functionMakeMasquerader(ExecState*);
</span><span class="cx"> 
</span><span class="lines">@@ -473,9 +474,10 @@
</span><span class="cx">         addFunction(vm, &quot;getElement&quot;, functionGetElement, 1);
</span><span class="cx">         addFunction(vm, &quot;setElementRoot&quot;, functionSetElementRoot, 2);
</span><span class="cx">         
</span><del>-        putDirectNativeFunction(vm, this, Identifier(&amp;vm, &quot;DFGTrue&quot;), 0, functionFalse, DFGTrueIntrinsic, DontEnum | JSC::Function);
-        putDirectNativeFunction(vm, this, Identifier(&amp;vm, &quot;OSRExit&quot;), 0, functionUndefined, OSRExitIntrinsic, DontEnum | JSC::Function);
-        putDirectNativeFunction(vm, this, Identifier(&amp;vm, &quot;isFinalTier&quot;), 0, functionOtherFalse, IsFinalTierIntrinsic, DontEnum | JSC::Function);
</del><ins>+        putDirectNativeFunction(vm, this, Identifier(&amp;vm, &quot;DFGTrue&quot;), 0, functionFalse1, DFGTrueIntrinsic, DontEnum | JSC::Function);
+        putDirectNativeFunction(vm, this, Identifier(&amp;vm, &quot;OSRExit&quot;), 0, functionUndefined1, OSRExitIntrinsic, DontEnum | JSC::Function);
+        putDirectNativeFunction(vm, this, Identifier(&amp;vm, &quot;isFinalTier&quot;), 0, functionFalse2, IsFinalTierIntrinsic, DontEnum | JSC::Function);
+        putDirectNativeFunction(vm, this, Identifier(&amp;vm, &quot;predictInt32&quot;), 0, functionUndefined2, SetInt32HeapPredictionIntrinsic, DontEnum | JSC::Function);
</ins><span class="cx">         
</span><span class="cx">         addFunction(vm, &quot;effectful42&quot;, functionEffectful42, 0);
</span><span class="cx">         addFunction(vm, &quot;makeMasquerader&quot;, functionMakeMasquerader, 0);
</span><span class="lines">@@ -893,21 +895,12 @@
</span><span class="cx"> #endif
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-EncodedJSValue JSC_HOST_CALL functionFalse(ExecState*)
-{
-    return JSValue::encode(jsBoolean(false));
-}
</del><ins>+EncodedJSValue JSC_HOST_CALL functionFalse1(ExecState*) { return JSValue::encode(jsBoolean(false)); }
+EncodedJSValue JSC_HOST_CALL functionFalse2(ExecState*) { return JSValue::encode(jsBoolean(false)); }
</ins><span class="cx"> 
</span><del>-EncodedJSValue JSC_HOST_CALL functionOtherFalse(ExecState*)
-{
-    return JSValue::encode(jsBoolean(false));
-}
</del><ins>+EncodedJSValue JSC_HOST_CALL functionUndefined1(ExecState*) { return JSValue::encode(jsUndefined()); }
+EncodedJSValue JSC_HOST_CALL functionUndefined2(ExecState*) { return JSValue::encode(jsUndefined()); }
</ins><span class="cx"> 
</span><del>-EncodedJSValue JSC_HOST_CALL functionUndefined(ExecState*)
-{
-    return JSValue::encode(jsUndefined());
-}
-
</del><span class="cx"> EncodedJSValue JSC_HOST_CALL functionEffectful42(ExecState*)
</span><span class="cx"> {
</span><span class="cx">     return JSValue::encode(jsNumber(42));
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeIntrinsich"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/Intrinsic.h (169144 => 169145)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/Intrinsic.h        2014-05-21 01:55:59 UTC (rev 169144)
+++ trunk/Source/JavaScriptCore/runtime/Intrinsic.h        2014-05-21 03:49:16 UTC (rev 169145)
</span><span class="lines">@@ -59,7 +59,8 @@
</span><span class="cx">     // Debugging intrinsics
</span><span class="cx">     DFGTrueIntrinsic,
</span><span class="cx">     OSRExitIntrinsic,
</span><del>-    IsFinalTierIntrinsic
</del><ins>+    IsFinalTierIntrinsic,
+    SetInt32HeapPredictionIntrinsic
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace JSC
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoretestsstressgetbyvaldoublepredictedintjs"></a>
<div class="addfile"><h4>Added: trunk/Source/JavaScriptCore/tests/stress/get-by-val-double-predicted-int.js (0 => 169145)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/tests/stress/get-by-val-double-predicted-int.js                                (rev 0)
+++ trunk/Source/JavaScriptCore/tests/stress/get-by-val-double-predicted-int.js        2014-05-21 03:49:16 UTC (rev 169145)
</span><span class="lines">@@ -0,0 +1,16 @@
</span><ins>+function foo(a, i) {
+    var x = a[i];
+    predictInt32(x);
+    return x + 2000000000;
+}
+
+noInline(foo);
+
+var array = [2000000000.5];
+
+for (var i = 0; i &lt; 1000000; ++i) {
+    var result = foo(array, 0);
+    if (result != 4000000000.5)
+        throw &quot;Error: bad result: &quot; + result;
+}
+
</ins></span></pre>
</div>
</div>

</body>
</html>