Bug 1580883 - Use TimeDuration for remaining global in nsJSEnvironment.cpp r=mccr8
authorJon Coppeard <jcoppeard@mozilla.com>
Wed, 18 Sep 2019 12:48:32 +0000
changeset 493808 c23405648344eb475592ff35aa6f47163565edbf
parent 493807 2139d06ac9d2e3847e6d4d0b36dc11bfeb598811
child 493809 94c4e9a25f1964c785e5153407b8c4a294ce2724
push id95696
push userjcoppeard@mozilla.com
push dateWed, 18 Sep 2019 12:51:30 +0000
treeherderautoland@94c4e9a25f19 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmccr8
bugs1580883
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 1580883 - Use TimeDuration for remaining global in nsJSEnvironment.cpp r=mccr8 Differential Revision: https://phabricator.services.mozilla.com/D45696
dom/base/nsJSEnvironment.cpp
--- a/dom/base/nsJSEnvironment.cpp
+++ b/dom/base/nsJSEnvironment.cpp
@@ -180,17 +180,18 @@ static TimeDuration sTotalForgetSkippabl
 static uint32_t sRemovedPurples = 0;
 static uint32_t sForgetSkippableBeforeCC = 0;
 static uint32_t sPreviousSuspectedCount = 0;
 static uint32_t sCleanupsSinceLastGC = UINT32_MAX;
 static bool sNeedsFullCC = false;
 static bool sNeedsFullGC = false;
 static bool sNeedsGCAfterCC = false;
 static bool sIncrementalCC = false;
-static int32_t sActiveIntersliceGCBudget = 5;  // ms;
+static TimeDuration sActiveIntersliceGCBudget =
+    TimeDuration::FromMilliseconds(5);
 
 static TimeStamp sFirstCollectionTime;
 
 static bool sIsInitialized;
 static bool sDidShutdown;
 static bool sShuttingDown;
 
 // nsJSEnvironmentObserver observes the user-interaction-inactive notifications
@@ -1718,39 +1719,37 @@ void nsJSContext::EndCycleCollectionCall
   sForgetSkippableBeforeCC = 0;
   sNeedsFullCC = false;
   sNeedsGCAfterCC = false;
   gCCStats.Clear();
 }
 
 // static
 bool InterSliceGCRunnerFired(TimeStamp aDeadline, void* aData) {
-  MOZ_ASSERT(sActiveIntersliceGCBudget > 0);
+  MOZ_ASSERT(sActiveIntersliceGCBudget);
   // We use longer budgets when the CC has been locked out but the CC has tried
   // to run since that means we may have significant amount garbage to collect
   // and better to GC in several longer slices than in a very long one.
-  int64_t budget =
-      aDeadline.IsNull()
-          ? int64_t(sActiveIntersliceGCBudget * 2)
-          : int64_t((aDeadline - TimeStamp::Now()).ToMilliseconds());
+  TimeDuration budget = aDeadline.IsNull() ? sActiveIntersliceGCBudget * 2
+                                           : aDeadline - TimeStamp::Now();
   if (sCCLockedOut && sCCLockedOutTime) {
     TimeDuration lockedTime = TimeStamp::Now() - sCCLockedOutTime;
-    int32_t maxSliceGCBudget = sActiveIntersliceGCBudget * 10;
+    TimeDuration maxSliceGCBudget = sActiveIntersliceGCBudget * 10;
     double percentOfLockedTime =
         std::min(lockedTime / kMaxCCLockedoutTime, 1.0);
-    budget = static_cast<int64_t>(
-        std::max((double)budget, percentOfLockedTime * maxSliceGCBudget));
+    budget = std::max(budget, maxSliceGCBudget.MultDouble(percentOfLockedTime));
   }
 
   TimeStamp startTimeStamp = TimeStamp::Now();
   TimeDuration duration = sGCUnnotifiedTotalTime;
   uintptr_t reason = reinterpret_cast<uintptr_t>(aData);
   nsJSContext::GarbageCollectNow(
       aData ? static_cast<JS::GCReason>(reason) : JS::GCReason::INTER_SLICE_GC,
-      nsJSContext::IncrementalGC, nsJSContext::NonShrinkingGC, budget);
+      nsJSContext::IncrementalGC, nsJSContext::NonShrinkingGC,
+      budget.ToMilliseconds());
 
   sGCUnnotifiedTotalTime = TimeDuration();
   TimeStamp now = TimeStamp::Now();
   TimeDuration sliceDuration = now - startTimeStamp;
   duration += sliceDuration;
   if (duration.ToSeconds()) {
     TimeDuration idleDuration;
     if (!aDeadline.IsNull()) {
@@ -1790,18 +1789,18 @@ void GCTimerFired(nsITimer* aTimer, void
 
   // Now start the actual GC after initial timer has fired.
   sInterSliceGCRunner = IdleTaskRunner::Create(
       [aClosure](TimeStamp aDeadline) {
         return InterSliceGCRunnerFired(aDeadline, aClosure);
       },
       "GCTimerFired::InterSliceGCRunnerFired",
       StaticPrefs::javascript_options_gc_delay_interslice(),
-      sActiveIntersliceGCBudget, true, [] { return sShuttingDown; },
-      TaskCategory::GarbageCollection);
+      sActiveIntersliceGCBudget.ToMilliseconds(), true,
+      [] { return sShuttingDown; }, TaskCategory::GarbageCollection);
 }
 
 // static
 void ShrinkingGCTimerFired(nsITimer* aTimer, void* aClosure) {
   nsJSContext::KillShrinkingGCTimer();
   sIsCompactingOnUserInactive = true;
   nsJSContext::GarbageCollectNow(JS::GCReason::USER_INACTIVE,
                                  nsJSContext::IncrementalGC,
@@ -2280,18 +2279,18 @@ static void DOMGCSliceCallback(JSContext
         // have a runner to ensure all the slices are handled. So, create
         // the runner here.
         sInterSliceGCRunner = IdleTaskRunner::Create(
             [](TimeStamp aDeadline) {
               return InterSliceGCRunnerFired(aDeadline, nullptr);
             },
             "DOMGCSliceCallback::InterSliceGCRunnerFired",
             StaticPrefs::javascript_options_gc_delay_interslice(),
-            sActiveIntersliceGCBudget, true, [] { return sShuttingDown; },
-            TaskCategory::GarbageCollection);
+            sActiveIntersliceGCBudget.ToMilliseconds(), true,
+            [] { return sShuttingDown; }, TaskCategory::GarbageCollection);
       }
 
       if (ShouldTriggerCC(nsCycleCollector_suspectedCount())) {
         nsCycleCollector_dispatchDeferredDeletion();
       }
 
       if (StaticPrefs::javascript_options_mem_log()) {
         nsString gcstats;
@@ -2425,17 +2424,17 @@ static void SetMemoryGCModePrefChangedCa
   SetGCParameter(JSGC_MODE, mode);
 }
 
 static void SetMemoryGCSliceTimePrefChangedCallback(const char* aPrefName,
                                                     void* aClosure) {
   int32_t pref = Preferences::GetInt(aPrefName, -1);
   // handle overflow and negative pref values
   if (pref > 0 && pref < 100000) {
-    sActiveIntersliceGCBudget = pref;
+    sActiveIntersliceGCBudget = TimeDuration::FromMilliseconds(pref);
     SetGCParameter(JSGC_SLICE_TIME_BUDGET_MS, pref);
   } else {
     ResetGCParameter(JSGC_SLICE_TIME_BUDGET_MS);
   }
 }
 
 static void SetIncrementalCCPrefChangedCallback(const char* aPrefName,
                                                 void* aClosure) {