diff --git a/js/xpconnect/src/XPCJSRuntime.cpp b/js/xpconnect/src/XPCJSRuntime.cpp index da169a7b91fa..6309252f9b6e 100644 --- a/js/xpconnect/src/XPCJSRuntime.cpp +++ b/js/xpconnect/src/XPCJSRuntime.cpp @@ -302,20 +302,9 @@ void XPCJSRuntime::TraceBlackJS(JSTracer* trc, void* data) // Skip this part if XPConnect is shutting down. We get into // bad locking problems with the thread iteration otherwise. if (!self->GetXPConnect()->IsShuttingDown()) { - Mutex* threadLock = XPCPerThreadData::GetLock(); - if (threadLock) - { // scoped lock - MutexAutoLock lock(*threadLock); - - XPCPerThreadData* iterp = nsnull; - XPCPerThreadData* thread; - - while (nsnull != (thread = - XPCPerThreadData::IterateThreads(&iterp))) { - // Trace those AutoMarkingPtr lists! - thread->TraceJS(trc); - } - } + // Trace those AutoMarkingPtr lists! + if (AutoMarkingPtr *roots = Get()->mAutoRoots) + roots->TraceJSAll(trc); } { @@ -709,29 +698,27 @@ XPCJSRuntime::FinalizeCallback(JSFreeOp *fop, JSFinalizeStatus status, JSBool is XPCPerThreadData* iterp = nsnull; XPCPerThreadData* thread; - while (nsnull != (thread = - XPCPerThreadData::IterateThreads(&iterp))) { - // Mark those AutoMarkingPtr lists! - thread->MarkAutoRootsAfterJSFinalize(); + // Mark those AutoMarkingPtr lists! + if (AutoMarkingPtr *roots = Get()->mAutoRoots) + roots->MarkAfterJSFinalizeAll(); - XPCCallContext* ccxp = XPCJSRuntime::Get()->GetCallContext(); - while (ccxp) { - // Deal with the strictness of callcontext that - // complains if you ask for a set when - // it is in a state where the set could not - // possibly be valid. - if (ccxp->CanGetSet()) { - XPCNativeSet* set = ccxp->GetSet(); - if (set) - set->Mark(); - } - if (ccxp->CanGetInterface()) { - XPCNativeInterface* iface = ccxp->GetInterface(); - if (iface) - iface->Mark(); - } - ccxp = ccxp->GetPrevCallContext(); + XPCCallContext* ccxp = XPCJSRuntime::Get()->GetCallContext(); + while (ccxp) { + // Deal with the strictness of callcontext that + // complains if you ask for a set when + // it is in a state where the set could not + // possibly be valid. + if (ccxp->CanGetSet()) { + XPCNativeSet* set = ccxp->GetSet(); + if (set) + set->Mark(); } + 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()), mJSCycleCollectionContext(nsnull), mCallContext(nsnull), + mAutoRoots(nsnull), mWrappedJSMap(JSObject2WrappedJSMap::newMap(XPC_JS_MAP_SIZE)), mWrappedJSClassMap(IID2WrappedJSClassMap::newMap(XPC_JS_CLASS_MAP_SIZE)), mIID2NativeInterfaceMap(IID2NativeInterfaceMap::newMap(XPC_NATIVE_INTERFACE_MAP_SIZE)), diff --git a/js/xpconnect/src/XPCThreadContext.cpp b/js/xpconnect/src/XPCThreadContext.cpp index 31f676480091..7b5ce2b1fbe6 100644 --- a/js/xpconnect/src/XPCThreadContext.cpp +++ b/js/xpconnect/src/XPCThreadContext.cpp @@ -243,8 +243,7 @@ void * XPCPerThreadData::sMainJSThread = nsnull; XPCPerThreadData::XPCPerThreadData() : mNextThread(nsnull), mResolveName(JSID_VOID), - mResolvingWrapper(nsnull), - mAutoRoots(nsnull) + mResolvingWrapper(nsnull) #ifdef XPC_CHECK_WRAPPER_THREADSAFETY , mWrappedNativeThreadsafetyReportDepth(0) #endif @@ -260,7 +259,6 @@ XPCPerThreadData::XPCPerThreadData() : void XPCPerThreadData::Cleanup() { - MOZ_ASSERT(!mAutoRoots); } XPCPerThreadData::~XPCPerThreadData() @@ -306,31 +304,6 @@ xpc_ThreadDataDtorCB(void* ptr) 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 XPCPerThreadData* XPCPerThreadData::GetDataImpl(JSContext *cx) diff --git a/js/xpconnect/src/xpcprivate.h b/js/xpconnect/src/xpcprivate.h index c8075d95878a..357f71b8d1d6 100644 --- a/js/xpconnect/src/xpcprivate.h +++ b/js/xpconnect/src/xpcprivate.h @@ -855,6 +855,8 @@ public: size_t SizeOfIncludingThis(nsMallocSizeOfFun mallocSizeOf); + AutoMarkingPtr** GetAutoRootsAdr() {return &mAutoRoots;} + private: XPCJSRuntime(); // no implementation XPCJSRuntime(nsXPConnect* aXPConnect); @@ -876,6 +878,7 @@ private: XPCJSContextStack* mJSContextStack; JSContext* mJSCycleCollectionContext; XPCCallContext* mCallContext; + AutoMarkingPtr* mAutoRoots; JSObject2WrappedJSMap* mWrappedJSMap; IID2WrappedJSClassMap* mWrappedJSClassMap; IID2NativeInterfaceMap* mIID2NativeInterfaceMap; @@ -3754,10 +3757,6 @@ public: // Must be called with the threads locked. static XPCPerThreadData* IterateThreads(XPCPerThreadData** iteratorp); - AutoMarkingPtr** GetAutoRootsAdr() {return &mAutoRoots;} - - void TraceJS(JSTracer* trc); - void MarkAutoRootsAfterJSFinalize(); static void InitStatics() { gLock = nsnull; gThreads = nsnull; gTLSIndex = BAD_TLS_INDEX; } @@ -3784,8 +3783,6 @@ private: jsid mResolveName; XPCWrappedNative* mResolvingWrapper; - AutoMarkingPtr* mAutoRoots; - #ifdef XPC_CHECK_WRAPPER_THREADSAFETY uint32_t mWrappedNativeThreadsafetyReportDepth; #endif @@ -4035,7 +4032,7 @@ class AutoMarkingPtr { public: AutoMarkingPtr(XPCCallContext& ccx) { - mRoot = ccx.GetThreadData()->GetAutoRootsAdr(); + mRoot = XPCJSRuntime::Get()->GetAutoRootsAdr(); mNext = *mRoot; *mRoot = this; }