Bug 1285134 part 1 - Move the runtime private to the context. r=efaust
authorJan de Mooij <jdemooij@mozilla.com>
Mon, 18 Jul 2016 14:36:13 +0200
changeset 305324 2fb342547aa8c02298f38714058411a651ea4b90
parent 305323 be09c9391d44f82e08c483996b2dbfe37f1327bb
child 305325 d8fb8e2d81a0bcd9d75703916c8e0593dac12d3c
push id79553
push userjandemooij@gmail.com
push dateMon, 18 Jul 2016 12:40:11 +0000
treeherdermozilla-inbound@d8fb8e2d81a0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersefaust
bugs1285134
milestone50.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 1285134 part 1 - Move the runtime private to the context. r=efaust
dom/bindings/AtomList.h
dom/workers/RuntimeService.cpp
js/src/jsapi.cpp
js/src/jsapi.h
js/src/jscntxt.cpp
js/src/jscntxt.h
js/src/shell/js.cpp
js/src/vm/Runtime.cpp
js/src/vm/Runtime.h
js/xpconnect/src/XPCJSRuntime.cpp
--- a/dom/bindings/AtomList.h
+++ b/dom/bindings/AtomList.h
@@ -11,19 +11,17 @@
 #include "mozilla/dom/GeneratedAtomList.h"
 
 namespace mozilla {
 namespace dom {
 
 template<class T>
 T* GetAtomCache(JSContext* aCx)
 {
-  JSRuntime* rt = JS_GetRuntime(aCx);
-
-  auto atomCache = static_cast<PerThreadAtomCache*>(JS_GetRuntimePrivate(rt));
+  auto atomCache = static_cast<PerThreadAtomCache*>(JS_GetContextPrivate(aCx));
 
   return static_cast<T*>(atomCache);
 }
 
 } // namespace dom
 } // namespace mozilla
 
 #endif // mozilla_dom_AtomList_h
--- a/dom/workers/RuntimeService.cpp
+++ b/dom/workers/RuntimeService.cpp
@@ -700,17 +700,17 @@ AsmJSCacheOpenEntryForWrite(JS::Handle<J
   }
 
   return asmjscache::OpenEntryForWrite(principal, aInstalled, aBegin, aEnd,
                                        aSize, aMemory, aHandle);
 }
 
 class WorkerJSRuntime;
 
-class WorkerThreadRuntimePrivate : private PerThreadAtomCache
+class WorkerThreadContextPrivate : private PerThreadAtomCache
 {
   friend class WorkerJSRuntime;
 
   WorkerPrivate* mWorkerPrivate;
 
 public:
   // This can't return null, but we can't lose the "Get" prefix in the name or
   // it will be ambiguous with the WorkerPrivate class name.
@@ -720,36 +720,36 @@ public:
     MOZ_ASSERT(!NS_IsMainThread());
     MOZ_ASSERT(mWorkerPrivate);
 
     return mWorkerPrivate;
   }
 
 private:
   explicit
-  WorkerThreadRuntimePrivate(WorkerPrivate* aWorkerPrivate)
+  WorkerThreadContextPrivate(WorkerPrivate* aWorkerPrivate)
     : mWorkerPrivate(aWorkerPrivate)
   {
     MOZ_ASSERT(!NS_IsMainThread());
 
     // Zero out the base class members.
     memset(this, 0, sizeof(PerThreadAtomCache));
 
     MOZ_ASSERT(mWorkerPrivate);
   }
 
-  ~WorkerThreadRuntimePrivate()
+  ~WorkerThreadContextPrivate()
   {
     MOZ_ASSERT(!NS_IsMainThread());
   }
 
-  WorkerThreadRuntimePrivate(const WorkerThreadRuntimePrivate&) = delete;
-
-  WorkerThreadRuntimePrivate&
-  operator=(const WorkerThreadRuntimePrivate&) = delete;
+  WorkerThreadContextPrivate(const WorkerThreadContextPrivate&) = delete;
+
+  WorkerThreadContextPrivate&
+  operator=(const WorkerThreadContextPrivate&) = delete;
 };
 
 JSContext*
 InitJSContextForWorker(WorkerPrivate* aWorkerPrivate, JSRuntime* aRuntime)
 {
   aWorkerPrivate->AssertIsOnWorkerThread();
   NS_ASSERTION(!aWorkerPrivate->GetJSContext(), "Already has a context!");
 
@@ -855,18 +855,19 @@ public:
 
   ~WorkerJSRuntime()
   {
     JSRuntime* rt = MaybeRuntime();
     if (!rt) {
       return;   // Initialize() must have failed
     }
 
-    delete static_cast<WorkerThreadRuntimePrivate*>(JS_GetRuntimePrivate(rt));
-    JS_SetRuntimePrivate(rt, nullptr);
+    JSContext* cx = JS_GetContext(rt);
+    delete static_cast<WorkerThreadContextPrivate*>(JS_GetContextPrivate(cx));
+    JS_SetContextPrivate(cx, nullptr);
 
     // The worker global should be unrooted and the shutdown cycle collection
     // should break all remaining cycles. The superclass destructor will run
     // the GC one final time and finalize any JSObjects that were participating
     // in cycles that were broken during CC shutdown.
     nsCycleCollector_shutdown();
 
     // The CC is shut down, and the superclass destructor will GC, so make sure
@@ -882,20 +883,20 @@ public:
                                           WORKER_DEFAULT_NURSERY_SIZE);
      if (NS_WARN_IF(NS_FAILED(rv))) {
        return rv;
      }
 
     JSRuntime* rt = Runtime();
     MOZ_ASSERT(rt);
 
-    JS_SetRuntimePrivate(rt, new WorkerThreadRuntimePrivate(mWorkerPrivate));
-
     JSContext* cx = JS_GetContext(rt);
 
+    JS_SetContextPrivate(cx, new WorkerThreadContextPrivate(mWorkerPrivate));
+
     js::SetPreserveWrapperCallback(cx, PreserveWrapper);
     JS_InitDestroyPrincipalsCallback(cx, DestroyWorkerPrincipals);
     JS_SetWrapObjectCallbacks(cx, &WrapObjectCallbacks);
     if (mWorkerPrivate->IsDedicatedWorker()) {
       JS_SetFutexCanWait(cx);
     }
 
     return NS_OK;
@@ -1230,44 +1231,41 @@ WorkerCrossThreadDispatcher::PostTask(Wo
 }
 
 WorkerPrivate*
 GetWorkerPrivateFromContext(JSContext* aCx)
 {
   MOZ_ASSERT(!NS_IsMainThread());
   MOZ_ASSERT(aCx);
 
-  JSRuntime* rt = JS_GetRuntime(aCx);
-  MOZ_ASSERT(rt);
-
-  void* rtPrivate = JS_GetRuntimePrivate(rt);
-  MOZ_ASSERT(rtPrivate);
+  void* cxPrivate = JS_GetContextPrivate(aCx);
+  MOZ_ASSERT(cxPrivate);
 
   return
-    static_cast<WorkerThreadRuntimePrivate*>(rtPrivate)->GetWorkerPrivate();
+    static_cast<WorkerThreadContextPrivate*>(cxPrivate)->GetWorkerPrivate();
 }
 
 WorkerPrivate*
 GetCurrentThreadWorkerPrivate()
 {
   MOZ_ASSERT(!NS_IsMainThread());
 
   CycleCollectedJSRuntime* ccrt = CycleCollectedJSRuntime::Get();
   if (!ccrt) {
     return nullptr;
   }
 
-  JSRuntime* rt = ccrt->Runtime();
-  MOZ_ASSERT(rt);
-
-  void* rtPrivate = JS_GetRuntimePrivate(rt);
-  MOZ_ASSERT(rtPrivate);
+  JSContext* cx = ccrt->Context();
+  MOZ_ASSERT(cx);
+
+  void* cxPrivate = JS_GetContextPrivate(cx);
+  MOZ_ASSERT(cxPrivate);
 
   return
-    static_cast<WorkerThreadRuntimePrivate*>(rtPrivate)->GetWorkerPrivate();
+    static_cast<WorkerThreadContextPrivate*>(cxPrivate)->GetWorkerPrivate();
 }
 
 bool
 IsCurrentThreadRunningChromeWorker()
 {
   return GetCurrentThreadWorkerPrivate()->UsesSystemPrincipal();
 }
 
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -489,25 +489,25 @@ JS_PUBLIC_API(double)
 JS_GetCurrentEmbedderTime()
 {
     if (currentEmbedderTimeFunction)
         return currentEmbedderTimeFunction();
     return PRMJ_Now() / static_cast<double>(PRMJ_USEC_PER_MSEC);
 }
 
 JS_PUBLIC_API(void*)
-JS_GetRuntimePrivate(JSRuntime* rt)
-{
-    return rt->data;
+JS_GetContextPrivate(JSContext* cx)
+{
+    return cx->data;
 }
 
 JS_PUBLIC_API(void)
-JS_SetRuntimePrivate(JSRuntime* rt, void* data)
-{
-    rt->data = data;
+JS_SetContextPrivate(JSContext* cx, void* data)
+{
+    cx->data = data;
 }
 
 JS_PUBLIC_API(void)
 JS_SetFutexCanWait(JSContext* cx)
 {
     cx->fx.setCanWait(true);
 }
 
--- a/js/src/jsapi.h
+++ b/js/src/jsapi.h
@@ -986,27 +986,27 @@ JS_SetCurrentEmbedderTimeFunction(JS_Cur
 /**
  * Return the time as computed using the current time function, or a
  * suitable default if one has not been set.
  */
 JS_PUBLIC_API(double)
 JS_GetCurrentEmbedderTime();
 
 JS_PUBLIC_API(void*)
-JS_GetRuntimePrivate(JSRuntime* rt);
+JS_GetContextPrivate(JSContext* cx);
+
+JS_PUBLIC_API(void)
+JS_SetContextPrivate(JSContext* cx, void* data);
 
 extern JS_PUBLIC_API(JSRuntime*)
 JS_GetRuntime(JSContext* cx);
 
 extern JS_PUBLIC_API(JSRuntime*)
 JS_GetParentRuntime(JSRuntime* rt);
 
-JS_PUBLIC_API(void)
-JS_SetRuntimePrivate(JSRuntime* rt, void* data);
-
 extern JS_PUBLIC_API(void)
 JS_BeginRequest(JSContext* cx);
 
 extern JS_PUBLIC_API(void)
 JS_EndRequest(JSContext* cx);
 
 extern JS_PUBLIC_API(void)
 JS_SetFutexCanWait(JSContext* cx);
--- a/js/src/jscntxt.cpp
+++ b/js/src/jscntxt.cpp
@@ -866,16 +866,17 @@ JSContext::JSContext(JSRuntime* parentRu
     throwing(false),
     unwrappedException_(this),
     overRecursed_(false),
     propagatingForcedReturn_(false),
     liveVolatileJitFrameIterators_(nullptr),
     reportGranularity(JS_DEFAULT_JITREPORT_GRANULARITY),
     resolvingList(nullptr),
     generatingError(false),
+    data(nullptr),
     outstandingRequests(0),
     jitIsBroken(false)
 {
     MOZ_ASSERT(static_cast<ContextFriendFields*>(this) ==
                ContextFriendFields::get(this));
 }
 
 JSContext::~JSContext()
--- a/js/src/jscntxt.h
+++ b/js/src/jscntxt.h
@@ -377,16 +377,19 @@ struct JSContext : public js::ExclusiveC
     js::AutoResolving*  resolvingList;
 
     /* True if generating an error, to prevent runaway recursion. */
     bool                generatingError;
 
     /* State for object and array toSource conversion. */
     js::AutoCycleDetector::Set cycleDetectorSet;
 
+    /* Client opaque pointer. */
+    void* data;
+
   public:
 
     /*
      * Return:
      * - The newest scripted frame's version, if there is such a frame.
      * - The version from the compartment.
      * - The default version.
      *
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -333,17 +333,18 @@ ShellRuntime::ShellRuntime(JSRuntime* rt
     quitting(false),
     readLineBufPos(0),
     spsProfilingStackSize(0)
 {}
 
 static ShellRuntime*
 GetShellRuntime(JSRuntime *rt)
 {
-    ShellRuntime* sr = static_cast<ShellRuntime*>(JS_GetRuntimePrivate(rt));
+    JSContext* cx = JS_GetContext(rt);
+    ShellRuntime* sr = static_cast<ShellRuntime*>(JS_GetContextPrivate(cx));
     MOZ_ASSERT(sr);
     return sr;
 }
 
 static char*
 GetLine(FILE* file, const char * prompt)
 {
 #ifdef EDITLINE
@@ -2952,17 +2953,17 @@ WorkerMain(void* arg)
         JS_DestroyRuntime(rt);
         js_delete(input);
         return;
     }
 
     JSContext* cx = JS_GetContext(rt);
 
     sr->isWorker = true;
-    JS_SetRuntimePrivate(rt, sr.get());
+    JS_SetContextPrivate(cx, sr.get());
     JS_SetFutexCanWait(cx);
     JS::SetWarningReporter(cx, WarningReporter);
     js::SetPreserveWrapperCallback(cx, DummyPreserveWrapperCallback);
     JS_InitDestroyPrincipalsCallback(cx, ShellPrincipals::destroy);
     SetWorkerContextOptions(cx);
 
     if (!JS::InitSelfHostedCode(cx)) {
         JS_DestroyRuntime(rt);
@@ -7458,17 +7459,17 @@ main(int argc, char** argv, char** envp)
         return 1;
 
     UniquePtr<ShellRuntime> sr = MakeUnique<ShellRuntime>(rt);
     if (!sr)
         return 1;
 
     JSContext* cx = JS_GetContext(rt);
 
-    JS_SetRuntimePrivate(rt, sr.get());
+    JS_SetContextPrivate(cx, sr.get());
     // Waiting is allowed on the shell's main thread, for now.
     JS_SetFutexCanWait(cx);
     JS::SetWarningReporter(cx, WarningReporter);
     if (!SetContextOptions(cx, op))
         return 1;
 
     JS_SetGCParameter(cx, JSGC_MAX_BYTES, 0xffffffff);
 
--- a/js/src/vm/Runtime.cpp
+++ b/js/src/vm/Runtime.cpp
@@ -203,17 +203,16 @@ JSRuntime::JSRuntime(JSRuntime* parentRu
     hadOutOfMemory(false),
 #ifdef DEBUG
     handlingInitFailure(false),
 #endif
 #if defined(DEBUG) || defined(JS_OOM_BREAKPOINT)
     runningOOMTest(false),
 #endif
     allowRelazificationForTesting(false),
-    data(nullptr),
     defaultFreeOp_(thisFromCtor()),
     debuggerMutations(0),
     securityCallbacks(&NullSecurityCallbacks),
     DOMcallbacks(nullptr),
     destroyPrincipals(nullptr),
     readPrincipals(nullptr),
     warningReporter(nullptr),
     buildIdOp(nullptr),
--- a/js/src/vm/Runtime.h
+++ b/js/src/vm/Runtime.h
@@ -965,19 +965,16 @@ struct JSRuntime : public JS::shadow::Ru
     mozilla::LinkedList<js::Debugger> debuggerList;
 
     /*
      * Head of circular list of all enabled Debuggers that have
      * onNewGlobalObject handler methods established.
      */
     JSCList             onNewGlobalObjectWatchers;
 
-    /* Client opaque pointers */
-    void*               data;
-
 #if defined(XP_DARWIN) && defined(ASMJS_MAY_USE_SIGNAL_HANDLERS)
     js::wasm::MachExceptionHandler wasmMachExceptionHandler;
 #endif
 
   private:
     js::FreeOp          defaultFreeOp_;
 
   public:
--- a/js/xpconnect/src/XPCJSRuntime.cpp
+++ b/js/xpconnect/src/XPCJSRuntime.cpp
@@ -1660,19 +1660,19 @@ XPCJSRuntime::~XPCJSRuntime()
     xpc_DelocalizeContext(Context());
 
     if (mWatchdogManager->GetWatchdog())
         mWatchdogManager->StopWatchdog();
 
     if (mCallContext)
         mCallContext->SystemIsBeingShutDown();
 
-    auto rtPrivate = static_cast<PerThreadAtomCache*>(JS_GetRuntimePrivate(Runtime()));
+    auto rtPrivate = static_cast<PerThreadAtomCache*>(JS_GetContextPrivate(Context()));
     delete rtPrivate;
-    JS_SetRuntimePrivate(Runtime(), nullptr);
+    JS_SetContextPrivate(Context(), nullptr);
 
     // clean up and destroy maps...
     mWrappedJSMap->ShutdownMarker();
     delete mWrappedJSMap;
     mWrappedJSMap = nullptr;
 
     delete mWrappedJSClassMap;
     mWrappedJSClassMap = nullptr;
@@ -3454,19 +3454,19 @@ XPCJSRuntime::Initialize()
 
     mUnprivilegedJunkScope.init(runtime, nullptr);
     mPrivilegedJunkScope.init(runtime, nullptr);
     mCompilationScope.init(runtime, nullptr);
 
     // these jsids filled in later when we have a JSContext to work with.
     mStrIDs[0] = JSID_VOID;
 
-    auto rtPrivate = new PerThreadAtomCache();
-    memset(rtPrivate, 0, sizeof(PerThreadAtomCache));
-    JS_SetRuntimePrivate(runtime, rtPrivate);
+    auto cxPrivate = new PerThreadAtomCache();
+    memset(cxPrivate, 0, sizeof(PerThreadAtomCache));
+    JS_SetContextPrivate(cx, cxPrivate);
 
     // Unconstrain the runtime's threshold on nominal heap size, to avoid
     // triggering GC too often if operating continuously near an arbitrary
     // finite threshold (0xffffffff is infinity for uint32_t parameters).
     // This leaves the maximum-JS_malloc-bytes threshold still in effect
     // to cause period, and we hope hygienic, last-ditch GCs from within
     // the GC's allocator.
     JS_SetGCParameter(cx, JSGC_MAX_BYTES, 0xffffffff);