mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-15 06:15:43 +00:00
Bug 965916 - Do an extra GC on memory pressure if it would be productive. r=smaug
This commit is contained in:
parent
9792594199
commit
caa9fa4d60
@ -238,6 +238,16 @@ KillTimers()
|
||||
nsJSContext::KillInterSliceGCTimer();
|
||||
}
|
||||
|
||||
// If we collected a substantial amount of cycles, poke the GC since more objects
|
||||
// might be unreachable now.
|
||||
static bool
|
||||
NeedsGCAfterCC()
|
||||
{
|
||||
return sCCollectedWaitingForGC > 250 ||
|
||||
sLikelyShortLivingObjectsNeedingGC > 2500 ||
|
||||
sNeedsGCAfterCC;
|
||||
}
|
||||
|
||||
class nsJSEnvironmentObserver MOZ_FINAL : public nsIObserver
|
||||
{
|
||||
public:
|
||||
@ -263,6 +273,12 @@ nsJSEnvironmentObserver::Observe(nsISupports* aSubject, const char* aTopic,
|
||||
nsJSContext::NonCompartmentGC,
|
||||
nsJSContext::ShrinkingGC);
|
||||
nsJSContext::CycleCollectNow();
|
||||
if (NeedsGCAfterCC()) {
|
||||
nsJSContext::GarbageCollectNow(JS::gcreason::MEM_PRESSURE,
|
||||
nsJSContext::NonIncrementalGC,
|
||||
nsJSContext::NonCompartmentGC,
|
||||
nsJSContext::ShrinkingGC);
|
||||
}
|
||||
} else if (!nsCRT::strcmp(aTopic, "quit-application")) {
|
||||
sShuttingDown = true;
|
||||
KillTimers();
|
||||
@ -2215,11 +2231,7 @@ nsJSContext::EndCycleCollectionCallback(CycleCollectorResults &aResults)
|
||||
|
||||
sCCollectedWaitingForGC += aResults.mFreedRefCounted + aResults.mFreedGCed;
|
||||
|
||||
// If we collected a substantial amount of cycles, poke the GC since more objects
|
||||
// might be unreachable now.
|
||||
if (sCCollectedWaitingForGC > 250 ||
|
||||
sLikelyShortLivingObjectsNeedingGC > 2500 ||
|
||||
sNeedsGCAfterCC) {
|
||||
if (NeedsGCAfterCC()) {
|
||||
PokeGC(JS::gcreason::CC_WAITING);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user