Bug 1029648 - Calculate GCRuntime::highFrequencyGC once rather than once per zone r=terrence
authorJon Coppeard <jcoppeard@mozilla.com>
Wed, 02 Jul 2014 08:06:49 +0100
changeset 192177 c76b804566e9663ee15b8b568f02180a2dbd43dd
parent 192176 055d2b0cec5785fdcb9972c7e487a7f410c2b622
child 192178 41da9bcec12e83e9c50c606d43801ad80cfe09fc
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersterrence
bugs1029648
milestone33.0a1
Bug 1029648 - Calculate GCRuntime::highFrequencyGC once rather than once per zone r=terrence
js/src/jsgc.cpp
--- a/js/src/jsgc.cpp
+++ b/js/src/jsgc.cpp
@@ -1691,34 +1691,31 @@ GCRuntime::computeHeapGrowthFactor(size_
 
     double factor;
     if (!dynamicHeapGrowth) {
         factor = 3.0;
     } else if (lastBytes < 1 * 1024 * 1024) {
         factor = lowFrequencyHeapGrowth;
     } else {
         JS_ASSERT(highFrequencyHighLimitBytes > highFrequencyLowLimitBytes);
-        uint64_t now = PRMJ_Now();
-        if (lastGCTime && lastGCTime + highFrequencyTimeThreshold * PRMJ_USEC_PER_MSEC > now) {
+        if (highFrequencyGC) {
             if (lastBytes <= highFrequencyLowLimitBytes) {
                 factor = highFrequencyHeapGrowthMax;
             } else if (lastBytes >= highFrequencyHighLimitBytes) {
                 factor = highFrequencyHeapGrowthMin;
             } else {
                 double k = (highFrequencyHeapGrowthMin - highFrequencyHeapGrowthMax)
                            / (double)(highFrequencyHighLimitBytes - highFrequencyLowLimitBytes);
                 factor = (k * (lastBytes - highFrequencyLowLimitBytes)
                                      + highFrequencyHeapGrowthMax);
                 JS_ASSERT(factor <= highFrequencyHeapGrowthMax
                           && factor >= highFrequencyHeapGrowthMin);
             }
-            highFrequencyGC = true;
         } else {
             factor = lowFrequencyHeapGrowth;
-            highFrequencyGC = false;
         }
     }
 
     return factor;
 }
 
 void
 Zone::setGCLastBytes(size_t lastBytes, JSGCInvocationKind gckind)
@@ -4471,16 +4468,20 @@ GCRuntime::endSweepPhase(JSGCInvocationK
 
         rt->freeLifoAlloc.freeAll();
 
         /* Ensure the compartments get swept if it's the last GC. */
         if (lastGC)
             sweepZones(&fop, lastGC);
     }
 
+    uint64_t currentTime = PRMJ_Now();
+    highFrequencyGC = dynamicHeapGrowth && lastGCTime &&
+        lastGCTime + highFrequencyTimeThreshold * PRMJ_USEC_PER_MSEC > currentTime;
+
     for (ZonesIter zone(rt, WithAtoms); !zone.done(); zone.next()) {
         zone->setGCLastBytes(zone->gcBytes, gckind);
         if (zone->isCollecting()) {
             JS_ASSERT(zone->isGCFinished());
             zone->setGCState(Zone::NoGC);
         }
 
 #ifdef DEBUG
@@ -4504,17 +4505,17 @@ GCRuntime::endSweepPhase(JSGCInvocationK
             if (e.front().key().kind != CrossCompartmentKey::StringWrapper)
                 AssertNotOnGrayList(&e.front().value().get().toObject());
         }
     }
 #endif
 
     finishMarkingValidation();
 
-    lastGCTime = PRMJ_Now();
+    lastGCTime = currentTime;
 }
 
 /* Start a new heap session. */
 AutoTraceSession::AutoTraceSession(JSRuntime *rt, js::HeapState heapState)
   : lock(rt),
     runtime(rt),
     prevState(rt->gc.heapState)
 {