Bug 882162: Part 7 - Move tracing of gray roots into mozilla::CycleCollectedJSRuntime. r=mccr8

This commit is contained in:
Kyle Huey 2013-06-18 12:02:15 -07:00
Родитель 3faff59469
Коммит 213c4bdde8
4 изменённых файлов: 60 добавлений и 44 удалений

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

@ -439,46 +439,8 @@ void XPCJSRuntime::TraceBlackJS(JSTracer* trc, void* data)
nsXPConnect::XPConnect()->IsShuttingDown()); nsXPConnect::XPConnect()->IsShuttingDown());
} }
// static void XPCJSRuntime::TraceAdditionalNativeRoots(JSTracer *trc)
void XPCJSRuntime::TraceGrayJS(JSTracer* trc, void* data)
{ {
XPCJSRuntime* self = (XPCJSRuntime*)data;
// Mark these roots as gray so the CC can walk them later.
self->TraceXPConnectRoots(trc);
}
struct JsGcTracer : public TraceCallbacks
{
virtual void Trace(JS::Heap<JS::Value> *p, const char *name, void *closure) const MOZ_OVERRIDE {
JS_CallHeapValueTracer(static_cast<JSTracer*>(closure), p, name);
}
virtual void Trace(JS::Heap<jsid> *p, const char *name, void *closure) const MOZ_OVERRIDE {
JS_CallHeapIdTracer(static_cast<JSTracer*>(closure), p, name);
}
virtual void Trace(JS::Heap<JSObject *> *p, const char *name, void *closure) const MOZ_OVERRIDE {
JS_CallHeapObjectTracer(static_cast<JSTracer*>(closure), p, name);
}
virtual void Trace(JS::Heap<JSString *> *p, const char *name, void *closure) const MOZ_OVERRIDE {
JS_CallHeapStringTracer(static_cast<JSTracer*>(closure), p, name);
}
virtual void Trace(JS::Heap<JSScript *> *p, const char *name, void *closure) const MOZ_OVERRIDE {
JS_CallHeapScriptTracer(static_cast<JSTracer*>(closure), p, name);
}
};
static PLDHashOperator
TraceJSHolder(void *holder, nsScriptObjectTracer *&tracer, void *arg)
{
tracer->Trace(holder, JsGcTracer(), arg);
return PL_DHASH_NEXT;
}
void XPCJSRuntime::TraceXPConnectRoots(JSTracer *trc)
{
MaybeTraceGlobals(trc);
XPCAutoLock lock(mMapLock); XPCAutoLock lock(mMapLock);
XPCWrappedNativeScope::TraceWrappedNativesInAllScopes(trc, this); XPCWrappedNativeScope::TraceWrappedNativesInAllScopes(trc, this);
@ -488,8 +450,6 @@ void XPCJSRuntime::TraceXPConnectRoots(JSTracer *trc)
for (XPCRootSetElem *e = mWrappedJSRoots; e ; e = e->GetNextRoot()) for (XPCRootSetElem *e = mWrappedJSRoots; e ; e = e->GetNextRoot())
static_cast<nsXPCWrappedJS*>(e)->TraceJS(trc); static_cast<nsXPCWrappedJS*>(e)->TraceJS(trc);
mJSHolders.Enumerate(TraceJSHolder, trc);
} }
// static // static
@ -2750,7 +2710,6 @@ XPCJSRuntime::XPCJSRuntime(nsXPConnect* aXPConnect)
mPrevGCSliceCallback = JS::SetGCSliceCallback(runtime, GCSliceCallback); mPrevGCSliceCallback = JS::SetGCSliceCallback(runtime, GCSliceCallback);
JS_SetFinalizeCallback(runtime, FinalizeCallback); JS_SetFinalizeCallback(runtime, FinalizeCallback);
JS_SetExtraGCRootsTracer(runtime, TraceBlackJS, this); JS_SetExtraGCRootsTracer(runtime, TraceBlackJS, this);
JS_SetGrayGCRootsTracer(runtime, TraceGrayJS, this);
JS_SetWrapObjectCallbacks(runtime, JS_SetWrapObjectCallbacks(runtime,
xpc::WrapperFactory::Rewrap, xpc::WrapperFactory::Rewrap,
xpc::WrapperFactory::WrapForSameCompartment, xpc::WrapperFactory::WrapForSameCompartment,

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

@ -765,9 +765,9 @@ public:
} }
static void TraceBlackJS(JSTracer* trc, void* data); static void TraceBlackJS(JSTracer* trc, void* data);
static void TraceGrayJS(JSTracer* trc, void* data);
void TraceXPConnectRoots(JSTracer *trc); void TraceXPConnectRoots(JSTracer *trc);
void TraverseAdditionalNativeRoots(nsCycleCollectionNoteRootCallback& cb); void TraverseAdditionalNativeRoots(nsCycleCollectionNoteRootCallback& cb);
void TraceAdditionalNativeRoots(JSTracer* aTracer);
void UnmarkSkippableJSHolders(); void UnmarkSkippableJSHolders();
static void GCCallback(JSRuntime *rt, JSGCStatus status); static void GCCallback(JSRuntime *rt, JSGCStatus status);

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

@ -418,6 +418,8 @@ CycleCollectedJSRuntime::CycleCollectedJSRuntime(uint32_t aMaxbytes,
MOZ_CRASH(); MOZ_CRASH();
} }
JS_SetGrayGCRootsTracer(mJSRuntime, TraceGrayJS, this);
mJSHolders.Init(512); mJSHolders.Init(512);
} }
@ -654,6 +656,54 @@ CycleCollectedJSRuntime::TraverseNativeRoots(nsCycleCollectionNoteRootCallback&
mJSHolders.Enumerate(NoteJSHolder, &closure); mJSHolders.Enumerate(NoteJSHolder, &closure);
} }
/* static */ void
CycleCollectedJSRuntime::TraceGrayJS(JSTracer* aTracer, void* aData)
{
CycleCollectedJSRuntime* self = static_cast<CycleCollectedJSRuntime*>(aData);
// Mark these roots as gray so the CC can walk them later.
self->TraceNativeRoots(aTracer);
}
struct JsGcTracer : public TraceCallbacks
{
virtual void Trace(JS::Heap<JS::Value> *p, const char *name, void *closure) const MOZ_OVERRIDE {
JS_CallHeapValueTracer(static_cast<JSTracer*>(closure), p, name);
}
virtual void Trace(JS::Heap<jsid> *p, const char *name, void *closure) const MOZ_OVERRIDE {
JS_CallHeapIdTracer(static_cast<JSTracer*>(closure), p, name);
}
virtual void Trace(JS::Heap<JSObject *> *p, const char *name, void *closure) const MOZ_OVERRIDE {
JS_CallHeapObjectTracer(static_cast<JSTracer*>(closure), p, name);
}
virtual void Trace(JS::Heap<JSString *> *p, const char *name, void *closure) const MOZ_OVERRIDE {
JS_CallHeapStringTracer(static_cast<JSTracer*>(closure), p, name);
}
virtual void Trace(JS::Heap<JSScript *> *p, const char *name, void *closure) const MOZ_OVERRIDE {
JS_CallHeapScriptTracer(static_cast<JSTracer*>(closure), p, name);
}
};
static PLDHashOperator
TraceJSHolder(void* aHolder, nsScriptObjectTracer*& aTracer, void* aArg)
{
aTracer->Trace(aHolder, JsGcTracer(), aArg);
return PL_DHASH_NEXT;
}
void
CycleCollectedJSRuntime::TraceNativeRoots(JSTracer* aTracer)
{
MaybeTraceGlobals(aTracer);
// NB: This is here just to preserve the existing XPConnect order. I doubt it
// would hurt to do this after the JS holders.
TraceAdditionalNativeRoots(aTracer);
mJSHolders.Enumerate(TraceJSHolder, aTracer);
}
void void
CycleCollectedJSRuntime::AddJSHolder(void* aHolder, nsScriptObjectTracer* aTracer) CycleCollectedJSRuntime::AddJSHolder(void* aHolder, nsScriptObjectTracer* aTracer)
{ {

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

@ -88,8 +88,9 @@ protected:
return mJSRuntime; return mJSRuntime;
} }
void MaybeTraceGlobals(JSTracer* aTracer) const;
virtual void TraverseAdditionalNativeRoots(nsCycleCollectionNoteRootCallback& aCb) = 0; virtual void TraverseAdditionalNativeRoots(nsCycleCollectionNoteRootCallback& aCb) = 0;
virtual void TraceAdditionalNativeRoots(JSTracer* aTracer) = 0;
private: private:
void void
@ -133,6 +134,12 @@ private:
void TraverseNativeRoots(nsCycleCollectionNoteRootCallback& aCb); void TraverseNativeRoots(nsCycleCollectionNoteRootCallback& aCb);
void MaybeTraceGlobals(JSTracer* aTracer) const;
static void TraceGrayJS(JSTracer* aTracer, void* aData);
void TraceNativeRoots(JSTracer* aTracer);
public: public:
void AddJSHolder(void* aHolder, nsScriptObjectTracer* aTracer); void AddJSHolder(void* aHolder, nsScriptObjectTracer* aTracer);
void RemoveJSHolder(void* aHolder); void RemoveJSHolder(void* aHolder);