Bug 1194555 - Part 0: Cleanup GetReportsState constructor. r=njn
authorEric Rahm <erahm@mozilla.com>
Wed, 14 Oct 2015 16:52:52 -0700
changeset 301180 e093cc10d7ca892d8bab175c3bdfcb8fb74787e8
parent 301179 fe814c6566479f9b567239e057839bae87a5810b
child 301181 647ea5d7f72675182fc31340feb4eade8f5cde70
push id5392
push userraliiev@mozilla.com
push dateMon, 14 Dec 2015 20:08:23 +0000
treeherdermozilla-beta@16ce8562a975 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnjn
bugs1194555
milestone44.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 1194555 - Part 0: Cleanup GetReportsState constructor. r=njn Move GetReportsState ctor to the impl so that mChildrenPending doesn't have to be heap allocated.
xpcom/base/nsMemoryReporterManager.cpp
xpcom/base/nsMemoryReporterManager.h
--- a/xpcom/base/nsMemoryReporterManager.cpp
+++ b/xpcom/base/nsMemoryReporterManager.cpp
@@ -1433,17 +1433,16 @@ nsMemoryReporterManager::GetReportsExten
                                          aAnonymize,
                                          aMinimize,
                                          concurrency,
                                          aHandleReport,
                                          aHandleReportData,
                                          aFinishReporting,
                                          aFinishReportingData,
                                          aDMDDumpIdent);
-  mGetReportsState->mChildrenPending = new nsTArray<nsRefPtr<mozilla::dom::ContentParent>>();
 
   if (aMinimize) {
     rv = MinimizeMemoryUsage(NS_NewRunnableMethod(
       this, &nsMemoryReporterManager::StartGettingReports));
   } else {
     rv = StartGettingReports();
   }
   return rv;
@@ -1474,17 +1473,17 @@ nsMemoryReporterManager::StartGettingRep
   ContentParent::GetAll(childWeakRefs);
   if (!childWeakRefs.IsEmpty()) {
     // Request memory reports from child processes.  This happens
     // after the parent report so that the parent's main thread will
     // be free to process the child reports, instead of causing them
     // to be buffered and consume (possibly scarce) memory.
 
     for (size_t i = 0; i < childWeakRefs.Length(); ++i) {
-      s->mChildrenPending->AppendElement(childWeakRefs[i]);
+      s->mChildrenPending.AppendElement(childWeakRefs[i]);
     }
 
     nsCOMPtr<nsITimer> timer = do_CreateInstance(NS_TIMER_CONTRACTID);
     // Don't use NS_ENSURE_* here; can't return until the report is finished.
     if (NS_WARN_IF(!timer)) {
       FinishReporting();
       return NS_ERROR_FAILURE;
     }
@@ -1671,39 +1670,39 @@ nsMemoryReporterManager::EndProcessRepor
   MOZ_ASSERT(s->mNumProcessesRunning > 0);
   s->mNumProcessesRunning--;
   s->mNumProcessesCompleted++;
   MEMORY_REPORTING_LOG("HandleChildReports (aGen=%u): process %u %s"
                        " (%u running, %u pending)\n",
                        aGeneration, s->mNumProcessesCompleted,
                        aSuccess ? "completed" : "exited during report",
                        s->mNumProcessesRunning,
-                       static_cast<unsigned>(s->mChildrenPending->Length()));
+                       static_cast<unsigned>(s->mChildrenPending.Length()));
 
   // Start pending children up to the concurrency limit.
   while (s->mNumProcessesRunning < s->mConcurrencyLimit &&
-         !s->mChildrenPending->IsEmpty()) {
+         !s->mChildrenPending.IsEmpty()) {
     // Pop last element from s->mChildrenPending
     nsRefPtr<ContentParent> nextChild;
-    nextChild.swap(s->mChildrenPending->LastElement());
-    s->mChildrenPending->TruncateLength(s->mChildrenPending->Length() - 1);
+    nextChild.swap(s->mChildrenPending.LastElement());
+    s->mChildrenPending.TruncateLength(s->mChildrenPending.Length() - 1);
     // Start report (if the child is still alive and not Nuwa).
     if (StartChildReport(nextChild, s)) {
       ++s->mNumProcessesRunning;
       MEMORY_REPORTING_LOG("HandleChildReports (aGen=%u): started child report"
                            " (%u running, %u pending)\n",
                            aGeneration, s->mNumProcessesRunning,
-                           static_cast<unsigned>(s->mChildrenPending->Length()));
+                           static_cast<unsigned>(s->mChildrenPending.Length()));
     }
   }
 
   // If all the child processes (if any) have reported, we can cancel
   // the timer (if started) and finish up.  Otherwise, just return.
   if (s->mNumProcessesRunning == 0) {
-    MOZ_ASSERT(s->mChildrenPending->IsEmpty());
+    MOZ_ASSERT(s->mChildrenPending.IsEmpty());
     if (s->mTimer) {
       s->mTimer->Cancel();
     }
     FinishReporting();
   }
 }
 
 /* static */ void
@@ -1713,17 +1712,17 @@ nsMemoryReporterManager::TimeoutCallback
   GetReportsState* s = mgr->mGetReportsState;
 
   // Release assert because: if the pointer is null we're about to
   // crash regardless of DEBUG, and this way the compiler doesn't
   // complain about unused variables.
   MOZ_RELEASE_ASSERT(s, "mgr->mGetReportsState");
   MEMORY_REPORTING_LOG("TimeoutCallback (s->gen=%u; %u running, %u pending)\n",
                        s->mGeneration, s->mNumProcessesRunning,
-                       static_cast<unsigned>(s->mChildrenPending->Length()));
+                       static_cast<unsigned>(s->mChildrenPending.Length()));
 
   // We don't bother sending any kind of cancellation message to the child
   // processes that haven't reported back.
   mgr->FinishReporting();
 }
 
 nsresult
 nsMemoryReporterManager::FinishReporting()
@@ -1744,19 +1743,37 @@ nsMemoryReporterManager::FinishReporting
   nsresult rv = mGetReportsState->mFinishReporting->Callback(
     mGetReportsState->mFinishReportingData);
 
   delete mGetReportsState;
   mGetReportsState = nullptr;
   return rv;
 }
 
-nsMemoryReporterManager::GetReportsState::~GetReportsState()
+nsMemoryReporterManager::GetReportsState::GetReportsState(
+    uint32_t aGeneration, bool aAnonymize, bool aMinimize,
+    uint32_t aConcurrencyLimit,
+    nsIHandleReportCallback* aHandleReport,
+    nsISupports* aHandleReportData,
+    nsIFinishReportingCallback* aFinishReporting,
+    nsISupports* aFinishReportingData,
+    const nsAString& aDMDDumpIdent)
+  : mGeneration(aGeneration)
+  , mAnonymize(aAnonymize)
+  , mMinimize(aMinimize)
+  , mChildrenPending()
+  , mNumProcessesRunning(1) // reporting starts with the parent
+  , mNumProcessesCompleted(0)
+  , mConcurrencyLimit(aConcurrencyLimit)
+  , mHandleReport(aHandleReport)
+  , mHandleReportData(aHandleReportData)
+  , mFinishReporting(aFinishReporting)
+  , mFinishReportingData(aFinishReportingData)
+  , mDMDDumpIdent(aDMDDumpIdent)
 {
-  delete mChildrenPending;
 }
 
 static void
 CrashIfRefcountIsZero(nsISupports* aObj)
 {
   // This will probably crash if the object's refcount is 0.
   uint32_t refcnt = NS_ADDREF(aObj);
   if (refcnt <= 1) {
--- a/xpcom/base/nsMemoryReporterManager.h
+++ b/xpcom/base/nsMemoryReporterManager.h
@@ -206,52 +206,33 @@ private:
   uint32_t mNextGeneration;
 
   struct GetReportsState
   {
     uint32_t                             mGeneration;
     bool                                 mAnonymize;
     bool                                 mMinimize;
     nsCOMPtr<nsITimer>                   mTimer;
-    // This is a pointer to an nsTArray because otherwise C++ is
-    // unhappy unless this header includes ContentParent.h, which not
-    // everything that includes this header knows how to find.
-    nsTArray<nsRefPtr<mozilla::dom::ContentParent>>* mChildrenPending;
+    nsTArray<nsRefPtr<mozilla::dom::ContentParent>> mChildrenPending;
     uint32_t                             mNumProcessesRunning;
     uint32_t                             mNumProcessesCompleted;
     uint32_t                             mConcurrencyLimit;
     nsCOMPtr<nsIHandleReportCallback>    mHandleReport;
     nsCOMPtr<nsISupports>                mHandleReportData;
     nsCOMPtr<nsIFinishReportingCallback> mFinishReporting;
     nsCOMPtr<nsISupports>                mFinishReportingData;
     nsString                             mDMDDumpIdent;
 
     GetReportsState(uint32_t aGeneration, bool aAnonymize, bool aMinimize,
                     uint32_t aConcurrencyLimit,
                     nsIHandleReportCallback* aHandleReport,
                     nsISupports* aHandleReportData,
                     nsIFinishReportingCallback* aFinishReporting,
                     nsISupports* aFinishReportingData,
-                    const nsAString& aDMDDumpIdent)
-      : mGeneration(aGeneration)
-      , mAnonymize(aAnonymize)
-      , mMinimize(aMinimize)
-      , mChildrenPending(nullptr)
-      , mNumProcessesRunning(1) // reporting starts with the parent
-      , mNumProcessesCompleted(0)
-      , mConcurrencyLimit(aConcurrencyLimit)
-      , mHandleReport(aHandleReport)
-      , mHandleReportData(aHandleReportData)
-      , mFinishReporting(aFinishReporting)
-      , mFinishReportingData(aFinishReportingData)
-      , mDMDDumpIdent(aDMDDumpIdent)
-    {
-    }
-
-    ~GetReportsState();
+                    const nsAString& aDMDDumpIdent);
   };
 
   // When this is non-null, a request is in flight.  Note: We use manual
   // new/delete for this because its lifetime doesn't match block scope or
   // anything like that.
   GetReportsState* mGetReportsState;
 
   GetReportsState* GetStateForGeneration(uint32_t aGeneration);