Bug 831193 (part 3) - Don't use NS_MEMORY_REPORTER_IMPLEMENT in XPCJSRuntime.cpp. r=terrence.
authorNicholas Nethercote <nnethercote@mozilla.com>
Tue, 15 Jan 2013 21:28:35 -0800
changeset 144666 76345eaa94fcf61a5e8dfcba7462887e974dd22a
parent 144665 9af570dfad86b8735f08456d4ce0dd047113082d
child 144667 3b94a25c83dffe5aff859dbb9f3b5beaf3900849
push id25171
push useremorley@mozilla.com
push dateWed, 28 Aug 2013 15:20:13 +0000
treeherdermozilla-central@f280351a238f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersterrence
bugs831193
milestone26.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 831193 (part 3) - Don't use NS_MEMORY_REPORTER_IMPLEMENT in XPCJSRuntime.cpp. r=terrence.
js/xpconnect/src/XPCJSRuntime.cpp
--- a/js/xpconnect/src/XPCJSRuntime.cpp
+++ b/js/xpconnect/src/XPCJSRuntime.cpp
@@ -1549,87 +1549,95 @@ GetCompartmentName(JSCompartment *c, nsC
         // (such as about:memory) have to undo this change.
         if (replaceSlashes)
             name.ReplaceChar('/', '\\');
     } else {
         name.AssignLiteral("null-principal");
     }
 }
 
-static int64_t
-GetGCChunkTotalBytes()
+// Telemetry relies on this being a single reporter (rather than part of the
+// "js" multi-reporter).
+class JSGCHeapReporter MOZ_FINAL : public MemoryReporterBase
 {
-    JSRuntime *rt = nsXPConnect::GetRuntimeInstance()->Runtime();
-    return int64_t(JS_GetGCParameter(rt, JSGC_TOTAL_CHUNKS)) * js::gc::ChunkSize;
-}
-
-// Telemetry relies on this memory reporter being a single-reporter (rather
-// than part of the "js" multi-reporter, which is too slow to run during a
-// telemetry ping).
-NS_MEMORY_REPORTER_IMPLEMENT(XPConnectJSGCHeap,
-                             "js-gc-heap",
-                             KIND_OTHER,
-                             nsIMemoryReporter::UNITS_BYTES,
-                             GetGCChunkTotalBytes,
-                             "Memory used by the garbage-collected JavaScript heap.")
-
-static int64_t
-GetJSSystemCompartmentCount()
-{
-    return JS::SystemCompartmentCount(nsXPConnect::GetRuntimeInstance()->Runtime());
-}
-
-static int64_t
-GetJSUserCompartmentCount()
-{
-    return JS::UserCompartmentCount(nsXPConnect::GetRuntimeInstance()->Runtime());
-}
-
-// Nb: js-system-compartment-count + js-user-compartment-count could be
+public:
+    JSGCHeapReporter()
+      : MemoryReporterBase("js-gc-heap", KIND_OTHER, UNITS_BYTES,
+"Memory used by the garbage-collected JavaScript heap.")
+    {}
+private:
+    int64_t Amount() MOZ_OVERRIDE
+    {
+        JSRuntime *rt = nsXPConnect::GetRuntimeInstance()->Runtime();
+        return int64_t(JS_GetGCParameter(rt, JSGC_TOTAL_CHUNKS)) *
+               js::gc::ChunkSize;
+    }
+};
+
+// Nb: js-compartments/system + js-compartments/user could be
 // different to the number of compartments reported by
 // JSMemoryMultiReporter if a garbage collection occurred
 // between them being consulted.  We could move these reporters into
 // XPConnectJSCompartmentCount to avoid that problem, but then we couldn't
 // easily report them via telemetry, so we live with the small risk of
 // inconsistencies.
-NS_MEMORY_REPORTER_IMPLEMENT(XPConnectJSSystemCompartmentCount,
-    "js-compartments/system",
-    KIND_OTHER,
-    nsIMemoryReporter::UNITS_COUNT,
-    GetJSSystemCompartmentCount,
-    "The number of JavaScript compartments for system code.  The sum of this "
-    "and 'js-compartments-user' might not match the number of compartments "
-    "listed under 'js' if a garbage collection occurs at an inopportune time, "
-    "but such cases should be rare.")
-
-NS_MEMORY_REPORTER_IMPLEMENT(XPConnectJSUserCompartmentCount,
-    "js-compartments/user",
-    KIND_OTHER,
-    nsIMemoryReporter::UNITS_COUNT,
-    GetJSUserCompartmentCount,
-    "The number of JavaScript compartments for user code.  The sum of this "
-    "and 'js-compartments-system' might not match the number of compartments "
-    "listed under 'js' if a garbage collection occurs at an inopportune time, "
-    "but such cases should be rare.")
-
-static int64_t
-GetJSMainRuntimeTemporaryPeakSize()
+
+class JSCompartmentsSystemReporter MOZ_FINAL : public MemoryReporterBase
 {
-    return JS::PeakSizeOfTemporary(nsXPConnect::GetRuntimeInstance()->Runtime());
-}
+public:
+    JSCompartmentsSystemReporter()
+      : MemoryReporterBase("js-compartments/system", KIND_OTHER, UNITS_COUNT,
+"The number of JavaScript compartments for system code.  The sum of this and "
+"'js-compartments/user' might not match the number of compartments listed "
+"in the 'explicit' tree if a garbage collection occurs at an inopportune "
+"time, but such cases should be rare.")
+    {}
+private:
+    int64_t Amount() MOZ_OVERRIDE
+    {
+        JSRuntime *rt = nsXPConnect::GetRuntimeInstance()->Runtime();
+        return JS::SystemCompartmentCount(rt);
+    }
+};
+
+class JSCompartmentsUserReporter MOZ_FINAL : public MemoryReporterBase
+{
+public:
+    JSCompartmentsUserReporter()
+      : MemoryReporterBase("js-compartments/user", KIND_OTHER, UNITS_COUNT,
+"The number of JavaScript compartments for user code.  The sum of this and "
+"'js-compartments/system' might not match the number of compartments listed "
+"under 'js' if a garbage collection occurs at an inopportune time, but such "
+"cases should be rare.")
+    {}
+private:
+    int64_t Amount() MOZ_OVERRIDE
+    {
+        JSRuntime *rt = nsXPConnect::GetRuntimeInstance()->Runtime();
+        return JS::UserCompartmentCount(rt);
+    }
+};
 
 // This is also a single reporter so it can be used by telemetry.
-NS_MEMORY_REPORTER_IMPLEMENT(JSMainRuntimeTemporaryPeak,
-    "js-main-runtime-temporary-peak",
-    KIND_OTHER,
-    nsIMemoryReporter::UNITS_BYTES,
-    GetJSMainRuntimeTemporaryPeakSize,
-    "The peak size of the transient storage in the main JSRuntime (the "
-    "current size of which is reported as "
-    "'explicit/js-non-window/runtime/temporary').");
+class JSMainRuntimeTemporaryPeakReporter MOZ_FINAL : public MemoryReporterBase
+{
+public:
+    JSMainRuntimeTemporaryPeakReporter()
+      : MemoryReporterBase("js-main-runtime-temporary-peak",
+                           KIND_OTHER, UNITS_BYTES,
+"The peak size of the transient storage in the main JSRuntime (the current "
+"size of which is reported as 'explicit/js-non-window/runtime/temporary').")
+    {}
+private:
+    int64_t Amount() MOZ_OVERRIDE
+    {
+        JSRuntime *rt = nsXPConnect::GetRuntimeInstance()->Runtime();
+        return JS::PeakSizeOfTemporary(rt);
+    }
+};
 
 // The REPORT* macros do an unconditional report.  The ZCREPORT* macros are for
 // compartments and zones; they aggregate any entries smaller than
 // SUNDRIES_THRESHOLD into the "sundries/gc-heap" and "sundries/malloc-heap"
 // entries for the compartment.
 
 #define SUNDRIES_THRESHOLD js::MemoryReportingSundriesThreshold()
 
@@ -2967,20 +2975,20 @@ XPCJSRuntime::XPCJSRuntime(nsXPConnect* 
     JS_SetSourceHook(runtime, SourceHook);
 
     // Set up locale information and callbacks for the newly-created runtime so
     // that the various toLocaleString() methods, localeCompare(), and other
     // internationalization APIs work as desired.
     if (!xpc_LocalizeRuntime(runtime))
         NS_RUNTIMEABORT("xpc_LocalizeRuntime failed.");
 
-    NS_RegisterMemoryReporter(new NS_MEMORY_REPORTER_NAME(XPConnectJSGCHeap));
-    NS_RegisterMemoryReporter(new NS_MEMORY_REPORTER_NAME(XPConnectJSSystemCompartmentCount));
-    NS_RegisterMemoryReporter(new NS_MEMORY_REPORTER_NAME(XPConnectJSUserCompartmentCount));
-    NS_RegisterMemoryReporter(new NS_MEMORY_REPORTER_NAME(JSMainRuntimeTemporaryPeak));
+    NS_RegisterMemoryReporter(new JSGCHeapReporter());
+    NS_RegisterMemoryReporter(new JSCompartmentsSystemReporter());
+    NS_RegisterMemoryReporter(new JSCompartmentsUserReporter());
+    NS_RegisterMemoryReporter(new JSMainRuntimeTemporaryPeakReporter());
     NS_RegisterMemoryMultiReporter(new JSCompartmentsMultiReporter);
 
     // Install a JavaScript 'debugger' keyword handler in debug builds only
 #ifdef DEBUG
     if (!JS_GetGlobalDebugHooks(runtime)->debuggerHandler)
         xpc_InstallJSDebuggerKeywordHandler(runtime);
 #endif
 }