mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 03:45:46 +00:00
Bug 937751, part 3 - Protect against reentrancy with when incrementally CCing. r=smaug
Cycle collection protects against reentrancy by setting a flag to indicate a collection is in progress. With synchronous CC, it is okay to set this in BeginCollection, and clear it in CleanupAfterCollection. With ICC, this must be set and cleared in every slice, so I moved the fixing of it to Collect. I also changed the name of the variable, because we can be in the middle of an ICC without the CC being actively running, and it is only the latter we are worried about here.
This commit is contained in:
parent
b33d8d0c09
commit
c77f88b2f3
@ -1006,7 +1006,7 @@ class nsCycleCollector : public MemoryMultiReporter
|
||||
{
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
bool mCollectionInProgress;
|
||||
bool mActivelyCollecting;
|
||||
// mScanInProgress should be false when we're collecting white objects.
|
||||
bool mScanInProgress;
|
||||
CycleCollectorResults mResults;
|
||||
@ -2552,7 +2552,7 @@ nsCycleCollector::CollectReports(nsIHandleReportCallback* aHandleReport,
|
||||
|
||||
nsCycleCollector::nsCycleCollector() :
|
||||
MemoryMultiReporter("cycle-collector"),
|
||||
mCollectionInProgress(false),
|
||||
mActivelyCollecting(false),
|
||||
mScanInProgress(false),
|
||||
mJSRuntime(nullptr),
|
||||
mIncrementalPhase(IdlePhase),
|
||||
@ -2679,7 +2679,6 @@ nsCycleCollector::CleanupAfterCollection()
|
||||
{
|
||||
MOZ_ASSERT(mIncrementalPhase == CleanupPhase);
|
||||
mGraph.Clear();
|
||||
mCollectionInProgress = false;
|
||||
|
||||
#ifdef XP_OS2
|
||||
// Now that the cycle collector has freed some memory, we can try to
|
||||
@ -2725,9 +2724,10 @@ nsCycleCollector::Collect(ccType aCCType,
|
||||
CheckThreadSafety();
|
||||
|
||||
// This can legitimately happen in a few cases. See bug 383651.
|
||||
if (mCollectionInProgress) {
|
||||
if (mActivelyCollecting) {
|
||||
return false;
|
||||
}
|
||||
mActivelyCollecting = true;
|
||||
|
||||
MOZ_ASSERT(mIncrementalPhase == IdlePhase);
|
||||
|
||||
@ -2736,6 +2736,7 @@ nsCycleCollector::Collect(ccType aCCType,
|
||||
ScanRoots();
|
||||
bool collectedAny = CollectWhite();
|
||||
CleanupAfterCollection();
|
||||
mActivelyCollecting = false;
|
||||
|
||||
MOZ_ASSERT(mIncrementalPhase == IdlePhase);
|
||||
|
||||
@ -2786,8 +2787,6 @@ nsCycleCollector::BeginCollection(ccType aCCType,
|
||||
|
||||
mCollectionStart = TimeStamp::Now();
|
||||
|
||||
mCollectionInProgress = true;
|
||||
|
||||
if (mJSRuntime) {
|
||||
mJSRuntime->BeginCycleCollectionCallback();
|
||||
timeLog.Checkpoint("BeginCycleCollectionCallback()");
|
||||
|
Loading…
Reference in New Issue
Block a user