Bug 755255 - Hoist auto root list into XPCJSRuntime. r=mrbkap

This commit is contained in:
Bobby Holley 2012-06-21 16:14:49 +02:00
parent e673afa8f2
commit 2ac86947b8
3 changed files with 28 additions and 70 deletions

View File

@ -302,20 +302,9 @@ void XPCJSRuntime::TraceBlackJS(JSTracer* trc, void* data)
// Skip this part if XPConnect is shutting down. We get into // Skip this part if XPConnect is shutting down. We get into
// bad locking problems with the thread iteration otherwise. // bad locking problems with the thread iteration otherwise.
if (!self->GetXPConnect()->IsShuttingDown()) { if (!self->GetXPConnect()->IsShuttingDown()) {
Mutex* threadLock = XPCPerThreadData::GetLock(); // Trace those AutoMarkingPtr lists!
if (threadLock) if (AutoMarkingPtr *roots = Get()->mAutoRoots)
{ // scoped lock roots->TraceJSAll(trc);
MutexAutoLock lock(*threadLock);
XPCPerThreadData* iterp = nsnull;
XPCPerThreadData* thread;
while (nsnull != (thread =
XPCPerThreadData::IterateThreads(&iterp))) {
// Trace those AutoMarkingPtr lists!
thread->TraceJS(trc);
}
}
} }
{ {
@ -709,29 +698,27 @@ XPCJSRuntime::FinalizeCallback(JSFreeOp *fop, JSFinalizeStatus status, JSBool is
XPCPerThreadData* iterp = nsnull; XPCPerThreadData* iterp = nsnull;
XPCPerThreadData* thread; XPCPerThreadData* thread;
while (nsnull != (thread = // Mark those AutoMarkingPtr lists!
XPCPerThreadData::IterateThreads(&iterp))) { if (AutoMarkingPtr *roots = Get()->mAutoRoots)
// Mark those AutoMarkingPtr lists! roots->MarkAfterJSFinalizeAll();
thread->MarkAutoRootsAfterJSFinalize();
XPCCallContext* ccxp = XPCJSRuntime::Get()->GetCallContext(); XPCCallContext* ccxp = XPCJSRuntime::Get()->GetCallContext();
while (ccxp) { while (ccxp) {
// Deal with the strictness of callcontext that // Deal with the strictness of callcontext that
// complains if you ask for a set when // complains if you ask for a set when
// it is in a state where the set could not // it is in a state where the set could not
// possibly be valid. // possibly be valid.
if (ccxp->CanGetSet()) { if (ccxp->CanGetSet()) {
XPCNativeSet* set = ccxp->GetSet(); XPCNativeSet* set = ccxp->GetSet();
if (set) if (set)
set->Mark(); set->Mark();
}
if (ccxp->CanGetInterface()) {
XPCNativeInterface* iface = ccxp->GetInterface();
if (iface)
iface->Mark();
}
ccxp = ccxp->GetPrevCallContext();
} }
if (ccxp->CanGetInterface()) {
XPCNativeInterface* iface = ccxp->GetInterface();
if (iface)
iface->Mark();
}
ccxp = ccxp->GetPrevCallContext();
} }
} }
} }
@ -1948,6 +1935,7 @@ XPCJSRuntime::XPCJSRuntime(nsXPConnect* aXPConnect)
mJSContextStack(new XPCJSContextStack()), mJSContextStack(new XPCJSContextStack()),
mJSCycleCollectionContext(nsnull), mJSCycleCollectionContext(nsnull),
mCallContext(nsnull), mCallContext(nsnull),
mAutoRoots(nsnull),
mWrappedJSMap(JSObject2WrappedJSMap::newMap(XPC_JS_MAP_SIZE)), mWrappedJSMap(JSObject2WrappedJSMap::newMap(XPC_JS_MAP_SIZE)),
mWrappedJSClassMap(IID2WrappedJSClassMap::newMap(XPC_JS_CLASS_MAP_SIZE)), mWrappedJSClassMap(IID2WrappedJSClassMap::newMap(XPC_JS_CLASS_MAP_SIZE)),
mIID2NativeInterfaceMap(IID2NativeInterfaceMap::newMap(XPC_NATIVE_INTERFACE_MAP_SIZE)), mIID2NativeInterfaceMap(IID2NativeInterfaceMap::newMap(XPC_NATIVE_INTERFACE_MAP_SIZE)),

View File

@ -243,8 +243,7 @@ void * XPCPerThreadData::sMainJSThread = nsnull;
XPCPerThreadData::XPCPerThreadData() : XPCPerThreadData::XPCPerThreadData() :
mNextThread(nsnull), mNextThread(nsnull),
mResolveName(JSID_VOID), mResolveName(JSID_VOID),
mResolvingWrapper(nsnull), mResolvingWrapper(nsnull)
mAutoRoots(nsnull)
#ifdef XPC_CHECK_WRAPPER_THREADSAFETY #ifdef XPC_CHECK_WRAPPER_THREADSAFETY
, mWrappedNativeThreadsafetyReportDepth(0) , mWrappedNativeThreadsafetyReportDepth(0)
#endif #endif
@ -260,7 +259,6 @@ XPCPerThreadData::XPCPerThreadData() :
void void
XPCPerThreadData::Cleanup() XPCPerThreadData::Cleanup()
{ {
MOZ_ASSERT(!mAutoRoots);
} }
XPCPerThreadData::~XPCPerThreadData() XPCPerThreadData::~XPCPerThreadData()
@ -306,31 +304,6 @@ xpc_ThreadDataDtorCB(void* ptr)
delete data; delete data;
} }
void XPCPerThreadData::TraceJS(JSTracer *trc)
{
#ifdef XPC_TRACK_AUTOMARKINGPTR_STATS
{
static int maxLength = 0;
int length = 0;
for (AutoMarkingPtr* p = mAutoRoots; p; p = p->GetNext())
length++;
if (length > maxLength)
maxLength = length;
printf("XPC gc on thread %x with %d AutoMarkingPtrs (%d max so far)\n",
this, length, maxLength);
}
#endif
if (mAutoRoots)
mAutoRoots->TraceJSAll(trc);
}
void XPCPerThreadData::MarkAutoRootsAfterJSFinalize()
{
if (mAutoRoots)
mAutoRoots->MarkAfterJSFinalizeAll();
}
// static // static
XPCPerThreadData* XPCPerThreadData*
XPCPerThreadData::GetDataImpl(JSContext *cx) XPCPerThreadData::GetDataImpl(JSContext *cx)

View File

@ -855,6 +855,8 @@ public:
size_t SizeOfIncludingThis(nsMallocSizeOfFun mallocSizeOf); size_t SizeOfIncludingThis(nsMallocSizeOfFun mallocSizeOf);
AutoMarkingPtr** GetAutoRootsAdr() {return &mAutoRoots;}
private: private:
XPCJSRuntime(); // no implementation XPCJSRuntime(); // no implementation
XPCJSRuntime(nsXPConnect* aXPConnect); XPCJSRuntime(nsXPConnect* aXPConnect);
@ -876,6 +878,7 @@ private:
XPCJSContextStack* mJSContextStack; XPCJSContextStack* mJSContextStack;
JSContext* mJSCycleCollectionContext; JSContext* mJSCycleCollectionContext;
XPCCallContext* mCallContext; XPCCallContext* mCallContext;
AutoMarkingPtr* mAutoRoots;
JSObject2WrappedJSMap* mWrappedJSMap; JSObject2WrappedJSMap* mWrappedJSMap;
IID2WrappedJSClassMap* mWrappedJSClassMap; IID2WrappedJSClassMap* mWrappedJSClassMap;
IID2NativeInterfaceMap* mIID2NativeInterfaceMap; IID2NativeInterfaceMap* mIID2NativeInterfaceMap;
@ -3754,10 +3757,6 @@ public:
// Must be called with the threads locked. // Must be called with the threads locked.
static XPCPerThreadData* IterateThreads(XPCPerThreadData** iteratorp); static XPCPerThreadData* IterateThreads(XPCPerThreadData** iteratorp);
AutoMarkingPtr** GetAutoRootsAdr() {return &mAutoRoots;}
void TraceJS(JSTracer* trc);
void MarkAutoRootsAfterJSFinalize();
static void InitStatics() static void InitStatics()
{ gLock = nsnull; gThreads = nsnull; gTLSIndex = BAD_TLS_INDEX; } { gLock = nsnull; gThreads = nsnull; gTLSIndex = BAD_TLS_INDEX; }
@ -3784,8 +3783,6 @@ private:
jsid mResolveName; jsid mResolveName;
XPCWrappedNative* mResolvingWrapper; XPCWrappedNative* mResolvingWrapper;
AutoMarkingPtr* mAutoRoots;
#ifdef XPC_CHECK_WRAPPER_THREADSAFETY #ifdef XPC_CHECK_WRAPPER_THREADSAFETY
uint32_t mWrappedNativeThreadsafetyReportDepth; uint32_t mWrappedNativeThreadsafetyReportDepth;
#endif #endif
@ -4035,7 +4032,7 @@ class AutoMarkingPtr
{ {
public: public:
AutoMarkingPtr(XPCCallContext& ccx) { AutoMarkingPtr(XPCCallContext& ccx) {
mRoot = ccx.GetThreadData()->GetAutoRootsAdr(); mRoot = XPCJSRuntime::Get()->GetAutoRootsAdr();
mNext = *mRoot; mNext = *mRoot;
*mRoot = this; *mRoot = this;
} }