From e4ec6f1178198cdd90ec309d93de3e8e0694ba68 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Thu, 16 Aug 2018 16:47:54 -0400 Subject: [PATCH] Bug 1483650 - Remove the component registration for nsCycleCollectorLogger; r=mccr8 --- dom/interfaces/base/nsIDOMWindowUtils.idl | 4 ---- js/xpconnect/idl/xpccomponents.idl | 8 ++++++++ js/xpconnect/src/XPCComponents.cpp | 11 +++++++++++ js/xpconnect/src/nsXPConnect.cpp | 9 +++------ xpcom/base/nsCycleCollector.cpp | 15 ++++----------- xpcom/base/nsCycleCollector.h | 1 + xpcom/base/nsICycleCollectorListener.idl | 10 ++++++---- xpcom/base/nsMemoryInfoDumper.cpp | 6 ++---- xpcom/build/XPCOMModule.inc | 1 - xpcom/build/nsXPCOMCID.h | 5 ----- 10 files changed, 35 insertions(+), 35 deletions(-) diff --git a/dom/interfaces/base/nsIDOMWindowUtils.idl b/dom/interfaces/base/nsIDOMWindowUtils.idl index 6788cc4fac7b..22f9f768f8d0 100644 --- a/dom/interfaces/base/nsIDOMWindowUtils.idl +++ b/dom/interfaces/base/nsIDOMWindowUtils.idl @@ -687,8 +687,6 @@ interface nsIDOMWindowUtils : nsISupports { * 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); @@ -699,8 +697,6 @@ interface nsIDOMWindowUtils : nsISupports { * 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); diff --git a/js/xpconnect/idl/xpccomponents.idl b/js/xpconnect/idl/xpccomponents.idl index 66642e547845..7ac275dc2ef8 100644 --- a/js/xpconnect/idl/xpccomponents.idl +++ b/js/xpconnect/idl/xpccomponents.idl @@ -296,6 +296,14 @@ interface nsIXPCComponents_Utils : nsISupports */ 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. * diff --git a/js/xpconnect/src/XPCComponents.cpp b/js/xpconnect/src/XPCComponents.cpp index e69cdbae4aa4..5e5b02114dec 100644 --- a/js/xpconnect/src/XPCComponents.cpp +++ b/js/xpconnect/src/XPCComponents.cpp @@ -31,6 +31,7 @@ #include "mozilla/Scheduler.h" #include "nsZipArchive.h" #include "nsWindowMemoryReporter.h" +#include "nsICycleCollectorListener.h" #include "nsIException.h" #include "nsIScriptError.h" #include "nsISimpleEnumerator.h" @@ -2317,6 +2318,16 @@ nsXPCComponents_Utils::ForceCC(nsICycleCollectorListener* listener) return NS_OK; } +NS_IMETHODIMP +nsXPCComponents_Utils::CreateCCLogger(nsICycleCollectorListener** aListener) +{ + NS_ENSURE_ARG_POINTER(aListener); + nsCOMPtr logger = + nsCycleCollector_createLogger(); + logger.forget(aListener); + return NS_OK; +} + NS_IMETHODIMP nsXPCComponents_Utils::FinishCC() { diff --git a/js/xpconnect/src/nsXPConnect.cpp b/js/xpconnect/src/nsXPConnect.cpp index 754e61de60b3..65abe63f71d8 100644 --- a/js/xpconnect/src/nsXPConnect.cpp +++ b/js/xpconnect/src/nsXPConnect.cpp @@ -32,6 +32,7 @@ #include "nsDOMMutationObserver.h" #include "nsICycleCollectorListener.h" +#include "nsCycleCollector.h" #include "nsIObjectInputStream.h" #include "nsIObjectOutputStream.h" #include "nsScriptSecurityManager.h" @@ -1111,12 +1112,8 @@ DumpJSStack() MOZ_EXPORT void DumpCompleteHeap() { - nsCOMPtr listener = - do_CreateInstance("@mozilla.org/cycle-collector-logger;1"); - if (!listener) { - NS_WARNING("Failed to create CC logger"); - return; - } + nsCOMPtr listener = nsCycleCollector_createLogger(); + MOZ_ASSERT(listener); nsCOMPtr alltracesListener; listener->AllTraces(getter_AddRefs(alltracesListener)); diff --git a/xpcom/base/nsCycleCollector.cpp b/xpcom/base/nsCycleCollector.cpp index 796bccd1c20b..b04913ad4e86 100644 --- a/xpcom/base/nsCycleCollector.cpp +++ b/xpcom/base/nsCycleCollector.cpp @@ -2050,18 +2050,11 @@ private: NS_IMPL_ISUPPORTS(nsCycleCollectorLogger, nsICycleCollectorListener) -nsresult -nsCycleCollectorLoggerConstructor(nsISupports* aOuter, - const nsIID& aIID, - void** aInstancePtr) +already_AddRefed +nsCycleCollector_createLogger() { - if (NS_WARN_IF(aOuter)) { - return NS_ERROR_NO_AGGREGATION; - } - - nsISupports* logger = new nsCycleCollectorLogger(); - - return logger->QueryInterface(aIID, aInstancePtr); + nsCOMPtr logger = new nsCycleCollectorLogger(); + return logger.forget(); } static bool diff --git a/xpcom/base/nsCycleCollector.h b/xpcom/base/nsCycleCollector.h index 7f18afa8e675..ba36fc7f7dcc 100644 --- a/xpcom/base/nsCycleCollector.h +++ b/xpcom/base/nsCycleCollector.h @@ -46,6 +46,7 @@ bool nsCycleCollector_doDeferredDeletion(); bool nsCycleCollector_doDeferredDeletionWithBudget(js::SliceBudget& aBudget); already_AddRefed nsCycleCollector_createLogSink(); +already_AddRefed nsCycleCollector_createLogger(); void nsCycleCollector_collect(nsICycleCollectorListener* aManualListener); diff --git a/xpcom/base/nsICycleCollectorListener.idl b/xpcom/base/nsICycleCollectorListener.idl index cfdf9abe90c9..ad6ec0020f81 100644 --- a/xpcom/base/nsICycleCollectorListener.idl +++ b/xpcom/base/nsICycleCollectorListener.idl @@ -16,7 +16,7 @@ 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. @@ -24,7 +24,7 @@ interface nsIFile; /** * 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 @@ -98,8 +98,10 @@ interface nsICycleCollectorLogSink : nsISupports * * 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. diff --git a/xpcom/base/nsMemoryInfoDumper.cpp b/xpcom/base/nsMemoryInfoDumper.cpp index 92c316d0c522..c95550cc98e1 100644 --- a/xpcom/base/nsMemoryInfoDumper.cpp +++ b/xpcom/base/nsMemoryInfoDumper.cpp @@ -384,8 +384,7 @@ nsMemoryInfoDumper::DumpGCAndCCLogsToFile(const nsAString& aIdentifier, } } - nsCOMPtr logger = - do_CreateInstance("@mozilla.org/cycle-collector-logger;1"); + nsCOMPtr logger = nsCycleCollector_createLogger(); if (aDumpAllTraces) { nsCOMPtr allTracesLogger; @@ -412,8 +411,7 @@ NS_IMETHODIMP nsMemoryInfoDumper::DumpGCAndCCLogsToSink(bool aDumpAllTraces, nsICycleCollectorLogSink* aSink) { - nsCOMPtr logger = - do_CreateInstance("@mozilla.org/cycle-collector-logger;1"); + nsCOMPtr logger = nsCycleCollector_createLogger(); if (aDumpAllTraces) { nsCOMPtr allTracesLogger; diff --git a/xpcom/build/XPCOMModule.inc b/xpcom/build/XPCOMModule.inc index 308a5d9a83c3..ee2e0d2134df 100644 --- a/xpcom/build/XPCOMModule.inc +++ b/xpcom/build/XPCOMModule.inc @@ -72,5 +72,4 @@ 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) diff --git a/xpcom/build/nsXPCOMCID.h b/xpcom/build/nsXPCOMCID.h index 0a4983d62e31..9d83a832b158 100644 --- a/xpcom/build/nsXPCOMCID.h +++ b/xpcom/build/nsXPCOMCID.h @@ -76,11 +76,6 @@ */ #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 */