Bug 1285134 part 1 - Move the runtime private to the context. r=efaust

This commit is contained in:
Jan de Mooij 2016-07-18 14:36:13 +02:00
Родитель ff4b4a08d8
Коммит b68d3ea4c4
10 изменённых файлов: 41 добавлений и 44 удалений

Просмотреть файл

@ -16,9 +16,7 @@ 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);
}

Просмотреть файл

@ -705,7 +705,7 @@ AsmJSCacheOpenEntryForWrite(JS::Handle<JSObject*> aGlobal,
class WorkerJSRuntime;
class WorkerThreadRuntimePrivate : private PerThreadAtomCache
class WorkerThreadContextPrivate : private PerThreadAtomCache
{
friend class WorkerJSRuntime;
@ -725,7 +725,7 @@ public:
private:
explicit
WorkerThreadRuntimePrivate(WorkerPrivate* aWorkerPrivate)
WorkerThreadContextPrivate(WorkerPrivate* aWorkerPrivate)
: mWorkerPrivate(aWorkerPrivate)
{
MOZ_ASSERT(!NS_IsMainThread());
@ -736,15 +736,15 @@ private:
MOZ_ASSERT(mWorkerPrivate);
}
~WorkerThreadRuntimePrivate()
~WorkerThreadContextPrivate()
{
MOZ_ASSERT(!NS_IsMainThread());
}
WorkerThreadRuntimePrivate(const WorkerThreadRuntimePrivate&) = delete;
WorkerThreadContextPrivate(const WorkerThreadContextPrivate&) = delete;
WorkerThreadRuntimePrivate&
operator=(const WorkerThreadRuntimePrivate&) = delete;
WorkerThreadContextPrivate&
operator=(const WorkerThreadContextPrivate&) = delete;
};
JSContext*
@ -860,8 +860,9 @@ public:
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
@ -887,10 +888,10 @@ public:
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);
@ -1235,14 +1236,11 @@ 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*
@ -1255,14 +1253,14 @@ GetCurrentThreadWorkerPrivate()
return nullptr;
}
JSRuntime* rt = ccrt->Runtime();
MOZ_ASSERT(rt);
JSContext* cx = ccrt->Context();
MOZ_ASSERT(cx);
void* rtPrivate = JS_GetRuntimePrivate(rt);
MOZ_ASSERT(rtPrivate);
void* cxPrivate = JS_GetContextPrivate(cx);
MOZ_ASSERT(cxPrivate);
return
static_cast<WorkerThreadRuntimePrivate*>(rtPrivate)->GetWorkerPrivate();
static_cast<WorkerThreadContextPrivate*>(cxPrivate)->GetWorkerPrivate();
}
bool

Просмотреть файл

@ -494,15 +494,15 @@ JS_GetCurrentEmbedderTime()
}
JS_PUBLIC_API(void*)
JS_GetRuntimePrivate(JSRuntime* rt)
JS_GetContextPrivate(JSContext* cx)
{
return rt->data;
return cx->data;
}
JS_PUBLIC_API(void)
JS_SetRuntimePrivate(JSRuntime* rt, void* data)
JS_SetContextPrivate(JSContext* cx, void* data)
{
rt->data = data;
cx->data = data;
}
JS_PUBLIC_API(void)

Просмотреть файл

@ -991,7 +991,10 @@ 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);
@ -999,9 +1002,6 @@ 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);

Просмотреть файл

@ -871,6 +871,7 @@ JSContext::JSContext(JSRuntime* parentRuntime)
reportGranularity(JS_DEFAULT_JITREPORT_GRANULARITY),
resolvingList(nullptr),
generatingError(false),
data(nullptr),
outstandingRequests(0),
jitIsBroken(false)
{

Просмотреть файл

@ -382,6 +382,9 @@ struct JSContext : public js::ExclusiveContext,
/* State for object and array toSource conversion. */
js::AutoCycleDetector::Set cycleDetectorSet;
/* Client opaque pointer. */
void* data;
public:
/*

Просмотреть файл

@ -338,7 +338,8 @@ ShellRuntime::ShellRuntime(JSRuntime* rt)
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;
}
@ -2957,7 +2958,7 @@ WorkerMain(void* arg)
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);
@ -7463,7 +7464,7 @@ main(int argc, char** argv, char** envp)
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);

Просмотреть файл

@ -208,7 +208,6 @@ JSRuntime::JSRuntime(JSRuntime* parentRuntime)
runningOOMTest(false),
#endif
allowRelazificationForTesting(false),
data(nullptr),
defaultFreeOp_(thisFromCtor()),
debuggerMutations(0),
securityCallbacks(&NullSecurityCallbacks),

Просмотреть файл

@ -970,9 +970,6 @@ struct JSRuntime : public JS::shadow::Runtime,
*/
JSCList onNewGlobalObjectWatchers;
/* Client opaque pointers */
void* data;
#if defined(XP_DARWIN) && defined(ASMJS_MAY_USE_SIGNAL_HANDLERS)
js::wasm::MachExceptionHandler wasmMachExceptionHandler;
#endif

Просмотреть файл

@ -1665,9 +1665,9 @@ XPCJSRuntime::~XPCJSRuntime()
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();
@ -3459,9 +3459,9 @@ XPCJSRuntime::Initialize()
// 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