Bug 1509283: Compile the last wasm function batch on the main thread; r=luke
authorBenjamin Bouvier <benj@benj.me>
Thu, 22 Nov 2018 11:12:20 +0100
changeset 507732 4201f7161e7a5323d7a9250f08c1d046aa85456d
parent 507731 44cd6ec4fbd5da73777883f4faf9fe822f7de513
child 507733 8d0013f9a06dc1a374e5725876ff24aa880f8978
push id1905
push userffxbld-merge
push dateMon, 21 Jan 2019 12:33:13 +0000
treeherdermozilla-release@c2fca1944d8c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke
bugs1509283
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1509283: Compile the last wasm function batch on the main thread; r=luke
js/src/wasm/WasmGenerator.cpp
js/src/wasm/WasmGenerator.h
--- a/js/src/wasm/WasmGenerator.cpp
+++ b/js/src/wasm/WasmGenerator.cpp
@@ -716,16 +716,30 @@ wasm::ExecuteCompileTaskFromHelperThread
             taskState->errorMessage = std::move(error);
         }
     }
 
     taskState.notify_one(/* failed or finished */);
 }
 
 bool
+ModuleGenerator::locallyCompileCurrentTask()
+{
+    if (!ExecuteCompileTask(currentTask_, error_)) {
+        return false;
+    }
+    if (!finishTask(currentTask_)) {
+        return false;
+    }
+    currentTask_ = nullptr;
+    batchedBytecode_ = 0;
+    return true;
+}
+
+bool
 ModuleGenerator::finishTask(CompileTask* task)
 {
     masm_.haltingAlign(CodeAlignment);
 
     // Before merging in the new function's code, if calls in a prior code range
     // might go out of range, insert far jumps to extend the range.
     if (!InRange(startOfUnpatchedCallsites_, masm_.size() + task->output.bytes.length())) {
         startOfUnpatchedCallsites_ = masm_.size();
@@ -751,30 +765,24 @@ bool
 ModuleGenerator::launchBatchCompile()
 {
     MOZ_ASSERT(currentTask_);
 
     if (cancelled_ && *cancelled_) {
         return false;
     }
 
-    if (parallel_) {
-        if (!StartOffThreadWasmCompile(currentTask_, mode())) {
-            return false;
-        }
-        outstanding_++;
-    } else {
-        if (!ExecuteCompileTask(currentTask_, error_)) {
-            return false;
-        }
-        if (!finishTask(currentTask_)) {
-            return false;
-        }
+    if (!parallel_) {
+        return locallyCompileCurrentTask();
     }
 
+    if (!StartOffThreadWasmCompile(currentTask_, mode())) {
+        return false;
+    }
+    outstanding_++;
     currentTask_ = nullptr;
     batchedBytecode_ = 0;
     return true;
 }
 
 bool
 ModuleGenerator::finishOutstandingTask()
 {
@@ -838,17 +846,17 @@ ModuleGenerator::compileFuncDef(uint32_t
     return batchedBytecode_ <= threshold || launchBatchCompile();
 }
 
 bool
 ModuleGenerator::finishFuncDefs()
 {
     MOZ_ASSERT(!finishedFuncDefs_);
 
-    if (currentTask_ && !launchBatchCompile()) {
+    if (currentTask_ && !locallyCompileCurrentTask()) {
         return false;
     }
 
     finishedFuncDefs_ = true;
     return true;
 }
 
 bool
--- a/js/src/wasm/WasmGenerator.h
+++ b/js/src/wasm/WasmGenerator.h
@@ -191,16 +191,17 @@ class MOZ_STACK_CLASS ModuleGenerator
 
     bool allocateGlobalBytes(uint32_t bytes, uint32_t align, uint32_t* globalDataOff);
 
     bool funcIsCompiled(uint32_t funcIndex) const;
     const CodeRange& funcCodeRange(uint32_t funcIndex) const;
     bool linkCallSites();
     void noteCodeRange(uint32_t codeRangeIndex, const CodeRange& codeRange);
     bool linkCompiledCode(const CompiledCode& code);
+    bool locallyCompileCurrentTask();
     bool finishTask(CompileTask* task);
     bool launchBatchCompile();
     bool finishOutstandingTask();
     bool finishCodegen();
     bool finishMetadataTier();
     UniqueCodeTier finishCodeTier();
     SharedMetadata finishMetadata(const Bytes& bytecode);