Bug 1385833 - Simplify incremental sweeping and combine script and JIT code finalization phases r=sfink
authorJon Coppeard <jcoppeard@mozilla.com>
Tue, 01 Aug 2017 11:03:33 +0100
changeset 420912 f2e435cfffbb19a1dc79f934c02405490b26e200
parent 420911 f2cf93fdcb4c1662470b75275b2bf36943ffe264
child 420913 896709cd1daf82ebe88f444e90ea3f2c995d49b9
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssfink
bugs1385833
milestone56.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 1385833 - Simplify incremental sweeping and combine script and JIT code finalization phases r=sfink
js/src/gc/GenerateStatsPhases.py
js/src/jsgc.cpp
--- a/js/src/gc/GenerateStatsPhases.py
+++ b/js/src/gc/GenerateStatsPhases.py
@@ -135,17 +135,16 @@ PhaseKindGraphRoots = [
             JoinParallelTasksPhaseKind
         ]),
         PhaseKind("SWEEP_OBJECT", "Sweep Object", 33),
         PhaseKind("SWEEP_STRING", "Sweep String", 34),
         PhaseKind("SWEEP_SCRIPT", "Sweep Script", 35),
         PhaseKind("SWEEP_SCOPE", "Sweep Scope", 59),
         PhaseKind("SWEEP_REGEXP_SHARED", "Sweep RegExpShared", 61),
         PhaseKind("SWEEP_SHAPE", "Sweep Shape", 36),
-        PhaseKind("SWEEP_JITCODE", "Sweep JIT code", 37),
         PhaseKind("FINALIZE_END", "Finalize End Callback", 38),
         PhaseKind("DESTROY", "Deallocate", 39),
         JoinParallelTasksPhaseKind
         ]),
     PhaseKind("COMPACT", "Compact", 40, [
         PhaseKind("COMPACT_MOVE", "Compact Move", 41),
         PhaseKind("COMPACT_UPDATE", "Compact Update", 42, [
             MarkRootsPhaseKind,
--- a/js/src/jsgc.cpp
+++ b/js/src/jsgc.cpp
@@ -342,26 +342,20 @@ static const FinalizePhase ForegroundObj
         AllocKind::OBJECT12,
         AllocKind::OBJECT16
     }
 };
 
 /*
  * Finalization order for GC things swept incrementally on the active thread.
  */
-static const FinalizePhase IncrementalFinalizePhases[] = {
-    {
-        gcstats::PhaseKind::SWEEP_SCRIPT, {
-            AllocKind::SCRIPT
-        }
-    },
-    {
-        gcstats::PhaseKind::SWEEP_JITCODE, {
-            AllocKind::JITCODE
-        }
+static const FinalizePhase ForegroundNonObjectFinalizePhase = {
+    gcstats::PhaseKind::SWEEP_SCRIPT, {
+        AllocKind::SCRIPT,
+        AllocKind::JITCODE
     }
 };
 
 /*
  * Finalization order for GC things swept on the background thread.
  */
 static const FinalizePhase BackgroundFinalizePhases[] = {
     {
@@ -5352,19 +5346,17 @@ GCRuntime::beginSweepingSweepGroup()
         startSweepingAtomsTable();
 
     // Queue all GC things in all zones for sweeping, either on the foreground
     // or on the background thread.
 
     for (GCSweepGroupIter zone(rt); !zone.done(); zone.next()) {
 
         zone->arenas.queueForForegroundSweep(&fop, ForegroundObjectFinalizePhase);
-        for (unsigned i = 0; i < ArrayLength(IncrementalFinalizePhases); ++i)
-            zone->arenas.queueForForegroundSweep(&fop, IncrementalFinalizePhases[i]);
-
+        zone->arenas.queueForForegroundSweep(&fop, ForegroundNonObjectFinalizePhase);
         for (unsigned i = 0; i < ArrayLength(BackgroundFinalizePhases); ++i)
             zone->arenas.queueForBackgroundSweep(&fop, BackgroundFinalizePhases[i]);
 
         zone->arenas.queueForegroundThingsForSweep(&fop);
     }
 
     sweepCache = nullptr;
     sweepActions->assertFinished();
@@ -5861,36 +5853,38 @@ struct IncrementalIter
         return maybeIter.ref().get();
     }
 
     void next() {
         maybeIter.ref().next();
     }
 };
 
+namespace sweepaction {
+
 // Implementation of the SweepAction interface that calls a function.
 template <typename... Args>
-class SweepActionFunc : public SweepAction<Args...>
+class SweepActionFunc final : public SweepAction<Args...>
 {
     using Func = IncrementalProgress (*)(Args...);
 
     Func func;
 
   public:
     explicit SweepActionFunc(Func f) : func(f) {}
     IncrementalProgress run(Args... args) override {
         return func(args...);
     }
     void assertFinished() const override { }
 };
 
 // Implementation of the SweepAction interface that calls a list of actions in
 // sequence.
 template <typename... Args>
-class SweepActionSequence : public SweepAction<Args...>
+class SweepActionSequence final : public SweepAction<Args...>
 {
     using Action = SweepAction<Args...>;
     using ActionVector = Vector<UniquePtr<Action>, 0, SystemAllocPolicy>;
     using Iter = IncrementalIter<ContainerIter<ActionVector>>;
 
     ActionVector actions;
     typename Iter::State iterState;
 
@@ -5914,17 +5908,17 @@ class SweepActionSequence : public Sweep
     void assertFinished() const override {
         MOZ_ASSERT(iterState.isNothing());
         for (const auto& action : actions)
             action->assertFinished();
     }
 };
 
 template <typename Iter, typename Init, typename... Args>
-class SweepActionForEach : public SweepAction<Args...>
+class SweepActionForEach final : public SweepAction<Args...>
 {
     using Elem = decltype(mozilla::DeclVal<Iter>().get());
     using Action = SweepAction<Args..., Elem>;
     using IncrIter = IncrementalIter<Iter>;
 
     Init iterInit;
     UniquePtr<Action> action;
     typename IncrIter::State iterState;
@@ -5982,80 +5976,78 @@ class RemoveLastTemplateParameter<Target
     };
 
   public:
     using Type = typename Impl<List<>, Args...>::Type;
 };
 
 template <typename... Args>
 static UniquePtr<SweepAction<Args...>>
-SweepFunc(IncrementalProgress (*func)(Args...)) {
+Func(IncrementalProgress (*func)(Args...)) {
     return MakeUnique<SweepActionFunc<Args...>>(func);
 }
 
 template <typename... Args, typename... Rest>
 static UniquePtr<SweepAction<Args...>>
-SweepSequence(UniquePtr<SweepAction<Args...>> first, Rest... rest)
+Sequence(UniquePtr<SweepAction<Args...>> first, Rest... rest)
 {
     UniquePtr<SweepAction<Args...>> actions[] = { Move(first), Move(rest)... };
     auto seq = MakeUnique<SweepActionSequence<Args...>>();
     if (!seq || !seq->init(actions, ArrayLength(actions)))
         return nullptr;
 
     return UniquePtr<SweepAction<Args...>>(Move(seq));
 }
 
 template <typename... Args>
 static UniquePtr<typename RemoveLastTemplateParameter<SweepAction<Args...>>::Type>
-SweepForEachZone(JSRuntime* rt, UniquePtr<SweepAction<Args...>> action)
+ForEachZoneInSweepGroup(JSRuntime* rt, UniquePtr<SweepAction<Args...>> action)
 {
     if (!action)
         return nullptr;
 
     using Action = typename RemoveLastTemplateParameter<
         SweepActionForEach<GCSweepGroupIter, JSRuntime*, Args...>>::Type;
     return js::MakeUnique<Action>(rt, Move(action));
 }
 
 template <typename... Args>
 static UniquePtr<typename RemoveLastTemplateParameter<SweepAction<Args...>>::Type>
-SweepForEachAllocKind(AllocKinds kinds, UniquePtr<SweepAction<Args...>> action)
+ForEachAllocKind(AllocKinds kinds, UniquePtr<SweepAction<Args...>> action)
 {
     if (!action)
         return nullptr;
 
     using Action = typename RemoveLastTemplateParameter<
         SweepActionForEach<ContainerIter<AllocKinds>, AllocKinds, Args...>>::Type;
     return js::MakeUnique<Action>(kinds, Move(action));
 }
 
+} // namespace sweepaction
+
 bool
 GCRuntime::initSweepActions()
 {
-    sweepActions.ref() = SweepSequence(
-        SweepFunc(sweepAtomsTable),
-        SweepFunc(sweepWeakCaches),
-        SweepForEachZone(rt,
-            SweepForEachAllocKind(ForegroundObjectFinalizePhase.kinds,
-                SweepFunc(finalizeAllocKind))),
-        SweepForEachZone(rt,
-            SweepSequence(
-                SweepFunc(sweepTypeInformation),
-                SweepFunc(mergeSweptObjectArenas))),
-        SweepForEachZone(rt,
-            SweepForEachAllocKind(IncrementalFinalizePhases[0].kinds,
-                SweepFunc(finalizeAllocKind))),
-        SweepForEachZone(rt,
-            SweepForEachAllocKind(IncrementalFinalizePhases[1].kinds,
-                SweepFunc(finalizeAllocKind))),
-        SweepForEachZone(rt,
-            SweepFunc(sweepShapeTree)));
-
-    static_assert(ArrayLength(IncrementalFinalizePhases) == 2,
-                  "We must have a phase for each element in IncrementalFinalizePhases");
+    using namespace sweepaction;
+
+    sweepActions.ref() = Sequence(
+        Func(sweepAtomsTable),
+        Func(sweepWeakCaches),
+        ForEachZoneInSweepGroup(rt,
+            ForEachAllocKind(ForegroundObjectFinalizePhase.kinds,
+                Func(finalizeAllocKind))),
+        ForEachZoneInSweepGroup(rt,
+            Sequence(
+                Func(sweepTypeInformation),
+                Func(mergeSweptObjectArenas))),
+        ForEachZoneInSweepGroup(rt,
+            ForEachAllocKind(ForegroundNonObjectFinalizePhase.kinds,
+                Func(finalizeAllocKind))),
+        ForEachZoneInSweepGroup(rt,
+            Func(sweepShapeTree)));
 
     return sweepActions != nullptr;
 }
 
 IncrementalProgress
 GCRuntime::performSweepActions(SliceBudget& budget, AutoLockForExclusiveAccess& lock)
 {
     AutoSetThreadIsSweeping threadIsSweeping;