Bug 805915 (part 4) - Add more detail to string memory reports. r=luke.

--HG--
extra : rebase_source : 010e28f10917ae4cc9d0d11abace9bcdabf0aba8
This commit is contained in:
Nicholas Nethercote 2012-10-29 08:51:21 +11:00
parent a39e01c750
commit 77a87b6eb8
5 changed files with 33 additions and 19 deletions

View File

@ -134,7 +134,8 @@ struct CompartmentStats
, gcHeapObjectsDenseArray(0)
, gcHeapObjectsSlowArray(0)
, gcHeapObjectsCrossCompartmentWrapper(0)
, gcHeapStrings(0)
, gcHeapStringsNormal(0)
, gcHeapStringsShort(0)
, gcHeapShapesTree(0)
, gcHeapShapesDict(0)
, gcHeapShapesBase(0)
@ -148,7 +149,7 @@ struct CompartmentStats
, objectElements(0)
, objectMisc(0)
, objectPrivate(0)
, nonHugeStringChars(0)
, stringCharsNonHuge(0)
, shapesExtraTreeTables(0)
, shapesExtraDictTables(0)
, shapesExtraTreeShapeKids(0)
@ -172,7 +173,8 @@ struct CompartmentStats
, gcHeapObjectsDenseArray(other.gcHeapObjectsDenseArray)
, gcHeapObjectsSlowArray(other.gcHeapObjectsSlowArray)
, gcHeapObjectsCrossCompartmentWrapper(other.gcHeapObjectsCrossCompartmentWrapper)
, gcHeapStrings(other.gcHeapStrings)
, gcHeapStringsNormal(other.gcHeapStringsNormal)
, gcHeapStringsShort(other.gcHeapStringsShort)
, gcHeapShapesTree(other.gcHeapShapesTree)
, gcHeapShapesDict(other.gcHeapShapesDict)
, gcHeapShapesBase(other.gcHeapShapesBase)
@ -186,7 +188,7 @@ struct CompartmentStats
, objectElements(other.objectElements)
, objectMisc(other.objectMisc)
, objectPrivate(other.objectPrivate)
, nonHugeStringChars(other.nonHugeStringChars)
, stringCharsNonHuge(other.stringCharsNonHuge)
, shapesExtraTreeTables(other.shapesExtraTreeTables)
, shapesExtraDictTables(other.shapesExtraDictTables)
, shapesExtraTreeShapeKids(other.shapesExtraTreeShapeKids)
@ -217,7 +219,8 @@ struct CompartmentStats
size_t gcHeapObjectsDenseArray;
size_t gcHeapObjectsSlowArray;
size_t gcHeapObjectsCrossCompartmentWrapper;
size_t gcHeapStrings;
size_t gcHeapStringsNormal;
size_t gcHeapStringsShort;
size_t gcHeapShapesTree;
size_t gcHeapShapesDict;
size_t gcHeapShapesBase;
@ -232,7 +235,7 @@ struct CompartmentStats
size_t objectElements;
size_t objectMisc;
size_t objectPrivate;
size_t nonHugeStringChars;
size_t stringCharsNonHuge;
size_t shapesExtraTreeTables;
size_t shapesExtraDictTables;
size_t shapesExtraTreeShapeKids;
@ -261,7 +264,8 @@ struct CompartmentStats
ADD(gcHeapObjectsDenseArray);
ADD(gcHeapObjectsSlowArray);
ADD(gcHeapObjectsCrossCompartmentWrapper);
ADD(gcHeapStrings);
ADD(gcHeapStringsNormal);
ADD(gcHeapStringsShort);
ADD(gcHeapShapesTree);
ADD(gcHeapShapesDict);
ADD(gcHeapShapesBase);
@ -276,7 +280,7 @@ struct CompartmentStats
ADD(objectElements);
ADD(objectMisc);
ADD(objectPrivate);
ADD(nonHugeStringChars);
ADD(stringCharsNonHuge);
ADD(shapesExtraTreeTables);
ADD(shapesExtraDictTables);
ADD(shapesExtraTreeShapeKids);

View File

@ -59,7 +59,8 @@ CompartmentStats::gcHeapThingsSize()
n += gcHeapObjectsDenseArray;
n += gcHeapObjectsSlowArray;
n += gcHeapObjectsCrossCompartmentWrapper;
n += gcHeapStrings;
n += gcHeapStringsNormal;
n += gcHeapStringsShort;
n += gcHeapShapesTree;
n += gcHeapShapesDict;
n += gcHeapShapesBase;
@ -173,19 +174,23 @@ StatsCellCallback(JSRuntime *rt, void *data, void *thing, JSGCTraceKind traceKin
case JSTRACE_STRING:
{
JSString *str = static_cast<JSString *>(thing);
cStats->gcHeapStrings += thingSize;
size_t strSize = str->sizeOfExcludingThis(rtStats->mallocSizeOf);
// If we can't grow hugeStrings, let's just call this string non-huge.
// We're probably about to OOM anyway.
if (strSize >= HugeStringInfo::MinSize() && cStats->hugeStrings.growBy(1)) {
cStats->gcHeapStringsNormal += thingSize;
HugeStringInfo &info = cStats->hugeStrings.back();
info.length = str->length();
info.size = str->sizeOfExcludingThis(rtStats->mallocSizeOf);
info.size = strSize;
PutEscapedString(info.buffer, sizeof(info.buffer), &str->asLinear(), 0);
} else if (str->isShort()) {
MOZ_ASSERT(strSize == 0);
cStats->gcHeapStringsShort += thingSize;
} else {
cStats->nonHugeStringChars += strSize;
cStats->gcHeapStringsNormal += thingSize;
cStats->stringCharsNonHuge += strSize;
}
break;
}

View File

@ -17,7 +17,6 @@
using namespace mozilla;
using namespace js;
#ifdef DEBUG
bool
JSString::isShort() const
{
@ -28,7 +27,6 @@ JSString::isShort() const
JS_ASSERT_IF(is_short, isFlat());
return is_short;
}
#endif
bool
JSString::isExternal() const

View File

@ -348,6 +348,8 @@ class JSString : public js::gc::Cell
return *(JSInlineString *)this;
}
bool isShort() const;
JS_ALWAYS_INLINE
JSStableString &asStable() const {
JS_ASSERT(!isInline());
@ -416,7 +418,6 @@ class JSString : public js::gc::Cell
static inline js::ThingRootKind rootKind() { return js::THING_ROOT_STRING; }
#ifdef DEBUG
bool isShort() const;
void dump();
static void dumpChars(const jschar *s, size_t len);
bool equals(const char *s);

View File

@ -1497,15 +1497,21 @@ ReportCompartmentStats(const JS::CompartmentStats &cStats,
"Memory on the garbage-collected JavaScript "
"heap that holds cross-compartment wrapper objects.");
CREPORT_GC_BYTES(cJSPathPrefix + NS_LITERAL_CSTRING("gc-heap/strings"),
cStats.gcHeapStrings,
CREPORT_GC_BYTES(cJSPathPrefix + NS_LITERAL_CSTRING("gc-heap/strings/normal"),
cStats.gcHeapStringsNormal,
"Memory on the garbage-collected JavaScript "
"heap that holds string headers. String headers contain "
"heap that holds normal string headers. String headers contain "
"various pieces of information about a string, but do not "
"contain (except in the case of very short strings) the "
"string characters; characters in longer strings are "
"counted under 'gc-heap/string-chars' instead.");
CREPORT_GC_BYTES(cJSPathPrefix + NS_LITERAL_CSTRING("gc-heap/strings/short"),
cStats.gcHeapStringsShort,
"Memory on the garbage-collected JavaScript "
"heap that holds over-sized string headers, in which "
"string characters are stored inline.");
CREPORT_GC_BYTES(cJSPathPrefix + NS_LITERAL_CSTRING("gc-heap/scripts"),
cStats.gcHeapScripts,
"Memory on the garbage-collected JavaScript "
@ -1645,7 +1651,7 @@ ReportCompartmentStats(const JS::CompartmentStats &cStats,
"transient analysis information. Cleared on GC.");
CREPORT_BYTES2(cJSPathPrefix + NS_LITERAL_CSTRING("string-chars/non-huge"),
cStats.nonHugeStringChars, nsPrintfCString(
cStats.stringCharsNonHuge, nsPrintfCString(
"Memory allocated to hold characters of strings whose "
"characters take up less than than %d bytes of memory.\n\n"
"Sometimes more memory is allocated than necessary, to "