Bug 1263355 - Report memory metrics for Scopes. (r=njn)
authorShu-yu Guo <shu@rfrn.org>
Thu, 25 Aug 2016 01:28:47 -0700
changeset 311177 18bec78f348ee0c68deba76a5da5529ece455393
parent 311176 cb6fc6d38f8df50e25502dc55ee1ed2dd3d7a304
child 311178 19267e198cd9a52e4471d26eba1ea9c2d96afbbc
push id30603
push userkwierso@gmail.com
push dateThu, 25 Aug 2016 23:59:44 +0000
treeherdermozilla-central@8f6cbb5a8f4a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnjn
bugs1263355
milestone51.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 1263355 - Report memory metrics for Scopes. (r=njn)
js/public/MemoryMetrics.h
js/src/vm/MemoryMetrics.cpp
js/src/vm/Scope.cpp
js/src/vm/Scope.h
js/xpconnect/src/XPCJSRuntime.cpp
--- a/js/public/MemoryMetrics.h
+++ b/js/public/MemoryMetrics.h
@@ -571,16 +571,17 @@ struct UnusedGCThingSizes
     macro(Other, GCHeapUnused, script) \
     macro(Other, GCHeapUnused, lazyScript) \
     macro(Other, GCHeapUnused, shape) \
     macro(Other, GCHeapUnused, baseShape) \
     macro(Other, GCHeapUnused, objectGroup) \
     macro(Other, GCHeapUnused, string) \
     macro(Other, GCHeapUnused, symbol) \
     macro(Other, GCHeapUnused, jitcode) \
+    macro(Other, GCHeapUnused, scope)
 
     UnusedGCThingSizes()
       : FOR_EACH_SIZE(ZERO_SIZE)
         dummy()
     {}
 
     UnusedGCThingSizes(UnusedGCThingSizes&& other)
       : FOR_EACH_SIZE(COPY_OTHER_SIZE)
@@ -593,16 +594,17 @@ struct UnusedGCThingSizes
           case JS::TraceKind::String:       string += n;      break;
           case JS::TraceKind::Symbol:       symbol += n;      break;
           case JS::TraceKind::Script:       script += n;      break;
           case JS::TraceKind::Shape:        shape += n;       break;
           case JS::TraceKind::BaseShape:    baseShape += n;   break;
           case JS::TraceKind::JitCode:      jitcode += n;     break;
           case JS::TraceKind::LazyScript:   lazyScript += n;  break;
           case JS::TraceKind::ObjectGroup:  objectGroup += n; break;
+          case JS::TraceKind::Scope:        scope += n;       break;
           default:
             MOZ_CRASH("Bad trace kind for UnusedGCThingSizes");
         }
     }
 
     void addSizes(const UnusedGCThingSizes& other) {
         FOR_EACH_SIZE(ADD_OTHER_SIZE)
     }
@@ -632,16 +634,18 @@ struct ZoneStats
 #define FOR_EACH_SIZE(macro) \
     macro(Other,   GCHeapUsed,  symbolsGCHeap) \
     macro(Other,   GCHeapAdmin, gcHeapArenaAdmin) \
     macro(Other,   GCHeapUsed,  lazyScriptsGCHeap) \
     macro(Other,   MallocHeap,  lazyScriptsMallocHeap) \
     macro(Other,   GCHeapUsed,  jitCodesGCHeap) \
     macro(Other,   GCHeapUsed,  objectGroupsGCHeap) \
     macro(Other,   MallocHeap,  objectGroupsMallocHeap) \
+    macro(Other,   GCHeapUsed,  scopesGCHeap) \
+    macro(Other,   MallocHeap,  scopesMallocHeap) \
     macro(Other,   MallocHeap,  typePool) \
     macro(Other,   MallocHeap,  baselineStubsOptimized) \
     macro(Other,   MallocHeap,  uniqueIdMap) \
     macro(Other,   MallocHeap,  shapeTables)
 
     ZoneStats()
       : FOR_EACH_SIZE(ZERO_SIZE)
         unusedGCThings(),
--- a/js/src/vm/MemoryMetrics.cpp
+++ b/js/src/vm/MemoryMetrics.cpp
@@ -584,16 +584,23 @@ StatsCellCallback(JSRuntime* rt, void* d
 
       case JS::TraceKind::ObjectGroup: {
         ObjectGroup* group = static_cast<ObjectGroup*>(thing);
         zStats->objectGroupsGCHeap += thingSize;
         zStats->objectGroupsMallocHeap += group->sizeOfExcludingThis(rtStats->mallocSizeOf_);
         break;
       }
 
+      case JS::TraceKind::Scope: {
+        Scope* scope = static_cast<Scope*>(thing);
+        zStats->scopesGCHeap += thingSize;
+        zStats->scopesMallocHeap += scope->sizeOfExcludingThis(rtStats->mallocSizeOf_);
+        break;
+      }
+
       default:
         MOZ_CRASH("invalid traceKind in StatsCellCallback");
     }
 
     // Yes, this is a subtraction:  see StatsArenaCallback() for details.
     zStats->unusedGCThings.addToKind(traceKind, -thingSize);
 }
 
--- a/js/src/vm/Scope.cpp
+++ b/js/src/vm/Scope.cpp
@@ -379,16 +379,24 @@ void
 Scope::finalize(FreeOp* fop)
 {
     if (data_) {
         fop->free_(reinterpret_cast<void*>(data_));
         data_ = 0;
     }
 }
 
+size_t
+Scope::sizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) const
+{
+    if (data_)
+        return mallocSizeOf(reinterpret_cast<void*>(data_));
+    return 0;
+}
+
 void
 Scope::dump()
 {
     for (ScopeIter si(this); si; si++) {
         fprintf(stderr, "%s [%p]", ScopeKindString(si.kind()), si.scope());
         if (si.scope()->enclosing())
             fprintf(stderr, " -> ");
     }
--- a/js/src/vm/Scope.h
+++ b/js/src/vm/Scope.h
@@ -281,16 +281,18 @@ class Scope : public js::gc::TenuredCell
         return false;
     }
 
     static Scope* clone(JSContext* cx, HandleScope scope, HandleScope enclosing);
 
     void traceChildren(JSTracer* trc);
     void finalize(FreeOp* fop);
 
+    size_t sizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
+
     void dump();
 };
 
 //
 // A lexical scope that holds let and const bindings. There are 4 kinds of
 // LexicalScopes.
 //
 // Lexical
--- a/js/xpconnect/src/XPCJSRuntime.cpp
+++ b/js/xpconnect/src/XPCJSRuntime.cpp
@@ -1939,30 +1939,38 @@ ReportZoneStats(const JS::ZoneStats& zSt
         "Tables storing shape information.");
 
     ZCREPORT_GC_BYTES(pathPrefix + NS_LITERAL_CSTRING("lazy-scripts/gc-heap"),
         zStats.lazyScriptsGCHeap,
         "Scripts that haven't executed yet.");
 
     ZCREPORT_BYTES(pathPrefix + NS_LITERAL_CSTRING("lazy-scripts/malloc-heap"),
         zStats.lazyScriptsMallocHeap,
-        "Lazy script tables containing free variables or inner functions.");
+        "Lazy script tables containing closed-over bindings or inner functions.");
 
     ZCREPORT_GC_BYTES(pathPrefix + NS_LITERAL_CSTRING("jit-codes-gc-heap"),
         zStats.jitCodesGCHeap,
         "References to executable code pools used by the JITs.");
 
     ZCREPORT_GC_BYTES(pathPrefix + NS_LITERAL_CSTRING("object-groups/gc-heap"),
         zStats.objectGroupsGCHeap,
         "Classification and type inference information about objects.");
 
     ZCREPORT_BYTES(pathPrefix + NS_LITERAL_CSTRING("object-groups/malloc-heap"),
         zStats.objectGroupsMallocHeap,
         "Object group addenda.");
 
+    ZCREPORT_GC_BYTES(pathPrefix + NS_LITERAL_CSTRING("scopes/gc-heap"),
+        zStats.scopesGCHeap,
+        "Scope information for scripts.");
+
+    ZCREPORT_BYTES(pathPrefix + NS_LITERAL_CSTRING("scopes/malloc-heap"),
+        zStats.scopesMallocHeap,
+        "Arrays of binding names and other binding-related data.");
+
     ZCREPORT_BYTES(pathPrefix + NS_LITERAL_CSTRING("type-pool"),
         zStats.typePool,
         "Type sets and related data.");
 
     ZCREPORT_BYTES(pathPrefix + NS_LITERAL_CSTRING("baseline/optimized-stubs"),
         zStats.baselineStubsOptimized,
         "The Baseline JIT's optimized IC stubs (excluding code).");
 
@@ -2952,16 +2960,20 @@ JSReporter::CollectReports(WindowPaths* 
     REPORT_BYTES(NS_LITERAL_CSTRING("js-main-runtime-gc-heap-committed/unused/gc-things/base-shapes"),
         KIND_OTHER, rtStats.zTotals.unusedGCThings.baseShape,
         "Unused base shape cells within non-empty arenas.");
 
     REPORT_BYTES(NS_LITERAL_CSTRING("js-main-runtime-gc-heap-committed/unused/gc-things/object-groups"),
         KIND_OTHER, rtStats.zTotals.unusedGCThings.objectGroup,
         "Unused object group cells within non-empty arenas.");
 
+    REPORT_BYTES(NS_LITERAL_CSTRING("js-main-runtime-gc-heap-committed/unused/gc-things/scopes"),
+        KIND_OTHER, rtStats.zTotals.unusedGCThings.scope,
+        "Unused scope cells within non-empty arenas.");
+
     REPORT_BYTES(NS_LITERAL_CSTRING("js-main-runtime-gc-heap-committed/unused/gc-things/scripts"),
         KIND_OTHER, rtStats.zTotals.unusedGCThings.script,
         "Unused script cells within non-empty arenas.");
 
     REPORT_BYTES(NS_LITERAL_CSTRING("js-main-runtime-gc-heap-committed/unused/gc-things/lazy-scripts"),
         KIND_OTHER, rtStats.zTotals.unusedGCThings.lazyScript,
         "Unused lazy script cells within non-empty arenas.");
 
@@ -2999,16 +3011,20 @@ JSReporter::CollectReports(WindowPaths* 
     MREPORT_BYTES(NS_LITERAL_CSTRING("js-main-runtime-gc-heap-committed/used/gc-things/base-shapes"),
         KIND_OTHER, rtStats.zTotals.shapeInfo.shapesGCHeapBase,
         "Used base shape cells.");
 
     MREPORT_BYTES(NS_LITERAL_CSTRING("js-main-runtime-gc-heap-committed/used/gc-things/object-groups"),
         KIND_OTHER, rtStats.zTotals.objectGroupsGCHeap,
         "Used object group cells.");
 
+    MREPORT_BYTES(NS_LITERAL_CSTRING("js-main-runtime-gc-heap-committed/used/gc-things/scopes"),
+        KIND_OTHER, rtStats.zTotals.scopesGCHeap,
+        "Used scope cells.");
+
     MREPORT_BYTES(NS_LITERAL_CSTRING("js-main-runtime-gc-heap-committed/used/gc-things/scripts"),
         KIND_OTHER, rtStats.cTotals.scriptsGCHeap,
         "Used script cells.");
 
     MREPORT_BYTES(NS_LITERAL_CSTRING("js-main-runtime-gc-heap-committed/used/gc-things/lazy-scripts"),
         KIND_OTHER, rtStats.zTotals.lazyScriptsGCHeap,
         "Used lazy script cells.");