Bug 1452982 part 13 - Misc cleanup related to cooperative scheduling. r=jonco
authorJan de Mooij <jdemooij@mozilla.com>
Tue, 17 Apr 2018 13:30:19 +0200
changeset 414093 4eb369e8ad7884a3dd20fe3145f7ad58c42db450
parent 414092 978eea13c27400155db08ecbb6da65e3155bbc19
child 414094 46caf0a4faa8d8c01cac0161af502ec2e2f60ba6
push id33858
push userncsoregi@mozilla.com
push dateTue, 17 Apr 2018 21:55:44 +0000
treeherdermozilla-central@d6eb5597d744 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjonco
bugs1452982
milestone61.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 1452982 part 13 - Misc cleanup related to cooperative scheduling. r=jonco
js/rust/src/rust.rs
js/src/jsfriendapi.h
js/src/shell/js.cpp
js/src/vm/JSContext.cpp
js/src/vm/MutexIDs.h
js/src/vm/Runtime.h
js/src/vm/TraceLogging.cpp
js/src/vm/TraceLogging.h
--- a/js/rust/src/rust.rs
+++ b/js/rust/src/rust.rs
@@ -184,17 +184,17 @@ impl Runtime {
             (*opts).set_nativeRegExp_(true);
 
             CONTEXT.with(|context| {
                 assert!(context.get().is_null());
                 context.set(js_context);
             });
 
             if use_internal_job_queue {
-                assert!(js::UseInternalJobQueues(js_context, false));
+                assert!(js::UseInternalJobQueues(js_context));
             }
 
             JS::InitSelfHostedCode(js_context);
 
             JS::SetWarningReporter(js_context, Some(report_warning));
 
             JS_BeginRequest(js_context);
 
--- a/js/src/jsfriendapi.h
+++ b/js/src/jsfriendapi.h
@@ -426,17 +426,17 @@ ForgetSourceHook(JSContext* cx);
  * will want to manage job queues themselves. For basic embeddings such as the
  * JS shell that don't have an event loop of their own, it's easier to have
  * SpiderMonkey handle job queues internally.
  *
  * Note that the embedding still has to trigger processing of job queues at
  * right time(s), such as after evaluation of a script has run to completion.
  */
 extern JS_FRIEND_API(bool)
-UseInternalJobQueues(JSContext* cx, bool cooperative = false);
+UseInternalJobQueues(JSContext* cx);
 
 /**
  * Enqueue |job| on the internal job queue.
  *
  * This is useful in tests for creating situations where a call occurs with no
  * other JavaScript on the stack.
  */
 extern JS_FRIEND_API(bool)
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -3543,44 +3543,32 @@ WorkerMain(void* arg)
 
     auto guard = mozilla::MakeScopeExit([&] {
         CancelOffThreadJobsForContext(cx);
         JS_DestroyContext(cx);
         js_delete(sc);
         js_delete(input);
     });
 
-    if (input->parentRuntime)
-        sc->isWorker = true;
+    sc->isWorker = true;
     JS_SetContextPrivate(cx, sc);
     SetWorkerContextOptions(cx);
     JS::SetBuildIdOp(cx, ShellBuildId);
 
-    Maybe<EnvironmentPreparer> environmentPreparer;
-    if (input->parentRuntime) {
-        JS_SetFutexCanWait(cx);
-        JS::SetWarningReporter(cx, WarningReporter);
-        js::SetPreserveWrapperCallback(cx, DummyPreserveWrapperCallback);
-        JS_InitDestroyPrincipalsCallback(cx, ShellPrincipals::destroy);
-
-        js::UseInternalJobQueues(cx);
-
-        if (!JS::InitSelfHostedCode(cx))
-            return;
-
-        environmentPreparer.emplace(cx);
-    } else {
-        JS_AddInterruptCallback(cx, ShellInterruptCallback);
-
-        js::UseInternalJobQueues(cx, /* cooperative = */true);
-
-        // The Gecko Profiler requires that all cooperating contexts have
-        // profiling stacks installed.
-        MOZ_ALWAYS_TRUE(EnsureGeckoProfilingStackInstalled(cx, sc));
-    }
+    JS_SetFutexCanWait(cx);
+    JS::SetWarningReporter(cx, WarningReporter);
+    js::SetPreserveWrapperCallback(cx, DummyPreserveWrapperCallback);
+    JS_InitDestroyPrincipalsCallback(cx, ShellPrincipals::destroy);
+
+    js::UseInternalJobQueues(cx);
+
+    if (!JS::InitSelfHostedCode(cx))
+        return;
+
+    EnvironmentPreparer environmentPreparer(cx);
 
     do {
         JSAutoRequest ar(cx);
 
         JS::CompartmentOptions compartmentOptions;
         SetStandardCompartmentOptions(compartmentOptions);
 
         RootedObject global(cx, NewGlobalObject(cx, compartmentOptions, nullptr));
--- a/js/src/vm/JSContext.cpp
+++ b/js/src/vm/JSContext.cpp
@@ -1066,31 +1066,30 @@ class MOZ_STACK_CLASS ReportExceptionClo
     }
 
   private:
     HandleValue exn_;
 };
 } // anonymous namespace
 
 JS_FRIEND_API(bool)
-js::UseInternalJobQueues(JSContext* cx, bool cooperative)
+js::UseInternalJobQueues(JSContext* cx)
 {
     // Internal job queue handling must be set up very early. Self-hosting
     // initialization is as good a marker for that as any.
-    MOZ_RELEASE_ASSERT(cooperative || !cx->runtime()->hasInitializedSelfHosting(),
+    MOZ_RELEASE_ASSERT(!cx->runtime()->hasInitializedSelfHosting(),
                        "js::UseInternalJobQueues must be called early during runtime startup.");
     MOZ_ASSERT(!cx->jobQueue);
     auto* queue = js_new<PersistentRooted<JobQueue>>(cx, JobQueue(SystemAllocPolicy()));
     if (!queue)
         return false;
 
     cx->jobQueue = queue;
 
-    if (!cooperative)
-        cx->runtime()->offThreadPromiseState.ref().initInternalDispatchQueue();
+    cx->runtime()->offThreadPromiseState.ref().initInternalDispatchQueue();
     MOZ_ASSERT(cx->runtime()->offThreadPromiseState.ref().initialized());
 
     JS::SetEnqueuePromiseJobCallback(cx, InternalEnqueuePromiseJobCallback);
 
     return true;
 }
 
 JS_FRIEND_API(bool)
--- a/js/src/vm/MutexIDs.h
+++ b/js/src/vm/MutexIDs.h
@@ -13,17 +13,16 @@
 //
 // Mutexes can only be acquired in increasing order. This prevents the
 // possibility of deadlock.
 
 #define FOR_EACH_MUTEX(_)             \
   _(TestMutex,                   100) \
   _(ShellContextWatchdog,        100) \
   _(ShellWorkerThreads,          100) \
-  _(ShellThreadCooperation,      100) \
   _(ShellArrayBufferMailbox,     100) \
                                       \
   _(RuntimeExclusiveAccess,      200) \
                                       \
   _(WasmInitBuiltinThunks,       250) \
   _(WasmLazyStubsTier1,          250) \
   _(WasmLazyStubsTier2,          251) \
                                       \
--- a/js/src/vm/Runtime.h
+++ b/js/src/vm/Runtime.h
@@ -475,20 +475,17 @@ struct JSRuntime : public js::MallocProv
      * Locking this only occurs if there is actually a thread other than the
      * active thread which could access this.
      */
     js::Mutex scriptDataLock;
 #ifdef DEBUG
     bool activeThreadHasScriptDataAccess;
 #endif
 
-    /*
-     * Number of zones which may be operated on by non-cooperating helper
-     * threads.
-     */
+    // Number of zones which may be operated on by helper threads.
     mozilla::Atomic<size_t> numActiveHelperThreadZones;
 
     friend class js::AutoLockForExclusiveAccess;
     friend class js::AutoLockScriptData;
 
   public:
     void setUsedByHelperThread(JS::Zone* zone);
     void clearUsedByHelperThread(JS::Zone* zone);
--- a/js/src/vm/TraceLogging.cpp
+++ b/js/src/vm/TraceLogging.cpp
@@ -864,28 +864,28 @@ TraceLoggerThreadState::init()
     const char* options = getenv("TLOPTIONS");
     if (options) {
         if (strstr(options, "help")) {
             fflush(nullptr);
             printf(
                 "\n"
                 "usage: TLOPTIONS=option,option,option,... where options can be:\n"
                 "\n"
-                "  EnableActiveThread      Start logging cooperating threads immediately.\n"
+                "  EnableMainThread        Start logging main threads immediately.\n"
                 "  EnableOffThread         Start logging helper threads immediately.\n"
                 "  EnableGraph             Enable spewing the tracelogging graph to a file.\n"
                 "  Errors                  Report errors during tracing to stderr.\n"
             );
             printf("\n");
             exit(0);
             /*NOTREACHED*/
         }
 
-        if (strstr(options, "EnableActiveThread"))
-            cooperatingThreadEnabled = true;
+        if (strstr(options, "EnableMainThread"))
+            mainThreadEnabled = true;
         if (strstr(options, "EnableOffThread"))
             helperThreadEnabled = true;
         if (strstr(options, "EnableGraph"))
             graphSpewingEnabled = true;
         if (strstr(options, "Errors"))
             spewErrors = true;
     }
 
@@ -980,17 +980,17 @@ TraceLoggerThreadState::forCurrentThread
         }
 
         threadLoggers.insertFront(logger);
         cx->traceLogger = logger;
 
         if (graphSpewingEnabled)
             logger->initGraph();
 
-        if (CurrentHelperThread() ? helperThreadEnabled : cooperatingThreadEnabled)
+        if (CurrentHelperThread() ? helperThreadEnabled : mainThreadEnabled)
             logger->enable();
     }
 
     return cx->traceLogger;
 }
 
 void
 TraceLoggerThreadState::destroyLogger(TraceLoggerThread* logger)
--- a/js/src/vm/TraceLogging.h
+++ b/js/src/vm/TraceLogging.h
@@ -373,17 +373,17 @@ class TraceLoggerThread : public mozilla
 class TraceLoggerThreadState
 {
 #ifdef JS_TRACE_LOGGING
 #ifdef DEBUG
     bool initialized;
 #endif
 
     bool enabledTextIds[TraceLogger_Last];
-    bool cooperatingThreadEnabled;
+    bool mainThreadEnabled;
     bool helperThreadEnabled;
     bool graphSpewingEnabled;
     bool spewErrors;
     mozilla::LinkedList<TraceLoggerThread> threadLoggers;
 
     typedef HashMap<const void*,
                     TraceLoggerEventPayload*,
                     PointerHasher<const void*>,
@@ -400,17 +400,17 @@ class TraceLoggerThreadState
     uint64_t startupTime;
     Mutex lock;
 
     TraceLoggerThreadState()
       :
 #ifdef DEBUG
         initialized(false),
 #endif
-        cooperatingThreadEnabled(false),
+        mainThreadEnabled(false),
         helperThreadEnabled(false),
         graphSpewingEnabled(false),
         spewErrors(false),
         nextTextId(TraceLogger_Last),
         startupTime(0),
         lock(js::mutexid::TraceLoggerThreadState)
     { }