<!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>[214566] 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/214566">214566</a></dd>
<dt>Author</dt> <dd>keith_miller@apple.com</dd>
<dt>Date</dt> <dd>2017-03-29 15:12:25 -0700 (Wed, 29 Mar 2017)</dd>
</dl>

<h3>Log Message</h3>
<pre>WebAssembly: Worklist should periodically check in to see if there are higher priority jobs to do.
https://bugs.webkit.org/show_bug.cgi?id=170204

Reviewed by Saam Barati.

This patch makes it so that Wasm::Plan's compileFunctions method can return periodically
to its caller. The main use for this is if a user asynchronously compiles a wasm module
then later synchronously compiles another module. In this case we want to be able to pause
compilation of other worklists.

This patch also adds support for size_t Options.

* runtime/Options.cpp:
(JSC::parse):
(JSC::Option::dump):
(JSC::Option::operator==):
* runtime/Options.h:
* wasm/WasmPlan.cpp:
(JSC::Wasm::Plan::moveToState):
(JSC::Wasm::Plan::ThreadCountHolder::~ThreadCountHolder):
(JSC::Wasm::Plan::compileFunctions):
* wasm/WasmPlan.h:
* wasm/WasmWorklist.cpp:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeOptionscpp">trunk/Source/JavaScriptCore/runtime/Options.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeOptionsh">trunk/Source/JavaScriptCore/runtime/Options.h</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmWasmPlancpp">trunk/Source/JavaScriptCore/wasm/WasmPlan.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmWasmPlanh">trunk/Source/JavaScriptCore/wasm/WasmPlan.h</a></li>
<li><a href="#trunkSourceJavaScriptCorewasmWasmWorklistcpp">trunk/Source/JavaScriptCore/wasm/WasmWorklist.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (214565 => 214566)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2017-03-29 22:10:25 UTC (rev 214565)
+++ trunk/Source/JavaScriptCore/ChangeLog        2017-03-29 22:12:25 UTC (rev 214566)
</span><span class="lines">@@ -1,3 +1,29 @@
</span><ins>+2017-03-29  Keith Miller  &lt;keith_miller@apple.com&gt;
+
+        WebAssembly: Worklist should periodically check in to see if there are higher priority jobs to do.
+        https://bugs.webkit.org/show_bug.cgi?id=170204
+
+        Reviewed by Saam Barati.
+
+        This patch makes it so that Wasm::Plan's compileFunctions method can return periodically
+        to its caller. The main use for this is if a user asynchronously compiles a wasm module
+        then later synchronously compiles another module. In this case we want to be able to pause
+        compilation of other worklists.
+
+        This patch also adds support for size_t Options.
+
+        * runtime/Options.cpp:
+        (JSC::parse):
+        (JSC::Option::dump):
+        (JSC::Option::operator==):
+        * runtime/Options.h:
+        * wasm/WasmPlan.cpp:
+        (JSC::Wasm::Plan::moveToState):
+        (JSC::Wasm::Plan::ThreadCountHolder::~ThreadCountHolder):
+        (JSC::Wasm::Plan::compileFunctions):
+        * wasm/WasmPlan.h:
+        * wasm/WasmWorklist.cpp:
+
</ins><span class="cx"> 2017-03-29  Mark Lam  &lt;mark.lam@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Remove obsolete references to HeapTimer in JavaScriptCore.order.
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeOptionscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/Options.cpp (214565 => 214566)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/Options.cpp        2017-03-29 22:10:25 UTC (rev 214565)
+++ trunk/Source/JavaScriptCore/runtime/Options.cpp        2017-03-29 22:12:25 UTC (rev 214566)
</span><span class="lines">@@ -89,6 +89,11 @@
</span><span class="cx">     return sscanf(string, &quot;%u&quot;, &amp;value) == 1;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static bool parse(const char* string, size_t&amp; value)
+{
+    return sscanf(string, &quot;%zu&quot;, &amp;value);
+}
+
</ins><span class="cx"> static bool parse(const char* string, double&amp; value)
</span><span class="cx"> {
</span><span class="cx">     return sscanf(string, &quot;%lf&quot;, &amp;value) == 1;
</span><span class="lines">@@ -814,6 +819,9 @@
</span><span class="cx">     case Options::Type::unsignedType:
</span><span class="cx">         builder.appendNumber(m_entry.unsignedVal);
</span><span class="cx">         break;
</span><ins>+    case Options::Type::sizeType:
+        builder.appendNumber(m_entry.sizeVal);
+        break;
</ins><span class="cx">     case Options::Type::doubleType:
</span><span class="cx">         builder.appendNumber(m_entry.doubleVal);
</span><span class="cx">         break;
</span><span class="lines">@@ -846,6 +854,8 @@
</span><span class="cx">         return m_entry.boolVal == other.m_entry.boolVal;
</span><span class="cx">     case Options::Type::unsignedType:
</span><span class="cx">         return m_entry.unsignedVal == other.m_entry.unsignedVal;
</span><ins>+    case Options::Type::sizeType:
+        return m_entry.sizeVal == other.m_entry.sizeVal;
</ins><span class="cx">     case Options::Type::doubleType:
</span><span class="cx">         return (m_entry.doubleVal == other.m_entry.doubleVal) || (std::isnan(m_entry.doubleVal) &amp;&amp; std::isnan(other.m_entry.doubleVal));
</span><span class="cx">     case Options::Type::int32Type:
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeOptionsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/Options.h (214565 => 214566)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/Options.h        2017-03-29 22:10:25 UTC (rev 214565)
+++ trunk/Source/JavaScriptCore/runtime/Options.h        2017-03-29 22:12:25 UTC (rev 214566)
</span><span class="lines">@@ -431,6 +431,7 @@
</span><span class="cx">     v(bool, useWebAssembly, true, Normal, &quot;Expose the WebAssembly global object.&quot;) \
</span><span class="cx">     \
</span><span class="cx">     v(bool, failToCompileWebAssemblyCode, false, Normal, &quot;If true, no Wasm::Plan will sucessfully compile a function.&quot;) \
</span><ins>+    v(size, webAssemblyPartialCompileLimit, 5000, Normal, &quot;Limit on the number of bytes a Wasm::Plan::compile should attempt before checking for other work.&quot;) \
</ins><span class="cx">     \
</span><span class="cx">     v(bool, simulateWebAssemblyLowMemory, false, Normal, &quot;If true, the Memory object won't mmap the full 'maximum' range and instead will allocate the minimum required amount.&quot;) \
</span><span class="cx">     v(bool, useWebAssemblyFastMemory, true, Normal, &quot;If true, we will try to use a 32-bit address space with a signal handler to bounds check wasm memory.&quot;) \
</span><span class="lines">@@ -494,6 +495,7 @@
</span><span class="cx">     // This typedef is to allow us to eliminate the '_' in the field name in
</span><span class="cx">     // union inside Entry. This is needed to keep the style checker happy.
</span><span class="cx">     typedef int32_t int32;
</span><ins>+    typedef size_t size;
</ins><span class="cx"> 
</span><span class="cx">     // Declare the option IDs:
</span><span class="cx">     enum ID {
</span><span class="lines">@@ -509,6 +511,7 @@
</span><span class="cx">         unsignedType,
</span><span class="cx">         doubleType,
</span><span class="cx">         int32Type,
</span><ins>+        sizeType,
</ins><span class="cx">         optionRangeType,
</span><span class="cx">         optionStringType,
</span><span class="cx">         gcLogLevelType,
</span><span class="lines">@@ -548,6 +551,7 @@
</span><span class="cx">         unsigned unsignedVal;
</span><span class="cx">         double doubleVal;
</span><span class="cx">         int32 int32Val;
</span><ins>+        size sizeVal;
</ins><span class="cx">         OptionRange optionRangeVal;
</span><span class="cx">         const char* optionStringVal;
</span><span class="cx">         GCLogging::Level gcLogLevelVal;
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmWasmPlancpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/wasm/WasmPlan.cpp (214565 => 214566)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/WasmPlan.cpp        2017-03-29 22:10:25 UTC (rev 214565)
+++ trunk/Source/JavaScriptCore/wasm/WasmPlan.cpp        2017-03-29 22:12:25 UTC (rev 214566)
</span><span class="lines">@@ -83,8 +83,8 @@
</span><span class="cx"> 
</span><span class="cx"> void Plan::moveToState(State state)
</span><span class="cx"> {
</span><del>-    ASSERT(state &gt; m_state);
-    dataLogLnIf(verbose, &quot;moving to state: &quot;, stateString(state), &quot; from state: &quot;, stateString(m_state));
</del><ins>+    ASSERT(state &gt;= m_state);
+    dataLogLnIf(verbose &amp;&amp; state != m_state, &quot;moving to state: &quot;, stateString(state), &quot; from state: &quot;, stateString(m_state));
</ins><span class="cx">     m_state = state;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -201,7 +201,7 @@
</span><span class="cx">         LockHolder locker(m_plan.m_lock);
</span><span class="cx">         m_plan.m_numberOfActiveThreads--;
</span><span class="cx"> 
</span><del>-        if (!m_plan.m_numberOfActiveThreads)
</del><ins>+        if (!m_plan.m_numberOfActiveThreads &amp;&amp; !m_plan.hasWork())
</ins><span class="cx">             m_plan.complete(locker);
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="lines">@@ -208,25 +208,31 @@
</span><span class="cx">     Plan&amp; m_plan;
</span><span class="cx"> };
</span><span class="cx"> 
</span><del>-void Plan::compileFunctions()
</del><ins>+void Plan::compileFunctions(CompilationEffort effort)
</ins><span class="cx"> {
</span><span class="cx">     ASSERT(m_state &gt;= State::Prepared);
</span><span class="cx">     dataLogLnIf(verbose, &quot;Starting compilation&quot;);
</span><span class="cx"> 
</span><del>-    if (m_state &gt;= State::Compiled)
</del><ins>+    if (!hasWork())
</ins><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx">     ThreadCountHolder holder(*this);
</span><ins>+
+    size_t bytesCompiled = 0;
</ins><span class="cx">     while (true) {
</span><ins>+        if (effort == Partial &amp;&amp; bytesCompiled &gt;= Options::webAssemblyPartialCompileLimit())
+            return;
+
</ins><span class="cx">         uint32_t functionIndex;
</span><span class="cx">         {
</span><span class="cx">             auto locker = holdLock(m_lock);
</span><del>-            if (m_currentIndex &gt;= m_functionLocationInBinary.size())
</del><ins>+            if (m_currentIndex &gt;= m_functionLocationInBinary.size()) {
+                if (hasWork())
+                    moveToState(State::Compiled);
</ins><span class="cx">                 return;
</span><ins>+            }
</ins><span class="cx">             functionIndex = m_currentIndex;
</span><span class="cx">             ++m_currentIndex;
</span><del>-            if (m_currentIndex == m_functionLocationInBinary.size())
-                moveToState(State::Compiled);
</del><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         const uint8_t* functionStart = m_source + m_functionLocationInBinary[functionIndex].start;
</span><span class="lines">@@ -252,6 +258,7 @@
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         m_wasmInternalFunctions[functionIndex] = WTFMove(*parseAndCompileResult);
</span><ins>+        bytesCompiled += functionLength;
</ins><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmWasmPlanh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/wasm/WasmPlan.h (214565 => 214566)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/WasmPlan.h        2017-03-29 22:10:25 UTC (rev 214565)
+++ trunk/Source/JavaScriptCore/wasm/WasmPlan.h        2017-03-29 22:12:25 UTC (rev 214566)
</span><span class="lines">@@ -58,7 +58,8 @@
</span><span class="cx">     bool parseAndValidateModule();
</span><span class="cx"> 
</span><span class="cx">     JS_EXPORT_PRIVATE void prepare();
</span><del>-    void compileFunctions();
</del><ins>+    enum CompilationEffort { All, Partial };
+    void compileFunctions(CompilationEffort = All);
</ins><span class="cx"> 
</span><span class="cx">     template&lt;typename Functor&gt;
</span><span class="cx">     void initializeCallees(const Functor&amp;);
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorewasmWasmWorklistcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/wasm/WasmWorklist.cpp (214565 => 214566)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/wasm/WasmWorklist.cpp        2017-03-29 22:10:25 UTC (rev 214565)
+++ trunk/Source/JavaScriptCore/wasm/WasmWorklist.cpp        2017-03-29 22:12:25 UTC (rev 214566)
</span><span class="lines">@@ -114,7 +114,7 @@
</span><span class="cx"> 
</span><span class="cx">         // FIXME: this should check in occasionally to see if there are new, higher priority e.g. synchronous, plans that need to be run.
</span><span class="cx">         // https://bugs.webkit.org/show_bug.cgi?id=170204
</span><del>-        plan-&gt;compileFunctions();
</del><ins>+        plan-&gt;compileFunctions(Plan::Partial);
</ins><span class="cx">         ASSERT(!plan-&gt;hasWork());
</span><span class="cx"> 
</span><span class="cx">         {
</span></span></pre>
</div>
</div>

</body>
</html>