Bug 1483650 - Remove the component registration for nsCycleCollectorLogger; r=mccr8
authorEhsan Akhgari <ehsan@mozilla.com>
Thu, 16 Aug 2018 16:47:54 -0400
changeset 432060 58650e51b8b7c5381f964b4404771642a5e9fb74
parent 432059 3b191205d529242b9936e97c0eb52f0dcf39239a
child 432061 94913c7ee691dd715b62b7d29fa20c2ba4fb59a9
push id34458
push userebalazs@mozilla.com
push dateFri, 17 Aug 2018 09:46:42 +0000
treeherdermozilla-central@b84213ec5a4d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmccr8
bugs1483650
milestone63.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 1483650 - Remove the component registration for nsCycleCollectorLogger; r=mccr8
dom/interfaces/base/nsIDOMWindowUtils.idl
js/xpconnect/idl/xpccomponents.idl
js/xpconnect/src/XPCComponents.cpp
js/xpconnect/src/nsXPConnect.cpp
xpcom/base/nsCycleCollector.cpp
xpcom/base/nsCycleCollector.h
xpcom/base/nsICycleCollectorListener.idl
xpcom/base/nsMemoryInfoDumper.cpp
xpcom/build/XPCOMModule.inc
xpcom/build/nsXPCOMCID.h
--- a/dom/interfaces/base/nsIDOMWindowUtils.idl
+++ b/dom/interfaces/base/nsIDOMWindowUtils.idl
@@ -682,30 +682,26 @@ interface nsIDOMWindowUtils : nsISupport
 
   /**
    * Force a garbage collection followed by a cycle collection.
    *
    * Will throw a DOM security error if called without chrome privileges in
    * non-debug builds. Available to all callers in debug builds.
    *
    * @param aListener listener that receives information about the CC graph
-   *                  (see @mozilla.org/cycle-collector-logger;1 for a logger
-   *                   component)
    */
   void garbageCollect([optional] in nsICycleCollectorListener aListener);
 
   /**
    * Force a cycle collection without garbage collection.
    *
    * Will throw a DOM security error if called without chrome privileges in
    * non-debug builds. Available to all callers in debug builds.
    *
    * @param aListener listener that receives information about the CC graph
-   *                  (see @mozilla.org/cycle-collector-logger;1 for a logger
-   *                   component)
    */
   void cycleCollect([optional] in nsICycleCollectorListener aListener);
 
   /**
    * Trigger whichever GC or CC timer is currently active and waiting to fire.
    * Don't do this too much for initiating heavy actions, like the start of a IGC.
    */
   void runNextCollectorTimer();
--- a/js/xpconnect/idl/xpccomponents.idl
+++ b/js/xpconnect/idl/xpccomponents.idl
@@ -292,16 +292,24 @@ interface nsIXPCComponents_Utils : nsISu
     /*
      * To be called from JS only.
      *
      * Force an immediate cycle collection cycle.
      */
     void forceCC([optional] in nsICycleCollectorListener aListener);
 
     /*
+     * To be called from JS only.  C++ callers should use the
+     * nsCycleCollector_createLogger() function instead.
+     *
+     * Create an instance of the built-in cycle collector logger object.
+     */
+    nsICycleCollectorListener createCCLogger();
+
+    /*
      * To be called from JS only.
      *
      * If any incremental CC is in progress, finish it. For testing.
      */
     void finishCC();
 
     /*
      * To be called from JS only.
--- a/js/xpconnect/src/XPCComponents.cpp
+++ b/js/xpconnect/src/XPCComponents.cpp
@@ -26,16 +26,17 @@
 #include "mozilla/dom/DOMException.h"
 #include "mozilla/dom/DOMExceptionBinding.h"
 #include "mozilla/dom/BindingUtils.h"
 #include "mozilla/dom/StructuredCloneTags.h"
 #include "mozilla/dom/WindowBinding.h"
 #include "mozilla/Scheduler.h"
 #include "nsZipArchive.h"
 #include "nsWindowMemoryReporter.h"
+#include "nsICycleCollectorListener.h"
 #include "nsIException.h"
 #include "nsIScriptError.h"
 #include "nsISimpleEnumerator.h"
 #include "nsPIDOMWindow.h"
 #include "nsGlobalWindow.h"
 #include "nsScriptError.h"
 #include "GeckoProfiler.h"
 
@@ -2313,16 +2314,26 @@ nsXPCComponents_Utils::ForceGC()
 NS_IMETHODIMP
 nsXPCComponents_Utils::ForceCC(nsICycleCollectorListener* listener)
 {
     nsJSContext::CycleCollectNow(listener);
     return NS_OK;
 }
 
 NS_IMETHODIMP
+nsXPCComponents_Utils::CreateCCLogger(nsICycleCollectorListener** aListener)
+{
+    NS_ENSURE_ARG_POINTER(aListener);
+    nsCOMPtr<nsICycleCollectorListener> logger =
+      nsCycleCollector_createLogger();
+    logger.forget(aListener);
+    return NS_OK;
+}
+
+NS_IMETHODIMP
 nsXPCComponents_Utils::FinishCC()
 {
     nsCycleCollector_finishAnyCurrentCollection();
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsXPCComponents_Utils::CcSlice(int64_t budget)
--- a/js/xpconnect/src/nsXPConnect.cpp
+++ b/js/xpconnect/src/nsXPConnect.cpp
@@ -27,16 +27,17 @@
 #include "mozilla/dom/DOMException.h"
 #include "mozilla/dom/DOMPrefs.h"
 #include "mozilla/dom/Exceptions.h"
 #include "mozilla/dom/Promise.h"
 #include "mozilla/dom/ResolveSystemBinding.h"
 
 #include "nsDOMMutationObserver.h"
 #include "nsICycleCollectorListener.h"
+#include "nsCycleCollector.h"
 #include "nsIObjectInputStream.h"
 #include "nsIObjectOutputStream.h"
 #include "nsScriptSecurityManager.h"
 #include "nsIPermissionManager.h"
 #include "nsIScriptError.h"
 #include "nsContentUtils.h"
 #include "nsScriptError.h"
 
@@ -1106,22 +1107,18 @@ MOZ_EXPORT void
 DumpJSStack()
 {
     xpc_DumpJSStack(true, true, false);
 }
 
 MOZ_EXPORT void
 DumpCompleteHeap()
 {
-    nsCOMPtr<nsICycleCollectorListener> listener =
-      do_CreateInstance("@mozilla.org/cycle-collector-logger;1");
-    if (!listener) {
-      NS_WARNING("Failed to create CC logger");
-      return;
-    }
+    nsCOMPtr<nsICycleCollectorListener> listener = nsCycleCollector_createLogger();
+    MOZ_ASSERT(listener);
 
     nsCOMPtr<nsICycleCollectorListener> alltracesListener;
     listener->AllTraces(getter_AddRefs(alltracesListener));
     if (!alltracesListener) {
       NS_WARNING("Failed to get all traces logger");
       return;
     }
 
--- a/xpcom/base/nsCycleCollector.cpp
+++ b/xpcom/base/nsCycleCollector.cpp
@@ -2045,28 +2045,21 @@ private:
   bool mWantAfterProcessing;
   nsCString mCurrentAddress;
   mozilla::LinkedList<CCGraphDescriber> mDescribers;
   FILE* mCCLog;
 };
 
 NS_IMPL_ISUPPORTS(nsCycleCollectorLogger, nsICycleCollectorListener)
 
-nsresult
-nsCycleCollectorLoggerConstructor(nsISupports* aOuter,
-                                  const nsIID& aIID,
-                                  void** aInstancePtr)
+already_AddRefed<nsICycleCollectorListener>
+nsCycleCollector_createLogger()
 {
-  if (NS_WARN_IF(aOuter)) {
-    return NS_ERROR_NO_AGGREGATION;
-  }
-
-  nsISupports* logger = new nsCycleCollectorLogger();
-
-  return logger->QueryInterface(aIID, aInstancePtr);
+  nsCOMPtr<nsICycleCollectorListener> logger = new nsCycleCollectorLogger();
+  return logger.forget();
 }
 
 static bool
 GCThingIsGrayCCThing(JS::GCCellPtr thing)
 {
     return AddToCCKind(thing.kind()) &&
            JS::GCThingIsMarkedGray(thing);
 }
--- a/xpcom/base/nsCycleCollector.h
+++ b/xpcom/base/nsCycleCollector.h
@@ -41,16 +41,17 @@ void nsCycleCollector_prepareForGarbageC
 void nsCycleCollector_finishAnyCurrentCollection();
 
 void nsCycleCollector_dispatchDeferredDeletion(bool aContinuation = false,
                                                bool aPurge = false);
 bool nsCycleCollector_doDeferredDeletion();
 bool nsCycleCollector_doDeferredDeletionWithBudget(js::SliceBudget& aBudget);
 
 already_AddRefed<nsICycleCollectorLogSink> nsCycleCollector_createLogSink();
+already_AddRefed<nsICycleCollectorListener> nsCycleCollector_createLogger();
 
 void nsCycleCollector_collect(nsICycleCollectorListener* aManualListener);
 
 void nsCycleCollector_collectSlice(js::SliceBudget& budget,
                                    bool aPreferShorterSlices = false);
 
 uint32_t nsCycleCollector_suspectedCount();
 
--- a/xpcom/base/nsICycleCollectorListener.idl
+++ b/xpcom/base/nsICycleCollectorListener.idl
@@ -11,25 +11,25 @@ class nsCycleCollectorLogger;
 %}
 
 [ptr] native FILE(FILE);
 [ptr] native nsCycleCollectorLoggerPtr (nsCycleCollectorLogger);
 interface nsIFile;
 
 /**
  * A set of interfaces for recording the cycle collector's work. An instance
- * of @mozilla.org/cycle-collector-logger;1 can be configured to enable various
+ * of nsICycleCollectorListener can be configured to enable various
  * options, then passed to the cycle collector when it runs.
  * Note that additional logging options are available by setting environment
  * variables, as described at the top of nsCycleCollector.cpp.
  */
 
 /**
  * nsICycleCollectorHandler is the interface JS code should implement to
- * receive the results logged by a @mozilla.org/cycle-collector-logger;1
+ * receive the results logged by an nsICycleCollectorListener
  * instance. Pass an instance of this to the logger's 'processNext' method
  * after the collection has run. This will describe the objects the cycle
  * collector visited, the edges it found, and the conclusions it reached
  * about the liveness of objects.
  *
  * In more detail:
  * - For each node in the graph:
  *   - a call is made to either |noteRefCountedObject| or |noteGCedObject|, to
@@ -93,18 +93,20 @@ interface nsICycleCollectorLogSink : nsI
 
 /**
  * This interface is used to configure some reporting options for the cycle
  * collector. This interface cannot be implemented by JavaScript code, as it
  * is called while the cycle collector is running.
  *
  * To analyze cycle collection data in JS:
  *
- * - Create an instance of @mozilla.org/cycle-collector-logger;1, which
- *   implements this interface.
+ * - Create an instance of nsICycleCollectorListener, which implements this
+ *   interface. In C++, this can be done by calling
+ *   nsCycleCollector_createLogger(). In JS, this can be done by calling
+ *   Components.utils.createCCLogger().
  *
  * - Set its |disableLog| property to true. This prevents the logger from
  *   printing messages about each method call to a temporary log file.
  *
  * - Set its |wantAfterProcessing| property to true. This tells the logger
  *   to record calls to its methods in memory. The |processNext| method
  *   returns events from this record.
  *
--- a/xpcom/base/nsMemoryInfoDumper.cpp
+++ b/xpcom/base/nsMemoryInfoDumper.cpp
@@ -379,18 +379,17 @@ nsMemoryInfoDumper::DumpGCAndCCLogsToFil
       logSink->SetFilenameIdentifier(identifier);
       logSink->SetProcessIdentifier(cp->Pid());
 
       Unused << cp->CycleCollectWithLogs(aDumpAllTraces, logSink,
                                          callbackHolder);
     }
   }
 
-  nsCOMPtr<nsICycleCollectorListener> logger =
-    do_CreateInstance("@mozilla.org/cycle-collector-logger;1");
+  nsCOMPtr<nsICycleCollectorListener> logger = nsCycleCollector_createLogger();
 
   if (aDumpAllTraces) {
     nsCOMPtr<nsICycleCollectorListener> allTracesLogger;
     logger->AllTraces(getter_AddRefs(allTracesLogger));
     logger = allTracesLogger;
   }
 
   nsCOMPtr<nsICycleCollectorLogSink> logSink;
@@ -407,18 +406,17 @@ nsMemoryInfoDumper::DumpGCAndCCLogsToFil
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsMemoryInfoDumper::DumpGCAndCCLogsToSink(bool aDumpAllTraces,
                                           nsICycleCollectorLogSink* aSink)
 {
-  nsCOMPtr<nsICycleCollectorListener> logger =
-    do_CreateInstance("@mozilla.org/cycle-collector-logger;1");
+  nsCOMPtr<nsICycleCollectorListener> logger = nsCycleCollector_createLogger();
 
   if (aDumpAllTraces) {
     nsCOMPtr<nsICycleCollectorListener> allTracesLogger;
     logger->AllTraces(getter_AddRefs(allTracesLogger));
     logger = allTracesLogger;
   }
 
   logger->SetLogSink(aSink);
--- a/xpcom/build/XPCOMModule.inc
+++ b/xpcom/build/XPCOMModule.inc
@@ -67,10 +67,9 @@
 #if defined(MOZ_WIDGET_COCOA)
     COMPONENT(MACUTILSIMPL, nsMacUtilsImplConstructor)
 #endif
 
     COMPONENT(SYSTEMINFO, nsSystemInfoConstructor)
     COMPONENT_M(MEMORY_REPORTER_MANAGER, nsMemoryReporterManagerConstructor, Module::ALLOW_IN_GPU_PROCESS)
     COMPONENT(MEMORY_INFO_DUMPER, nsMemoryInfoDumperConstructor)
     COMPONENT(IOUTIL, nsIOUtilConstructor)
-    COMPONENT(CYCLE_COLLECTOR_LOGGER, nsCycleCollectorLoggerConstructor)
     COMPONENT(MESSAGE_LOOP, nsMessageLoopConstructor)
--- a/xpcom/build/nsXPCOMCID.h
+++ b/xpcom/build/nsXPCOMCID.h
@@ -72,21 +72,16 @@
 #define NS_MEMORY_REPORTER_MANAGER_CONTRACTID "@mozilla.org/memory-reporter-manager;1"
 
 /**
  * Memory info dumper service CID
  */
 #define NS_MEMORY_INFO_DUMPER_CONTRACTID "@mozilla.org/memory-info-dumper;1"
 
 /**
- * Cycle collector logger contract id
- */
-#define NS_CYCLE_COLLECTOR_LOGGER_CONTRACTID "@mozilla.org/cycle-collector-logger;1"
-
-/**
  * nsMessageLoop contract id
  */
 #define NS_MESSAGE_LOOP_CONTRACTID "@mozilla.org/message-loop;1"
 
 #define NS_COMPARTMENT_INFO_CONTRACTID "@mozilla.org/compartment-info;1"
 
 /**
  * The following are the CIDs and Contract IDs of the nsISupports wrappers for