diff --git a/js/xpconnect/src/XPCJSRuntime.cpp b/js/xpconnect/src/XPCJSRuntime.cpp index 6bc2609212fa..50a48c112878 100644 --- a/js/xpconnect/src/XPCJSRuntime.cpp +++ b/js/xpconnect/src/XPCJSRuntime.cpp @@ -525,18 +525,11 @@ XPCJSRuntime::TraverseAdditionalNativeRoots(nsCycleCollectionNoteRootCallback &c } } -static PLDHashOperator -UnmarkJSHolder(void *holder, nsScriptObjectTracer *&tracer, void *arg) -{ - tracer->CanSkip(holder, true); - return PL_DHASH_NEXT; -} - void XPCJSRuntime::UnmarkSkippableJSHolders() { XPCAutoLock lock(mMapLock); - mJSHolders.Enumerate(UnmarkJSHolder, nullptr); + CycleCollectedJSRuntime::UnmarkSkippableJSHolders(); } void @@ -1113,9 +1106,7 @@ XPCJSRuntime::SizeOfIncludingThis(nsMallocSizeOfFun mallocSizeOf) n += mClassInfo2NativeSetMap->ShallowSizeOfIncludingThis(mallocSizeOf); n += mNativeSetMap->SizeOfIncludingThis(mallocSizeOf); - // NULL for the second arg; we're not measuring anything hanging off the - // entries in mJSHolders. - n += mJSHolders.SizeOfExcludingThis(nullptr, mallocSizeOf); + n += CycleCollectedJSRuntime::SizeOfExcludingThis(mallocSizeOf); // There are other XPCJSRuntime members that could be measured; the above // ones have been seen by DMD to be worth measuring. More stuff may be diff --git a/xpcom/base/CycleCollectedJSRuntime.cpp b/xpcom/base/CycleCollectedJSRuntime.cpp index 9f93ce193350..d914221c3aad 100644 --- a/xpcom/base/CycleCollectedJSRuntime.cpp +++ b/xpcom/base/CycleCollectedJSRuntime.cpp @@ -479,6 +479,31 @@ CycleCollectedJSRuntime::~CycleCollectedJSRuntime() mJSRuntime = nullptr; } +size_t +CycleCollectedJSRuntime::SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf) const +{ + size_t n = 0; + + // NULL for the second arg; we're not measuring anything hanging off the + // entries in mJSHolders. + n += mJSHolders.SizeOfExcludingThis(nullptr, aMallocSizeOf); + + return n; +} + +static PLDHashOperator +UnmarkJSHolder(void* holder, nsScriptObjectTracer*& tracer, void* arg) +{ + tracer->CanSkip(holder, true); + return PL_DHASH_NEXT; +} + +void +CycleCollectedJSRuntime::UnmarkSkippableJSHolders() +{ + mJSHolders.Enumerate(UnmarkJSHolder, nullptr); +} + void CycleCollectedJSRuntime::MaybeTraceGlobals(JSTracer* aTracer) const { diff --git a/xpcom/base/CycleCollectedJSRuntime.h b/xpcom/base/CycleCollectedJSRuntime.h index e6c19a673d09..b5230ff3ada9 100644 --- a/xpcom/base/CycleCollectedJSRuntime.h +++ b/xpcom/base/CycleCollectedJSRuntime.h @@ -88,6 +88,9 @@ protected: return mJSRuntime; } + size_t SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf) const; + void UnmarkSkippableJSHolders(); + virtual void TraverseAdditionalNativeRoots(nsCycleCollectionNoteRootCallback& aCb) = 0; virtual void TraceAdditionalNativeGrayRoots(JSTracer* aTracer) = 0; @@ -168,10 +171,6 @@ public: bool NeedCollect() const; void Collect(uint32_t reason) const; -// XXXkhuey should be private -protected: - nsDataHashtable, nsScriptObjectTracer*> mJSHolders; - private: typedef const CCParticipantVTable::Type GCThingParticipantVTable; const GCThingParticipantVTable mGCThingCycleCollectorGlobal; @@ -181,6 +180,8 @@ private: JSRuntime* mJSRuntime; + nsDataHashtable, nsScriptObjectTracer*> mJSHolders; + #ifdef DEBUG void* mObjectToUnlink; bool mExpectUnrootedGlobals;