Bug 1519794 - Reset incremental GC on allocation triggers that happen late in an incremental collection r=sfink
authorJon Coppeard <jcoppeard@mozilla.com>
Mon, 14 Jan 2019 18:59:27 +0000
changeset 510883 43022e5e375774afce6db2316028e16bb09a9ec9
parent 510882 c15d04c80f5b966cd0cb5bee952eb28b7c96d9ee
child 510884 8ec327de0ba7c25c185b887a57877657bda20d47
child 510949 362ff47b225e4899d3cdccb1ffa849340d85bde0
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssfink
bugs1519794
milestone66.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 1519794 - Reset incremental GC on allocation triggers that happen late in an incremental collection r=sfink
js/src/gc/GC.cpp
--- a/js/src/gc/GC.cpp
+++ b/js/src/gc/GC.cpp
@@ -7244,45 +7244,54 @@ GCRuntime::IncrementalResult GCRuntime::
     budget.makeUnlimited();
     stats().nonincremental(unsafeReason);
     return resetIncrementalGC(unsafeReason);
   }
 
   if (mallocCounter.shouldTriggerGC(tunables) == NonIncrementalTrigger) {
     budget.makeUnlimited();
     stats().nonincremental(AbortReason::MallocBytesTrigger);
-  }
-
-  bool reset = false;
+    if (isIncrementalGCInProgress() && state() > State::Sweep) {
+      return resetIncrementalGC(AbortReason::MallocBytesTrigger);
+    }
+  }
+
+  AbortReason resetReason = AbortReason::None;
   for (ZonesIter zone(rt, WithAtoms); !zone.done(); zone.next()) {
     if (!zone->canCollect()) {
       continue;
     }
 
     if (zone->usage.gcBytes() >= zone->threshold.gcTriggerBytes()) {
       CheckZoneIsScheduled(zone, reason, "GC bytes");
       budget.makeUnlimited();
       stats().nonincremental(AbortReason::GCBytesTrigger);
+      if (zone->wasGCStarted() && zone->gcState() > Zone::Sweep) {
+        resetReason = AbortReason::GCBytesTrigger;
+      }
     }
 
     if (zone->shouldTriggerGCForTooMuchMalloc() == NonIncrementalTrigger) {
       CheckZoneIsScheduled(zone, reason, "malloc bytes");
       budget.makeUnlimited();
       stats().nonincremental(AbortReason::MallocBytesTrigger);
+      if (zone->wasGCStarted() && zone->gcState() > Zone::Sweep) {
+        resetReason = AbortReason::MallocBytesTrigger;
+      }
     }
 
     if (isIncrementalGCInProgress() &&
         zone->isGCScheduled() != zone->wasGCStarted()) {
-      reset = true;
-    }
-  }
-
-  if (reset) {
-    budget.makeUnlimited();
-    return resetIncrementalGC(AbortReason::ZoneChange);
+      budget.makeUnlimited();
+      resetReason = AbortReason::ZoneChange;
+    }
+  }
+
+  if (resetReason != AbortReason::None) {
+    return resetIncrementalGC(resetReason);
   }
 
   return IncrementalResult::Ok;
 }
 
 namespace {
 
 class AutoScheduleZonesForGC {
@@ -7626,16 +7635,25 @@ void GCRuntime::collect(bool nonincremen
         reason = JS::gcreason::ROOTS_REMOVED;
       } else if (shouldRepeatForDeadZone(reason)) {
         repeat = true;
         reason = JS::gcreason::COMPARTMENT_REVIVED;
       }
     }
   } while (repeat);
 
+#ifdef DEBUG
+  if (!isIncrementalGCInProgress()) {
+    for (ZonesIter zone(rt, WithAtoms); zone.done(); zone.next()) {
+      MOZ_ASSERT(!zone->gcMallocCounter.triggered());
+      MOZ_ASSERT(!zone->jitCodeCounter.triggered());
+    }
+  }
+#endif
+
   if (reason == JS::gcreason::COMPARTMENT_REVIVED) {
     maybeDoCycleCollection();
   }
 
 #ifdef JS_GC_ZEAL
   if (hasZealMode(ZealMode::CheckHeapAfterGC)) {
     gcstats::AutoPhase ap(stats(), gcstats::PhaseKind::TRACE_HEAP);
     CheckHeapAfterGC(rt);