Bug 937751, part 7 - Incrementalize nsCycleCollector::MarkRoots. r=smaug

Now that all of MarkRoots's state is stored on the heap, it can be run
incrementally. Like with Collect, it takes a budget to determine how
long it can run. Any residual budget will be available to the caller.

One difference is that Collect calls checkOverBudget() which always checks
the time, but MarkRoots uses isOverBudget() to determine if there is
any time remaining. This only checks the current time every
kNumNodesBetweenTimeChecks nodes, to reduce the overhead of checking.
This commit is contained in:
Andrew McCreight 2013-12-03 10:47:47 -08:00
Родитель bd8bf20017
Коммит ea3497e170
1 изменённых файлов: 13 добавлений и 4 удалений

Просмотреть файл

@ -1085,7 +1085,7 @@ private:
bool ShouldMergeZones(ccType aCCType);
void BeginCollection(ccType aCCType, nsICycleCollectorListener *aManualListener);
void MarkRoots();
void MarkRoots(SliceBudget &aBudget);
void ScanRoots();
void ScanWeakMaps();
@ -2211,8 +2211,11 @@ nsCycleCollector::ForgetSkippable(bool aRemoveChildlessNodes,
}
MOZ_NEVER_INLINE void
nsCycleCollector::MarkRoots()
nsCycleCollector::MarkRoots(SliceBudget &aBudget)
{
const intptr_t kNumNodesBetweenTimeChecks = 1000;
const intptr_t kStep = SliceBudget::CounterReset / kNumNodesBetweenTimeChecks;
TimeLog timeLog;
AutoRestore<bool> ar(mScanInProgress);
MOZ_ASSERT(!mScanInProgress);
@ -2220,14 +2223,20 @@ nsCycleCollector::MarkRoots()
MOZ_ASSERT(mIncrementalPhase == GraphBuildingPhase);
MOZ_ASSERT(mCurrNode);
while (!mCurrNode->IsDone()) {
while (!aBudget.isOverBudget() && !mCurrNode->IsDone()) {
PtrInfo *pi = mCurrNode->GetNext();
CC_AbortIfNull(pi);
mBuilder->Traverse(pi);
if (mCurrNode->AtBlockEnd()) {
mBuilder->SetLastChild();
}
aBudget.step(kStep);
}
if (!mCurrNode->IsDone()) {
return;
}
if (mGraph.mRootCount > 0) {
mBuilder->SetLastChild();
}
@ -2763,7 +2772,7 @@ nsCycleCollector::Collect(ccType aCCType,
break;
case GraphBuildingPhase:
PrintPhase("MarkRoots");
MarkRoots();
MarkRoots(aBudget);
break;
case ScanAndCollectWhitePhase:
// We do ScanRoots and CollectWhite in a single slice to ensure