Bug 1580474 - Replace #defines with constants in nsJSEnvironment files r=mccr8
authorJon Coppeard <jcoppeard@mozilla.com>
Thu, 12 Sep 2019 09:56:52 +0000
changeset 492823 147a816393af8c1cf36a17cb66b8590f35be3ed8
parent 492822 21386d8f21ae6f1eae3d8284817267d5750652c7
child 492824 f3c4877536d5e0654913a7270b8d00a2622ec59a
push id114076
push userncsoregi@mozilla.com
push dateThu, 12 Sep 2019 15:29:15 +0000
treeherdermozilla-inbound@d1dfae9fbdc6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmccr8
bugs1580474
milestone71.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 1580474 - Replace #defines with constants in nsJSEnvironment files r=mccr8 Differential Revision: https://phabricator.services.mozilla.com/D45531
dom/base/nsCCUncollectableMarker.cpp
dom/base/nsJSEnvironment.cpp
dom/base/nsJSEnvironment.h
--- a/dom/base/nsCCUncollectableMarker.cpp
+++ b/dom/base/nsCCUncollectableMarker.cpp
@@ -381,17 +381,17 @@ nsresult nsCCUncollectableMarker::Observ
     eInitial = 0,
     eUnmarkJSEventListeners = 1,
     eUnmarkMessageManagers = 2,
     eUnmarkStrongObservers = 3,
     eUnmarkJSHolders = 4,
     eDone = 5
   };
 
-  static_assert(eDone == NS_MAJOR_FORGET_SKIPPABLE_CALLS,
+  static_assert(eDone == kMajorForgetSkippableCalls,
                 "There must be one forgetSkippable call per cleanup state.");
 
   static uint32_t sFSState = eDone;
   if (prepareForCC) {
     sFSState = eDone;
     return NS_OK;
   }
 
--- a/dom/base/nsJSEnvironment.cpp
+++ b/dom/base/nsJSEnvironment.cpp
@@ -100,24 +100,24 @@ const size_t gStackSize = 8192;
 
 // Thank you Microsoft!
 #ifdef CompareString
 #  undef CompareString
 #endif
 
 // The amount of time we wait between a request to CC (after GC ran)
 // and doing the actual CC.
-#define NS_CC_DELAY 6000  // ms
-
-#define NS_CC_SKIPPABLE_DELAY 250  // ms
+static const uint32_t kCCDelay = 6000;  // ms
+
+static const int32_t kCCSkippableDelay = 250;  // ms
 
 // In case the cycle collector isn't run at all, we don't want
 // forget skippables to run too often. So limit the forget skippable cycle to
 // start at earliest 2000 ms after the end of the previous cycle.
-#define NS_TIME_BETWEEN_FORGET_SKIPPABLE_CYCLES 2000  // ms
+static const uint32_t kTimeBetweenForgetSkippableCycles = 2000;  // ms
 
 // ForgetSkippable is usually fast, so we can use small budgets.
 // This isn't a real budget but a hint to IdleTaskRunner whether there
 // is enough time to call ForgetSkippable.
 static const int64_t kForgetSkippableSliceDuration = 2;
 
 // Maximum amount of time that should elapse between incremental CC slices
 static const int64_t kICCIntersliceDelay = 64;  // ms
@@ -127,27 +127,25 @@ static const int64_t kICCSliceBudget = 3
 // Minimum budget for an incremental CC slice when using idle time to run it.
 static const int64_t kIdleICCSliceBudget = 2;  // ms
 
 // Maximum total duration for an ICC
 static const uint32_t kMaxICCDuration = 2000;  // ms
 
 // Force a CC after this long if there's more than NS_CC_FORCED_PURPLE_LIMIT
 // objects in the purple buffer.
-#define NS_CC_FORCED (2 * 60 * PR_USEC_PER_SEC)  // 2 min
-#define NS_CC_FORCED_PURPLE_LIMIT 10
+static const uint32_t kCCForced = (2 * 60 * PR_USEC_PER_SEC);  // 2 min
+static const uint32_t kCCForcedPurpleLimit = 10;
 
 // Don't allow an incremental GC to lock out the CC for too long.
-#define NS_MAX_CC_LOCKEDOUT_TIME (30 * PR_USEC_PER_SEC)  // 30 seconds
+static const int64_t kMaxCCLockedoutTime =
+    (30 * PR_USEC_PER_SEC);  // 30 seconds
 
 // Trigger a CC if the purple buffer exceeds this size when we check it.
-#define NS_CC_PURPLE_LIMIT 200
-
-// Large value used to specify that a script should run essentially forever
-#define NS_UNLIMITED_SCRIPT_RUNTIME (0x40000000LL << 32)
+static const uint32_t kCCPurpleLimit = 200;
 
 // if you add statics here, add them to the list in StartupJSEnvironment
 
 static nsITimer* sGCTimer;
 static nsITimer* sShrinkingGCTimer;
 static StaticRefPtr<IdleTaskRunner> sCCRunner;
 static StaticRefPtr<IdleTaskRunner> sICCRunner;
 static nsITimer* sFullGCTimer;
@@ -1173,18 +1171,17 @@ static void FireForgetSkippable(uint32_t
     Telemetry::Accumulate(Telemetry::FORGET_SKIPPABLE_FREQUENCY,
                           frequencyPerMinute);
     sForgetSkippableCounter = 0;
     sForgetSkippableFrequencyStartTime = startTimeStamp;
   }
   ++sForgetSkippableCounter;
 
   FinishAnyIncrementalGC();
-  bool earlyForgetSkippable =
-      sCleanupsSinceLastGC < NS_MAJOR_FORGET_SKIPPABLE_CALLS;
+  bool earlyForgetSkippable = sCleanupsSinceLastGC < kMajorForgetSkippableCalls;
 
   int64_t budgetMs =
       aDeadline.IsNull()
           ? kForgetSkippableSliceDuration
           : int64_t((aDeadline - TimeStamp::Now()).ToMilliseconds());
   js::SliceBudget budget = js::SliceBudget(js::TimeBudget(budgetMs));
   nsCycleCollector_forgetSkippable(budget, aRemoveChildless,
                                    earlyForgetSkippable);
@@ -1383,17 +1380,17 @@ void CycleCollectorStats::PrepareForCycl
   }
 }
 
 void CycleCollectorStats::RunForgetSkippable() {
   // Run forgetSkippable synchronously to reduce the size of the CC graph. This
   // is particularly useful if we recently finished a GC.
   TimeStamp beginForgetSkippable = TimeStamp::Now();
   bool ranSyncForgetSkippable = false;
-  while (sCleanupsSinceLastGC < NS_MAJOR_FORGET_SKIPPABLE_CALLS) {
+  while (sCleanupsSinceLastGC < kMajorForgetSkippableCalls) {
     FireForgetSkippable(nsCycleCollector_suspectedCount(), false, TimeStamp());
     ranSyncForgetSkippable = true;
   }
 
   if (ranSyncForgetSkippable) {
     mMaxSkippableDuration =
         std::max(mMaxSkippableDuration, TimeUntilNow(beginForgetSkippable));
     mRanSyncForgetSkippable = true;
@@ -1506,17 +1503,17 @@ static bool ICCRunnerFired(TimeStamp aDe
   // to synchronously finish the GC, which is bad.
 
   if (sCCLockedOut) {
     PRTime now = PR_Now();
     if (sCCLockedOutTime == 0) {
       sCCLockedOutTime = now;
       return false;
     }
-    if (now - sCCLockedOutTime < NS_MAX_CC_LOCKEDOUT_TIME) {
+    if (now - sCCLockedOutTime < kMaxCCLockedoutTime) {
       return false;
     }
   }
 
   nsJSContext::RunCycleCollectorSlice(aDeadline);
   return true;
 }
 
@@ -1713,17 +1710,17 @@ bool InterSliceGCRunnerFired(TimeStamp a
   int64_t budget =
       aDeadline.IsNull()
           ? int64_t(sActiveIntersliceGCBudget * 2)
           : int64_t((aDeadline - TimeStamp::Now()).ToMilliseconds());
   if (sCCLockedOut && sCCLockedOutTime) {
     int64_t lockedTime = PR_Now() - sCCLockedOutTime;
     int32_t maxSliceGCBudget = sActiveIntersliceGCBudget * 10;
     double percentOfLockedTime =
-        std::min((double)lockedTime / NS_MAX_CC_LOCKEDOUT_TIME, 1.0);
+        std::min((double)lockedTime / kMaxCCLockedoutTime, 1.0);
     budget = static_cast<int64_t>(
         std::max((double)budget, percentOfLockedTime * maxSliceGCBudget));
   }
 
   TimeStamp startTimeStamp = TimeStamp::Now();
   TimeDuration duration = sGCUnnotifiedTotalTime;
   uintptr_t reason = reinterpret_cast<uintptr_t>(aData);
   nsJSContext::GarbageCollectNow(
@@ -1787,56 +1784,56 @@ void ShrinkingGCTimerFired(nsITimer* aTi
   nsJSContext::KillShrinkingGCTimer();
   sIsCompactingOnUserInactive = true;
   nsJSContext::GarbageCollectNow(JS::GCReason::USER_INACTIVE,
                                  nsJSContext::IncrementalGC,
                                  nsJSContext::ShrinkingGC);
 }
 
 static bool ShouldTriggerCC(uint32_t aSuspected) {
-  return sNeedsFullCC || aSuspected > NS_CC_PURPLE_LIMIT ||
-         (aSuspected > NS_CC_FORCED_PURPLE_LIMIT &&
-          TimeUntilNow(sLastCCEndTime) > NS_CC_FORCED);
+  return sNeedsFullCC || aSuspected > kCCPurpleLimit ||
+         (aSuspected > kCCForcedPurpleLimit &&
+          TimeUntilNow(sLastCCEndTime) > kCCForced);
 }
 
 static bool CCRunnerFired(TimeStamp aDeadline) {
   if (sDidShutdown) {
     return false;
   }
 
-  static uint32_t ccDelay = NS_CC_DELAY;
+  static uint32_t ccDelay = kCCDelay;
   if (sCCLockedOut) {
-    ccDelay = NS_CC_DELAY / 3;
+    ccDelay = kCCDelay / 3;
 
     PRTime now = PR_Now();
     if (sCCLockedOutTime == 0) {
       // Reset sCCRunnerFireCount so that we run forgetSkippable
       // often enough before CC. Because of reduced ccDelay
       // forgetSkippable will be called just a few times.
-      // NS_MAX_CC_LOCKEDOUT_TIME limit guarantees that we end up calling
+      // kMaxCCLockedoutTime limit guarantees that we end up calling
       // forgetSkippable and CycleCollectNow eventually.
       sCCRunnerFireCount = 0;
       sCCLockedOutTime = now;
       return false;
     }
-    if (now - sCCLockedOutTime < NS_MAX_CC_LOCKEDOUT_TIME) {
+    if (now - sCCLockedOutTime < kMaxCCLockedoutTime) {
       return false;
     }
   }
 
   ++sCCRunnerFireCount;
 
   bool didDoWork = false;
 
   // During early timer fires, we only run forgetSkippable. During the first
   // late timer fire, we decide if we are going to have a second and final
   // late timer fire, where we may begin to run the CC. Should run at least one
   // early timer fire to allow cleanup before the CC.
   int32_t numEarlyTimerFires =
-      std::max((int32_t)ccDelay / NS_CC_SKIPPABLE_DELAY - 2, 1);
+      std::max((int32_t)ccDelay / kCCSkippableDelay - 2, 1);
   bool isLateTimerFire = sCCRunnerFireCount > numEarlyTimerFires;
   uint32_t suspected = nsCycleCollector_suspectedCount();
   if (isLateTimerFire && ShouldTriggerCC(suspected)) {
     if (sCCRunnerFireCount == numEarlyTimerFires + 1) {
       FireForgetSkippable(suspected, true, aDeadline);
       didDoWork = true;
       if (ShouldTriggerCC(nsCycleCollector_suspectedCount())) {
         // Our efforts to avoid a CC have failed, so we return to let the
@@ -1856,32 +1853,32 @@ static bool CCRunnerFired(TimeStamp aDea
     } else {
       // We are in the final timer fire and still meet the conditions for
       // triggering a CC. Let RunCycleCollectorSlice finish the current IGC, if
       // any because that will allow us to include the GC time in the CC pause.
       nsJSContext::RunCycleCollectorSlice(aDeadline);
       didDoWork = true;
     }
   } else if (((sPreviousSuspectedCount + 100) <= suspected) ||
-             (sCleanupsSinceLastGC < NS_MAJOR_FORGET_SKIPPABLE_CALLS)) {
+             (sCleanupsSinceLastGC < kMajorForgetSkippableCalls)) {
     // Only do a forget skippable if there are more than a few new objects
     // or we're doing the initial forget skippables.
     FireForgetSkippable(suspected, false, aDeadline);
     didDoWork = true;
   } else if (!isLateTimerFire && !aDeadline.IsNull()) {
     MOZ_ASSERT(!didDoWork);
     // If we're called during idle time, try to find some work to do by calling
     // the method recursively, effectively bypassing some possible forget
     // skippable calls.
     sCCRunnerFireCount = numEarlyTimerFires;
     return CCRunnerFired(aDeadline);
   }
 
   if (isLateTimerFire) {
-    ccDelay = NS_CC_DELAY;
+    ccDelay = kCCDelay;
 
     // We have either just run the CC or decided we don't want to run the CC
     // next time, so kill the timer.
     sPreviousSuspectedCount = 0;
     nsJSContext::KillCCRunner();
 
     if (!didDoWork) {
       sLastForgetSkippableCycleEndTime = TimeStamp::Now();
@@ -2055,41 +2052,40 @@ void nsJSContext::PokeShrinkingGC() {
 void nsJSContext::MaybePokeCC() {
   if (sCCRunner || sICCRunner || !sHasRunGC || sShuttingDown) {
     return;
   }
 
   // Don't run consecutive CCs too often.
   if (sCleanupsSinceLastGC && !sLastCCEndTime.IsNull()) {
     uint32_t sinceLastCCEnd = TimeUntilNow(sLastCCEndTime);
-    if (sinceLastCCEnd < NS_CC_DELAY) {
+    if (sinceLastCCEnd < kCCDelay) {
       return;
     }
   }
 
   // If GC hasn't run recently and forget skippable only cycle was run,
   // don't start a new cycle too soon.
-  if ((sCleanupsSinceLastGC > NS_MAJOR_FORGET_SKIPPABLE_CALLS) &&
+  if ((sCleanupsSinceLastGC > kMajorForgetSkippableCalls) &&
       !sLastForgetSkippableCycleEndTime.IsNull()) {
     uint32_t sinceLastForgetSkippableCycle =
         TimeUntilNow(sLastForgetSkippableCycleEndTime);
-    if (sinceLastForgetSkippableCycle <
-        NS_TIME_BETWEEN_FORGET_SKIPPABLE_CYCLES) {
+    if (sinceLastForgetSkippableCycle < kTimeBetweenForgetSkippableCycles) {
       return;
     }
   }
 
   if (ShouldTriggerCC(nsCycleCollector_suspectedCount())) {
     sCCRunnerFireCount = 0;
 
     // We can kill some objects before running forgetSkippable.
     nsCycleCollector_dispatchDeferredDeletion();
 
     sCCRunner = IdleTaskRunner::Create(
-        CCRunnerFired, "MaybePokeCC::CCRunnerFired", NS_CC_SKIPPABLE_DELAY,
+        CCRunnerFired, "MaybePokeCC::CCRunnerFired", kCCSkippableDelay,
         kForgetSkippableSliceDuration, true, [] { return sShuttingDown; },
         TaskCategory::GarbageCollection);
   }
 }
 
 // static
 void nsJSContext::KillGCTimer() {
   if (sGCTimer) {
--- a/dom/base/nsJSEnvironment.h
+++ b/dom/base/nsJSEnvironment.h
@@ -18,22 +18,24 @@
 #include "mozilla/TimeStamp.h"
 #include "nsThreadUtils.h"
 #include "xpcpublic.h"
 
 class nsICycleCollectorListener;
 class nsIDocShell;
 
 namespace mozilla {
+
 template <class>
 class Maybe;
 struct CycleCollectorResults;
-}  // namespace mozilla
 
-#define NS_MAJOR_FORGET_SKIPPABLE_CALLS 5
+static const uint32_t kMajorForgetSkippableCalls = 5;
+
+}  // namespace mozilla
 
 class nsJSContext : public nsIScriptContext {
  public:
   nsJSContext(bool aGCOnDestruction, nsIScriptGlobalObject* aGlobalObject);
 
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsJSContext,
                                                          nsIScriptContext)