Bug 814229 (part 1) - Add "objects-extra/ctypes-data" memory report. r=jorendorff.

--HG--
extra : rebase_source : 8b65b74b5c22ebf7525eeff51601e36274d56736
This commit is contained in:
Nicholas Nethercote 2012-11-21 17:05:39 -08:00
parent 3224cf64f6
commit 615e573039
7 changed files with 45 additions and 6 deletions

View File

@ -166,6 +166,7 @@ struct CompartmentStats
, objectsExtraArgumentsData(0)
, objectsExtraRegExpStatics(0)
, objectsExtraPropertyIteratorData(0)
, objectsExtraCtypesData(0)
, objectsExtraPrivate(0)
, stringCharsNonHuge(0)
, shapesExtraTreeTables(0)
@ -208,6 +209,7 @@ struct CompartmentStats
, objectsExtraArgumentsData(other.objectsExtraArgumentsData)
, objectsExtraRegExpStatics(other.objectsExtraRegExpStatics)
, objectsExtraPropertyIteratorData(other.objectsExtraPropertyIteratorData)
, objectsExtraCtypesData(other.objectsExtraCtypesData)
, objectsExtraPrivate(other.objectsExtraPrivate)
, stringCharsNonHuge(other.stringCharsNonHuge)
, shapesExtraTreeTables(other.shapesExtraTreeTables)
@ -258,6 +260,7 @@ struct CompartmentStats
size_t objectsExtraArgumentsData;
size_t objectsExtraRegExpStatics;
size_t objectsExtraPropertyIteratorData;
size_t objectsExtraCtypesData;
size_t objectsExtraPrivate;
size_t stringCharsNonHuge;
size_t shapesExtraTreeTables;
@ -306,6 +309,7 @@ struct CompartmentStats
ADD(objectsExtraArgumentsData);
ADD(objectsExtraRegExpStatics);
ADD(objectsExtraPropertyIteratorData);
ADD(objectsExtraCtypesData);
ADD(objectsExtraPrivate);
ADD(stringCharsNonHuge);
ADD(shapesExtraTreeTables);

View File

@ -1330,6 +1330,28 @@ JS_SetCTypesCallbacks(JSRawObject ctypesObj, JSCTypesCallbacks* callbacks)
}
namespace js {
JS_FRIEND_API(size_t)
SizeOfDataIfCDataObject(JSMallocSizeOfFun mallocSizeOf, JSObject *obj)
{
if (!CData::IsCData(obj))
return 0;
size_t n = 0;
jsval slot = JS_GetReservedSlot(obj, ctypes::SLOT_OWNS);
if (!JSVAL_IS_VOID(slot)) {
JSBool owns = JSVAL_TO_BOOLEAN(slot);
slot = JS_GetReservedSlot(obj, ctypes::SLOT_DATA);
if (!JSVAL_IS_VOID(slot)) {
char** buffer = static_cast<char**>(JSVAL_TO_PRIVATE(slot));
n += mallocSizeOf(buffer);
if (owns)
n += mallocSizeOf(*buffer);
}
}
return n;
}
namespace ctypes {
/*******************************************************************************

View File

@ -298,6 +298,9 @@ GCThingTraceKind(void *thing);
extern JS_FRIEND_API(void)
IterateGrayObjects(JSCompartment *compartment, GCThingCallback cellCallback, void *data);
extern JS_FRIEND_API(size_t)
SizeOfDataIfCDataObject(JSMallocSizeOfFun mallocSizeOf, JSObject *obj);
/*
* Shadow declarations of JS internal structures, for access by inline access
* functions below. Do not use these structures in any other way. When adding

View File

@ -152,15 +152,16 @@ StatsCellCallback(JSRuntime *rt, void *data, void *thing, JSGCTraceKind traceKin
cStats->gcHeapObjectsOrdinary += thingSize;
}
size_t slotsSize, elementsSize, argumentsDataSize, regExpStaticsSize,
propertyIteratorDataSize;
propertyIteratorDataSize, ctypesDataSize;
obj->sizeOfExcludingThis(rtStats->mallocSizeOf, &slotsSize, &elementsSize,
&argumentsDataSize, &regExpStaticsSize,
&propertyIteratorDataSize);
&propertyIteratorDataSize, &ctypesDataSize);
cStats->objectsExtraSlots += slotsSize;
cStats->objectsExtraElements += elementsSize;
cStats->objectsExtraArgumentsData += argumentsDataSize;
cStats->objectsExtraRegExpStatics += regExpStaticsSize;
cStats->objectsExtraPropertyIteratorData += propertyIteratorDataSize;
cStats->objectsExtraCtypesData += ctypesDataSize;
if (ObjectPrivateVisitor *opv = closure->opv) {
js::Class *clazz = js::GetObjectClass(obj);

View File

@ -371,7 +371,8 @@ struct JSObject : public js::ObjectImpl
inline void sizeOfExcludingThis(JSMallocSizeOfFun mallocSizeOf, size_t *slotsSize,
size_t *elementsSize, size_t *argumentsDataSize,
size_t *regExpStaticsSize,
size_t *propertyIteratorDataSize) const;
size_t *propertyIteratorDataSize,
size_t *ctypesDataSize) const;
bool hasIdempotentProtoChain() const;

View File

@ -1001,7 +1001,8 @@ JSObject::computedSizeOfThisSlotsElements() const
inline void
JSObject::sizeOfExcludingThis(JSMallocSizeOfFun mallocSizeOf, size_t *slotsSize,
size_t *elementsSize, size_t *argumentsDataSize,
size_t *regExpStaticsSize, size_t *propertyIteratorDataSize) const
size_t *regExpStaticsSize, size_t *propertyIteratorDataSize,
size_t *ctypesDataSize) const
{
*slotsSize = 0;
if (hasDynamicSlots()) {
@ -1017,12 +1018,16 @@ JSObject::sizeOfExcludingThis(JSMallocSizeOfFun mallocSizeOf, size_t *slotsSize,
*argumentsDataSize = 0;
*regExpStaticsSize = 0;
*propertyIteratorDataSize = 0;
*ctypesDataSize = 0;
if (isArguments()) {
*argumentsDataSize += asArguments().sizeOfMisc(mallocSizeOf);
} else if (isRegExpStatics()) {
*regExpStaticsSize += js::SizeOfRegExpStaticsData(this, mallocSizeOf);
} else if (isPropertyIterator()) {
*propertyIteratorDataSize += asPropertyIterator().sizeOfMisc(mallocSizeOf);
} else {
// This must be the last case.
*ctypesDataSize += js::SizeOfDataIfCDataObject(mallocSizeOf, const_cast<JSObject *>(this));
}
}

View File

@ -1620,9 +1620,12 @@ ReportCompartmentStats(const JS::CompartmentStats &cStats,
CREPORT_BYTES(cJSPathPrefix + NS_LITERAL_CSTRING("objects-extra/property-iterator-data"),
cStats.objectsExtraPropertyIteratorData,
"Memory allocated for data belonging to property iterator "
"objects.");
"Memory allocated for data belonging to property iterator objects.");
CREPORT_BYTES(cJSPathPrefix + NS_LITERAL_CSTRING("objects-extra/ctypes-data"),
cStats.objectsExtraCtypesData,
"Memory allocated for data belonging to ctypes objects.");
// Note that we use cDOMPathPrefix here. This is because we measure orphan
// DOM nodes in the JS multi-reporter, but we want to report them in a
// "dom" sub-tree rather than a "js" sub-tree.