diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index aa483881439..6e095e1f51f 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -12635,7 +12635,7 @@ nsDocument::DocAddSizeOfExcludingThis(nsWindowSizes* aWindowSizes) const 0; aWindowSizes->mDOMOtherSize += - mStyledLinks.SizeOfExcludingThis(nullptr, aWindowSizes->mMallocSizeOf); + mStyledLinks.ShallowSizeOfExcludingThis(aWindowSizes->mMallocSizeOf); aWindowSizes->mDOMOtherSize += mIdentifierMap.SizeOfExcludingThis(aWindowSizes->mMallocSizeOf); diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index 86009bdcdc9..a80763262ae 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -13598,12 +13598,8 @@ nsGlobalWindow::AddSizeOfIncludingThis(nsWindowSizes* aWindowSizes) const mNavigator->SizeOfIncludingThis(aWindowSizes->mMallocSizeOf); } - // The things pointed to by the entries will be measured below, so we - // use nullptr for the callback here. aWindowSizes->mDOMEventTargetsSize += - mEventTargetObjects.SizeOfExcludingThis(nullptr, - aWindowSizes->mMallocSizeOf); - + mEventTargetObjects.ShallowSizeOfExcludingThis(aWindowSizes->mMallocSizeOf); for (auto iter = mEventTargetObjects.ConstIter(); !iter.Done(); iter.Next()) { DOMEventTargetHelper* et = iter.Get()->GetKey(); diff --git a/dom/media/MediaCache.cpp b/dom/media/MediaCache.cpp index 5dbf0504704..702911080f3 100644 --- a/dom/media/MediaCache.cpp +++ b/dom/media/MediaCache.cpp @@ -403,8 +403,7 @@ size_t MediaCacheStream::SizeOfExcludingThis( size_t MediaCacheStream::BlockList::SizeOfExcludingThis( MallocSizeOf aMallocSizeOf) const { - return mEntries.SizeOfExcludingThis(/* sizeOfEntryExcludingThis = */ nullptr, - aMallocSizeOf); + return mEntries.ShallowSizeOfExcludingThis(aMallocSizeOf); } void MediaCacheStream::BlockList::AddFirstBlock(int32_t aBlock) diff --git a/dom/media/webaudio/AudioContext.cpp b/dom/media/webaudio/AudioContext.cpp index b57a70e6d18..4f37ed731d1 100644 --- a/dom/media/webaudio/AudioContext.cpp +++ b/dom/media/webaudio/AudioContext.cpp @@ -1040,8 +1040,8 @@ AudioContext::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const for (uint32_t i = 0; i < mDecodeJobs.Length(); ++i) { amount += mDecodeJobs[i]->SizeOfIncludingThis(aMallocSizeOf); } - amount += mActiveNodes.SizeOfExcludingThis(nullptr, aMallocSizeOf); - amount += mPannerNodes.SizeOfExcludingThis(nullptr, aMallocSizeOf); + amount += mActiveNodes.ShallowSizeOfExcludingThis(aMallocSizeOf); + amount += mPannerNodes.ShallowSizeOfExcludingThis(aMallocSizeOf); return amount; } diff --git a/gfx/thebes/gfxFT2Fonts.cpp b/gfx/thebes/gfxFT2Fonts.cpp index 0141b1505d7..7339eb9ebbe 100644 --- a/gfx/thebes/gfxFT2Fonts.cpp +++ b/gfx/thebes/gfxFT2Fonts.cpp @@ -218,7 +218,7 @@ gfxFT2Font::AddSizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf, { gfxFont::AddSizeOfExcludingThis(aMallocSizeOf, aSizes); aSizes->mFontInstances += - mCharGlyphCache.SizeOfExcludingThis(nullptr, aMallocSizeOf); + mCharGlyphCache.ShallowSizeOfExcludingThis(aMallocSizeOf); } void diff --git a/gfx/thebes/gfxFont.cpp b/gfx/thebes/gfxFont.cpp index 3aea181d0ee..97773a64f36 100644 --- a/gfx/thebes/gfxFont.cpp +++ b/gfx/thebes/gfxFont.cpp @@ -312,30 +312,16 @@ gfxFontCache::FlushShapedWordCaches() } } -/*static*/ -size_t -gfxFontCache::AddSizeOfFontEntryExcludingThis(HashEntry* aHashEntry, - MallocSizeOf aMallocSizeOf, - void* aUserArg) -{ - HashEntry *entry = static_cast(aHashEntry); - FontCacheSizes *sizes = static_cast(aUserArg); - entry->mFont->AddSizeOfExcludingThis(aMallocSizeOf, sizes); - - // The entry's size is recorded in the |sizes| parameter, so we return zero - // here to the hashtable enumerator. - return 0; -} - void gfxFontCache::AddSizeOfExcludingThis(MallocSizeOf aMallocSizeOf, FontCacheSizes* aSizes) const { // TODO: add the overhead of the expiration tracker (generation arrays) - aSizes->mFontInstances += - mFonts.SizeOfExcludingThis(AddSizeOfFontEntryExcludingThis, - aMallocSizeOf, aSizes); + aSizes->mFontInstances += mFonts.ShallowSizeOfExcludingThis(aMallocSizeOf); + for (auto iter = mFonts.ConstIter(); !iter.Done(); iter.Next()) { + iter.Get()->mFont->AddSizeOfExcludingThis(aMallocSizeOf, aSizes); + } } void diff --git a/gfx/thebes/gfxFont.h b/gfx/thebes/gfxFont.h index ac66c66c2bf..c3f34a760b2 100644 --- a/gfx/thebes/gfxFont.h +++ b/gfx/thebes/gfxFont.h @@ -387,10 +387,6 @@ protected: gfxFont* mFont; }; - static size_t AddSizeOfFontEntryExcludingThis(HashEntry* aHashEntry, - mozilla::MallocSizeOf aMallocSizeOf, - void* aUserArg); - nsTHashtable mFonts; static void WordCacheExpirationTimerCallback(nsITimer* aTimer, void* aCache); diff --git a/gfx/thebes/gfxGlyphExtents.cpp b/gfx/thebes/gfxGlyphExtents.cpp index 2d3c33dd1a1..ce5440e499f 100644 --- a/gfx/thebes/gfxGlyphExtents.cpp +++ b/gfx/thebes/gfxGlyphExtents.cpp @@ -141,7 +141,7 @@ size_t gfxGlyphExtents::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const { return mContainedGlyphWidths.SizeOfExcludingThis(aMallocSizeOf) + - mTightGlyphExtents.SizeOfExcludingThis(nullptr, aMallocSizeOf); + mTightGlyphExtents.ShallowSizeOfExcludingThis(aMallocSizeOf); } size_t diff --git a/gfx/thebes/gfxPlatformFontList.cpp b/gfx/thebes/gfxPlatformFontList.cpp index 371f60fb0cb..95b72ec103d 100644 --- a/gfx/thebes/gfxPlatformFontList.cpp +++ b/gfx/thebes/gfxPlatformFontList.cpp @@ -1095,21 +1095,6 @@ SizeOfPrefFontEntryExcludingThis return aList.ShallowSizeOfExcludingThis(aMallocSizeOf); } -static size_t -SizeOfSharedCmapExcludingThis(CharMapHashKey* aHashEntry, - MallocSizeOf aMallocSizeOf, - void* aUserArg) -{ - FontListSizes *sizes = static_cast(aUserArg); - - uint32_t size = aHashEntry->GetKey()->SizeOfIncludingThis(aMallocSizeOf); - sizes->mCharMapsSize += size; - - // we return zero here because the measurements have been added directly - // to the relevant fields of the FontListSizes record - return 0; -} - void gfxPlatformFontList::AddSizeOfExcludingThis(MallocSizeOf aMallocSizeOf, FontListSizes* aSizes) const @@ -1144,8 +1129,11 @@ gfxPlatformFontList::AddSizeOfExcludingThis(MallocSizeOf aMallocSizeOf, mBadUnderlineFamilyNames.SizeOfExcludingThis(aMallocSizeOf); aSizes->mFontListSize += - mSharedCmaps.SizeOfExcludingThis(SizeOfSharedCmapExcludingThis, - aMallocSizeOf, aSizes); + mSharedCmaps.ShallowSizeOfExcludingThis(aMallocSizeOf); + for (auto iter = mSharedCmaps.ConstIter(); !iter.Done(); iter.Next()) { + aSizes->mCharMapsSize += + iter.Get()->GetKey()->SizeOfIncludingThis(aMallocSizeOf); + } } void diff --git a/layout/base/nsPresShell.cpp b/layout/base/nsPresShell.cpp index e84bcafac5c..f61834f6fdc 100644 --- a/layout/base/nsPresShell.cpp +++ b/layout/base/nsPresShell.cpp @@ -10726,12 +10726,8 @@ PresShell::AddSizeOfIncludingThis(MallocSizeOf aMallocSizeOf, if (mCaret) { *aPresShellSize += mCaret->SizeOfIncludingThis(aMallocSizeOf); } - *aPresShellSize += mVisibleImages.SizeOfExcludingThis(nullptr, - aMallocSizeOf, - nullptr); - *aPresShellSize += mFramesToDirty.SizeOfExcludingThis(nullptr, - aMallocSizeOf, - nullptr); + *aPresShellSize += mVisibleImages.ShallowSizeOfExcludingThis(aMallocSizeOf); + *aPresShellSize += mFramesToDirty.ShallowSizeOfExcludingThis(aMallocSizeOf); *aPresShellSize += aArenaObjectsSize->mOther; *aStyleSetsSize += StyleSet()->SizeOfIncludingThis(aMallocSizeOf); diff --git a/netwerk/dns/nsEffectiveTLDService.cpp b/netwerk/dns/nsEffectiveTLDService.cpp index c1424db10d9..f8eb9c363b3 100644 --- a/netwerk/dns/nsEffectiveTLDService.cpp +++ b/netwerk/dns/nsEffectiveTLDService.cpp @@ -122,7 +122,7 @@ size_t nsEffectiveTLDService::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) { size_t n = aMallocSizeOf(this); - n += mHash.SizeOfExcludingThis(nullptr, aMallocSizeOf); + n += mHash.ShallowSizeOfExcludingThis(aMallocSizeOf); // Measurement of the following members may be added later if DMD finds it is // worthwhile: diff --git a/toolkit/components/telemetry/Telemetry.cpp b/toolkit/components/telemetry/Telemetry.cpp index 51cf9dfa3a4..090b2cc711b 100644 --- a/toolkit/components/telemetry/Telemetry.cpp +++ b/toolkit/components/telemetry/Telemetry.cpp @@ -399,10 +399,12 @@ public: } size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const { - size_t size; - size = mFileStats.SizeOfExcludingThis(SizeOfFileIOEntryTypeExcludingThis, - aMallocSizeOf) + - mSafeDirs.ShallowSizeOfExcludingThis(aMallocSizeOf); + size_t size = 0; + size += mFileStats.ShallowSizeOfExcludingThis(aMallocSizeOf); + for (auto iter = mFileStats.ConstIter(); !iter.Done(); iter.Next()) { + size += iter.Get()->GetKey().SizeOfExcludingThisIfUnshared(aMallocSizeOf); + } + size += mSafeDirs.ShallowSizeOfExcludingThis(aMallocSizeOf); uint32_t safeDirsLen = mSafeDirs.Length(); for (uint32_t i = 0; i < safeDirsLen; ++i) { size += mSafeDirs[i].SizeOfExcludingThis(aMallocSizeOf); @@ -451,13 +453,6 @@ private: */ static bool ReflectFileStats(FileIOEntryType* entry, JSContext *cx, JS::Handle obj); - - static size_t SizeOfFileIOEntryTypeExcludingThis(FileIOEntryType* aEntry, - mozilla::MallocSizeOf mallocSizeOf, - void*) - { - return aEntry->GetKey().SizeOfExcludingThisIfUnshared(mallocSizeOf); - } }; TelemetryIOInterposeObserver::TelemetryIOInterposeObserver(nsIFile* aXreDir) @@ -3584,8 +3579,8 @@ TelemetryImpl::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) size_t n = aMallocSizeOf(this); // Ignore the hashtables in mAddonMap; they are not significant. - n += mAddonMap.SizeOfExcludingThis(nullptr, aMallocSizeOf); - n += mHistogramMap.SizeOfExcludingThis(nullptr, aMallocSizeOf); + n += mAddonMap.ShallowSizeOfExcludingThis(aMallocSizeOf); + n += mHistogramMap.ShallowSizeOfExcludingThis(aMallocSizeOf); { // Scope for mHashMutex lock MutexAutoLock lock(mHashMutex); n += mPrivateSQL.SizeOfExcludingThis(aMallocSizeOf); diff --git a/xpcom/components/nsCategoryManager.cpp b/xpcom/components/nsCategoryManager.cpp index c83b36be0df..9a62ccdc778 100644 --- a/xpcom/components/nsCategoryManager.cpp +++ b/xpcom/components/nsCategoryManager.cpp @@ -318,7 +318,7 @@ CategoryNode::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) { // We don't measure the strings pointed to by the entries because the // pointers are non-owning. - return mTable.SizeOfExcludingThis(nullptr, aMallocSizeOf); + return mTable.ShallowSizeOfExcludingThis(aMallocSizeOf); } // diff --git a/xpcom/ds/nsAtomTable.cpp b/xpcom/ds/nsAtomTable.cpp index 810fa8bf861..342f2ef286c 100644 --- a/xpcom/ds/nsAtomTable.cpp +++ b/xpcom/ds/nsAtomTable.cpp @@ -517,9 +517,9 @@ NS_SizeOfAtomTablesIncludingThis(MallocSizeOf aMallocSizeOf, } // The atoms in the this table are almost certainly stored in static data, so - // we don't need a SizeOfEntry function. + // we don't need to measure entries separately. *aStatic = gStaticAtomTable - ? gStaticAtomTable->SizeOfIncludingThis(nullptr, aMallocSizeOf) + ? gStaticAtomTable->ShallowSizeOfIncludingThis(aMallocSizeOf) : 0; } diff --git a/xpcom/glue/nsTHashtable.h b/xpcom/glue/nsTHashtable.h index dfca0d18240..f79a2f37995 100644 --- a/xpcom/glue/nsTHashtable.h +++ b/xpcom/glue/nsTHashtable.h @@ -273,70 +273,47 @@ public: } /** - * client must provide a SizeOfEntryExcludingThisFun function for - * SizeOfExcludingThis. - * @param aEntry the entry being enumerated - * @param mallocSizeOf the function used to measure heap-allocated blocks - * @param arg passed unchanged from SizeOf{In,Ex}cludingThis - * @return summed size of the things pointed to by the entries + * Measure the size of the table's entry storage. Does *not* measure anything + * hanging off table entries; hence the "Shallow" prefix. To measure that, + * either use SizeOfExcludingThis() or iterate manually over the entries, + * calling SizeOfExcludingThis() on each one. + * + * @param aMallocSizeOf the function used to measure heap-allocated blocks + * @return the measured shallow size of the table */ - typedef size_t (*SizeOfEntryExcludingThisFun)(EntryType* aEntry, - mozilla::MallocSizeOf aMallocSizeOf, - void* aArg); + size_t ShallowSizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const + { + return mTable.ShallowSizeOfExcludingThis(aMallocSizeOf); + } /** - * Measure the size of the table's entry storage, and if - * |aSizeOfEntryExcludingThis| is non-nullptr, measure the size of things - * pointed to by entries. - * - * @param sizeOfEntryExcludingThis the - * SizeOfEntryExcludingThisFun function to call - * @param mallocSizeOf the function used to measure heap-allocated blocks - * @param userArg a pointer to pass to the - * SizeOfEntryExcludingThisFun function - * @return the summed size of all the entries + * Like ShallowSizeOfExcludingThis, but includes sizeof(*this). */ - size_t SizeOfExcludingThis(SizeOfEntryExcludingThisFun aSizeOfEntryExcludingThis, - mozilla::MallocSizeOf aMallocSizeOf, - void* aUserArg = nullptr) const + size_t ShallowSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const { - size_t n = 0; - n += mTable.ShallowSizeOfExcludingThis(aMallocSizeOf); - if (aSizeOfEntryExcludingThis) { - for (auto iter = ConstIter(); !iter.Done(); iter.Next()) { - n += aSizeOfEntryExcludingThis(iter.Get(), aMallocSizeOf, aUserArg); - } + return aMallocSizeOf(this) + ShallowSizeOfExcludingThis(aMallocSizeOf); + } + + /** + * This is a "deep" measurement of the table. To use it, |EntryType| must + * define SizeOfExcludingThis, and that method will be called on all live + * entries. + */ + size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const + { + size_t n = ShallowSizeOfExcludingThis(aMallocSizeOf); + for (auto iter = ConstIter(); !iter.Done(); iter.Next()) { + n += (*iter.Get()).SizeOfExcludingThis(aMallocSizeOf); } return n; } - /** - * If the EntryType defines SizeOfExcludingThis, there's no need to define a new - * SizeOfEntryExcludingThisFun. - */ - size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const - { - return SizeOfExcludingThis(BasicSizeOfEntryExcludingThisFun, aMallocSizeOf); - } - /** * Like SizeOfExcludingThis, but includes sizeof(*this). */ - size_t SizeOfIncludingThis(SizeOfEntryExcludingThisFun aSizeOfEntryExcludingThis, - mozilla::MallocSizeOf aMallocSizeOf, - void* aUserArg = nullptr) const - { - return aMallocSizeOf(this) + - SizeOfExcludingThis(aSizeOfEntryExcludingThis, aMallocSizeOf, aUserArg); - } - - /** - * If the EntryType defines SizeOfExcludingThis, there's no need to define a new - * SizeOfEntryExcludingThisFun. - */ size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const { - return SizeOfIncludingThis(BasicSizeOfEntryExcludingThisFun, aMallocSizeOf); + return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf); } /** @@ -388,14 +365,6 @@ private: */ static const PLDHashTableOps* Ops(); - /** - * An implementation of SizeOfEntryExcludingThisFun that calls SizeOfExcludingThis() - * on each entry. - */ - static size_t BasicSizeOfEntryExcludingThisFun(EntryType* aEntry, - mozilla::MallocSizeOf aMallocSizeOf, - void*); - // assignment operator, not implemented nsTHashtable& operator=(nsTHashtable& aToEqual) = delete; }; @@ -436,16 +405,6 @@ nsTHashtable::Ops() return &sOps; } -// static -template -size_t -nsTHashtable::BasicSizeOfEntryExcludingThisFun(EntryType* aEntry, - mozilla::MallocSizeOf aMallocSizeOf, - void*) -{ - return aEntry->SizeOfExcludingThis(aMallocSizeOf); -} - // static definitions template