Bug 1290589 - Make JSRuntime's exclusiveAccessOwner a js::Thread::Id instead of a PRThread*; r=terrence
☠☠ backed out by 85272f8ab75c ☠ ☠
authorNick Fitzgerald <fitzgen@gmail.com>
Mon, 08 Aug 2016 13:26:10 -0700
changeset 308713 b61757c08a5fbe9df2a1af7e462650b8c5b556ba
parent 308712 ea0953a122a2547376117423088f0a26675527aa
child 308714 0329537bee24225608e30e865ea44dfa9d9aa6a9
push id20266
push usercbook@mozilla.com
push dateTue, 09 Aug 2016 13:49:06 +0000
treeherderfx-team@613fec9a571e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersterrence
bugs1290589
milestone51.0a1
Bug 1290589 - Make JSRuntime's exclusiveAccessOwner a js::Thread::Id instead of a PRThread*; r=terrence
js/src/jscntxt.h
js/src/vm/Runtime.cpp
js/src/vm/Runtime.h
--- a/js/src/jscntxt.h
+++ b/js/src/jscntxt.h
@@ -744,17 +744,17 @@ class MOZ_RAII AutoLockForExclusiveAcces
     JSRuntime* runtime;
 
     void init(JSRuntime* rt) {
         runtime = rt;
         if (runtime->numExclusiveThreads) {
             runtime->assertCanLock(ExclusiveAccessLock);
             runtime->exclusiveAccessLock.lock();
 #ifdef DEBUG
-            runtime->exclusiveAccessOwner = PR_GetCurrentThread();
+            runtime->exclusiveAccessOwner = mozilla::Some(ThisThread::GetId());
 #endif
         } else {
             MOZ_ASSERT(!runtime->mainThreadHasExclusiveAccess);
 #ifdef DEBUG
             runtime->mainThreadHasExclusiveAccess = true;
 #endif
         }
     }
@@ -770,18 +770,18 @@ class MOZ_RAII AutoLockForExclusiveAcces
     }
     explicit AutoLockForExclusiveAccess(JSContext* cx MOZ_GUARD_OBJECT_NOTIFIER_PARAM) {
         MOZ_GUARD_OBJECT_NOTIFIER_INIT;
         init(cx->runtime());
     }
     ~AutoLockForExclusiveAccess() {
         if (runtime->numExclusiveThreads) {
 #ifdef DEBUG
-            MOZ_ASSERT(runtime->exclusiveAccessOwner == PR_GetCurrentThread());
-            runtime->exclusiveAccessOwner = nullptr;
+            MOZ_ASSERT(*runtime->exclusiveAccessOwner == ThisThread::GetId());
+            runtime->exclusiveAccessOwner.reset();
 #endif
             runtime->exclusiveAccessLock.unlock();
         } else {
             MOZ_ASSERT(runtime->mainThreadHasExclusiveAccess);
 #ifdef DEBUG
             runtime->mainThreadHasExclusiveAccess = false;
 #endif
         }
--- a/js/src/vm/Runtime.cpp
+++ b/js/src/vm/Runtime.cpp
@@ -156,17 +156,16 @@ JSRuntime::JSRuntime(JSRuntime* parentRu
     handlingJitInterrupt_(false),
     interruptCallback(nullptr),
     getIncumbentGlobalCallback(nullptr),
     enqueuePromiseJobCallback(nullptr),
     enqueuePromiseJobCallbackData(nullptr),
     promiseRejectionTrackerCallback(nullptr),
     promiseRejectionTrackerCallbackData(nullptr),
 #ifdef DEBUG
-    exclusiveAccessOwner(nullptr),
     mainThreadHasExclusiveAccess(false),
 #endif
     numExclusiveThreads(0),
     numCompartments(0),
     localeCallbacks(nullptr),
     defaultLocale(nullptr),
     defaultVersion_(JSVERSION_DEFAULT),
     ownerThread_(nullptr),
@@ -427,17 +426,17 @@ JSRuntime::destroyRuntime()
     MOZ_ASSERT(ionLazyLinkList_.isEmpty());
 
     /*
      * Clear the self-hosted global and delete self-hosted classes *after*
      * GC, as finalizers for objects check for clasp->finalize during GC.
      */
     finishSelfHosting();
 
-    MOZ_ASSERT(!exclusiveAccessOwner);
+    MOZ_ASSERT(exclusiveAccessOwner.isNothing());
 
     MOZ_ASSERT(!numExclusiveThreads);
     AutoLockForExclusiveAccess lock(this);
 
     /*
      * Even though all objects in the compartment are dead, we may have keep
      * some filenames around because of gcKeepAtoms.
      */
@@ -894,17 +893,18 @@ js::CurrentThreadCanAccessZone(Zone* zon
 void
 JSRuntime::assertCanLock(RuntimeLock which)
 {
     // In the switch below, each case falls through to the one below it. None
     // of the runtime locks are reentrant, and when multiple locks are acquired
     // it must be done in the order below.
     switch (which) {
       case ExclusiveAccessLock:
-        MOZ_ASSERT(exclusiveAccessOwner != PR_GetCurrentThread());
+        MOZ_ASSERT_IF(exclusiveAccessOwner.isSome(),
+                      exclusiveAccessOwner.ref() != js::ThisThread::GetId());
         MOZ_FALLTHROUGH;
       case HelperThreadStateLock:
         MOZ_FALLTHROUGH;
       case GCLock:
         break;
       default:
         MOZ_CRASH();
     }
--- a/js/src/vm/Runtime.h
+++ b/js/src/vm/Runtime.h
@@ -34,16 +34,17 @@
 #include "js/Debug.h"
 #include "js/GCVector.h"
 #include "js/HashTable.h"
 #ifdef DEBUG
 # include "js/Proxy.h" // For AutoEnterPolicy
 #endif
 #include "js/UniquePtr.h"
 #include "js/Vector.h"
+#include "threading/Thread.h"
 #include "vm/CodeCoverage.h"
 #include "vm/CommonPropertyNames.h"
 #include "vm/DateTime.h"
 #include "vm/MallocProvider.h"
 #include "vm/SharedImmutableStringsCache.h"
 #include "vm/SPSProfiler.h"
 #include "vm/Stack.h"
 #include "vm/Stopwatch.h"
@@ -689,33 +690,33 @@ struct JSRuntime : public JS::shadow::Ru
      * be accessed simultaneously by both the main thread and another thread
      * with an ExclusiveContext.
      *
      * Locking this only occurs if there is actually a thread other than the
      * main thread with an ExclusiveContext which could access such data.
      */
     js::Mutex exclusiveAccessLock;
 #ifdef DEBUG
-    PRThread* exclusiveAccessOwner;
+    mozilla::Maybe<js::Thread::Id> exclusiveAccessOwner;
     bool mainThreadHasExclusiveAccess;
 #endif
 
     /* Number of non-main threads with an ExclusiveContext. */
     size_t numExclusiveThreads;
 
     friend class js::AutoLockForExclusiveAccess;
 
   public:
     void setUsedByExclusiveThread(JS::Zone* zone);
     void clearUsedByExclusiveThread(JS::Zone* zone);
 
 #ifdef DEBUG
     bool currentThreadHasExclusiveAccess() {
         return (!numExclusiveThreads && mainThreadHasExclusiveAccess) ||
-               exclusiveAccessOwner == PR_GetCurrentThread();
+               exclusiveAccessOwner == mozilla::Some(js::ThisThread::GetId());
     }
 #endif // DEBUG
 
     bool exclusiveThreadsPresent() const {
         return numExclusiveThreads > 0;
     }
 
     // How many compartments there are across all zones. This number includes