Bug 1116455 - Move Zone::isCloseToAllocTrigger() method to ZoneHeapThreshold class r=terrence
authorJon Coppeard <jcoppeard@mozilla.com>
Wed, 31 Dec 2014 10:36:04 +0000
changeset 247543 e66b5fdd480c6728db85ef8ac047f47856bd631a
parent 247542 31b943721eba82e77b8673e7ef11c749136244f0
child 247544 f996eb4935c61fa1be6fe610bb6d2536fbf285b8
push id4489
push userraliiev@mozilla.com
push dateMon, 23 Feb 2015 15:17:55 +0000
treeherdermozilla-beta@fd7c3dc24146 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersterrence
bugs1116455
milestone37.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1116455 - Move Zone::isCloseToAllocTrigger() method to ZoneHeapThreshold class r=terrence
js/src/gc/Zone.cpp
js/src/gc/Zone.h
js/src/jsgc.cpp
--- a/js/src/gc/Zone.cpp
+++ b/js/src/gc/Zone.cpp
@@ -102,23 +102,16 @@ void
 Zone::onTooMuchMalloc()
 {
     if (!gcMallocGCTriggered) {
         GCRuntime &gc = runtimeFromAnyThread()->gc;
         gcMallocGCTriggered = gc.triggerZoneGC(this, JS::gcreason::TOO_MUCH_MALLOC);
     }
 }
 
-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)
 {
     // Periodically release observed types for all scripts. This is safe to
     // do when there are no frames for the zone on the stack.
     if (active)
         releaseTypes = false;
 
--- a/js/src/gc/Zone.h
+++ b/js/src/gc/Zone.h
@@ -57,16 +57,17 @@ class ZoneHeapThreshold
   public:
     ZoneHeapThreshold()
       : gcHeapGrowthFactor_(3.0),
         gcTriggerBytes_(0)
     {}
 
     double gcHeapGrowthFactor() const { return gcHeapGrowthFactor_; }
     size_t gcTriggerBytes() const { return gcTriggerBytes_; }
+    bool isCloseToAllocTrigger(const js::gc::HeapUsage& usage, bool highFrequencyGC) const;
 
     void updateAfterGC(size_t lastBytes, JSGCInvocationKind gckind,
                        const GCSchedulingTunables &tunables, const GCSchedulingState &state);
     void updateForRemovedArena(const GCSchedulingTunables &tunables);
 
   private:
     static double computeZoneHeapGrowthFactorForHeapSize(size_t lastBytes,
                                                          const GCSchedulingTunables &tunables,
@@ -148,18 +149,16 @@ struct Zone : public JS::shadow::Zone,
         gcMallocBytes -= ptrdiff_t(nbytes);
         if (MOZ_UNLIKELY(isTooMuchMalloc()))
             onTooMuchMalloc();
     }
 
     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);
     }
     void reportAllocationOverflow() { js_ReportAllocationOverflow(nullptr); }
 
     void beginSweepTypes(js::FreeOp *fop, bool releaseTypes);
 
     bool hasMarkedCompartments();
--- a/js/src/jsgc.cpp
+++ b/js/src/jsgc.cpp
@@ -1743,16 +1743,23 @@ GCRuntime::updateMallocCounter(JS::Zone 
 
 void
 GCRuntime::onTooMuchMalloc()
 {
     if (!mallocGCTriggered)
         mallocGCTriggered = triggerGC(JS::gcreason::TOO_MUCH_MALLOC);
 }
 
+bool
+ZoneHeapThreshold::isCloseToAllocTrigger(const js::gc::HeapUsage& usage, bool highFrequencyGC) const
+{
+    double factor = highFrequencyGC ? 0.85 : 0.9;
+    return usage.gcBytes() >= factor * gcTriggerBytes();
+}
+
 /* static */ double
 ZoneHeapThreshold::computeZoneHeapGrowthFactorForHeapSize(size_t lastBytes,
                                                           const GCSchedulingTunables &tunables,
                                                           const GCSchedulingState &state)
 {
     if (!tunables.isDynamicHeapGrowthEnabled())
         return 3.0;
 
@@ -3304,17 +3311,17 @@ GCRuntime::maybeGC(Zone *zone)
         return true;
     }
 #endif
 
     if (gcIfNeeded())
         return true;
 
     if (zone->usage.gcBytes() > 1024 * 1024 &&
-        zone->isCloseToAllocTrigger(schedulingState.inHighFrequencyGCMode()) &&
+        zone->threshold.isCloseToAllocTrigger(zone->usage, schedulingState.inHighFrequencyGCMode()) &&
         incrementalState == NO_INCREMENTAL &&
         !isBackgroundSweeping())
     {
         PrepareZoneForGC(zone);
         gcSlice(GC_NORMAL, JS::gcreason::MAYBEGC);
         return true;
     }
 
@@ -6214,17 +6221,17 @@ GCRuntime::scanZonesBeforeGC()
         if (mode == JSGC_MODE_GLOBAL)
             zone->scheduleGC();
 
         /* This is a heuristic to avoid resets. */
         if (incrementalState != NO_INCREMENTAL && zone->needsIncrementalBarrier())
             zone->scheduleGC();
 
         /* This is a heuristic to reduce the total number of collections. */
-        if (zone->isCloseToAllocTrigger(schedulingState.inHighFrequencyGCMode()))
+        if (zone->threshold.isCloseToAllocTrigger(zone->usage, schedulingState.inHighFrequencyGCMode()))
             zone->scheduleGC();
 
         zoneStats.zoneCount++;
         if (zone->isGCScheduled()) {
             zoneStats.collectedZoneCount++;
             zoneStats.collectedCompartmentCount += zone->compartments.length();
         }
     }