Bug 943744 (part 1) - Remove StringInfo::length. r=till.
authorNicholas Nethercote <nnethercote@mozilla.com>
Mon, 02 Dec 2013 21:40:25 -0800
changeset 173528 4b89621c00ca4ffbff369f0a0e9071d11edf7004
parent 173527 87468d6fc9361e5bce74ee4306c4538ddafd07dd
child 173529 a00cff07e0f0c780034556515f2057bd702e59d7
push id3224
push userlsblakk@mozilla.com
push dateTue, 04 Feb 2014 01:06:49 +0000
treeherdermozilla-beta@60c04d0987f1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstill
bugs943744
milestone28.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 943744 (part 1) - Remove StringInfo::length. r=till.
js/public/MemoryMetrics.h
js/src/vm/MemoryMetrics.cpp
--- a/js/public/MemoryMetrics.h
+++ b/js/public/MemoryMetrics.h
@@ -210,54 +210,48 @@ struct CodeSizes
 };
 
 // This class holds information about the memory taken up by identical copies of
 // a particular string.  Multiple JSStrings may have their sizes aggregated
 // together into one StringInfo object.
 struct StringInfo
 {
     StringInfo()
-      : length(0), numCopies(0), shortGCHeap(0), normalGCHeap(0), normalMallocHeap(0)
+      : numCopies(0), shortGCHeap(0), normalGCHeap(0), normalMallocHeap(0)
     {}
 
-    StringInfo(size_t len, size_t shorts, size_t normals, size_t chars)
-      : length(len),
-        numCopies(1),
+    StringInfo(size_t shorts, size_t normals, size_t chars)
+      : numCopies(1),
         shortGCHeap(shorts),
         normalGCHeap(normals),
         normalMallocHeap(chars)
     {}
 
     void add(size_t shorts, size_t normals, size_t chars) {
         shortGCHeap += shorts;
         normalGCHeap += normals;
         normalMallocHeap += chars;
         numCopies++;
     }
 
     void add(const StringInfo& info) {
-        MOZ_ASSERT(length == info.length);
-
         shortGCHeap += info.shortGCHeap;
         normalGCHeap += info.normalGCHeap;
         normalMallocHeap += info.normalMallocHeap;
         numCopies += info.numCopies;
     }
 
     size_t totalSizeOf() const {
         return shortGCHeap + normalGCHeap + normalMallocHeap;
     }
 
     size_t totalGCHeapSizeOf() const {
         return shortGCHeap + normalGCHeap;
     }
 
-    // The string's length, excluding the null-terminator.
-    size_t length;
-
     // How many copies of the string have we seen?
     size_t numCopies;
 
     // These are all totals across all copies of the string we've seen.
     size_t shortGCHeap;
     size_t normalGCHeap;
     size_t normalMallocHeap;
 };
@@ -281,16 +275,17 @@ struct NotableStringInfo : public String
 
     // A string needs to take up this many bytes of storage before we consider
     // it to be "notable".
     static size_t notableSize() {
         return js::MemoryReportingSundriesThreshold();
     }
 
     char *buffer;
+    size_t length;
 
   private:
     NotableStringInfo(const NotableStringInfo& info) MOZ_DELETE;
 };
 
 // These measurements relate directly to the JSRuntime, and not to zones and
 // compartments within it.
 struct RuntimeSizes
--- a/js/src/vm/MemoryMetrics.cpp
+++ b/js/src/vm/MemoryMetrics.cpp
@@ -89,21 +89,24 @@ InefficientNonFlatteningStringHashPolicy
     return PodEqual(c1, c2, k->length());
 }
 
 } // namespace js
 
 namespace JS {
 
 NotableStringInfo::NotableStringInfo()
-  : buffer(0)
-{}
+  : buffer(0),
+    length(0)
+{
+}
 
 NotableStringInfo::NotableStringInfo(JSString *str, const StringInfo &info)
-  : StringInfo(info)
+  : StringInfo(info),
+    length(str->length())
 {
     size_t bufferSize = Min(str->length() + 1, size_t(4096));
     buffer = js_pod_malloc<char>(bufferSize);
     if (!buffer) {
         MOZ_CRASH("oom");
     }
 
     const jschar* chars;
@@ -118,17 +121,18 @@ NotableStringInfo::NotableStringInfo(JSS
 
     // We might truncate |str| even if it's much shorter than 4096 chars, if
     // |str| contains unicode chars.  Since this is just for a memory reporter,
     // we don't care.
     PutEscapedString(buffer, bufferSize, chars, str->length(), /* quote */ 0);
 }
 
 NotableStringInfo::NotableStringInfo(NotableStringInfo &&info)
-  : StringInfo(Move(info))
+  : StringInfo(Move(info)),
+    length(info.length)
 {
     buffer = info.buffer;
     info.buffer = nullptr;
 }
 
 NotableStringInfo &NotableStringInfo::operator=(NotableStringInfo &&info)
 {
     MOZ_ASSERT(this != &info, "self-move assignment is prohibited");
@@ -280,17 +284,17 @@ StatsCellCallback(JSRuntime *rt, void *d
         size_t normalStringThingSize = !str->isShort() ? thingSize : 0;
 
         // 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(str->length(), shortStringThingSize,
+                JS::StringInfo info(shortStringThingSize,
                                     normalStringThingSize, strCharsSize);
                 zStats->strings.add(p, str, info);
             } else {
                 p->value().add(shortStringThingSize, normalStringThingSize, strCharsSize);
             }
         }
 
         zStats->stringsShortGCHeap += shortStringThingSize;