Bug 1052626, part 2 - Report the total size of nsXPCWrappedJS. r=bholley,froydnj

This commit is contained in:
Andrew McCreight 2014-08-25 12:34:00 -07:00
parent eb17f3480d
commit e22baa3a1e
8 changed files with 65 additions and 2 deletions

View File

@ -2769,7 +2769,9 @@ JSReporter::CollectReports(WindowPaths *windowPaths,
return NS_ERROR_FAILURE;
}
size_t xpconnect = xpcrt->SizeOfIncludingThis(JSMallocSizeOf);
size_t xpcJSRuntimeSize = xpcrt->SizeOfIncludingThis(JSMallocSizeOf);
size_t wrappedJSSize = xpcrt->GetWrappedJSMap()->SizeOfWrappedJS(JSMallocSizeOf);
XPCWrappedNativeScope::ScopeSizeInfo sizeInfo(JSMallocSizeOf);
XPCWrappedNativeScope::AddSizeOfAllScopesIncludingThis(&sizeInfo);
@ -2849,9 +2851,13 @@ JSReporter::CollectReports(WindowPaths *windowPaths,
// Report xpconnect.
REPORT_BYTES(NS_LITERAL_CSTRING("explicit/xpconnect/runtime"),
KIND_HEAP, xpconnect,
KIND_HEAP, xpcJSRuntimeSize,
"The XPConnect runtime.");
REPORT_BYTES(NS_LITERAL_CSTRING("explicit/xpconnect/wrappedjs"),
KIND_HEAP, wrappedJSSize,
"Wrappers used to implement XPIDL interfaces with JS.");
REPORT_BYTES(NS_LITERAL_CSTRING("explicit/xpconnect/scopes"),
KIND_HEAP, sizeInfo.mScopeAndMapSize,
"XPConnect scopes.");

View File

@ -119,6 +119,15 @@ JSObject2WrappedJSMap::SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) c
return n;
}
size_t
JSObject2WrappedJSMap::SizeOfWrappedJS(mozilla::MallocSizeOf mallocSizeOf) const
{
size_t n = 0;
for (Map::Range r = mTable.all(); !r.empty(); r.popFront())
n += r.front().value()->SizeOfIncludingThis(mallocSizeOf);
return n;
}
/***************************************************************************/
// implement Native2WrappedNativeMap...

View File

@ -74,6 +74,10 @@ public:
size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
// Report the sum of SizeOfIncludingThis() for all wrapped JS in the map.
// Each wrapped JS is only in one map.
size_t SizeOfWrappedJS(mozilla::MallocSizeOf mallocSizeOf) const;
private:
JSObject2WrappedJSMap() {}

View File

@ -552,6 +552,25 @@ nsXPCWrappedJS::SystemIsBeingShutDown()
mNext->SystemIsBeingShutDown();
}
size_t
nsXPCWrappedJS::SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const
{
// mJSObject is a JS pointer, so don't measure the object.
// mClass is not uniquely owned by this WrappedJS. Measure it in IID2WrappedJSClassMap.
// mRoot is not measured because it is either |this| or we have already measured it.
// mOuter is rare and probably not uniquely owned by this.
size_t n = mallocSizeOf(this);
n += nsAutoXPTCStub::SizeOfExcludingThis(mallocSizeOf);
// Wrappers form a linked list via the mNext field, so include them all
// in the measurement. Only root wrappers are stored in the map, so
// everything will be measured exactly once.
if (mNext)
n += mNext->SizeOfIncludingThis(mallocSizeOf);
return n;
}
/***************************************************************************/
/* readonly attribute nsISimpleEnumerator enumerator; */

View File

@ -2489,6 +2489,8 @@ public:
void TraceJS(JSTracer* trc);
static void GetTraceName(JSTracer* trc, char *buf, size_t bufsize);
size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
virtual ~nsXPCWrappedJS();
protected:
nsXPCWrappedJS(); // not implemented

View File

@ -8,6 +8,7 @@
#define nsXPTCUtils_h__
#include "xptcall.h"
#include "mozilla/MemoryReporting.h"
/**
* A helper class that initializes an xptcall helper at construction
@ -33,6 +34,12 @@ protected:
NS_DestroyXPTCallStub(mXPTCStub);
}
}
size_t
SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
{
return mXPTCStub ? NS_SizeOfIncludingThisXPTCallStub(mXPTCStub, aMallocSizeOf) : 0;
}
};
#endif // nsXPTCUtils_h__

View File

@ -66,3 +66,12 @@ NS_DestroyXPTCallStub(nsISomeInterface* aStub)
nsXPTCStubBase* stub = static_cast<nsXPTCStubBase*>(aStub);
delete(stub);
}
EXPORT_XPCOM_API(size_t)
NS_SizeOfIncludingThisXPTCallStub(const nsISomeInterface* aStub,
mozilla::MallocSizeOf aMallocSizeOf)
{
// We could cast aStub to nsXPTCStubBase, but that class doesn't seem to own anything,
// so just measure the size of the object itself.
return aMallocSizeOf(aStub);
}

View File

@ -13,6 +13,7 @@
#include "xpt_struct.h"
#include "xptinfo.h"
#include "js/Value.h"
#include "mozilla/MemoryReporting.h"
struct nsXPTCMiniVariant
{
@ -179,6 +180,12 @@ NS_GetXPTCallStub(REFNSIID aIID, nsIXPTCProxy* aOuter,
XPCOM_API(void)
NS_DestroyXPTCallStub(nsISomeInterface* aStub);
/**
* Measures the size of an XPTCall stub previously created with NS_GetXPTCallStub.
*/
XPCOM_API(size_t)
NS_SizeOfIncludingThisXPTCallStub(const nsISomeInterface* aStub, mozilla::MallocSizeOf aMallocSizeOf);
XPCOM_API(nsresult)
NS_InvokeByIndex(nsISupports* that, uint32_t methodIndex,
uint32_t paramCount, nsXPTCVariant* params);