diff --git a/js/public/SliceBudget.h b/js/public/SliceBudget.h index cea1f571eeb4..46c27392e830 100644 --- a/js/public/SliceBudget.h +++ b/js/public/SliceBudget.h @@ -37,7 +37,12 @@ struct JS_PUBLIC_API(WorkBudget) */ class JS_PUBLIC_API(SliceBudget) { - static const mozilla::TimeStamp unlimitedDeadline; + const mozilla::TimeStamp &UnlimitedDeadline() const { + static const mozilla::TimeStamp unlimitedDeadline = + mozilla::TimeStamp::Now() + mozilla::TimeDuration::Forever(); + return unlimitedDeadline; + } + static const intptr_t unlimitedStartCounter = INTPTR_MAX; bool checkOverBudget(); @@ -69,7 +74,7 @@ class JS_PUBLIC_API(SliceBudget) explicit SliceBudget(WorkBudget work); void makeUnlimited() { - deadline = unlimitedDeadline; + deadline = UnlimitedDeadline(); counter = unlimitedStartCounter; } @@ -85,7 +90,7 @@ class JS_PUBLIC_API(SliceBudget) bool isWorkBudget() const { return deadline.IsNull(); } bool isTimeBudget() const { return !deadline.IsNull() && !isUnlimited(); } - bool isUnlimited() const { return deadline == unlimitedDeadline; } + bool isUnlimited() const { return deadline == UnlimitedDeadline(); } int describe(char* buffer, size_t maxlen) const; }; diff --git a/js/src/gc/GC.cpp b/js/src/gc/GC.cpp index e52322947258..8b20f72e0e5a 100644 --- a/js/src/gc/GC.cpp +++ b/js/src/gc/GC.cpp @@ -305,7 +305,7 @@ namespace TuningDefaults { static const bool DynamicHeapGrowthEnabled = false; /* JSGC_HIGH_FREQUENCY_TIME_LIMIT */ - static const auto HighFrequencyThreshold = mozilla::TimeDuration::FromSeconds(1); + static const auto HighFrequencyThreshold = 1; // in seconds /* JSGC_HIGH_FREQUENCY_LOW_LIMIT */ static const uint64_t HighFrequencyLowLimitBytes = 100 * 1024 * 1024; @@ -346,8 +346,6 @@ namespace TuningDefaults { }}} // namespace js::gc::TuningDefaults -static const auto ONE_SECOND = mozilla::TimeDuration::FromSeconds(1); - /* * We start to incremental collection for a zone when a proportion of its * threshold is reached. This is configured by the @@ -1572,7 +1570,7 @@ GCSchedulingTunables::GCSchedulingTunables() allocThresholdFactorAvoidInterrupt_(TuningDefaults::AllocThresholdFactorAvoidInterrupt), zoneAllocDelayBytes_(TuningDefaults::ZoneAllocDelayBytes), dynamicHeapGrowthEnabled_(TuningDefaults::DynamicHeapGrowthEnabled), - highFrequencyThreshold_(TuningDefaults::HighFrequencyThreshold), + highFrequencyThreshold_(mozilla::TimeDuration::FromSeconds(TuningDefaults::HighFrequencyThreshold)), highFrequencyLowLimitBytes_(TuningDefaults::HighFrequencyLowLimitBytes), highFrequencyHighLimitBytes_(TuningDefaults::HighFrequencyHighLimitBytes), highFrequencyHeapGrowthMax_(TuningDefaults::HighFrequencyHeapGrowthMax), @@ -1624,7 +1622,7 @@ GCSchedulingTunables::resetParameter(JSGCParamKey key, const AutoLockGC& lock) break; case JSGC_HIGH_FREQUENCY_TIME_LIMIT: highFrequencyThreshold_ = - TuningDefaults::HighFrequencyThreshold; + mozilla::TimeDuration::FromSeconds(TuningDefaults::HighFrequencyThreshold); break; case JSGC_HIGH_FREQUENCY_LOW_LIMIT: setHighFrequencyLowLimit(TuningDefaults::HighFrequencyLowLimitBytes); @@ -2125,6 +2123,8 @@ GCRuntime::shouldCompact() // if we are currently animating, unless the user is inactive or we're // responding to memory pressure. + static const auto oneSecond = mozilla::TimeDuration::FromSeconds(1); + if (invocationKind != GC_SHRINK || !isCompactingGCEnabled()) return false; @@ -2135,7 +2135,9 @@ GCRuntime::shouldCompact() } const auto &lastAnimationTime = rt->lastAnimationTime.ref(); - return !isIncremental || lastAnimationTime.IsNull() || lastAnimationTime + ONE_SECOND < mozilla::TimeStamp::Now(); + return !isIncremental + || lastAnimationTime.IsNull() + || lastAnimationTime + oneSecond < mozilla::TimeStamp::Now(); } bool @@ -3229,8 +3231,6 @@ ArenaLists::queueForegroundThingsForSweep() gcScriptArenasToUpdate = arenaListsToSweep(AllocKind::SCRIPT); } -const mozilla::TimeStamp SliceBudget::unlimitedDeadline = mozilla::TimeStamp::Now() + mozilla::TimeDuration::Forever(); - SliceBudget::SliceBudget() : timeBudget(UnlimitedTimeBudget), workBudget(UnlimitedWorkBudget) { @@ -4046,6 +4046,7 @@ bool GCRuntime::shouldPreserveJITCode(Realm* realm, const mozilla::TimeStamp ¤tTime, JS::gcreason::Reason reason, bool canAllocateMoreCode) { + static const auto oneSecond = mozilla::TimeDuration::FromSeconds(1); if (cleanUpEverything) return false; @@ -4058,7 +4059,7 @@ GCRuntime::shouldPreserveJITCode(Realm* realm, const mozilla::TimeStamp ¤t return true; const auto &lastAnimationTime = realm->lastAnimationTime.ref(); - if (!lastAnimationTime.IsNull() && lastAnimationTime + ONE_SECOND >= currentTime) + if (!lastAnimationTime.IsNull() && lastAnimationTime + oneSecond >= currentTime) return true; if (reason == JS::gcreason::DEBUG_GC)