Bug 1029648 - Calculate GCRuntime::highFrequencyGC once rather than once per zone r=terrence
--- 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)
{