Bug 1473818: Fix global constructors count regression r=jonco
Bug 1465505 moved from PRJ_Now to mozilla::TimeStamp. As a side effect,
it introduced a few extra global constructors calls.
This patch fixes it.
MozReview-Commit-ID: 9VX83JZIyds
--- a/js/public/SliceBudget.h
+++ b/js/public/SliceBudget.h
@@ -32,17 +32,22 @@ struct JS_PUBLIC_API(WorkBudget)
/*
* This class records how much work has been done in a given collection slice,
* so that we can return before pausing for too long. Some slices are allowed
* to run for unlimited time, and others are bounded. To reduce the number of
* gettimeofday calls, we only check the time every 1000 operations.
*/
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();
SliceBudget();
public:
// Memory of the originally requested budget. If isUnlimited, neither of
@@ -64,32 +69,32 @@ class JS_PUBLIC_API(SliceBudget)
/* Instantiate as SliceBudget(TimeBudget(n)). */
explicit SliceBudget(TimeBudget time);
/* Instantiate as SliceBudget(WorkBudget(n)). */
explicit SliceBudget(WorkBudget work);
void makeUnlimited() {
- deadline = unlimitedDeadline;
+ deadline = UnlimitedDeadline();
counter = unlimitedStartCounter;
}
void step(intptr_t amt = 1) {
counter -= amt;
}
bool isOverBudget() {
if (counter > 0)
return false;
return checkOverBudget();
}
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;
};
} // namespace js
#endif /* js_SliceBudget_h */
--- a/js/src/gc/GC.cpp
+++ b/js/src/gc/GC.cpp
@@ -300,17 +300,17 @@ namespace TuningDefaults {
/* no parameter */
static const size_t ZoneAllocDelayBytes = 1024 * 1024;
/* JSGC_DYNAMIC_HEAP_GROWTH */
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;
/* JSGC_HIGH_FREQUENCY_HIGH_LIMIT */
static const uint64_t HighFrequencyHighLimitBytes = 500 * 1024 * 1024;
/* JSGC_HIGH_FREQUENCY_HEAP_GROWTH_MAX */
@@ -341,18 +341,16 @@ namespace TuningDefaults {
static const bool CompactingEnabled = true;
/* JSGC_NURSERY_FREE_THRESHOLD_FOR_IDLE_COLLECTION */
static const uint32_t NurseryFreeThresholdForIdleCollection =
Nursery::NurseryChunkUsableSize / 4;
}}} // 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
* JSGC_ALLOCATION_THRESHOLD_FACTOR and
* JSGC_ALLOCATION_THRESHOLD_FACTOR_AVOID_INTERRUPT parameters.
*/
static const double MinAllocationThresholdFactor = 0.9;
@@ -1567,17 +1565,17 @@ GCSchedulingTunables::GCSchedulingTunabl
: gcMaxBytes_(0),
maxMallocBytes_(TuningDefaults::MaxMallocBytes),
gcMaxNurseryBytes_(0),
gcZoneAllocThresholdBase_(TuningDefaults::GCZoneAllocThresholdBase),
allocThresholdFactor_(TuningDefaults::AllocThresholdFactor),
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),
highFrequencyHeapGrowthMin_(TuningDefaults::HighFrequencyHeapGrowthMin),
lowFrequencyHeapGrowth_(TuningDefaults::LowFrequencyHeapGrowth),
dynamicMarkSliceEnabled_(TuningDefaults::DynamicMarkSliceEnabled),
minEmptyChunkCount_(TuningDefaults::MinEmptyChunkCount),
maxEmptyChunkCount_(TuningDefaults::MaxEmptyChunkCount),
@@ -1619,17 +1617,17 @@ GCSchedulingTunables::resetParameter(JSG
case JSGC_MAX_BYTES:
gcMaxBytes_ = 0xffffffff;
break;
case JSGC_MAX_NURSERY_BYTES:
gcMaxNurseryBytes_ = JS::DefaultNurseryBytes;
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);
break;
case JSGC_HIGH_FREQUENCY_HIGH_LIMIT:
setHighFrequencyHighLimit(TuningDefaults::HighFrequencyHighLimitBytes);
break;
case JSGC_HIGH_FREQUENCY_HEAP_GROWTH_MAX:
@@ -2130,27 +2128,31 @@ ArenaLists::unmarkPreMarkedFreeCells()
bool
GCRuntime::shouldCompact()
{
// Compact on shrinking GC if enabled. Skip compacting in incremental GCs
// 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;
if (initialReason == JS::gcreason::USER_INACTIVE ||
initialReason == JS::gcreason::MEM_PRESSURE)
{
return true;
}
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
GCRuntime::isCompactingGCEnabled() const
{
return compactingEnabled && rt->mainContextFromOwnThread()->compactingDisabledCount == 0;
}
@@ -3246,18 +3248,16 @@ void
ArenaLists::queueForegroundThingsForSweep()
{
gcShapeArenasToUpdate = arenaListsToSweep(AllocKind::SHAPE);
gcAccessorShapeArenasToUpdate = arenaListsToSweep(AllocKind::ACCESSOR_SHAPE);
gcObjectGroupArenasToUpdate = arenaListsToSweep(AllocKind::OBJECT_GROUP);
gcScriptArenasToUpdate = arenaListsToSweep(AllocKind::SCRIPT);
}
-const mozilla::TimeStamp SliceBudget::unlimitedDeadline = mozilla::TimeStamp::Now() + mozilla::TimeDuration::Forever();
-
SliceBudget::SliceBudget()
: timeBudget(UnlimitedTimeBudget), workBudget(UnlimitedWorkBudget)
{
makeUnlimited();
}
SliceBudget::SliceBudget(TimeBudget time)
: timeBudget(time), workBudget(UnlimitedWorkBudget)
@@ -4059,29 +4059,30 @@ GCRuntime::purgeRuntime()
MOZ_ASSERT(unmarkGrayStack.empty());
unmarkGrayStack.clearAndFree();
}
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;
if (!canAllocateMoreCode)
return false;
if (alwaysPreserveCode)
return true;
if (realm->preserveJitCode())
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)
return true;
return false;
}