Bug 1046477 (part 2) - Don't measure the heap size of static atoms. r=froydnj.

This commit is contained in:
Nicholas Nethercote
2014-07-30 23:19:23 -07:00
parent d8d1d82534
commit 10cef5f3cb

View File

@@ -106,7 +106,7 @@ public:
// for |#ifdef NS_BUILD_REFCNT_LOGGING| access to reference count
nsrefcnt GetRefCount() { return mRefCnt; }
size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const;
size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf);
};
/**
@@ -470,12 +470,20 @@ AtomImpl::IsStaticAtom()
}
size_t
AtomImpl::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
AtomImpl::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf)
{
return aMallocSizeOf(this) +
nsStringBuffer::FromData(mString)->SizeOfIncludingThisIfUnshared(
size_t n = aMallocSizeOf(this);
// Don't measure static atoms. Nb: here "static" means "permanent", and while
// it's not guaranteed that permanent atoms are actually stored in static
// data, it is very likely. And we don't want to call |aMallocSizeOf| on
// static data, so we err on the side of caution.
if (!IsStaticAtom()) {
n += nsStringBuffer::FromData(mString)->SizeOfIncludingThisIfUnshared(
aMallocSizeOf);
}
return n;
}
//----------------------------------------------------------------------
@@ -488,15 +496,6 @@ SizeOfAtomTableEntryExcludingThis(PLDHashEntryHdr* aHdr,
return entry->mAtom->SizeOfIncludingThis(aMallocSizeOf);
}
static size_t
SizeOfStaticAtomTableEntryExcludingThis(const nsAString& aKey,
nsIAtom* const& aData,
MallocSizeOf aMallocSizeOf,
void* aArg)
{
return aKey.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
}
void
NS_SizeOfAtomTablesIncludingThis(MallocSizeOf aMallocSizeOf,
size_t* aMain, size_t* aStatic)
@@ -507,9 +506,10 @@ NS_SizeOfAtomTablesIncludingThis(MallocSizeOf aMallocSizeOf,
aMallocSizeOf)
: 0;
// The atoms in the this table are almost certainly stored in static data, so
// we don't need a SizeOfEntry function.
*aStatic = gStaticAtomTable
? gStaticAtomTable->SizeOfIncludingThis(SizeOfStaticAtomTableEntryExcludingThis,
aMallocSizeOf)
? gStaticAtomTable->SizeOfIncludingThis(nullptr, aMallocSizeOf)
: 0;
}