From eb8fe4ffcfb971c51c08c417b32e4909269396f7 Mon Sep 17 00:00:00 2001 From: Jon Coppeard Date: Wed, 2 Jul 2014 08:05:58 +0100 Subject: [PATCH] Bug 1032750 - Don't update GC triggers on uncollected zones r=terrence --- js/src/gc/Zone.cpp | 7 +++++++ js/src/gc/Zone.h | 2 ++ js/src/jsgc.cpp | 13 ++++++++----- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/js/src/gc/Zone.cpp b/js/src/gc/Zone.cpp index 898cd63c6fd..997f9ad800e 100644 --- a/js/src/gc/Zone.cpp +++ b/js/src/gc/Zone.cpp @@ -107,6 +107,13 @@ Zone::onTooMuchMalloc() } } +bool +Zone::isCloseToAllocTrigger(bool highFrequencyGC) const +{ + double factor = highFrequencyGC ? 0.85 : 0.9; + return usage.gcBytes() >= factor * threshold.gcTriggerBytes(); +} + void Zone::beginSweepTypes(FreeOp *fop, bool releaseTypes) { diff --git a/js/src/gc/Zone.h b/js/src/gc/Zone.h index 6f4173e98f0..3a867e43f71 100644 --- a/js/src/gc/Zone.h +++ b/js/src/gc/Zone.h @@ -153,6 +153,8 @@ struct Zone : public JS::shadow::Zone, bool isTooMuchMalloc() const { return gcMallocBytes <= 0; } void onTooMuchMalloc(); + bool isCloseToAllocTrigger(bool highFrequencyGC) const; + void *onOutOfMemory(void *p, size_t nbytes) { return runtimeFromMainThread()->onOutOfMemory(p, nbytes); } diff --git a/js/src/jsgc.cpp b/js/src/jsgc.cpp index 6101eae98f8..e4e5f6796d9 100644 --- a/js/src/jsgc.cpp +++ b/js/src/jsgc.cpp @@ -1113,7 +1113,7 @@ GCRuntime::GCRuntime(JSRuntime *rt) : verifyPostData(nullptr), chunkAllocationSinceLastGC(false), nextFullGCTime(0), - lastGCTime(0), + lastGCTime(PRMJ_Now()), mode(JSGC_MODE_INCREMENTAL), decommitThreshold(32 * 1024 * 1024), cleanUpEverything(false), @@ -3308,9 +3308,8 @@ GCRuntime::maybeGC(Zone *zone) if (gcIfNeeded()) return true; - double factor = schedulingState.inHighFrequencyGCMode() ? 0.85 : 0.9; if (zone->usage.gcBytes() > 1024 * 1024 && - zone->usage.gcBytes() >= factor * zone->threshold.gcTriggerBytes() && + zone->isCloseToAllocTrigger(schedulingState.inHighFrequencyGCMode()) && incrementalState == NO_INCREMENTAL && !isBackgroundSweeping()) { @@ -5628,10 +5627,10 @@ GCRuntime::finishCollection() schedulingState.updateHighFrequencyMode(lastGCTime, currentTime, tunables); for (ZonesIter zone(rt, WithAtoms); !zone.done(); zone.next()) { - zone->threshold.updateAfterGC(zone->usage.gcBytes(), invocationKind, tunables, - schedulingState); if (zone->isCollecting()) { MOZ_ASSERT(zone->isGCFinished() || zone->isGCCompacting()); + zone->threshold.updateAfterGC(zone->usage.gcBytes(), invocationKind, tunables, + schedulingState); zone->setGCState(Zone::NoGC); zone->active = false; } @@ -6219,6 +6218,10 @@ GCRuntime::scanZonesBeforeGC() if (incrementalState != NO_INCREMENTAL && zone->needsIncrementalBarrier()) zone->scheduleGC(); + /* This is a heuristic to reduce the total number of collections. */ + if (zone->isCloseToAllocTrigger(schedulingState.inHighFrequencyGCMode())) + zone->scheduleGC(); + zoneStats.zoneCount++; if (zone->isGCScheduled()) { zoneStats.collectedZoneCount++;