Bug 972712 (part 1) - Don't report short strings separately. r=till.

--HG--
extra : rebase_source : 631fe6137935cfb2fbfc3339406c5418d458ad38
This commit is contained in:
Nicholas Nethercote 2014-02-26 17:53:02 -08:00
parent 9edb9a4e06
commit bee7f6eba5
3 changed files with 24 additions and 64 deletions

View File

@ -112,9 +112,8 @@ struct ZoneStatsPod
macro(Other, IsLiveGCThing, typeObjectsGCHeap) \
macro(Other, NotLiveGCThing, typeObjectsMallocHeap) \
macro(Other, NotLiveGCThing, typePool) \
macro(Strings, IsLiveGCThing, stringsShortGCHeap) \
macro(Strings, IsLiveGCThing, stringsNormalGCHeap) \
macro(Strings, NotLiveGCThing, stringsNormalMallocHeap)
macro(Strings, IsLiveGCThing, stringsGCHeap) \
macro(Strings, NotLiveGCThing, stringsMallocHeap)
ZoneStatsPod()
: FOR_EACH_SIZE(ZERO_SIZE)
@ -243,34 +242,29 @@ struct StringInfo
{
StringInfo()
: numCopies(0),
isShort(0),
gcHeap(0),
mallocHeap(0)
{}
StringInfo(bool isShort, size_t gcSize, size_t mallocSize)
StringInfo(size_t gcSize, size_t mallocSize)
: numCopies(1),
isShort(isShort),
gcHeap(gcSize),
mallocHeap(mallocSize)
{}
void add(bool isShort, size_t gcSize, size_t mallocSize) {
void add(size_t gcSize, size_t mallocSize) {
numCopies++;
MOZ_ASSERT(isShort == this->isShort);
gcHeap += gcSize;
mallocHeap += mallocSize;
}
void add(const StringInfo& info) {
numCopies += info.numCopies;
MOZ_ASSERT(info.isShort == isShort);
gcHeap += info.gcHeap;
mallocHeap += info.mallocHeap;
}
uint32_t numCopies:31; // How many copies of the string have we seen?
uint32_t isShort:1; // Is it a short string?
uint32_t numCopies; // How many copies of the string have we seen?
// These are all totals across all copies of the string we've seen.
size_t gcHeap;

View File

@ -56,15 +56,7 @@ InefficientNonFlatteningStringHashPolicy::hash(const Lookup &l)
chars = ownedChars;
}
// We include the result of isShort() in the hash. This is because it is
// possible for a particular string (i.e. unique char sequence) to have one
// or more copies as short strings and one or more copies as non-short
// strings, and treating them separately for the purposes of notable string
// detection makes things simpler. In practice, although such collisions
// do happen, they are sufficiently rare that they are unlikely to have a
// significant effect on which strings are considered notable.
return mozilla::AddToHash(mozilla::HashString(chars, l->length()),
l->isShort());
return mozilla::HashString(chars, l->length());
}
/* static */ bool
@ -74,10 +66,6 @@ InefficientNonFlatteningStringHashPolicy::match(const JSString *const &k, const
if (k->length() != l->length())
return false;
// Just like in hash(), we must consider isShort() for the two strings.
if (k->isShort() != l->isShort())
return false;
const jschar *c1;
ScopedJSFreePtr<jschar> ownedChars1;
if (k->hasPureChars()) {
@ -255,6 +243,9 @@ enum Granularity {
CoarseGrained // Corresponds to AddSizeOfTab()
};
// The various kinds of hashing are expensive, and the results are unused when
// doing coarse-grained measurements. Skipping them more than doubles the
// profile speed for complex pages such as gmail.com.
template <Granularity granularity>
static void
StatsCellCallback(JSRuntime *rt, void *data, void *thing, JSGCTraceKind traceKind,
@ -289,28 +280,18 @@ StatsCellCallback(JSRuntime *rt, void *data, void *thing, JSGCTraceKind traceKin
case JSTRACE_STRING: {
JSString *str = static_cast<JSString *>(thing);
bool isShort = str->isShort();
size_t strCharsSize = str->sizeOfExcludingThis(rtStats->mallocSizeOf_);
zStats->stringsGCHeap += thingSize;
zStats->stringsMallocHeap += strCharsSize;
if (isShort) {
zStats->stringsShortGCHeap += thingSize;
MOZ_ASSERT(strCharsSize == 0);
} else {
zStats->stringsNormalGCHeap += thingSize;
zStats->stringsNormalMallocHeap += strCharsSize;
}
// This string hashing is expensive. Its results are unused when doing
// coarse-grained measurements, and skipping it more than doubles the
// profile speed for complex pages such as gmail.com.
if (granularity == FineGrained) {
ZoneStats::StringsHashMap::AddPtr p = zStats->strings->lookupForAdd(str);
if (!p) {
JS::StringInfo info(isShort, thingSize, strCharsSize);
JS::StringInfo info(thingSize, strCharsSize);
zStats->strings->add(p, str, info);
} else {
p->value().add(isShort, thingSize, strCharsSize);
p->value().add(thingSize, strCharsSize);
}
}
@ -423,16 +404,10 @@ FindNotableStrings(ZoneStats &zStats)
// We're moving this string from a non-notable to a notable bucket, so
// subtract it out of the non-notable tallies.
if (info.isShort) {
MOZ_ASSERT(zStats.stringsShortGCHeap >= info.gcHeap);
zStats.stringsShortGCHeap -= info.gcHeap;
MOZ_ASSERT(info.mallocHeap == 0);
} else {
MOZ_ASSERT(zStats.stringsNormalGCHeap >= info.gcHeap);
MOZ_ASSERT(zStats.stringsNormalMallocHeap >= info.mallocHeap);
zStats.stringsNormalGCHeap -= info.gcHeap;
zStats.stringsNormalMallocHeap -= info.mallocHeap;
}
MOZ_ASSERT(zStats.stringsGCHeap >= info.gcHeap);
MOZ_ASSERT(zStats.stringsMallocHeap >= info.mallocHeap);
zStats.stringsGCHeap -= info.gcHeap;
zStats.stringsMallocHeap -= info.mallocHeap;
}
}

View File

@ -1892,23 +1892,14 @@ ReportZoneStats(const JS::ZoneStats &zStats,
}
}
ZCREPORT_GC_BYTES(pathPrefix + NS_LITERAL_CSTRING("strings/short-gc-heap"),
zStats.stringsShortGCHeap,
"Memory on the garbage-collected JavaScript "
"heap that holds headers for strings which are short "
"enough to be stored completely within the header. That "
"is, a 'short' string uses no string-chars.");
ZCREPORT_GC_BYTES(pathPrefix + NS_LITERAL_CSTRING("strings/non-notable/gc-heap"),
zStats.stringsGCHeap,
"Memory on the garbage-collected JavaScript heap that "
"holds string headers. The character data for such "
"strings is counted under strings/non-notable/malloc-heap.");
ZCREPORT_GC_BYTES(pathPrefix + NS_LITERAL_CSTRING("strings/normal/gc-heap"),
zStats.stringsNormalGCHeap,
"Memory on the garbage-collected JavaScript "
"heap that holds string headers for strings which are too "
"long to fit entirely within the header. The character "
"data for such strings is counted under "
"strings/normal/malloc-heap.");
ZCREPORT_BYTES(pathPrefix + NS_LITERAL_CSTRING("strings/normal/malloc-heap"),
zStats.stringsNormalMallocHeap,
ZCREPORT_BYTES(pathPrefix + NS_LITERAL_CSTRING("strings/non-notable/malloc-heap"),
zStats.stringsMallocHeap,
"Memory allocated to hold characters for strings which are too long "
"to fit entirely within their string headers.\n\n"
"Sometimes more memory is allocated than necessary, to "