Bug 1639547: Add override switch to startHandlingCompressionTasks. r=jonco
authorAndré Bargull <andre.bargull@gmail.com>
Sat, 23 May 2020 12:41:27 +0000
changeset 531771 8f6fbfc7558c71bf283696578d148389fc7c2392
parent 531770 2b2753c09568fbdc264846ceffe8123312f9432d
child 531772 79ef4e6927106b67cc0190c85563bf368dca6897
push id37443
push usercbrindusan@mozilla.com
push dateSat, 23 May 2020 21:42:57 +0000
treeherdermozilla-central@9a2f741cef6a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjonco
bugs1639547
milestone78.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 1639547: Add override switch to startHandlingCompressionTasks. r=jonco Differential Revision: https://phabricator.services.mozilla.com/D76302
js/src/gc/GC.cpp
js/src/vm/HelperThreads.cpp
js/src/vm/HelperThreads.h
--- a/js/src/gc/GC.cpp
+++ b/js/src/gc/GC.cpp
@@ -4200,17 +4200,18 @@ bool GCRuntime::beginMarkPhase(JS::GCRea
   stats().measureInitialHeapSize();
 
   /*
    * Process any queued source compressions during the start of a major
    * GC.
    */
   {
     AutoLockHelperThreadState helperLock;
-    HelperThreadState().startHandlingCompressionTasks(helperLock);
+    HelperThreadState().startHandlingCompressionTasks(
+        helperLock, GlobalHelperThreadState::ScheduleCompressionTask::GC);
   }
 
   return true;
 }
 
 void GCRuntime::findDeadCompartments() {
   gcstats::AutoPhase ap1(stats(), gcstats::PhaseKind::MARK_ROOTS);
   gcstats::AutoPhase ap2(stats(), gcstats::PhaseKind::MARK_COMPARTMENTS);
--- a/js/src/vm/HelperThreads.cpp
+++ b/js/src/vm/HelperThreads.cpp
@@ -1670,30 +1670,30 @@ bool GlobalHelperThreadState::canStartPa
 
 bool GlobalHelperThreadState::canStartCompressionTask(
     const AutoLockHelperThreadState& lock) {
   return !compressionWorklist(lock).empty() &&
          checkTaskThreadLimit<SourceCompressionTask*>(maxCompressionThreads());
 }
 
 void GlobalHelperThreadState::startHandlingCompressionTasks(
-    const AutoLockHelperThreadState& lock) {
-  scheduleCompressionTasks(lock);
+    const AutoLockHelperThreadState& lock, ScheduleCompressionTask schedule) {
+  scheduleCompressionTasks(lock, schedule);
   if (canStartCompressionTask(lock)) {
     notifyOne(PRODUCER, lock);
   }
 }
 
 void GlobalHelperThreadState::scheduleCompressionTasks(
-    const AutoLockHelperThreadState& lock) {
+    const AutoLockHelperThreadState& lock, ScheduleCompressionTask schedule) {
   auto& pending = compressionPendingList(lock);
   auto& worklist = compressionWorklist(lock);
 
   for (size_t i = 0; i < pending.length(); i++) {
-    if (pending[i]->shouldStart()) {
+    if (pending[i]->shouldStart() || schedule != ScheduleCompressionTask::GC) {
       // OOMing during appending results in the task not being scheduled
       // and deleted.
       Unused << worklist.append(std::move(pending[i]));
       remove(pending, &i);
     }
   }
 }
 
@@ -2364,23 +2364,27 @@ void js::AttachFinishedCompressions(JSRu
 
 void js::RunPendingSourceCompressions(JSRuntime* runtime) {
   AutoLockHelperThreadState lock;
 
   if (!HelperThreadState().threads) {
     return;
   }
 
-  HelperThreadState().startHandlingCompressionTasks(lock);
-
-  // Wait for all in-process compression tasks to complete.
+  HelperThreadState().startHandlingCompressionTasks(
+      lock, GlobalHelperThreadState::ScheduleCompressionTask::API);
+
+  // Wait until all tasks have started compression.
   while (!HelperThreadState().compressionWorklist(lock).empty()) {
     HelperThreadState().wait(lock, GlobalHelperThreadState::CONSUMER);
   }
 
+  // Wait for all in-process compression tasks to complete.
+  HelperThreadState().waitForAllThreadsLocked(lock);
+
   AttachFinishedCompressions(runtime, lock);
 }
 
 void PromiseHelperTask::executeAndResolveAndDestroy(JSContext* cx) {
   execute();
   run(cx, JS::Dispatchable::NotShuttingDown);
 }
 
--- a/js/src/vm/HelperThreads.h
+++ b/js/src/vm/HelperThreads.h
@@ -289,24 +289,28 @@ class GlobalHelperThreadState {
   bool canStartWasmTier2Generator(const AutoLockHelperThreadState& lock);
   bool canStartPromiseHelperTask(const AutoLockHelperThreadState& lock);
   bool canStartIonCompile(const AutoLockHelperThreadState& lock);
   bool canStartIonFreeTask(const AutoLockHelperThreadState& lock);
   bool canStartParseTask(const AutoLockHelperThreadState& lock);
   bool canStartCompressionTask(const AutoLockHelperThreadState& lock);
   bool canStartGCParallelTask(const AutoLockHelperThreadState& lock);
 
+  enum class ScheduleCompressionTask { GC, API };
+
   // Used by a major GC to signal processing enqueued compression tasks.
-  void startHandlingCompressionTasks(const AutoLockHelperThreadState&);
+  void startHandlingCompressionTasks(const AutoLockHelperThreadState&,
+                                     ScheduleCompressionTask schedule);
 
   jit::IonCompileTask* highestPriorityPendingIonCompile(
       const AutoLockHelperThreadState& lock);
 
  private:
-  void scheduleCompressionTasks(const AutoLockHelperThreadState&);
+  void scheduleCompressionTasks(const AutoLockHelperThreadState&,
+                                ScheduleCompressionTask schedule);
 
   UniquePtr<ParseTask> finishParseTaskCommon(JSContext* cx, ParseTaskKind kind,
                                              JS::OffThreadToken* token);
 
   JSScript* finishSingleParseTask(JSContext* cx, ParseTaskKind kind,
                                   JS::OffThreadToken* token);
   bool finishMultiParseTask(JSContext* cx, ParseTaskKind kind,
                             JS::OffThreadToken* token,