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

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.)
This commit is contained in:
Nicholas Nethercote 2015-07-30 21:19:57 -07:00
parent bfe87aa496
commit 845b474b3c
24 changed files with 198 additions and 355 deletions

View File

@ -555,21 +555,15 @@ nsDOMAttributeMap::Enumerate(AttrCache::EnumReadFunction aFunc,
return mAttributeCache.EnumerateRead(aFunc, aUserArg);
}
size_t
AttrCacheSizeEnumerator(const nsAttrKey& aKey,
const nsRefPtr<Attr>& aValue,
MallocSizeOf aMallocSizeOf,
void* aUserArg)
{
return aMallocSizeOf(aValue.get());
}
size_t
nsDOMAttributeMap::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
{
size_t n = aMallocSizeOf(this);
n += mAttributeCache.SizeOfExcludingThis(AttrCacheSizeEnumerator,
aMallocSizeOf);
n += mAttributeCache.ShallowSizeOfExcludingThis(aMallocSizeOf);
for (auto iter = mAttributeCache.ConstIter(); !iter.Done(); iter.Next()) {
n += aMallocSizeOf(iter.Data().get());
}
// NB: mContent is non-owning and thus not counted.
return n;

View File

@ -1346,8 +1346,7 @@ gfxDWriteFontList::AddSizeOfExcludingThis(MallocSizeOf aMallocSizeOf,
gfxPlatformFontList::AddSizeOfExcludingThis(aMallocSizeOf, aSizes);
aSizes->mFontListSize +=
mFontSubstitutes.SizeOfExcludingThis(SizeOfFamilyNameEntryExcludingThis,
aMallocSizeOf);
SizeOfFontFamilyTableExcludingThis(mFontSubstitutes, aMallocSizeOf);
aSizes->mFontListSize +=
mNonExistingFonts.ShallowSizeOfExcludingThis(aMallocSizeOf);

View File

@ -657,7 +657,7 @@ gfxDWriteFont::AddSizeOfExcludingThis(MallocSizeOf aMallocSizeOf,
aSizes->mFontInstances += aMallocSizeOf(mMetrics);
if (mGlyphWidths) {
aSizes->mFontInstances +=
mGlyphWidths->SizeOfIncludingThis(nullptr, aMallocSizeOf);
mGlyphWidths->ShallowSizeOfIncludingThis(aMallocSizeOf);
}
}

View File

@ -528,7 +528,7 @@ gfxGDIFont::AddSizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf,
aSizes->mFontInstances += aMallocSizeOf(mMetrics);
if (mGlyphWidths) {
aSizes->mFontInstances +=
mGlyphWidths->SizeOfIncludingThis(nullptr, aMallocSizeOf);
mGlyphWidths->ShallowSizeOfIncludingThis(aMallocSizeOf);
}
}

View File

@ -880,8 +880,7 @@ gfxGDIFontList::AddSizeOfExcludingThis(MallocSizeOf aMallocSizeOf,
{
gfxPlatformFontList::AddSizeOfExcludingThis(aMallocSizeOf, aSizes);
aSizes->mFontListSize +=
mFontSubstitutes.SizeOfExcludingThis(SizeOfFamilyNameEntryExcludingThis,
aMallocSizeOf);
SizeOfFontFamilyTableExcludingThis(mFontSubstitutes, aMallocSizeOf);
aSizes->mFontListSize +=
mNonExistingFonts.ShallowSizeOfExcludingThis(aMallocSizeOf);
for (uint32_t i = 0; i < mNonExistingFonts.Length(); ++i) {

View File

@ -1042,57 +1042,20 @@ gfxPlatformFontList::RebuildLocalFonts()
// Support for memory reporting
static size_t
SizeOfFamilyEntryExcludingThis(const nsAString& aKey,
const nsRefPtr<gfxFontFamily>& aFamily,
MallocSizeOf aMallocSizeOf,
void* aUserArg)
{
FontListSizes *sizes = static_cast<FontListSizes*>(aUserArg);
aFamily->AddSizeOfExcludingThis(aMallocSizeOf, sizes);
sizes->mFontListSize += aKey.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
// we return zero here because the measurements have been added directly
// to the relevant fields of the FontListSizes record
return 0;
}
// this is also used by subclasses that hold additional hashes of family names
// this is also used by subclasses that hold additional font tables
/*static*/ size_t
gfxPlatformFontList::SizeOfFamilyNameEntryExcludingThis
(const nsAString& aKey,
const nsRefPtr<gfxFontFamily>& aFamily,
MallocSizeOf aMallocSizeOf,
void* aUserArg)
gfxPlatformFontList::SizeOfFontFamilyTableExcludingThis(
const FontFamilyTable& aTable,
MallocSizeOf aMallocSizeOf)
{
// we don't count the size of the family here, because this is an *extra*
// reference to a family that will have already been counted in the main list
return aKey.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
}
static size_t
SizeOfFontNameEntryExcludingThis(const nsAString& aKey,
const nsRefPtr<gfxFontEntry>& aFont,
MallocSizeOf aMallocSizeOf,
void* aUserArg)
{
// the font itself is counted by its owning family; here we only care about
// the name stored in the hashtable key
return aKey.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
}
static size_t
SizeOfPrefFontEntryExcludingThis
(const uint32_t& aKey,
const nsTArray<nsRefPtr<gfxFontFamily> >& aList,
MallocSizeOf aMallocSizeOf,
void* aUserArg)
{
// again, we only care about the size of the array itself; we don't follow
// the refPtrs stored in it, because they point to entries already owned
// and accounted-for by the main font list
return aList.ShallowSizeOfExcludingThis(aMallocSizeOf);
size_t n = aTable.ShallowSizeOfExcludingThis(aMallocSizeOf);
for (auto iter = aTable.ConstIter(); !iter.Done(); iter.Next()) {
// We don't count the size of the family here, because this is an
// *extra* reference to a family that will have already been counted in
// the main list.
n += iter.Key().SizeOfExcludingThisIfUnshared(aMallocSizeOf);
}
return n;
}
void
@ -1100,20 +1063,36 @@ gfxPlatformFontList::AddSizeOfExcludingThis(MallocSizeOf aMallocSizeOf,
FontListSizes* aSizes) const
{
aSizes->mFontListSize +=
mFontFamilies.SizeOfExcludingThis(SizeOfFamilyEntryExcludingThis,
aMallocSizeOf, aSizes);
mFontFamilies.ShallowSizeOfExcludingThis(aMallocSizeOf);
for (auto iter = mFontFamilies.ConstIter(); !iter.Done(); iter.Next()) {
aSizes->mFontListSize +=
iter.Key().SizeOfExcludingThisIfUnshared(aMallocSizeOf);
iter.Data()->AddSizeOfIncludingThis(aMallocSizeOf, aSizes);
}
aSizes->mFontListSize +=
mOtherFamilyNames.SizeOfExcludingThis(SizeOfFamilyNameEntryExcludingThis,
aMallocSizeOf);
SizeOfFontFamilyTableExcludingThis(mOtherFamilyNames, aMallocSizeOf);
if (mExtraNames) {
// For these two tables, the font itself is counted by its owning
// family; here we only care about the names stored in the hashtable
// keys.
aSizes->mFontListSize +=
mExtraNames->mFullnames.SizeOfExcludingThis(SizeOfFontNameEntryExcludingThis,
aMallocSizeOf);
mExtraNames->mFullnames.ShallowSizeOfExcludingThis(aMallocSizeOf);
for (auto iter = mExtraNames->mFullnames.ConstIter();
!iter.Done();
iter.Next()) {
aSizes->mFontListSize +=
iter.Key().SizeOfExcludingThisIfUnshared(aMallocSizeOf);
}
aSizes->mFontListSize +=
mExtraNames->mPostscriptNames.SizeOfExcludingThis(SizeOfFontNameEntryExcludingThis,
aMallocSizeOf);
mExtraNames->mPostscriptNames.ShallowSizeOfExcludingThis(aMallocSizeOf);
for (auto iter = mExtraNames->mPostscriptNames.ConstIter();
!iter.Done();
iter.Next()) {
aSizes->mFontListSize +=
iter.Key().SizeOfExcludingThisIfUnshared(aMallocSizeOf);
}
}
aSizes->mFontListSize +=
@ -1122,8 +1101,14 @@ gfxPlatformFontList::AddSizeOfExcludingThis(MallocSizeOf aMallocSizeOf,
mFontFamiliesToLoad.ShallowSizeOfExcludingThis(aMallocSizeOf);
aSizes->mFontListSize +=
mPrefFonts.SizeOfExcludingThis(SizeOfPrefFontEntryExcludingThis,
aMallocSizeOf);
mPrefFonts.ShallowSizeOfExcludingThis(aMallocSizeOf);
for (auto iter = mPrefFonts.ConstIter(); !iter.Done(); iter.Next()) {
// Again, we only care about the size of the array itself; we don't
// follow the refPtrs stored in it, because they point to entries
// already owned and accounted-for by the main font list.
aSizes->mFontListSize +=
iter.Data().ShallowSizeOfExcludingThis(aMallocSizeOf);
}
aSizes->mFontListSize +=
mBadUnderlineFamilyNames.SizeOfExcludingThis(aMallocSizeOf);

View File

@ -298,12 +298,10 @@ protected:
typedef nsRefPtrHashtable<nsStringHashKey, gfxFontFamily> FontFamilyTable;
// used by memory reporter to accumulate sizes of family names in the hash
// used by memory reporter to accumulate sizes of family names in the table
static size_t
SizeOfFamilyNameEntryExcludingThis(const nsAString& aKey,
const nsRefPtr<gfxFontFamily>& aFamily,
mozilla::MallocSizeOf aMallocSizeOf,
void* aUserArg);
SizeOfFontFamilyTableExcludingThis(const FontFamilyTable& aTable,
mozilla::MallocSizeOf aMallocSizeOf);
// canonical family name ==> family entry (unique, one name per family entry)
FontFamilyTable mFontFamilies;

View File

@ -441,34 +441,28 @@ mozJSComponentLoader::FindTargetObject(JSContext* aCx,
return NS_OK;
}
/* static */ size_t
mozJSComponentLoader::DataEntrySizeOfExcludingThis(const nsACString& aKey,
ModuleEntry* const& aData,
MallocSizeOf aMallocSizeOf, void*)
// This requires that the keys be strings and the values be pointers.
template <class Key, class Data, class UserData>
static size_t
SizeOfTableExcludingThis(const nsBaseHashtable<Key, Data, UserData>& aTable,
MallocSizeOf aMallocSizeOf)
{
return aKey.SizeOfExcludingThisIfUnshared(aMallocSizeOf) +
aData->SizeOfIncludingThis(aMallocSizeOf);
}
/* static */ size_t
mozJSComponentLoader::ClassEntrySizeOfExcludingThis(const nsACString& aKey,
const nsAutoPtr<ModuleEntry>& aData,
MallocSizeOf aMallocSizeOf, void*)
{
return aKey.SizeOfExcludingThisIfUnshared(aMallocSizeOf) +
aData->SizeOfIncludingThis(aMallocSizeOf);
size_t n = aTable.ShallowSizeOfExcludingThis(aMallocSizeOf);
for (auto iter = aTable.ConstIter(); !iter.Done(); iter.Next()) {
n += iter.Key().SizeOfExcludingThisIfUnshared(aMallocSizeOf);
n += iter.Data()->SizeOfIncludingThis(aMallocSizeOf);
}
return n;
}
size_t
mozJSComponentLoader::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf)
{
size_t amount = aMallocSizeOf(this);
amount += mModules.SizeOfExcludingThis(DataEntrySizeOfExcludingThis, aMallocSizeOf);
amount += mImports.SizeOfExcludingThis(ClassEntrySizeOfExcludingThis, aMallocSizeOf);
amount += mInProgressImports.SizeOfExcludingThis(DataEntrySizeOfExcludingThis, aMallocSizeOf);
return amount;
size_t n = aMallocSizeOf(this);
n += SizeOfTableExcludingThis(mModules, aMallocSizeOf);
n += SizeOfTableExcludingThis(mImports, aMallocSizeOf);
n += SizeOfTableExcludingThis(mInProgressImports, aMallocSizeOf);
return n;
}
// Some stack based classes for cleaning up on early return

View File

@ -204,24 +204,16 @@ CSSVariableDeclarations::AddVariablesToResolver(
aResolver);
}
static size_t
SizeOfTableEntry(const nsAString& aKey,
const nsString& aValue,
MallocSizeOf aMallocSizeOf,
void* aUserArg)
{
size_t n = 0;
n += aKey.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
n += aValue.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
return n;
}
size_t
CSSVariableDeclarations::SizeOfIncludingThis(
mozilla::MallocSizeOf aMallocSizeOf) const
{
size_t n = aMallocSizeOf(this);
n += mVariables.SizeOfExcludingThis(SizeOfTableEntry, aMallocSizeOf);
n += mVariables.ShallowSizeOfExcludingThis(aMallocSizeOf);
for (auto iter = mVariables.ConstIter(); !iter.Done(); iter.Next()) {
n += iter.Key().SizeOfExcludingThisIfUnshared(aMallocSizeOf);
n += iter.Data().SizeOfExcludingThisIfUnshared(aMallocSizeOf);
}
return n;
}

View File

@ -2547,36 +2547,26 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(Loader, AddRef)
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(Loader, Release)
struct SheetMemoryCounter {
size_t size;
mozilla::MallocSizeOf mallocSizeOf;
};
static size_t
CountSheetMemory(URIPrincipalReferrerPolicyAndCORSModeHashKey* /* unused */,
const nsRefPtr<CSSStyleSheet>& aSheet,
mozilla::MallocSizeOf aMallocSizeOf,
void* /* unused */)
{
// If aSheet has a parent, then its parent will report it so we don't
// have to worry about it here.
// Likewise, if aSheet has an owning node, then the document that
// node is in will report it.
if (aSheet->GetOwnerNode() || aSheet->GetParentSheet()) {
return 0;
}
return aSheet->SizeOfIncludingThis(aMallocSizeOf);
}
size_t
Loader::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
{
size_t s = aMallocSizeOf(this);
size_t n = aMallocSizeOf(this);
if (mSheets) {
s += mSheets->mCompleteSheets.SizeOfExcludingThis(CountSheetMemory, aMallocSizeOf);
n += mSheets->mCompleteSheets.ShallowSizeOfExcludingThis(aMallocSizeOf);
for (auto iter = mSheets->mCompleteSheets.ConstIter();
!iter.Done();
iter.Next()) {
// If aSheet has a parent, then its parent will report it so we don't
// have to worry about it here. Likewise, if aSheet has an owning node,
// then the document that node is in will report it.
const nsRefPtr<CSSStyleSheet>& aSheet = iter.Data();
n += (aSheet->GetOwnerNode() || aSheet->GetParentSheet())
? 0
: aSheet->SizeOfIncludingThis(aMallocSizeOf);
}
}
s += mObservers.ShallowSizeOfExcludingThis(aMallocSizeOf);
n += mObservers.ShallowSizeOfExcludingThis(aMallocSizeOf);
// Measurement of the following members may be added later if DMD finds it is
// worthwhile:
@ -2589,7 +2579,7 @@ Loader::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
// - mDocument, because it's a weak backpointer
// - mPreferredSheet, because it can be a shared string
return s;
return n;
}
} // namespace css

View File

@ -930,22 +930,6 @@ SizeOfSelectorsHashTable(const PLDHashTable& aTable, MallocSizeOf aMallocSizeOf)
return n;
}
static size_t
SizeOfKeyframesRuleEntryExcludingThis(nsStringHashKey::KeyType aKey,
nsCSSKeyframesRule* const& aData,
mozilla::MallocSizeOf aMallocSizeOf,
void* aUserArg)
{
// We don't own the nsCSSKeyframesRule objects so we don't count them. We do
// care about the size of the keys' nsAString members' buffers though.
//
// Note that we depend on nsStringHashKey::GetKey() returning a reference,
// since otherwise aKey would be a copy of the string key and we would not be
// measuring the right object here.
return aKey.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
}
size_t
RuleCascadeData::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
{
@ -976,9 +960,17 @@ RuleCascadeData::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
n += mFontFeatureValuesRules.ShallowSizeOfExcludingThis(aMallocSizeOf);
n += mPageRules.ShallowSizeOfExcludingThis(aMallocSizeOf);
n += mCounterStyleRules.ShallowSizeOfExcludingThis(aMallocSizeOf);
n += mKeyframesRuleTable.SizeOfExcludingThis(SizeOfKeyframesRuleEntryExcludingThis,
aMallocSizeOf,
nullptr);
n += mKeyframesRuleTable.ShallowSizeOfExcludingThis(aMallocSizeOf);
for (auto iter = mKeyframesRuleTable.ConstIter(); !iter.Done(); iter.Next()) {
// We don't own the nsCSSKeyframesRule objects so we don't count them. We
// do care about the size of the keys' nsAString members' buffers though.
//
// Note that we depend on nsStringHashKey::GetKey() returning a reference,
// since otherwise aKey would be a copy of the string key and we would not
// be measuring the right object here.
n += iter.Key().SizeOfExcludingThisIfUnshared(aMallocSizeOf);
}
return n;
}

View File

@ -161,26 +161,21 @@ nsHTMLCSSStyleSheet::MediumFeaturesChanged(nsPresContext* aPresContext)
return false;
}
size_t
SizeOfCachedStyleAttrsEntryExcludingThis(nsStringHashKey::KeyType& aKey,
MiscContainer* const& aData,
mozilla::MallocSizeOf aMallocSizeOf,
void* userArg)
{
// We don't own the MiscContainers so we don't count them. We do care about
// the size of the nsString members in the keys though.
return aKey.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
}
/* virtual */ size_t
nsHTMLCSSStyleSheet::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
{
// The size of mCachedStyleAttrs's mTable member (a PLDHashTable) is
// significant in itself, but more significant is the size of the nsString
// members of the nsStringHashKeys.
return mCachedStyleAttrs.SizeOfExcludingThis(SizeOfCachedStyleAttrsEntryExcludingThis,
aMallocSizeOf,
nullptr);
size_t n = 0;
n += mCachedStyleAttrs.ShallowSizeOfExcludingThis(aMallocSizeOf);
for (auto iter = mCachedStyleAttrs.ConstIter(); !iter.Done(); iter.Next()) {
// We don't own the MiscContainers (the hash table values) so we don't
// count them. We do care about the size of the nsString members in the
// keys though.
n += iter.Key().SizeOfExcludingThisIfUnshared(aMallocSizeOf);
}
return n;
}
/* virtual */ size_t

View File

@ -218,18 +218,6 @@ AssertNotAlreadyCached(const char* aPrefType,
}
#endif
static size_t
SizeOfObserverEntryExcludingThis(ValueObserverHashKey* aKey,
const nsRefPtr<ValueObserver>& aData,
mozilla::MallocSizeOf aMallocSizeOf,
void*)
{
size_t n = 0;
n += aKey->mPrefName.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
n += aData->mClosures.ShallowSizeOfExcludingThis(aMallocSizeOf);
return n;
}
// Although this is a member of Preferences, it measures sPreferences and
// several other global structures.
/* static */ int64_t
@ -251,8 +239,11 @@ Preferences::SizeOfIncludingThisAndOtherStuff(mozilla::MallocSizeOf aMallocSizeO
}
if (gObserverTable) {
n += aMallocSizeOf(gObserverTable);
n += gObserverTable->SizeOfExcludingThis(SizeOfObserverEntryExcludingThis,
aMallocSizeOf);
n += gObserverTable->ShallowSizeOfIncludingThis(aMallocSizeOf);
for (auto iter = gObserverTable->Iter(); !iter.Done(); iter.Next()) {
n += iter.Key()->mPrefName.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
n += iter.Data()->mClosures.ShallowSizeOfExcludingThis(aMallocSizeOf);
}
}
// We don't measure sRootBranch and sDefaultRootBranch here because
// DMD indicates they are not significant.

View File

@ -1981,20 +1981,6 @@ CacheFile::InitIndexEntry()
return NS_OK;
}
// Memory reporting
namespace {
size_t
CollectChunkSize(uint32_t const & aIdx,
nsRefPtr<mozilla::net::CacheFileChunk> const & aChunk,
mozilla::MallocSizeOf mallocSizeOf, void* aClosure)
{
return aChunk->SizeOfIncludingThis(mallocSizeOf);
}
} // namespace
size_t
CacheFile::SizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) const
{
@ -2002,8 +1988,14 @@ CacheFile::SizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) const
size_t n = 0;
n += mKey.SizeOfExcludingThisIfUnshared(mallocSizeOf);
n += mChunks.SizeOfExcludingThis(CollectChunkSize, mallocSizeOf);
n += mCachedChunks.SizeOfExcludingThis(CollectChunkSize, mallocSizeOf);
n += mChunks.ShallowSizeOfExcludingThis(mallocSizeOf);
for (auto iter = mChunks.ConstIter(); !iter.Done(); iter.Next()) {
n += iter.Data()->SizeOfIncludingThis(mallocSizeOf);
}
n += mCachedChunks.ShallowSizeOfExcludingThis(mallocSizeOf);
for (auto iter = mCachedChunks.ConstIter(); !iter.Done(); iter.Next()) {
n += iter.Data()->SizeOfIncludingThis(mallocSizeOf);
}
if (mMetadata) {
n += mMetadata->SizeOfIncludingThis(mallocSizeOf);
}
@ -2020,7 +2012,7 @@ CacheFile::SizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) const
}
// The listeners are usually classes reported just above.
n += mChunkListeners.SizeOfExcludingThis(nullptr, mallocSizeOf);
n += mChunkListeners.ShallowSizeOfExcludingThis(mallocSizeOf);
n += mObjsToRelease.ShallowSizeOfExcludingThis(mallocSizeOf);
// mHandle reported directly from CacheFileIOManager.

View File

@ -1976,7 +1976,7 @@ CacheStorageService::SizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) con
n += Pool(false).mExpirationArray.ShallowSizeOfExcludingThis(mallocSizeOf);
// Entries reported manually in CacheStorageService::CollectReports callback
if (sGlobalEntryTables) {
n += sGlobalEntryTables->SizeOfIncludingThis(nullptr, mallocSizeOf);
n += sGlobalEntryTables->ShallowSizeOfIncludingThis(mallocSizeOf);
}
return n;
@ -1997,36 +1997,28 @@ public:
nsISupports *mData;
};
size_t CollectEntryMemory(nsACString const & aKey,
nsRefPtr<mozilla::net::CacheEntry> const & aEntry,
mozilla::MallocSizeOf mallocSizeOf,
void * aClosure)
{
CacheStorageService::Self()->Lock().AssertCurrentThreadOwns();
CacheEntryTable* aTable = static_cast<CacheEntryTable*>(aClosure);
size_t n = 0;
n += aKey.SizeOfExcludingThisIfUnshared(mallocSizeOf);
// Bypass memory-only entries, those will be reported when iterating
// the memory only table. Memory-only entries are stored in both ALL_ENTRIES
// and MEMORY_ONLY hashtables.
if (aTable->Type() == CacheEntryTable::MEMORY_ONLY || aEntry->IsUsingDisk())
n += aEntry->SizeOfIncludingThis(mallocSizeOf);
return n;
}
PLDHashOperator ReportStorageMemory(const nsACString& aKey,
CacheEntryTable* aTable,
void* aClosure)
{
CacheStorageService::Self()->Lock().AssertCurrentThreadOwns();
size_t size = aTable->SizeOfIncludingThis(&CollectEntryMemory,
CacheStorageService::MallocSizeOf,
aTable);
size_t size = 0;
mozilla::MallocSizeOf mallocSizeOf = CacheStorageService::MallocSizeOf;
size += aTable->ShallowSizeOfIncludingThis(mallocSizeOf);
for (auto iter = aTable->Iter(); !iter.Done(); iter.Next()) {
size += iter.Key().SizeOfExcludingThisIfUnshared(mallocSizeOf);
// Bypass memory-only entries, those will be reported when iterating
// the memory only table. Memory-only entries are stored in both ALL_ENTRIES
// and MEMORY_ONLY hashtables.
nsRefPtr<mozilla::net::CacheEntry> const& entry = iter.Data();
if (aTable->Type() == CacheEntryTable::MEMORY_ONLY ||
entry->IsUsingDisk()) {
size += entry->SizeOfIncludingThis(mallocSizeOf);
}
}
ReportStorageMemoryData& data =
*static_cast<ReportStorageMemoryData*>(aClosure);

View File

@ -377,20 +377,21 @@ StartupCache::SizeOfMapping()
}
size_t
StartupCache::HeapSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf)
StartupCache::HeapSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
{
// This function could measure more members, but they haven't been found by
// DMD to be significant. They can be added later if necessary.
return aMallocSizeOf(this) +
mTable.SizeOfExcludingThis(SizeOfEntryExcludingThis, aMallocSizeOf) +
mPendingWrites.ShallowSizeOfExcludingThis(aMallocSizeOf);
}
/* static */ size_t
StartupCache::SizeOfEntryExcludingThis(const nsACString& key, const nsAutoPtr<CacheEntry>& data,
mozilla::MallocSizeOf mallocSizeOf, void *)
{
return data->SizeOfExcludingThis(mallocSizeOf);
size_t n = aMallocSizeOf(this);
n += mTable.ShallowSizeOfExcludingThis(aMallocSizeOf);
for (auto iter = mTable.ConstIter(); !iter.Done(); iter.Next()) {
n += iter.Data()->SizeOfIncludingThis(aMallocSizeOf);
}
n += mPendingWrites.ShallowSizeOfExcludingThis(aMallocSizeOf);
return n;
}
struct CacheWriteHolder

View File

@ -85,8 +85,8 @@ struct CacheEntry
{
}
size_t SizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) {
return mallocSizeOf(data);
size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) {
return mallocSizeOf(this) + mallocSizeOf(data);
}
};
@ -135,7 +135,7 @@ public:
// This measures all the heap memory used by the StartupCache, i.e. it
// excludes the mapping.
size_t HeapSizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf);
size_t HeapSizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
size_t SizeOfMapping();
@ -159,11 +159,6 @@ private:
static void WriteTimeout(nsITimer *aTimer, void *aClosure);
static void ThreadedWrite(void *aClosure);
static size_t SizeOfEntryExcludingThis(const nsACString& key,
const nsAutoPtr<CacheEntry>& data,
mozilla::MallocSizeOf mallocSizeOf,
void *);
nsClassHashtable<nsCStringHashKey, CacheEntry> mTable;
nsTArray<nsCString> mPendingWrites;
nsRefPtr<nsZipArchive> mArchive;

View File

@ -455,9 +455,9 @@ CycleCollectedJSRuntime::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
{
size_t n = 0;
// nullptr for the second arg; we're not measuring anything hanging off the
// entries in mJSHolders.
n += mJSHolders.SizeOfExcludingThis(nullptr, aMallocSizeOf);
// We're deliberately not measuring anything hanging off the entries in
// mJSHolders.
n += mJSHolders.ShallowSizeOfExcludingThis(aMallocSizeOf);
return n;
}

View File

@ -455,17 +455,6 @@ nsCategoryManager::CollectReports(nsIHandleReportCallback* aHandleReport,
"Memory used for the XPCOM category manager.");
}
static size_t
SizeOfCategoryManagerTableEntryExcludingThis(nsDepCharHashKey::KeyType aKey,
const nsAutoPtr<CategoryNode>& aData,
MallocSizeOf aMallocSizeOf,
void* aUserArg)
{
// We don't measure the string pointed to by aKey because it's a non-owning
// pointer.
return aData.get()->SizeOfExcludingThis(aMallocSizeOf);
}
size_t
nsCategoryManager::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf)
{
@ -473,8 +462,11 @@ nsCategoryManager::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf)
n += PL_SizeOfArenaPoolExcludingPool(&mArena, aMallocSizeOf);
n += mTable.SizeOfExcludingThis(SizeOfCategoryManagerTableEntryExcludingThis,
aMallocSizeOf);
n += mTable.ShallowSizeOfExcludingThis(aMallocSizeOf);
for (auto iter = mTable.ConstIter(); !iter.Done(); iter.Next()) {
// We don't measure the key string because it's a non-owning pointer.
n += iter.Data().get()->SizeOfExcludingThis(aMallocSizeOf);
}
return n;
}

View File

@ -1815,26 +1815,6 @@ nsComponentManagerImpl::ContractIDToCID(const char* aContractID,
return NS_ERROR_FACTORY_NOT_REGISTERED;
}
static size_t
SizeOfFactoriesEntryExcludingThis(nsIDHashKey::KeyType aKey,
nsFactoryEntry* const& aData,
MallocSizeOf aMallocSizeOf,
void* aUserArg)
{
return aData->SizeOfIncludingThis(aMallocSizeOf);
}
static size_t
SizeOfContractIDsEntryExcludingThis(nsCStringHashKey::KeyType aKey,
nsFactoryEntry* const& aData,
MallocSizeOf aMallocSizeOf,
void* aUserArg)
{
// We don't measure the nsFactoryEntry data because its owned by mFactories
// (which measures them in SizeOfFactoriesEntryExcludingThis).
return aKey.SizeOfExcludingThisMustBeUnshared(aMallocSizeOf);
}
MOZ_DEFINE_MALLOC_SIZE_OF(ComponentManagerMallocSizeOf)
NS_IMETHODIMP
@ -1849,19 +1829,29 @@ nsComponentManagerImpl::CollectReports(nsIHandleReportCallback* aHandleReport,
size_t
nsComponentManagerImpl::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf)
const
{
size_t n = aMallocSizeOf(this);
n += mLoaderMap.SizeOfExcludingThis(nullptr, aMallocSizeOf);
n += mFactories.SizeOfExcludingThis(SizeOfFactoriesEntryExcludingThis,
aMallocSizeOf);
n += mContractIDs.SizeOfExcludingThis(SizeOfContractIDsEntryExcludingThis,
aMallocSizeOf);
n += mLoaderMap.ShallowSizeOfExcludingThis(aMallocSizeOf);
n += mFactories.ShallowSizeOfExcludingThis(aMallocSizeOf);
for (auto iter = mFactories.ConstIter(); !iter.Done(); iter.Next()) {
n += iter.Data()->SizeOfIncludingThis(aMallocSizeOf);
}
n += mContractIDs.ShallowSizeOfExcludingThis(aMallocSizeOf);
for (auto iter = mContractIDs.ConstIter(); !iter.Done(); iter.Next()) {
// We don't measure the nsFactoryEntry data because it's owned by
// mFactories (which is measured above).
n += iter.Key().SizeOfExcludingThisMustBeUnshared(aMallocSizeOf);
}
n += sStaticModules->ShallowSizeOfIncludingThis(aMallocSizeOf);
n += sModuleLocations->ShallowSizeOfIncludingThis(aMallocSizeOf);
n += mKnownStaticModules.ShallowSizeOfExcludingThis(aMallocSizeOf);
n += mKnownModules.SizeOfExcludingThis(nullptr, aMallocSizeOf);
n += mKnownModules.ShallowSizeOfExcludingThis(aMallocSizeOf);
n += PL_SizeOfArenaPoolExcludingPool(&mArena, aMallocSizeOf);

View File

@ -337,7 +337,7 @@ public:
nsTArray<PendingServiceInfo> mPendingServices;
size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf);
size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
#ifdef MOZ_B2G_LOADER
// Preload XPT interface info for B2G loader.

View File

@ -144,15 +144,6 @@ public:
PR_DestroyLock(mLock);
}
static size_t
SizeOfEntryExcludingThis(const T* aKey, const nsAutoPtr<OrderingEntry>& aEntry,
MallocSizeOf aMallocSizeOf, void* aUserArg)
{
// NB: Key is accounted for in the entry.
size_t n = aEntry->SizeOfIncludingThis(aMallocSizeOf);
return n;
}
size_t
SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
{
@ -160,7 +151,11 @@ public:
{
PRAutoLock _(mLock);
n += mOrdering.SizeOfExcludingThis(SizeOfEntryExcludingThis, aMallocSizeOf);
n += mOrdering.ShallowSizeOfExcludingThis(aMallocSizeOf);
for (auto iter = mOrdering.ConstIter(); !iter.Done(); iter.Next()) {
// NB: Key is accounted for in the entry.
n += iter.Data()->SizeOfIncludingThis(aMallocSizeOf);
}
}
return n;

View File

@ -267,66 +267,23 @@ public:
void Clear() { nsTHashtable<EntryType>::Clear(); }
/**
* client must provide a SizeOfEntryExcludingThisFun function for
* SizeOfExcludingThis.
* @param aKey the key being enumerated
* @param aData Reference to data being enumerated.
* @param aMallocSizeOf the function used to measure heap-allocated blocks
* @param aUserArg passed unchanged from SizeOf{In,Ex}cludingThis
* @return summed size of the things pointed to by the entries
*/
typedef size_t
(*SizeOfEntryExcludingThisFun)(KeyType aKey,
const DataType& aData,
mozilla::MallocSizeOf aMallocSizeOf,
void* aUserArg);
/**
* Measure the size of the table's entry storage and the table itself.
* If |aSizeOfEntryExcludingThis| is non-nullptr, measure the size of things
* pointed to by entries.
* Measure the size of the table's entry storage. The size of things pointed
* to by entries must be measured separately; hence the "Shallow" prefix.
*
* @param aSizeOfEntryExcludingThis
* the <code>SizeOfEntryExcludingThisFun</code> function to call
* @param aMallocSizeOf the function used to meeasure heap-allocated blocks
* @param aUserArg a point to pass to the
* <code>SizeOfEntryExcludingThisFun</code> function
* @return the summed size of the entries, the table, and the table's storage
* @param aMallocSizeOf the function used to measure heap-allocated blocks
* @return the summed size of the table's storage
*/
size_t SizeOfIncludingThis(SizeOfEntryExcludingThisFun aSizeOfEntryExcludingThis,
mozilla::MallocSizeOf aMallocSizeOf,
void* aUserArg = nullptr)
size_t ShallowSizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
{
return aMallocSizeOf(this) +
this->SizeOfExcludingThis(aSizeOfEntryExcludingThis, aMallocSizeOf,
aUserArg);
return this->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 aSizeOfEntryExcludingThis the
* <code>SizeOfEntryExcludingThisFun</code> function to call
* @param aMallocSizeOf the function used to measure heap-allocated blocks
* @param aUserArg a pointer to pass to the
* <code>SizeOfEntryExcludingThisFun</code> 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 += this->mTable.ShallowSizeOfExcludingThis(aMallocSizeOf);
if (aSizeOfEntryExcludingThis) {
for (auto iter = ConstIter(); !iter.Done(); iter.Next()) {
n += aSizeOfEntryExcludingThis(iter.Key(), iter.Data(), aMallocSizeOf,
aUserArg);
}
}
return n;
return aMallocSizeOf(this) + ShallowSizeOfExcludingThis(aMallocSizeOf);
}
#ifdef DEBUG

View File

@ -36,8 +36,8 @@ XPTInterfaceInfoManager::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf
ReentrantMonitorAutoEnter monitor(mWorkingSet.mTableReentrantMonitor);
// The entries themselves are allocated out of an arena accounted
// for elsewhere, so don't measure them
n += mWorkingSet.mIIDTable.SizeOfExcludingThis(nullptr, aMallocSizeOf);
n += mWorkingSet.mNameTable.SizeOfExcludingThis(nullptr, aMallocSizeOf);
n += mWorkingSet.mIIDTable.ShallowSizeOfExcludingThis(aMallocSizeOf);
n += mWorkingSet.mNameTable.ShallowSizeOfExcludingThis(aMallocSizeOf);
return n;
}