Title: [214566] trunk/Source/_javascript_Core
Revision
214566
Author
keith_mil...@apple.com
Date
2017-03-29 15:12:25 -0700 (Wed, 29 Mar 2017)

Log Message

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:

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (214565 => 214566)


--- trunk/Source/_javascript_Core/ChangeLog	2017-03-29 22:10:25 UTC (rev 214565)
+++ trunk/Source/_javascript_Core/ChangeLog	2017-03-29 22:12:25 UTC (rev 214566)
@@ -1,3 +1,29 @@
+2017-03-29  Keith Miller  <keith_mil...@apple.com>
+
+        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:
+
 2017-03-29  Mark Lam  <mark....@apple.com>
 
         Remove obsolete references to HeapTimer in _javascript_Core.order.

Modified: trunk/Source/_javascript_Core/runtime/Options.cpp (214565 => 214566)


--- trunk/Source/_javascript_Core/runtime/Options.cpp	2017-03-29 22:10:25 UTC (rev 214565)
+++ trunk/Source/_javascript_Core/runtime/Options.cpp	2017-03-29 22:12:25 UTC (rev 214566)
@@ -89,6 +89,11 @@
     return sscanf(string, "%u", &value) == 1;
 }
 
+static bool parse(const char* string, size_t& value)
+{
+    return sscanf(string, "%zu", &value);
+}
+
 static bool parse(const char* string, double& value)
 {
     return sscanf(string, "%lf", &value) == 1;
@@ -814,6 +819,9 @@
     case Options::Type::unsignedType:
         builder.appendNumber(m_entry.unsignedVal);
         break;
+    case Options::Type::sizeType:
+        builder.appendNumber(m_entry.sizeVal);
+        break;
     case Options::Type::doubleType:
         builder.appendNumber(m_entry.doubleVal);
         break;
@@ -846,6 +854,8 @@
         return m_entry.boolVal == other.m_entry.boolVal;
     case Options::Type::unsignedType:
         return m_entry.unsignedVal == other.m_entry.unsignedVal;
+    case Options::Type::sizeType:
+        return m_entry.sizeVal == other.m_entry.sizeVal;
     case Options::Type::doubleType:
         return (m_entry.doubleVal == other.m_entry.doubleVal) || (std::isnan(m_entry.doubleVal) && std::isnan(other.m_entry.doubleVal));
     case Options::Type::int32Type:

Modified: trunk/Source/_javascript_Core/runtime/Options.h (214565 => 214566)


--- trunk/Source/_javascript_Core/runtime/Options.h	2017-03-29 22:10:25 UTC (rev 214565)
+++ trunk/Source/_javascript_Core/runtime/Options.h	2017-03-29 22:12:25 UTC (rev 214566)
@@ -431,6 +431,7 @@
     v(bool, useWebAssembly, true, Normal, "Expose the WebAssembly global object.") \
     \
     v(bool, failToCompileWebAssemblyCode, false, Normal, "If true, no Wasm::Plan will sucessfully compile a function.") \
+    v(size, webAssemblyPartialCompileLimit, 5000, Normal, "Limit on the number of bytes a Wasm::Plan::compile should attempt before checking for other work.") \
     \
     v(bool, simulateWebAssemblyLowMemory, false, Normal, "If true, the Memory object won't mmap the full 'maximum' range and instead will allocate the minimum required amount.") \
     v(bool, useWebAssemblyFastMemory, true, Normal, "If true, we will try to use a 32-bit address space with a signal handler to bounds check wasm memory.") \
@@ -494,6 +495,7 @@
     // This typedef is to allow us to eliminate the '_' in the field name in
     // union inside Entry. This is needed to keep the style checker happy.
     typedef int32_t int32;
+    typedef size_t size;
 
     // Declare the option IDs:
     enum ID {
@@ -509,6 +511,7 @@
         unsignedType,
         doubleType,
         int32Type,
+        sizeType,
         optionRangeType,
         optionStringType,
         gcLogLevelType,
@@ -548,6 +551,7 @@
         unsigned unsignedVal;
         double doubleVal;
         int32 int32Val;
+        size sizeVal;
         OptionRange optionRangeVal;
         const char* optionStringVal;
         GCLogging::Level gcLogLevelVal;

Modified: trunk/Source/_javascript_Core/wasm/WasmPlan.cpp (214565 => 214566)


--- trunk/Source/_javascript_Core/wasm/WasmPlan.cpp	2017-03-29 22:10:25 UTC (rev 214565)
+++ trunk/Source/_javascript_Core/wasm/WasmPlan.cpp	2017-03-29 22:12:25 UTC (rev 214566)
@@ -83,8 +83,8 @@
 
 void Plan::moveToState(State state)
 {
-    ASSERT(state > m_state);
-    dataLogLnIf(verbose, "moving to state: ", stateString(state), " from state: ", stateString(m_state));
+    ASSERT(state >= m_state);
+    dataLogLnIf(verbose && state != m_state, "moving to state: ", stateString(state), " from state: ", stateString(m_state));
     m_state = state;
 }
 
@@ -201,7 +201,7 @@
         LockHolder locker(m_plan.m_lock);
         m_plan.m_numberOfActiveThreads--;
 
-        if (!m_plan.m_numberOfActiveThreads)
+        if (!m_plan.m_numberOfActiveThreads && !m_plan.hasWork())
             m_plan.complete(locker);
     }
 
@@ -208,25 +208,31 @@
     Plan& m_plan;
 };
 
-void Plan::compileFunctions()
+void Plan::compileFunctions(CompilationEffort effort)
 {
     ASSERT(m_state >= State::Prepared);
     dataLogLnIf(verbose, "Starting compilation");
 
-    if (m_state >= State::Compiled)
+    if (!hasWork())
         return;
 
     ThreadCountHolder holder(*this);
+
+    size_t bytesCompiled = 0;
     while (true) {
+        if (effort == Partial && bytesCompiled >= Options::webAssemblyPartialCompileLimit())
+            return;
+
         uint32_t functionIndex;
         {
             auto locker = holdLock(m_lock);
-            if (m_currentIndex >= m_functionLocationInBinary.size())
+            if (m_currentIndex >= m_functionLocationInBinary.size()) {
+                if (hasWork())
+                    moveToState(State::Compiled);
                 return;
+            }
             functionIndex = m_currentIndex;
             ++m_currentIndex;
-            if (m_currentIndex == m_functionLocationInBinary.size())
-                moveToState(State::Compiled);
         }
 
         const uint8_t* functionStart = m_source + m_functionLocationInBinary[functionIndex].start;
@@ -252,6 +258,7 @@
         }
 
         m_wasmInternalFunctions[functionIndex] = WTFMove(*parseAndCompileResult);
+        bytesCompiled += functionLength;
     }
 }
 

Modified: trunk/Source/_javascript_Core/wasm/WasmPlan.h (214565 => 214566)


--- trunk/Source/_javascript_Core/wasm/WasmPlan.h	2017-03-29 22:10:25 UTC (rev 214565)
+++ trunk/Source/_javascript_Core/wasm/WasmPlan.h	2017-03-29 22:12:25 UTC (rev 214566)
@@ -58,7 +58,8 @@
     bool parseAndValidateModule();
 
     JS_EXPORT_PRIVATE void prepare();
-    void compileFunctions();
+    enum CompilationEffort { All, Partial };
+    void compileFunctions(CompilationEffort = All);
 
     template<typename Functor>
     void initializeCallees(const Functor&);

Modified: trunk/Source/_javascript_Core/wasm/WasmWorklist.cpp (214565 => 214566)


--- trunk/Source/_javascript_Core/wasm/WasmWorklist.cpp	2017-03-29 22:10:25 UTC (rev 214565)
+++ trunk/Source/_javascript_Core/wasm/WasmWorklist.cpp	2017-03-29 22:12:25 UTC (rev 214566)
@@ -114,7 +114,7 @@
 
         // FIXME: this should check in occasionally to see if there are new, higher priority e.g. synchronous, plans that need to be run.
         // https://bugs.webkit.org/show_bug.cgi?id=170204
-        plan->compileFunctions();
+        plan->compileFunctions(Plan::Partial);
         ASSERT(!plan->hasWork());
 
         {
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to