From e4b1a62a1a79eb411680384cc6079cbef6d8e881 Mon Sep 17 00:00:00 2001 From: Andrew McCreight Date: Wed, 20 Nov 2013 14:35:16 -0800 Subject: [PATCH] Bug 935721, part 3 - Use RAII to set mScanInProgress, hoist out MarkRoots and ScanRoots. r=smaug With ICC, mScanInProgress gets set and cleared a bunch of times so add an RAII class to turn it on when we're doing stuff and clear it when we're not. With that in place, we can easily move MarkRoots and ScanRoots out of BeginCollection in preparation for making them separate phases in ICC. --- xpcom/base/nsCycleCollector.cpp | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/xpcom/base/nsCycleCollector.cpp b/xpcom/base/nsCycleCollector.cpp index 26e3c6fc2ad4..be85e04b68ed 100644 --- a/xpcom/base/nsCycleCollector.cpp +++ b/xpcom/base/nsCycleCollector.cpp @@ -98,12 +98,13 @@ #include "base/process_util.h" +#include "mozilla/AutoRestore.h" +#include "mozilla/CycleCollectedJSRuntime.h" /* This must occur *after* base/process_util.h to avoid typedefs conflicts. */ #include "mozilla/MemoryReporting.h" #include "mozilla/Util.h" #include "mozilla/LinkedList.h" -#include "mozilla/CycleCollectedJSRuntime.h" #include "nsCycleCollectionParticipant.h" #include "nsCycleCollectionNoteRootCallback.h" #include "nsDeque.h" @@ -2150,6 +2151,11 @@ nsCycleCollector::ForgetSkippable(bool aRemoveChildlessNodes, MOZ_NEVER_INLINE void nsCycleCollector::MarkRoots() { + TimeLog timeLog; + AutoRestore ar(mScanInProgress); + MOZ_ASSERT(!mScanInProgress); + mScanInProgress = true; + mGraph.mRootCount = mBuilder->Count(); // read the PtrInfo out of the graph that we are building @@ -2172,6 +2178,7 @@ nsCycleCollector::MarkRoots() } mBuilder = nullptr; + timeLog.Checkpoint("MarkRoots()"); } @@ -2294,6 +2301,10 @@ nsCycleCollector::ScanWeakMaps() void nsCycleCollector::ScanRoots() { + TimeLog timeLog; + AutoRestore ar(mScanInProgress); + MOZ_ASSERT(!mScanInProgress); + mScanInProgress = true; mWhiteNodeCount = 0; // On the assumption that most nodes will be black, it's @@ -2336,6 +2347,7 @@ nsCycleCollector::ScanRoots() mListener->End(); mListener = nullptr; } + timeLog.Checkpoint("ScanRoots()"); } @@ -2714,6 +2726,8 @@ nsCycleCollector::Collect(ccType aCCType, PrepareForCollection(aResults, aWhiteNodes); BeginCollection(aCCType, aManualListener); + MarkRoots(); + ScanRoots(); bool collectedAny = CollectWhite(); CleanupAfterCollection(); return collectedAny; @@ -2804,18 +2818,11 @@ nsCycleCollector::BeginCollection(ccType aCCType, timeLog.Checkpoint("mJSRuntime->BeginCycleCollection()"); } + AutoRestore ar(mScanInProgress); + MOZ_ASSERT(!mScanInProgress); mScanInProgress = true; mPurpleBuf.SelectPointers(*mBuilder); timeLog.Checkpoint("SelectPointers()"); - - // The main Bacon & Rajan collection algorithm. - MarkRoots(); - timeLog.Checkpoint("MarkRoots()"); - - ScanRoots(); - timeLog.Checkpoint("ScanRoots()"); - - mScanInProgress = false; } uint32_t