<!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>[168480] 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/168480">168480</a></dd>
<dt>Author</dt> <dd>fpizlo@apple.com</dd>
<dt>Date</dt> <dd>2014-05-08 12:07:45 -0700 (Thu, 08 May 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>SSA conversion should delete PhantomLocals for captured variables
https://bugs.webkit.org/show_bug.cgi?id=132693
Reviewed by Mark Hahnenberg.
* dfg/DFGCommon.cpp:
(JSC::DFG::startCrashing): Parallel JIT and a JIT bug means that we man dump IR in parallel. This is the workaround. This patch uses it in all of the places where we dump IR and crash.
* dfg/DFGCommon.h:
* dfg/DFGFixupPhase.cpp:
(JSC::DFG::FixupPhase::injectTypeConversionsForEdge): Use the workaround.
* dfg/DFGLivenessAnalysisPhase.cpp:
(JSC::DFG::LivenessAnalysisPhase::run): Use the workaround.
* dfg/DFGSSAConversionPhase.cpp:
(JSC::DFG::SSAConversionPhase::run): Fix the bug - it's true that PhantomLocal for captured variables doesn't need anything done to it, but it's wrong that we didn't delete it outright.
* dfg/DFGValidate.cpp: Use the workaround.
* tests/stress/phantom-local-captured-but-not-flushed-to-ssa.js: Added.
(foo):
(bar):</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoredfgDFGCommoncpp">trunk/Source/JavaScriptCore/dfg/DFGCommon.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoredfgDFGCommonh">trunk/Source/JavaScriptCore/dfg/DFGCommon.h</a></li>
<li><a href="#trunkSourceJavaScriptCoredfgDFGFixupPhasecpp">trunk/Source/JavaScriptCore/dfg/DFGFixupPhase.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoredfgDFGLivenessAnalysisPhasecpp">trunk/Source/JavaScriptCore/dfg/DFGLivenessAnalysisPhase.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoredfgDFGSSAConversionPhasecpp">trunk/Source/JavaScriptCore/dfg/DFGSSAConversionPhase.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoredfgDFGValidatecpp">trunk/Source/JavaScriptCore/dfg/DFGValidate.cpp</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoretestsstressphantomlocalcapturedbutnotflushedtossajs">trunk/Source/JavaScriptCore/tests/stress/phantom-local-captured-but-not-flushed-to-ssa.js</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (168479 => 168480)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2014-05-08 19:03:38 UTC (rev 168479)
+++ trunk/Source/JavaScriptCore/ChangeLog        2014-05-08 19:07:45 UTC (rev 168480)
</span><span class="lines">@@ -1,3 +1,24 @@
</span><ins>+2014-05-08 Filip Pizlo <fpizlo@apple.com>
+
+ SSA conversion should delete PhantomLocals for captured variables
+ https://bugs.webkit.org/show_bug.cgi?id=132693
+
+ Reviewed by Mark Hahnenberg.
+
+ * dfg/DFGCommon.cpp:
+ (JSC::DFG::startCrashing): Parallel JIT and a JIT bug means that we man dump IR in parallel. This is the workaround. This patch uses it in all of the places where we dump IR and crash.
+ * dfg/DFGCommon.h:
+ * dfg/DFGFixupPhase.cpp:
+ (JSC::DFG::FixupPhase::injectTypeConversionsForEdge): Use the workaround.
+ * dfg/DFGLivenessAnalysisPhase.cpp:
+ (JSC::DFG::LivenessAnalysisPhase::run): Use the workaround.
+ * dfg/DFGSSAConversionPhase.cpp:
+ (JSC::DFG::SSAConversionPhase::run): Fix the bug - it's true that PhantomLocal for captured variables doesn't need anything done to it, but it's wrong that we didn't delete it outright.
+ * dfg/DFGValidate.cpp: Use the workaround.
+ * tests/stress/phantom-local-captured-but-not-flushed-to-ssa.js: Added.
+ (foo):
+ (bar):
+
</ins><span class="cx"> 2014-05-07 Commit Queue <commit-queue@webkit.org>
</span><span class="cx">
</span><span class="cx"> Unreviewed, rolling out r168451.
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoredfgDFGCommoncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/dfg/DFGCommon.cpp (168479 => 168480)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/dfg/DFGCommon.cpp        2014-05-08 19:03:38 UTC (rev 168479)
+++ trunk/Source/JavaScriptCore/dfg/DFGCommon.cpp        2014-05-08 19:07:45 UTC (rev 168480)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2013 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2013, 2014 Apple Inc. All rights reserved.
</ins><span class="cx"> *
</span><span class="cx"> * Redistribution and use in source and binary forms, with or without
</span><span class="cx"> * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -31,6 +31,19 @@
</span><span class="cx"> #include "DFGNode.h"
</span><span class="cx"> #include "JSCInlines.h"
</span><span class="cx">
</span><ins>+namespace JSC { namespace DFG {
+
+void startCrashing()
+{
+#if ENABLE(COMPARE_AND_SWAP)
+ static unsigned lock;
+ while (!WTF::weakCompareAndSwap(&lock, 0, 1))
+ std::this_thread::yield();
+#endif
+}
+
+} } // namespace JSC::DFG
+
</ins><span class="cx"> namespace WTF {
</span><span class="cx">
</span><span class="cx"> using namespace JSC::DFG;
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoredfgDFGCommonh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/dfg/DFGCommon.h (168479 => 168480)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/dfg/DFGCommon.h        2014-05-08 19:03:38 UTC (rev 168479)
+++ trunk/Source/JavaScriptCore/dfg/DFGCommon.h        2014-05-08 19:07:45 UTC (rev 168480)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2011, 2012, 2013 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2011-2014 Apple Inc. All rights reserved.
</ins><span class="cx"> *
</span><span class="cx"> * Redistribution and use in source and binary forms, with or without
</span><span class="cx"> * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -206,6 +206,11 @@
</span><span class="cx"> return true;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+// If possible, this will acquire a lock to make sure that if multiple threads
+// start crashing at the same time, you get coherent dump output. Use this only
+// when you're forcing a crash with diagnostics.
+void startCrashing();
+
</ins><span class="cx"> } } // namespace JSC::DFG
</span><span class="cx">
</span><span class="cx"> namespace WTF {
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoredfgDFGFixupPhasecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/dfg/DFGFixupPhase.cpp (168479 => 168480)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/dfg/DFGFixupPhase.cpp        2014-05-08 19:03:38 UTC (rev 168479)
+++ trunk/Source/JavaScriptCore/dfg/DFGFixupPhase.cpp        2014-05-08 19:07:45 UTC (rev 168480)
</span><span class="lines">@@ -1898,6 +1898,7 @@
</span><span class="cx"> Node* result;
</span><span class="cx"> if (edge->hasDoubleResult()) {
</span><span class="cx"> // This will never happen.
</span><ins>+ startCrashing();
</ins><span class="cx"> dataLog("Found an Int52RepUse to a double result: ", node, " -> ", edge, "\n");
</span><span class="cx"> m_graph.dump();
</span><span class="cx"> RELEASE_ASSERT_NOT_REACHED();
</span><span class="lines">@@ -1908,6 +1909,7 @@
</span><span class="cx"> } else {
</span><span class="cx"> // This is only here for dealing with constants.
</span><span class="cx"> if (edge->op() != JSConstant) {
</span><ins>+ startCrashing();
</ins><span class="cx"> dataLog("Found an Int52RepUse on something that is neither Int32 nor a constant: ", node, " -> ", edge, "\n");
</span><span class="cx"> m_graph.dump();
</span><span class="cx"> RELEASE_ASSERT_NOT_REACHED();
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoredfgDFGLivenessAnalysisPhasecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/dfg/DFGLivenessAnalysisPhase.cpp (168479 => 168480)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/dfg/DFGLivenessAnalysisPhase.cpp        2014-05-08 19:03:38 UTC (rev 168479)
+++ trunk/Source/JavaScriptCore/dfg/DFGLivenessAnalysisPhase.cpp        2014-05-08 19:07:45 UTC (rev 168480)
</span><span class="lines">@@ -68,6 +68,7 @@
</span><span class="cx"> } while (m_changed);
</span><span class="cx">
</span><span class="cx"> if (!m_graph.block(0)->ssa->liveAtHead.isEmpty()) {
</span><ins>+ startCrashing();
</ins><span class="cx"> dataLog(
</span><span class="cx"> "Bad liveness analysis result: live at root is not empty: ",
</span><span class="cx"> nodeListDump(m_graph.block(0)->ssa->liveAtHead), "\n");
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoredfgDFGSSAConversionPhasecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/dfg/DFGSSAConversionPhase.cpp (168479 => 168480)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/dfg/DFGSSAConversionPhase.cpp        2014-05-08 19:03:38 UTC (rev 168479)
+++ trunk/Source/JavaScriptCore/dfg/DFGSSAConversionPhase.cpp        2014-05-08 19:07:45 UTC (rev 168480)
</span><span class="lines">@@ -347,12 +347,23 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> case PhantomLocal: {
</span><ins>+ ASSERT(node->child1().useKind() == UntypedUse);
</ins><span class="cx"> VariableAccessData* variable = node->variableAccessData();
</span><del>- if (variable->isCaptured())
- break;
- ASSERT(node->child1().useKind() == UntypedUse);
- node->child1() =
- block->variablesAtHead.operand(variable->local())->defaultEdge();
</del><ins>+ if (variable->isCaptured()) {
+ // This is a fun case. We could have a captured variable that had some
+ // or all of its uses strength reduced to phantoms rather than flushes.
+ // SSA conversion will currently still treat it as flushed, in the sense
+ // that it will just keep the SetLocal. Therefore, there is nothing that
+ // needs to be done here: we don't need to also keep the source value
+ // alive. And even if we did want to keep the source value alive, we
+ // wouldn't be able to, because the variablesAtHead value for a captured
+ // local wouldn't have been computed by the Phi reduction algorithm
+ // above.
+ node->children.reset();
+ } else {
+ node->child1() =
+ block->variablesAtHead.operand(variable->local())->defaultEdge();
+ }
</ins><span class="cx"> node->convertToPhantom();
</span><span class="cx"> // This is only for Upsilons. An Upsilon will only refer to a
</span><span class="cx"> // PhantomLocal if there were no SetLocals or GetLocals in the block.
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoredfgDFGValidatecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/dfg/DFGValidate.cpp (168479 => 168480)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/dfg/DFGValidate.cpp        2014-05-08 19:03:38 UTC (rev 168479)
+++ trunk/Source/JavaScriptCore/dfg/DFGValidate.cpp        2014-05-08 19:07:45 UTC (rev 168480)
</span><span class="lines">@@ -45,6 +45,7 @@
</span><span class="cx">
</span><span class="cx"> #define VALIDATE(context, assertion) do { \
</span><span class="cx"> if (!(assertion)) { \
</span><ins>+ startCrashing(); \
</ins><span class="cx"> dataLogF("\n\n\nAt "); \
</span><span class="cx"> reportValidationContext context; \
</span><span class="cx"> dataLogF(": validation %s (%s:%d) failed.\n", #assertion, __FILE__, __LINE__); \
</span><span class="lines">@@ -56,6 +57,7 @@
</span><span class="cx">
</span><span class="cx"> #define V_EQUAL(context, left, right) do { \
</span><span class="cx"> if (left != right) { \
</span><ins>+ startCrashing(); \
</ins><span class="cx"> dataLogF("\n\n\nAt "); \
</span><span class="cx"> reportValidationContext context; \
</span><span class="cx"> dataLogF(": validation (%s = ", #left); \
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoretestsstressphantomlocalcapturedbutnotflushedtossajs"></a>
<div class="addfile"><h4>Added: trunk/Source/JavaScriptCore/tests/stress/phantom-local-captured-but-not-flushed-to-ssa.js (0 => 168480)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/tests/stress/phantom-local-captured-but-not-flushed-to-ssa.js         (rev 0)
+++ trunk/Source/JavaScriptCore/tests/stress/phantom-local-captured-but-not-flushed-to-ssa.js        2014-05-08 19:07:45 UTC (rev 168480)
</span><span class="lines">@@ -0,0 +1,21 @@
</span><ins>+function foo(x, y) {
+ if (y) {
+ if (x < 10)
+ x = 15;
+ }
+ if (false)
+ arguments[0] = 42;
+ return x;
+}
+
+function bar(x) {
+ return foo(10, x);
+}
+
+noInline(bar);
+
+for (var i = 0; i < 100000; ++i) {
+ var result = bar(true);
+ if (result != 10)
+ throw "Error: bad result: " + result;
+}
</ins></span></pre>
</div>
</div>
</body>
</html>