Bug 1452982 part 12 - Clean up ContextKind and CheckThreadLocal. r=jonco
authorJan de Mooij <jdemooij@mozilla.com>
Tue, 17 Apr 2018 10:48:10 +0200
changeset 467610 d46b75deaae586798e885c3e61f8efb0bfdb3069
parent 467609 7cb5e6101f4a788d162e8aa7e8002f0f8c6d080e
child 467611 3f214ca585db301f1c1f284b9a63dd5c98c15f8b
push id9165
push userasasaki@mozilla.com
push dateThu, 26 Apr 2018 21:04:54 +0000
treeherdermozilla-beta@064c3804de2e [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 12 - Clean up ContextKind and CheckThreadLocal. r=jonco
js/src/jsapi.cpp
js/src/threading/ProtectedData.cpp
js/src/vm/HelperThreads.cpp
js/src/vm/JSContext.cpp
js/src/vm/JSContext.h
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -1635,17 +1635,17 @@ JS_SetNativeStackQuota(JSContext* cx, si
         untrustedScriptStackSize = trustedScriptStackSize;
     else
         MOZ_ASSERT(untrustedScriptStackSize < trustedScriptStackSize);
 
     SetNativeStackQuotaAndLimit(cx, JS::StackForSystemCode, systemCodeStackSize);
     SetNativeStackQuotaAndLimit(cx, JS::StackForTrustedScript, trustedScriptStackSize);
     SetNativeStackQuotaAndLimit(cx, JS::StackForUntrustedScript, untrustedScriptStackSize);
 
-    if (cx->isCooperativelyScheduled())
+    if (cx->isMainThreadContext())
         cx->initJitStackLimit();
 }
 
 /************************************************************************/
 
 JS_PUBLIC_API(bool)
 JS_ValueToId(JSContext* cx, HandleValue value, MutableHandleId idp)
 {
--- a/js/src/threading/ProtectedData.cpp
+++ b/js/src/threading/ProtectedData.cpp
@@ -33,24 +33,19 @@ OnHelperThread()
     return false;
 }
 
 void
 CheckThreadLocal::check() const
 {
     JSContext* cx = TlsContext.get();
     MOZ_ASSERT(cx);
-
-    // As for CheckZone, in a cooperatively scheduled runtime the active
-    // thread is permitted access to thread local state for other suspended
-    // threads in the same runtime.
-    if (cx->isCooperativelyScheduled())
-        MOZ_ASSERT(CurrentThreadCanAccessRuntime(cx->runtime()));
-    else
-        MOZ_ASSERT(id == ThisThread::GetId());
+    MOZ_ASSERT_IF(cx->isMainThreadContext(),
+                  CurrentThreadCanAccessRuntime(cx->runtime()));
+    MOZ_ASSERT(id == ThisThread::GetId());
 }
 
 template <AllowedHelperThread Helper>
 void
 CheckMainThread<Helper>::check() const
 {
     if (OnHelperThread<Helper>())
         return;
--- a/js/src/vm/HelperThreads.cpp
+++ b/js/src/vm/HelperThreads.cpp
@@ -2219,17 +2219,17 @@ HelperThread::threadLoop()
     MOZ_ASSERT(CanUseExtraThreads());
 
     JS::AutoSuppressGCAnalysis nogc;
     AutoLockHelperThreadState lock;
 
     JSContext cx(nullptr, JS::ContextOptions());
     {
         AutoEnterOOMUnsafeRegion oomUnsafe;
-        if (!cx.init(ContextKind::Background))
+        if (!cx.init(ContextKind::HelperThread))
             oomUnsafe.crash("HelperThread cx.init()");
     }
     cx.setHelperThread(this);
     JS_SetNativeStackQuota(&cx, HELPER_STACK_QUOTA);
 
     while (!terminate) {
         MOZ_ASSERT(idle());
 
--- a/js/src/vm/JSContext.cpp
+++ b/js/src/vm/JSContext.cpp
@@ -95,17 +95,17 @@ js::AutoCycleDetector::~AutoCycleDetecto
         }
     }
 }
 
 bool
 JSContext::init(ContextKind kind)
 {
     // Skip most of the initialization if this thread will not be running JS.
-    if (kind == ContextKind::Cooperative) {
+    if (kind == ContextKind::MainThread) {
         if (!regexpStack.ref().init())
             return false;
 
         if (!fx.initInstance())
             return false;
 
 #ifdef JS_SIMULATOR
         simulator_ = jit::Simulator::Create(this);
@@ -148,17 +148,17 @@ js::NewContext(uint32_t maxBytes, uint32
 
     if (!runtime->init(cx, maxBytes, maxNurseryBytes)) {
         runtime->destroyRuntime();
         js_delete(cx);
         js_delete(runtime);
         return nullptr;
     }
 
-    if (!cx->init(ContextKind::Cooperative)) {
+    if (!cx->init(ContextKind::MainThread)) {
         runtime->destroyRuntime();
         js_delete(cx);
         js_delete(runtime);
         return nullptr;
     }
 
     return cx;
 }
@@ -1215,17 +1215,17 @@ JSContext::alreadyReportedError()
     if (!helperThread())
         MOZ_ASSERT(isExceptionPending());
 #endif
     return mozilla::Err(reportedError);
 }
 
 JSContext::JSContext(JSRuntime* runtime, const JS::ContextOptions& options)
   : runtime_(runtime),
-    kind_(ContextKind::Background),
+    kind_(ContextKind::HelperThread),
     helperThread_(nullptr),
     options_(options),
     arenas_(nullptr),
     enterCompartmentDepth_(0),
     jitActivation(nullptr),
     activation_(nullptr),
     profilingActivation_(nullptr),
     nativeStackBase(GetNativeStackBase()),
@@ -1313,17 +1313,17 @@ JSContext::JSContext(JSRuntime* runtime,
     for (size_t i = 0; i < mozilla::ArrayLength(nativeStackQuota); i++)
         nativeStackQuota[i] = 0;
 }
 
 JSContext::~JSContext()
 {
     // Clear the ContextKind first, so that ProtectedData checks will allow us to
     // destroy this context even if the runtime is already gone.
-    kind_ = ContextKind::Background;
+    kind_ = ContextKind::HelperThread;
 
     /* Free the stuff hanging off of cx. */
     MOZ_ASSERT(!resolvingList);
 
     js_delete(ionPcScriptCache.ref());
 
     if (dtoaState)
         DestroyDtoaState(dtoaState);
--- a/js/src/vm/JSContext.h
+++ b/js/src/vm/JSContext.h
@@ -75,18 +75,21 @@ class AutoLockScriptData;
 
 void ReportOverRecursed(JSContext* cx, unsigned errorNumber);
 
 /* Thread Local Storage slot for storing the context for a thread. */
 extern MOZ_THREAD_LOCAL(JSContext*) TlsContext;
 
 enum class ContextKind
 {
-    Cooperative,
-    Background
+    // Context for the main thread of a JSRuntime.
+    MainThread,
+
+    // Context for a helper thread.
+    HelperThread
 };
 
 #ifdef DEBUG
 bool
 CurrentThreadIsParseThread();
 #endif
 
 } /* namespace js */
@@ -117,17 +120,17 @@ struct JSContext : public JS::RootingCon
 
     js::ThreadLocalData<js::gc::ArenaLists*> arenas_;
 
   public:
     // This is used by helper threads to change the runtime their context is
     // currently operating on.
     void setRuntime(JSRuntime* rt);
 
-    bool isCooperativelyScheduled() const { return kind_ == js::ContextKind::Cooperative; }
+    bool isMainThreadContext() const { return kind_ == js::ContextKind::MainThread; }
 
     inline js::gc::ArenaLists* arenas() const { return arenas_; }
 
     template <typename T>
     bool isInsideCurrentZone(T thing) const {
         return thing->zoneFromAnyThread() == zone_;
     }