ParseTask::runTaskLocked draft
authorYoshi Cheng-Hao Huang <allstars.chh@gmail.com>
Wed, 01 Jul 2020 15:09:44 +0200
changeset 3016311 f728afe0e7b5dd17a0229f7aa3487e5c716d3dc5
parent 3016243 be49630cbd146ac744960d9a8fdfb6f88fbe0790
child 3016312 77e3dd1e774e30d82ccc06d7a916f7b92696b459
push id562773
push userallstars.chh@gmail.com
push dateWed, 01 Jul 2020 13:10:32 +0000
treeherdertry@77e3dd1e774e [default view] [failures only]
milestone79.0a1
ParseTask::runTaskLocked
js/src/vm/HelperThreads.cpp
js/src/vm/HelperThreads.h
--- a/js/src/vm/HelperThreads.cpp
+++ b/js/src/vm/HelperThreads.cpp
@@ -529,16 +529,39 @@ void ParseTask::trace(JSTracer* trc) {
 }
 
 size_t ParseTask::sizeOfExcludingThis(
     mozilla::MallocSizeOf mallocSizeOf) const {
   return options.sizeOfExcludingThis(mallocSizeOf) +
          errors.sizeOfExcludingThis(mallocSizeOf);
 }
 
+void ParseTask::runTaskLocked(AutoLockHelperThreadState& locked) {
+#ifdef DEBUG
+  JSRuntime* runtime = parseGlobal->runtimeFromAnyThread();
+  runtime->incOffThreadParsesRunning();
+#endif
+
+  {
+    AutoUnlockHelperThreadState unlock(locked);
+    runTask();
+  }
+
+  // The callback is invoked while we are still off thread.
+  callback(this, callbackData);
+
+  // FinishOffThreadScript will need to be called on the script to
+  // migrate it into the correct compartment.
+  HelperThreadState().parseFinishedList(locked).insertBack(this);
+
+#ifdef DEBUG
+  runtime->decOffThreadParsesRunning();
+#endif
+}
+
 void ParseTask::runTask() {
   AutoSetHelperThreadContext usesContext;
 
   JSContext* cx = TlsContext.get();
   JSRuntime* runtime = parseGlobal->runtimeFromAnyThread();
 
   AutoSetContextRuntime ascr(runtime);
   AutoSetContextParse parsetask(this);
@@ -2143,35 +2166,17 @@ void JSContext::addPendingOutOfMemory() 
 
 void HelperThread::handleParseWorkload(AutoLockHelperThreadState& locked) {
   MOZ_ASSERT(HelperThreadState().canStartParseTask(locked));
   MOZ_ASSERT(idle());
 
   currentTask.emplace(HelperThreadState().parseWorklist(locked).popCopy());
   ParseTask* task = parseTask();
 
-#ifdef DEBUG
-  JSRuntime* runtime = task->parseGlobal->runtimeFromAnyThread();
-  runtime->incOffThreadParsesRunning();
-#endif
-
-  {
-    AutoUnlockHelperThreadState unlock(locked);
-    task->runTask();
-  }
-  // The callback is invoked while we are still off thread.
-  task->callback(task, task->callbackData);
-
-  // FinishOffThreadScript will need to be called on the script to
-  // migrate it into the correct compartment.
-  HelperThreadState().parseFinishedList(locked).insertBack(task);
-
-#ifdef DEBUG
-  runtime->decOffThreadParsesRunning();
-#endif
+  task->runTaskLocked(locked);
 
   currentTask.reset();
 
   // Notify the main thread in case it is waiting for the parse/emit to finish.
   HelperThreadState().notifyAll(GlobalHelperThreadState::CONSUMER, locked);
 }
 
 void HelperThread::handleCompressionWorkload(
--- a/js/src/vm/HelperThreads.h
+++ b/js/src/vm/HelperThreads.h
@@ -752,16 +752,17 @@ struct ParseTask : public mozilla::Linke
 
   void trace(JSTracer* trc);
 
   size_t sizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
   size_t sizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const {
     return mallocSizeOf(this) + sizeOfExcludingThis(mallocSizeOf);
   }
 
+  void runTaskLocked(AutoLockHelperThreadState& locked);
   void runTask() override;
   ThreadType threadType() override { return ThreadType::THREAD_TYPE_PARSE; }
 };
 
 struct ScriptDecodeTask : public ParseTask {
   const JS::TranscodeRange range;
 
   ScriptDecodeTask(JSContext* cx, const JS::TranscodeRange& range,