Bug 1711063 - Part 7: Refactor the interface to Zone::discardJitCode to use an options struct in preparation for adding more options r=jandem
authorJon Coppeard <jcoppeard@mozilla.com>
Tue, 01 Jun 2021 09:57:01 +0000
changeset 654065 9a01131eb9666bedd30058ea2e6a2b26638d5724
parent 654064 d5f2380c3962d5537bbf2de610ac821f8c7a4f56
child 654066 13737f4e5ff90ab27afcdaa892de26ab2beaa9ff
push id2623
push userffxbld-merge
push dateMon, 02 Aug 2021 14:47:51 +0000
treeherdermozilla-release@8500ce65f7c6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem
bugs1711063
milestone91.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 1711063 - Part 7: Refactor the interface to Zone::discardJitCode to use an options struct in preparation for adding more options r=jandem Differential Revision: https://phabricator.services.mozilla.com/D115494
js/src/gc/GC.cpp
js/src/gc/Zone.cpp
js/src/gc/Zone.h
--- a/js/src/gc/GC.cpp
+++ b/js/src/gc/GC.cpp
@@ -4209,18 +4209,20 @@ bool GCRuntime::prepareZonesForCollectio
   /* Check that at least one zone is scheduled for collection. */
   return any;
 }
 
 void GCRuntime::discardJITCodeForGC() {
   js::CancelOffThreadIonCompile(rt, JS::Zone::Prepare);
   for (GCZonesIter zone(this); !zone.done(); zone.next()) {
     gcstats::AutoPhase ap(stats(), gcstats::PhaseKind::MARK_DISCARD_CODE);
-    zone->discardJitCode(rt->defaultFreeOp(), Zone::DiscardBaselineCode,
-                         Zone::DiscardJitScripts);
+    Zone::DiscardOptions options;
+    options.discardBaselineCode = true;
+    options.discardJitScripts = true;
+    zone->discardJitCode(rt->defaultFreeOp(), options);
   }
 }
 
 void GCRuntime::relazifyFunctionsForShrinkingGC() {
   gcstats::AutoPhase ap(stats(), gcstats::PhaseKind::RELAZIFY_FUNCTIONS);
   for (GCZonesIter zone(this); !zone.done(); zone.next()) {
     if (zone->isSelfHostingZone()) {
       continue;
--- a/js/src/gc/Zone.cpp
+++ b/js/src/gc/Zone.cpp
@@ -392,28 +392,26 @@ void Zone::checkStringWrappersAfterMovin
 }
 #endif
 
 void Zone::sweepWeakMaps() {
   /* Finalize unreachable (key,value) pairs in all weak maps. */
   WeakMapBase::sweepZone(this);
 }
 
-void Zone::discardJitCode(JSFreeOp* fop,
-                          ShouldDiscardBaselineCode discardBaselineCode,
-                          ShouldDiscardJitScripts discardJitScripts) {
+void Zone::discardJitCode(JSFreeOp* fop, const DiscardOptions& options) {
   if (!jitZone()) {
     return;
   }
 
   if (isPreservingCode()) {
     return;
   }
 
-  if (discardBaselineCode || discardJitScripts) {
+  if (options.discardBaselineCode || options.discardJitScripts) {
 #ifdef DEBUG
     // Assert no JitScripts are marked as active.
     for (auto iter = cellIter<BaseScript>(); !iter.done(); iter.next()) {
       BaseScript* base = iter.unbarrieredGet();
       if (jit::JitScript* jitScript = base->maybeJitScript()) {
         MOZ_ASSERT(!jitScript->active());
       }
     }
@@ -431,17 +429,17 @@ void Zone::discardJitCode(JSFreeOp* fop,
     if (!jitScript) {
       continue;
     }
 
     JSScript* script = base->asJSScript();
     jit::FinishInvalidation(fop, script);
 
     // Discard baseline script if it's not marked as active.
-    if (discardBaselineCode) {
+    if (options.discardBaselineCode) {
       if (jitScript->hasBaselineScript() && !jitScript->active()) {
         jit::FinishDiscardBaselineScript(fop, script);
       }
     }
 
 #ifdef JS_CACHEIR_SPEW
     maybeUpdateWarmUpCount(script);
 #endif
@@ -449,48 +447,48 @@ void Zone::discardJitCode(JSFreeOp* fop,
     // Warm-up counter for scripts are reset on GC. After discarding code we
     // need to let it warm back up to get information such as which
     // opcodes are setting array holes or accessing getter properties.
     script->resetWarmUpCounterForGC();
 
     // Try to release the script's JitScript. This should happen after
     // releasing JIT code because we can't do this when the script still has
     // JIT code.
-    if (discardJitScripts) {
+    if (options.discardJitScripts) {
       script->maybeReleaseJitScript(fop);
       jitScript = script->maybeJitScript();
       if (!jitScript) {
         // Try to discard the ScriptCounts too.
         if (!script->realm()->collectCoverageForDebug() &&
             !fop->runtime()->profilingScripts) {
           script->destroyScriptCounts();
         }
         continue;
       }
     }
 
     // If we did not release the JitScript, we need to purge optimized IC
     // stubs because the optimizedStubSpace will be purged below.
-    if (discardBaselineCode) {
+    if (options.discardBaselineCode) {
       jitScript->purgeOptimizedStubs(script);
     }
 
     // Finally, reset the active flag.
     jitScript->resetActive();
   }
 
   /*
    * When scripts contains pointers to nursery things, the store buffer
    * can contain entries that point into the optimized stub space. Since
    * this method can be called outside the context of a GC, this situation
    * could result in us trying to mark invalid store buffer entries.
    *
    * Defer freeing any allocated blocks until after the next minor GC.
    */
-  if (discardBaselineCode) {
+  if (options.discardBaselineCode) {
     jitZone()->optimizedStubSpace()->freeAllAfterMinorGC(this);
     jitZone()->purgeIonCacheIRStubInfo();
   }
 }
 
 void JS::Zone::beforeClearDelegateInternal(JSObject* wrapper,
                                            JSObject* delegate) {
   MOZ_ASSERT(js::gc::detail::GetDelegate(wrapper) == delegate);
--- a/js/src/gc/Zone.h
+++ b/js/src/gc/Zone.h
@@ -371,30 +371,24 @@ class Zone : public js::ZoneAllocator, p
   }
   void clearUsedByHelperThread() {
     MOZ_ASSERT(helperThreadUse_ != HelperThreadUse::None);
     helperThreadUse_ = HelperThreadUse::None;
   }
 
   [[nodiscard]] bool findSweepGroupEdges(Zone* atomsZone);
 
-  enum ShouldDiscardBaselineCode : bool {
-    KeepBaselineCode = false,
-    DiscardBaselineCode
+  struct DiscardOptions {
+    DiscardOptions() {}
+    bool discardBaselineCode = true;
+    bool discardJitScripts = false;
   };
 
-  enum ShouldDiscardJitScripts : bool {
-    KeepJitScripts = false,
-    DiscardJitScripts
-  };
-
-  void discardJitCode(
-      JSFreeOp* fop,
-      ShouldDiscardBaselineCode discardBaselineCode = DiscardBaselineCode,
-      ShouldDiscardJitScripts discardJitScripts = KeepJitScripts);
+  void discardJitCode(JSFreeOp* fop,
+                      const DiscardOptions& options = DiscardOptions());
 
   void addSizeOfIncludingThis(
       mozilla::MallocSizeOf mallocSizeOf, JS::CodeSizes* code,
       size_t* regexpZone, size_t* jitZone, size_t* baselineStubsOptimized,
       size_t* uniqueIdMap, size_t* shapeCaches, size_t* atomsMarkBitmaps,
       size_t* compartmentObjects, size_t* crossCompartmentWrappersTables,
       size_t* compartmentsPrivateData, size_t* scriptCountsMapArg);