From f15f25613ce8ba0e6274fdbc65afbc8fd928aca0 Mon Sep 17 00:00:00 2001 From: Eric Rahm Date: Tue, 6 Oct 2015 11:23:30 -0700 Subject: [PATCH] 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 | 39 ++++++++++++++++++-------- xpcom/base/nsMemoryReporterManager.h | 23 ++------------- 2 files changed, 30 insertions(+), 32 deletions(-) diff --git a/xpcom/base/nsMemoryReporterManager.cpp b/xpcom/base/nsMemoryReporterManager.cpp index 4deb7883969..5139ab2af36 100644 --- a/xpcom/base/nsMemoryReporterManager.cpp +++ b/xpcom/base/nsMemoryReporterManager.cpp @@ -1438,7 +1438,6 @@ nsMemoryReporterManager::GetReportsExtended( aFinishReporting, aFinishReportingData, aDMDDumpIdent); - mGetReportsState->mChildrenPending = new nsTArray>(); if (aMinimize) { rv = MinimizeMemoryUsage(NS_NewRunnableMethod( @@ -1479,7 +1478,7 @@ nsMemoryReporterManager::StartGettingReports() // 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 timer = do_CreateInstance(NS_TIMER_CONTRACTID); @@ -1676,29 +1675,29 @@ nsMemoryReporterManager::EndProcessReport(uint32_t aGeneration, bool aSuccess) aGeneration, s->mNumProcessesCompleted, aSuccess ? "completed" : "exited during report", s->mNumProcessesRunning, - static_cast(s->mChildrenPending->Length())); + static_cast(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 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(s->mChildrenPending->Length())); + static_cast(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(); } @@ -1718,7 +1717,7 @@ nsMemoryReporterManager::TimeoutCallback(nsITimer* aTimer, void* aData) MOZ_RELEASE_ASSERT(s, "mgr->mGetReportsState"); MEMORY_REPORTING_LOG("TimeoutCallback (s->gen=%u; %u running, %u pending)\n", s->mGeneration, s->mNumProcessesRunning, - static_cast(s->mChildrenPending->Length())); + static_cast(s->mChildrenPending.Length())); // We don't bother sending any kind of cancellation message to the child // processes that haven't reported back. @@ -1749,9 +1748,27 @@ nsMemoryReporterManager::FinishReporting() 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 diff --git a/xpcom/base/nsMemoryReporterManager.h b/xpcom/base/nsMemoryReporterManager.h index 152e83a69b1..4adfa60b80a 100644 --- a/xpcom/base/nsMemoryReporterManager.h +++ b/xpcom/base/nsMemoryReporterManager.h @@ -211,10 +211,7 @@ private: bool mAnonymize; bool mMinimize; nsCOMPtr 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>* mChildrenPending; + nsTArray> mChildrenPending; uint32_t mNumProcessesRunning; uint32_t mNumProcessesCompleted; uint32_t mConcurrencyLimit; @@ -230,23 +227,7 @@ private: 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