Bug 1189156 (part 2) - Don't use enumeration style for nsTHashtable::SizeOf{In,Ex}cludingThis(). r=erahm.

After this change, we have ShallowSizeOf{In,Ex}cludingThis(), which don't do
anything to measure children. (They can be combined with iteration to measure
children.)

And we still have the existing single-arg SizeOf{In,Ex}cluding() functions,
which work if the entry type itself defines SizeOfExcludingThis().
This commit is contained in:
Nicholas Nethercote 2015-07-29 01:50:52 -07:00
parent 6d0613afeb
commit 4a526ace27
15 changed files with 57 additions and 142 deletions

View File

@ -12635,7 +12635,7 @@ nsDocument::DocAddSizeOfExcludingThis(nsWindowSizes* aWindowSizes) const
0; 0;
aWindowSizes->mDOMOtherSize += aWindowSizes->mDOMOtherSize +=
mStyledLinks.SizeOfExcludingThis(nullptr, aWindowSizes->mMallocSizeOf); mStyledLinks.ShallowSizeOfExcludingThis(aWindowSizes->mMallocSizeOf);
aWindowSizes->mDOMOtherSize += aWindowSizes->mDOMOtherSize +=
mIdentifierMap.SizeOfExcludingThis(aWindowSizes->mMallocSizeOf); mIdentifierMap.SizeOfExcludingThis(aWindowSizes->mMallocSizeOf);

View File

@ -13598,12 +13598,8 @@ nsGlobalWindow::AddSizeOfIncludingThis(nsWindowSizes* aWindowSizes) const
mNavigator->SizeOfIncludingThis(aWindowSizes->mMallocSizeOf); 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 += aWindowSizes->mDOMEventTargetsSize +=
mEventTargetObjects.SizeOfExcludingThis(nullptr, mEventTargetObjects.ShallowSizeOfExcludingThis(aWindowSizes->mMallocSizeOf);
aWindowSizes->mMallocSizeOf);
for (auto iter = mEventTargetObjects.ConstIter(); !iter.Done(); iter.Next()) { for (auto iter = mEventTargetObjects.ConstIter(); !iter.Done(); iter.Next()) {
DOMEventTargetHelper* et = iter.Get()->GetKey(); DOMEventTargetHelper* et = iter.Get()->GetKey();

View File

@ -403,8 +403,7 @@ size_t MediaCacheStream::SizeOfExcludingThis(
size_t MediaCacheStream::BlockList::SizeOfExcludingThis( size_t MediaCacheStream::BlockList::SizeOfExcludingThis(
MallocSizeOf aMallocSizeOf) const MallocSizeOf aMallocSizeOf) const
{ {
return mEntries.SizeOfExcludingThis(/* sizeOfEntryExcludingThis = */ nullptr, return mEntries.ShallowSizeOfExcludingThis(aMallocSizeOf);
aMallocSizeOf);
} }
void MediaCacheStream::BlockList::AddFirstBlock(int32_t aBlock) void MediaCacheStream::BlockList::AddFirstBlock(int32_t aBlock)

View File

@ -1040,8 +1040,8 @@ AudioContext::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
for (uint32_t i = 0; i < mDecodeJobs.Length(); ++i) { for (uint32_t i = 0; i < mDecodeJobs.Length(); ++i) {
amount += mDecodeJobs[i]->SizeOfIncludingThis(aMallocSizeOf); amount += mDecodeJobs[i]->SizeOfIncludingThis(aMallocSizeOf);
} }
amount += mActiveNodes.SizeOfExcludingThis(nullptr, aMallocSizeOf); amount += mActiveNodes.ShallowSizeOfExcludingThis(aMallocSizeOf);
amount += mPannerNodes.SizeOfExcludingThis(nullptr, aMallocSizeOf); amount += mPannerNodes.ShallowSizeOfExcludingThis(aMallocSizeOf);
return amount; return amount;
} }

View File

@ -218,7 +218,7 @@ gfxFT2Font::AddSizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf,
{ {
gfxFont::AddSizeOfExcludingThis(aMallocSizeOf, aSizes); gfxFont::AddSizeOfExcludingThis(aMallocSizeOf, aSizes);
aSizes->mFontInstances += aSizes->mFontInstances +=
mCharGlyphCache.SizeOfExcludingThis(nullptr, aMallocSizeOf); mCharGlyphCache.ShallowSizeOfExcludingThis(aMallocSizeOf);
} }
void void

View File

@ -312,30 +312,16 @@ gfxFontCache::FlushShapedWordCaches()
} }
} }
/*static*/
size_t
gfxFontCache::AddSizeOfFontEntryExcludingThis(HashEntry* aHashEntry,
MallocSizeOf aMallocSizeOf,
void* aUserArg)
{
HashEntry *entry = static_cast<HashEntry*>(aHashEntry);
FontCacheSizes *sizes = static_cast<FontCacheSizes*>(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 void
gfxFontCache::AddSizeOfExcludingThis(MallocSizeOf aMallocSizeOf, gfxFontCache::AddSizeOfExcludingThis(MallocSizeOf aMallocSizeOf,
FontCacheSizes* aSizes) const FontCacheSizes* aSizes) const
{ {
// TODO: add the overhead of the expiration tracker (generation arrays) // TODO: add the overhead of the expiration tracker (generation arrays)
aSizes->mFontInstances += aSizes->mFontInstances += mFonts.ShallowSizeOfExcludingThis(aMallocSizeOf);
mFonts.SizeOfExcludingThis(AddSizeOfFontEntryExcludingThis, for (auto iter = mFonts.ConstIter(); !iter.Done(); iter.Next()) {
aMallocSizeOf, aSizes); iter.Get()->mFont->AddSizeOfExcludingThis(aMallocSizeOf, aSizes);
}
} }
void void

View File

@ -387,10 +387,6 @@ protected:
gfxFont* mFont; gfxFont* mFont;
}; };
static size_t AddSizeOfFontEntryExcludingThis(HashEntry* aHashEntry,
mozilla::MallocSizeOf aMallocSizeOf,
void* aUserArg);
nsTHashtable<HashEntry> mFonts; nsTHashtable<HashEntry> mFonts;
static void WordCacheExpirationTimerCallback(nsITimer* aTimer, void* aCache); static void WordCacheExpirationTimerCallback(nsITimer* aTimer, void* aCache);

View File

@ -141,7 +141,7 @@ size_t
gfxGlyphExtents::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const gfxGlyphExtents::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
{ {
return mContainedGlyphWidths.SizeOfExcludingThis(aMallocSizeOf) + return mContainedGlyphWidths.SizeOfExcludingThis(aMallocSizeOf) +
mTightGlyphExtents.SizeOfExcludingThis(nullptr, aMallocSizeOf); mTightGlyphExtents.ShallowSizeOfExcludingThis(aMallocSizeOf);
} }
size_t size_t

View File

@ -1095,21 +1095,6 @@ SizeOfPrefFontEntryExcludingThis
return aList.ShallowSizeOfExcludingThis(aMallocSizeOf); return aList.ShallowSizeOfExcludingThis(aMallocSizeOf);
} }
static size_t
SizeOfSharedCmapExcludingThis(CharMapHashKey* aHashEntry,
MallocSizeOf aMallocSizeOf,
void* aUserArg)
{
FontListSizes *sizes = static_cast<FontListSizes*>(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 void
gfxPlatformFontList::AddSizeOfExcludingThis(MallocSizeOf aMallocSizeOf, gfxPlatformFontList::AddSizeOfExcludingThis(MallocSizeOf aMallocSizeOf,
FontListSizes* aSizes) const FontListSizes* aSizes) const
@ -1144,8 +1129,11 @@ gfxPlatformFontList::AddSizeOfExcludingThis(MallocSizeOf aMallocSizeOf,
mBadUnderlineFamilyNames.SizeOfExcludingThis(aMallocSizeOf); mBadUnderlineFamilyNames.SizeOfExcludingThis(aMallocSizeOf);
aSizes->mFontListSize += aSizes->mFontListSize +=
mSharedCmaps.SizeOfExcludingThis(SizeOfSharedCmapExcludingThis, mSharedCmaps.ShallowSizeOfExcludingThis(aMallocSizeOf);
aMallocSizeOf, aSizes); for (auto iter = mSharedCmaps.ConstIter(); !iter.Done(); iter.Next()) {
aSizes->mCharMapsSize +=
iter.Get()->GetKey()->SizeOfIncludingThis(aMallocSizeOf);
}
} }
void void

View File

@ -10726,12 +10726,8 @@ PresShell::AddSizeOfIncludingThis(MallocSizeOf aMallocSizeOf,
if (mCaret) { if (mCaret) {
*aPresShellSize += mCaret->SizeOfIncludingThis(aMallocSizeOf); *aPresShellSize += mCaret->SizeOfIncludingThis(aMallocSizeOf);
} }
*aPresShellSize += mVisibleImages.SizeOfExcludingThis(nullptr, *aPresShellSize += mVisibleImages.ShallowSizeOfExcludingThis(aMallocSizeOf);
aMallocSizeOf, *aPresShellSize += mFramesToDirty.ShallowSizeOfExcludingThis(aMallocSizeOf);
nullptr);
*aPresShellSize += mFramesToDirty.SizeOfExcludingThis(nullptr,
aMallocSizeOf,
nullptr);
*aPresShellSize += aArenaObjectsSize->mOther; *aPresShellSize += aArenaObjectsSize->mOther;
*aStyleSetsSize += StyleSet()->SizeOfIncludingThis(aMallocSizeOf); *aStyleSetsSize += StyleSet()->SizeOfIncludingThis(aMallocSizeOf);

View File

@ -122,7 +122,7 @@ size_t
nsEffectiveTLDService::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) nsEffectiveTLDService::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf)
{ {
size_t n = aMallocSizeOf(this); 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 // Measurement of the following members may be added later if DMD finds it is
// worthwhile: // worthwhile:

View File

@ -399,10 +399,12 @@ public:
} }
size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const { size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const {
size_t size; size_t size = 0;
size = mFileStats.SizeOfExcludingThis(SizeOfFileIOEntryTypeExcludingThis, size += mFileStats.ShallowSizeOfExcludingThis(aMallocSizeOf);
aMallocSizeOf) + for (auto iter = mFileStats.ConstIter(); !iter.Done(); iter.Next()) {
mSafeDirs.ShallowSizeOfExcludingThis(aMallocSizeOf); size += iter.Get()->GetKey().SizeOfExcludingThisIfUnshared(aMallocSizeOf);
}
size += mSafeDirs.ShallowSizeOfExcludingThis(aMallocSizeOf);
uint32_t safeDirsLen = mSafeDirs.Length(); uint32_t safeDirsLen = mSafeDirs.Length();
for (uint32_t i = 0; i < safeDirsLen; ++i) { for (uint32_t i = 0; i < safeDirsLen; ++i) {
size += mSafeDirs[i].SizeOfExcludingThis(aMallocSizeOf); size += mSafeDirs[i].SizeOfExcludingThis(aMallocSizeOf);
@ -451,13 +453,6 @@ private:
*/ */
static bool ReflectFileStats(FileIOEntryType* entry, JSContext *cx, static bool ReflectFileStats(FileIOEntryType* entry, JSContext *cx,
JS::Handle<JSObject*> obj); JS::Handle<JSObject*> obj);
static size_t SizeOfFileIOEntryTypeExcludingThis(FileIOEntryType* aEntry,
mozilla::MallocSizeOf mallocSizeOf,
void*)
{
return aEntry->GetKey().SizeOfExcludingThisIfUnshared(mallocSizeOf);
}
}; };
TelemetryIOInterposeObserver::TelemetryIOInterposeObserver(nsIFile* aXreDir) TelemetryIOInterposeObserver::TelemetryIOInterposeObserver(nsIFile* aXreDir)
@ -3584,8 +3579,8 @@ TelemetryImpl::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf)
size_t n = aMallocSizeOf(this); size_t n = aMallocSizeOf(this);
// Ignore the hashtables in mAddonMap; they are not significant. // Ignore the hashtables in mAddonMap; they are not significant.
n += mAddonMap.SizeOfExcludingThis(nullptr, aMallocSizeOf); n += mAddonMap.ShallowSizeOfExcludingThis(aMallocSizeOf);
n += mHistogramMap.SizeOfExcludingThis(nullptr, aMallocSizeOf); n += mHistogramMap.ShallowSizeOfExcludingThis(aMallocSizeOf);
{ // Scope for mHashMutex lock { // Scope for mHashMutex lock
MutexAutoLock lock(mHashMutex); MutexAutoLock lock(mHashMutex);
n += mPrivateSQL.SizeOfExcludingThis(aMallocSizeOf); n += mPrivateSQL.SizeOfExcludingThis(aMallocSizeOf);

View File

@ -318,7 +318,7 @@ CategoryNode::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf)
{ {
// We don't measure the strings pointed to by the entries because the // We don't measure the strings pointed to by the entries because the
// pointers are non-owning. // pointers are non-owning.
return mTable.SizeOfExcludingThis(nullptr, aMallocSizeOf); return mTable.ShallowSizeOfExcludingThis(aMallocSizeOf);
} }
// //

View File

@ -517,9 +517,9 @@ NS_SizeOfAtomTablesIncludingThis(MallocSizeOf aMallocSizeOf,
} }
// The atoms in the this table are almost certainly stored in static data, so // 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 *aStatic = gStaticAtomTable
? gStaticAtomTable->SizeOfIncludingThis(nullptr, aMallocSizeOf) ? gStaticAtomTable->ShallowSizeOfIncludingThis(aMallocSizeOf)
: 0; : 0;
} }

View File

@ -273,70 +273,47 @@ public:
} }
/** /**
* client must provide a <code>SizeOfEntryExcludingThisFun</code> function for * Measure the size of the table's entry storage. Does *not* measure anything
* SizeOfExcludingThis. * hanging off table entries; hence the "Shallow" prefix. To measure that,
* @param aEntry the entry being enumerated * either use SizeOfExcludingThis() or iterate manually over the entries,
* @param mallocSizeOf the function used to measure heap-allocated blocks * calling SizeOfExcludingThis() on each one.
* @param arg passed unchanged from <code>SizeOf{In,Ex}cludingThis</code> *
* @return summed size of the things pointed to by the entries * @param aMallocSizeOf the function used to measure heap-allocated blocks
* @return the measured shallow size of the table
*/ */
typedef size_t (*SizeOfEntryExcludingThisFun)(EntryType* aEntry, size_t ShallowSizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
mozilla::MallocSizeOf aMallocSizeOf, {
void* aArg); return mTable.ShallowSizeOfExcludingThis(aMallocSizeOf);
}
/** /**
* Measure the size of the table's entry storage, and if * Like ShallowSizeOfExcludingThis, but includes sizeof(*this).
* |aSizeOfEntryExcludingThis| is non-nullptr, measure the size of things
* pointed to by entries.
*
* @param sizeOfEntryExcludingThis the
* <code>SizeOfEntryExcludingThisFun</code> function to call
* @param mallocSizeOf the function used to measure heap-allocated blocks
* @param userArg a pointer to pass to the
* <code>SizeOfEntryExcludingThisFun</code> function
* @return the summed size of all the entries
*/ */
size_t SizeOfExcludingThis(SizeOfEntryExcludingThisFun aSizeOfEntryExcludingThis, size_t ShallowSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
mozilla::MallocSizeOf aMallocSizeOf,
void* aUserArg = nullptr) const
{ {
size_t n = 0; return aMallocSizeOf(this) + ShallowSizeOfExcludingThis(aMallocSizeOf);
n += mTable.ShallowSizeOfExcludingThis(aMallocSizeOf); }
if (aSizeOfEntryExcludingThis) {
for (auto iter = ConstIter(); !iter.Done(); iter.Next()) { /**
n += aSizeOfEntryExcludingThis(iter.Get(), aMallocSizeOf, aUserArg); * 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; 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). * 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 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(); 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 // assignment operator, not implemented
nsTHashtable<EntryType>& operator=(nsTHashtable<EntryType>& aToEqual) = delete; nsTHashtable<EntryType>& operator=(nsTHashtable<EntryType>& aToEqual) = delete;
}; };
@ -436,16 +405,6 @@ nsTHashtable<EntryType>::Ops()
return &sOps; return &sOps;
} }
// static
template<class EntryType>
size_t
nsTHashtable<EntryType>::BasicSizeOfEntryExcludingThisFun(EntryType* aEntry,
mozilla::MallocSizeOf aMallocSizeOf,
void*)
{
return aEntry->SizeOfExcludingThis(aMallocSizeOf);
}
// static definitions // static definitions
template<class EntryType> template<class EntryType>