Bug 1099152 - Separate out external APIs to start and continute an incremental GC r=terrence r=mccr8
authorJon Coppeard <jcoppeard@mozilla.com>
Fri, 02 Jan 2015 17:19:43 +0000
changeset 248565 e07fc74ab87ed1069cb7ecfa98c8b62743909978
parent 248564 37bbd26f087003d5232a63dd38e97df0ed1f4ff7
child 248566 2f43b22848b0ee8cee9b9b5a770e0e5ba4b24b0c
push id4489
push userraliiev@mozilla.com
push dateMon, 23 Feb 2015 15:17:55 +0000
treeherdermozilla-beta@fd7c3dc24146 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersterrence, mccr8
bugs1099152
milestone37.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 1099152 - Separate out external APIs to start and continute an incremental GC r=terrence r=mccr8
dom/base/nsJSEnvironment.cpp
js/public/GCAPI.h
js/src/jsapi-tests/testGCFinalizeCallback.cpp
js/src/jsfriendapi.cpp
--- a/dom/base/nsJSEnvironment.cpp
+++ b/dom/base/nsJSEnvironment.cpp
@@ -1276,30 +1276,30 @@ nsJSContext::GarbageCollectNow(JS::gcrea
 
   if (!nsContentUtils::XPConnect() || !sRuntime) {
     return;
   }
 
   if (sCCLockedOut && aIncremental == IncrementalGC) {
     // We're in the middle of incremental GC. Do another slice.
     JS::PrepareForIncrementalGC(sRuntime);
-    JS::IncrementalGC(sRuntime, aReason, aSliceMillis);
+    JS::IncrementalGCSlice(sRuntime, aReason, aSliceMillis);
     return;
   }
 
   if (sNeedsFullGC || aReason != JS::gcreason::CC_WAITING) {
     sNeedsFullGC = false;
     JS::PrepareForFullGC(sRuntime);
   } else {
     CycleCollectedJSRuntime::Get()->PrepareWaitingZonesForGC();
   }
 
   if (aIncremental == IncrementalGC) {
     MOZ_ASSERT(aShrinking == NonShrinkingGC);
-    JS::IncrementalGC(sRuntime, aReason, aSliceMillis);
+    JS::StartIncrementalGC(sRuntime, aReason, aSliceMillis);
   } else if (aShrinking == ShrinkingGC) {
     JS::ShrinkingGC(sRuntime, aReason);
   } else {
     JS::GCForReason(sRuntime, aReason);
   }
 }
 
 //static
--- a/js/public/GCAPI.h
+++ b/js/public/GCAPI.h
@@ -202,26 +202,37 @@ ShrinkingGC(JSRuntime *rt, gcreason::Rea
  *    implement read and write barriers with the JSCLASS_IMPLEMENTS_BARRIERS
  *    flag.
  *
  * Note: Even if incremental GC is enabled and working correctly,
  *       non-incremental collections can still happen when low on memory.
  */
 
 /*
- * Begin an incremental collection and perform one slice worth of work or
- * perform a slice of an ongoing incremental collection. When this function
- * returns, the collection is not complete. This function must be called
- * repeatedly until !IsIncrementalGCInProgress(rt).
+ * Begin an incremental collection and perform one slice worth of work. When
+ * this function returns, the collection may not be complete.
+ * IncrementalGCSlice() must be called repeatedly until
+ * !IsIncrementalGCInProgress(rt).
  *
  * Note: SpiderMonkey's GC is not realtime. Slices in practice may be longer or
  *       shorter than the requested interval.
  */
 extern JS_FRIEND_API(void)
-IncrementalGC(JSRuntime *rt, gcreason::Reason reason, int64_t millis = 0);
+StartIncrementalGC(JSRuntime *rt, gcreason::Reason reason, int64_t millis = 0);
+
+/*
+ * Perform a slice of an ongoing incremental collection. When this function
+ * returns, the collection may not be complete. It must be called repeatedly
+ * until !IsIncrementalGCInProgress(rt).
+ *
+ * Note: SpiderMonkey's GC is not realtime. Slices in practice may be longer or
+ *       shorter than the requested interval.
+ */
+extern JS_FRIEND_API(void)
+IncrementalGCSlice(JSRuntime *rt, gcreason::Reason reason, int64_t millis = 0);
 
 /*
  * If IsIncrementalGCInProgress(rt), this call finishes the ongoing collection
  * by performing an arbitrarily long slice. If !IsIncrementalGCInProgress(rt),
  * this is equivalent to GCForReason. When this function returns,
  * IsIncrementalGCInProgress(rt) will always be false.
  */
 extern JS_FRIEND_API(void)
--- a/js/src/jsapi-tests/testGCFinalizeCallback.cpp
+++ b/js/src/jsapi-tests/testGCFinalizeCallback.cpp
@@ -19,17 +19,17 @@ BEGIN_TEST(testGCFinalizeCallback)
     CHECK(rt->gc.isFullGc());
     CHECK(checkSingleGroup());
     CHECK(checkFinalizeStatus());
     CHECK(checkFinalizeIsCompartmentGC(false));
 
     /* Full GC, incremental. */
     FinalizeCalls = 0;
     JS::PrepareForFullGC(rt);
-    JS::IncrementalGC(rt, JS::gcreason::API, 1000000);
+    JS::StartIncrementalGC(rt, JS::gcreason::API, 1000000);
     CHECK(!rt->gc.isIncrementalGCInProgress());
     CHECK(rt->gc.isFullGc());
     CHECK(checkMultipleGroups());
     CHECK(checkFinalizeStatus());
     CHECK(checkFinalizeIsCompartmentGC(false));
 
     JS::RootedObject global1(cx, createTestGlobal());
     JS::RootedObject global2(cx, createTestGlobal());
@@ -56,29 +56,29 @@ BEGIN_TEST(testGCFinalizeCallback)
     CHECK(!rt->gc.isFullGc());
     CHECK(checkSingleGroup());
     CHECK(checkFinalizeStatus());
     CHECK(checkFinalizeIsCompartmentGC(true));
 
     /* Compartment GC, incremental, single compartment. */
     FinalizeCalls = 0;
     JS::PrepareZoneForGC(global1->zone());
-    JS::IncrementalGC(rt, JS::gcreason::API, 1000000);
+    JS::StartIncrementalGC(rt, JS::gcreason::API, 1000000);
     CHECK(!rt->gc.isIncrementalGCInProgress());
     CHECK(!rt->gc.isFullGc());
     CHECK(checkSingleGroup());
     CHECK(checkFinalizeStatus());
     CHECK(checkFinalizeIsCompartmentGC(true));
 
     /* Compartment GC, incremental, multiple compartments. */
     FinalizeCalls = 0;
     JS::PrepareZoneForGC(global1->zone());
     JS::PrepareZoneForGC(global2->zone());
     JS::PrepareZoneForGC(global3->zone());
-    JS::IncrementalGC(rt, JS::gcreason::API, 1000000);
+    JS::StartIncrementalGC(rt, JS::gcreason::API, 1000000);
     CHECK(!rt->gc.isIncrementalGCInProgress());
     CHECK(!rt->gc.isFullGc());
     CHECK(checkMultipleGroups());
     CHECK(checkFinalizeStatus());
     CHECK(checkFinalizeIsCompartmentGC(true));
 
 #ifdef JS_GC_ZEAL
 
--- a/js/src/jsfriendapi.cpp
+++ b/js/src/jsfriendapi.cpp
@@ -203,22 +203,25 @@ JS::GCForReason(JSRuntime *rt, gcreason:
 
 JS_FRIEND_API(void)
 JS::ShrinkingGC(JSRuntime *rt, gcreason::Reason reason)
 {
     rt->gc.gc(GC_SHRINK, reason);
 }
 
 JS_FRIEND_API(void)
-JS::IncrementalGC(JSRuntime *rt, gcreason::Reason reason, int64_t millis)
+JS::StartIncrementalGC(JSRuntime *rt, gcreason::Reason reason, int64_t millis)
 {
-    if (!rt->gc.isIncrementalGCInProgress())
-        rt->gc.startGC(GC_NORMAL, reason, millis);
-    else
-        rt->gc.gcSlice(reason, millis);
+    rt->gc.startGC(GC_NORMAL, reason, millis);
+}
+
+JS_FRIEND_API(void)
+JS::IncrementalGCSlice(JSRuntime *rt, gcreason::Reason reason, int64_t millis)
+{
+    rt->gc.gcSlice(reason, millis);
 }
 
 JS_FRIEND_API(void)
 JS::FinishIncrementalGC(JSRuntime *rt, gcreason::Reason reason)
 {
     rt->gc.finishGC(reason);
 }