Bug 977940, part 2 - Don't automatically trigger the ghost window detector during ICC. r=smaug

This commit is contained in:
Andrew McCreight 2014-03-08 05:38:53 -08:00
parent 441f162633
commit b6035c87a3
3 changed files with 34 additions and 1 deletions

View File

@ -31,7 +31,9 @@ StaticRefPtr<nsWindowMemoryReporter> sWindowReporter;
const int32_t kTimeBetweenChecks = 45; /* seconds */
nsWindowMemoryReporter::nsWindowMemoryReporter()
: mLastCheckForGhostWindows(TimeStamp::NowLoRes())
: mLastCheckForGhostWindows(TimeStamp::NowLoRes()),
mCycleCollectorIsRunning(false),
mCheckTimerWaitingForCCEnd(false)
{
}
@ -116,6 +118,10 @@ nsWindowMemoryReporter::Init()
/* weakRef = */ true);
os->AddObserver(sWindowReporter, "after-minimize-memory-usage",
/* weakRef = */ true);
os->AddObserver(sWindowReporter, "cycle-collector-begin",
/* weakRef = */ true);
os->AddObserver(sWindowReporter, "cycle-collector-end",
/* weakRef = */ true);
}
RegisterStrongMemoryReporter(new GhostWindowsReporter());
@ -619,6 +625,18 @@ nsWindowMemoryReporter::Observe(nsISupports *aSubject, const char *aTopic,
ObserveDOMWindowDetached(aSubject);
} else if (!strcmp(aTopic, "after-minimize-memory-usage")) {
ObserveAfterMinimizeMemoryUsage();
} else if (!strcmp(aTopic, "cycle-collector-begin")) {
if (mCheckTimer) {
mCheckTimerWaitingForCCEnd = true;
KillCheckTimer();
}
mCycleCollectorIsRunning = true;
} else if (!strcmp(aTopic, "cycle-collector-end")) {
mCycleCollectorIsRunning = false;
if (mCheckTimerWaitingForCCEnd) {
mCheckTimerWaitingForCCEnd = false;
AsyncCheckForGhostWindows();
}
} else {
MOZ_ASSERT(false);
}
@ -645,6 +663,7 @@ void
nsWindowMemoryReporter::CheckTimerFired(nsITimer* aTimer, void* aClosure)
{
if (sWindowReporter) {
MOZ_ASSERT(!sWindowReporter->mCycleCollectorIsRunning);
sWindowReporter->CheckForGhostWindows();
}
}
@ -656,6 +675,11 @@ nsWindowMemoryReporter::AsyncCheckForGhostWindows()
return;
}
if (mCycleCollectorIsRunning) {
mCheckTimerWaitingForCCEnd = true;
return;
}
// If more than kTimeBetweenChecks seconds have elapsed since the last check,
// timerDelay is 0. Otherwise, it is kTimeBetweenChecks, reduced by the time
// since the last check. Reducing the delay by the time since the last check

View File

@ -237,6 +237,10 @@ private:
mozilla::TimeStamp mLastCheckForGhostWindows;
nsCOMPtr<nsITimer> mCheckTimer;
bool mCycleCollectorIsRunning;
bool mCheckTimerWaitingForCCEnd;
};
#endif // nsWindowMemoryReporter_h__

View File

@ -729,6 +729,11 @@ void
XPCJSRuntime::EndCycleCollectionCallback(CycleCollectorResults &aResults)
{
nsJSContext::EndCycleCollectionCallback(aResults);
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
if (obs) {
obs->NotifyObservers(nullptr, "cycle-collector-end", nullptr);
}
}
void