Bug 1532950 - Disallow NO_REASON as a reason to GC, and fix ExplainGCReason to handle it r=pbone
authorJon Coppeard <jcoppeard@mozilla.com>
Wed, 06 Mar 2019 11:46:12 +0000
changeset 506566 144dfd01fb48d8ae338391e0263d867998d4de3b
parent 506563 fa767271520314149dfa231a5f3e265a533c91db
child 506567 b9a53cec8555d13272107a0e17ff52d3a093131e
push id138
push usermtabara@mozilla.com
push dateWed, 20 Mar 2019 18:12:49 +0000
reviewerspbone
bugs1532950
milestone68.0a1
Bug 1532950 - Disallow NO_REASON as a reason to GC, and fix ExplainGCReason to handle it r=pbone Differential Revision: https://phabricator.services.mozilla.com/D22277
js/src/gc/GC.cpp
js/src/gc/Statistics.cpp
js/src/jsapi-tests/testBinASTReader.cpp
--- a/js/src/gc/GC.cpp
+++ b/js/src/gc/GC.cpp
@@ -7543,16 +7543,18 @@ bool GCRuntime::shouldRepeatForDeadZone(
     }
   }
 
   return false;
 }
 
 void GCRuntime::collect(bool nonincrementalByAPI, SliceBudget budget,
                         JS::GCReason reason) {
+  MOZ_ASSERT(reason != JS::GCReason::NO_REASON);
+
   // Checks run for each request, even if we do not actually GC.
   checkCanCallAPI();
 
   // Check if we are allowed to GC at this time before proceeding.
   if (!checkIfGCAllowedInCurrentState(reason)) {
     return;
   }
 
--- a/js/src/gc/Statistics.cpp
+++ b/js/src/gc/Statistics.cpp
@@ -62,20 +62,23 @@ const char* js::gcstats::ExplainInvocati
 }
 
 JS_PUBLIC_API const char* JS::ExplainGCReason(JS::GCReason reason) {
   switch (reason) {
 #define SWITCH_REASON(name, _) \
   case JS::GCReason::name:     \
     return #name;
     GCREASONS(SWITCH_REASON)
+#undef SWITCH_REASON
+
+    case JS::GCReason::NO_REASON:
+      return "NO_REASON";
 
     default:
       MOZ_CRASH("bad GC reason");
-#undef SWITCH_REASON
   }
 }
 
 const char* js::gcstats::ExplainAbortReason(gc::AbortReason reason) {
   switch (reason) {
 #define SWITCH_REASON(name, _) \
   case gc::AbortReason::name:  \
     return #name;
--- a/js/src/jsapi-tests/testBinASTReader.cpp
+++ b/js/src/jsapi-tests/testBinASTReader.cpp
@@ -235,23 +235,21 @@ void runTestFromPath(JSContext* cx, cons
       }
       if (!subPath.append(0)) {
         MOZ_CRASH();
       }
       runTestFromPath<Tok>(cx, subPath.begin());
       continue;
     }
 
-    {
-      // Make sure that we run GC between two tests. Otherwise, since we're
-      // running everything from the same cx and without returning to JS, there
-      // is nothing to deallocate the ASTs.
-      JS::PrepareForFullGC(cx);
-      cx->runtime()->gc.gc(GC_NORMAL, JS::GCReason::NO_REASON);
-    }
+    // Make sure that we run GC between two tests. Otherwise, since we're
+    // running everything from the same cx and without returning to JS, there is
+    // nothing to deallocate the ASTs.
+    JS_GC(cx);
+
     LifoAllocScope allocScope(&cx->tempLifoAlloc());
 
     // Find files whose name ends with ".binjs".
     fprintf(stderr, "Considering %s\n", d_name);
     if (namlen < sizeof(BIN_SUFFIX)) {
       continue;
     }
     if (strncmp(d_name + namlen - (sizeof(BIN_SUFFIX) - 1), BIN_SUFFIX,