Bug 1084651 - Part 5: Simplify Cycle Collector logic now that SliceBudget makes more sense. r=mccr8
☠☠ backed out by 3ad6929d9571 ☠ ☠
authorEmanuel Hoogeveen <emanuel.hoogeveen@gmail.com>
Tue, 21 Oct 2014 11:54:00 +0200
changeset 214097 2711fbd9181959f3a8a923111595b24c2b08979d
parent 214096 59a163addd791fc094735c6c60016c7a78af578a
child 214098 dd2b3e78b4259b0c2e9f1abd62a52b551be1758b
push id27771
push userryanvm@gmail.com
push dateWed, 05 Nov 2014 19:04:24 +0000
treeherdermozilla-central@305b4fecce99 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmccr8
bugs1084651
milestone36.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 1084651 - Part 5: Simplify Cycle Collector logic now that SliceBudget makes more sense. r=mccr8
dom/base/nsJSEnvironment.cpp
xpcom/base/nsCycleCollector.cpp
xpcom/base/nsCycleCollector.h
--- a/dom/base/nsJSEnvironment.cpp
+++ b/dom/base/nsJSEnvironment.cpp
@@ -40,16 +40,17 @@
 #include "nsIXULRuntime.h"
 #include "nsTextFormatter.h"
 #include "ScriptSettings.h"
 
 #include "xpcpublic.h"
 
 #include "jsapi.h"
 #include "jswrapper.h"
+#include "js/SliceBudget.h"
 #include "nsIArray.h"
 #include "nsIObjectInputStream.h"
 #include "nsIObjectOutputStream.h"
 #include "prmem.h"
 #include "WrapperFactory.h"
 #include "nsGlobalWindow.h"
 #include "nsScriptNameSpaceManager.h"
 #include "StructuredCloneTags.h"
@@ -1687,51 +1688,54 @@ nsJSContext::RunCycleCollectorSlice()
 
   PROFILER_LABEL("nsJSContext", "RunCycleCollectorSlice",
     js::ProfileEntry::Category::CC);
 
   gCCStats.PrepareForCycleCollectionSlice();
 
   // Decide how long we want to budget for this slice. By default,
   // use an unlimited budget.
-  int64_t sliceBudget = -1;
+  js::SliceBudget budget;
 
   if (sIncrementalCC) {
     if (gCCStats.mBeginTime.IsNull()) {
       // If no CC is in progress, use the standard slice time.
-      sliceBudget = kICCSliceBudget;
+      budget = js::SliceBudget(js::TimeBudget(kICCSliceBudget));
     } else {
       TimeStamp now = TimeStamp::Now();
 
       // Only run a limited slice if we're within the max running time.
       if (TimeBetween(gCCStats.mBeginTime, now) < kMaxICCDuration) {
         float sliceMultiplier = std::max(TimeBetween(gCCStats.mEndSliceTime, now) / (float)kICCIntersliceDelay, 1.0f);
-        sliceBudget = kICCSliceBudget * sliceMultiplier;
+        budget = js::SliceBudget(js::TimeBudget(kICCSliceBudget * sliceMultiplier));
       }
     }
   }
 
-  nsCycleCollector_collectSlice(sliceBudget);
+  nsCycleCollector_collectSlice(budget);
 
   gCCStats.FinishCycleCollectionSlice();
 }
 
 //static
 void
 nsJSContext::RunCycleCollectorWorkSlice(int64_t aWorkBudget)
 {
   if (!NS_IsMainThread()) {
     return;
   }
 
   PROFILER_LABEL("nsJSContext", "RunCycleCollectorWorkSlice",
     js::ProfileEntry::Category::CC);
 
   gCCStats.PrepareForCycleCollectionSlice();
-  nsCycleCollector_collectSliceWork(aWorkBudget);
+
+  js::SliceBudget budget = js::SliceBudget(js::WorkBudget(aWorkBudget));
+  nsCycleCollector_collectSlice(budget);
+
   gCCStats.FinishCycleCollectionSlice();
 }
 
 void
 nsJSContext::ClearMaxCCSliceTime()
 {
   gCCStats.mMaxSliceTimeSinceClear = 0;
 }
--- a/xpcom/base/nsCycleCollector.cpp
+++ b/xpcom/base/nsCycleCollector.cpp
@@ -4183,50 +4183,27 @@ nsCycleCollector_collect(nsICycleCollect
   PROFILER_LABEL("nsCycleCollector", "collect",
                  js::ProfileEntry::Category::CC);
 
   SliceBudget unlimitedBudget;
   data->mCollector->Collect(ManualCC, unlimitedBudget, aManualListener);
 }
 
 void
-nsCycleCollector_collectSlice(int64_t aSliceTime)
+nsCycleCollector_collectSlice(SliceBudget& budget)
 {
   CollectorData* data = sCollectorData.get();
 
   // We should have started the cycle collector by now.
   MOZ_ASSERT(data);
   MOZ_ASSERT(data->mCollector);
 
   PROFILER_LABEL("nsCycleCollector", "collectSlice",
                  js::ProfileEntry::Category::CC);
 
-  SliceBudget budget;
-  if (aSliceTime >= 0) {
-    budget = SliceBudget(js::TimeBudget(aSliceTime));
-  }
-  data->mCollector->Collect(SliceCC, budget, nullptr);
-}
-
-void
-nsCycleCollector_collectSliceWork(int64_t aSliceWork)
-{
-  CollectorData* data = sCollectorData.get();
-
-  // We should have started the cycle collector by now.
-  MOZ_ASSERT(data);
-  MOZ_ASSERT(data->mCollector);
-
-  PROFILER_LABEL("nsCycleCollector", "collectSliceWork",
-                 js::ProfileEntry::Category::CC);
-
-  SliceBudget budget;
-  if (aSliceWork >= 0) {
-    budget = SliceBudget(js::WorkBudget(aSliceWork));
-  }
   data->mCollector->Collect(SliceCC, budget, nullptr);
 }
 
 void
 nsCycleCollector_prepareForGarbageCollection()
 {
   CollectorData* data = sCollectorData.get();
 
--- a/xpcom/base/nsCycleCollector.h
+++ b/xpcom/base/nsCycleCollector.h
@@ -10,16 +10,18 @@
 class nsICycleCollectorListener;
 class nsICycleCollectorLogSink;
 class nsISupports;
 template<class T> struct already_AddRefed;
 
 #include "nsError.h"
 #include "nsID.h"
 
+namespace js { struct SliceBudget; };
+
 namespace mozilla {
 
 class CycleCollectedJSRuntime;
 
 // Called back from DeferredFinalize.  Should add 'thing' to the array of smart
 // pointers in 'pointers', creating the array if 'pointers' is null, and return
 // the array.
 typedef void* (*DeferredFinalizeAppendFunction)(void* aPointers, void* aThing);
@@ -51,23 +53,17 @@ void nsCycleCollector_finishAnyCurrentCo
 
 void nsCycleCollector_dispatchDeferredDeletion(bool aContinuation = false);
 bool nsCycleCollector_doDeferredDeletion();
 
 already_AddRefed<nsICycleCollectorLogSink> nsCycleCollector_createLogSink();
 
 void nsCycleCollector_collect(nsICycleCollectorListener* aManualListener);
 
-// If aSliceTime is negative, the CC will run to completion. Otherwise,
-// aSliceTime will be used as the time budget for the slice, in ms.
-void nsCycleCollector_collectSlice(int64_t aSliceTime);
-
-// If aSliceTime is negative, the CC will run to completion. Otherwise,
-// aSliceTime will be used as the work budget for the slice.
-void nsCycleCollector_collectSliceWork(int64_t aSliceWork);
+void nsCycleCollector_collectSlice(js::SliceBudget& budget);
 
 uint32_t nsCycleCollector_suspectedCount();
 void nsCycleCollector_shutdown();
 
 // Helpers for interacting with JS
 void nsCycleCollector_registerJSRuntime(mozilla::CycleCollectedJSRuntime* aRt);
 void nsCycleCollector_forgetJSRuntime();