Bug 1620495 - Remove type-overloads using LazyScript r=mgaudet
authorTed Campbell <tcampbell@mozilla.com>
Mon, 16 Mar 2020 19:37:25 +0000
changeset 519042 17f0784ab346b5a6cda72984d0b72c804b1fac7f
parent 519041 c1233643f6affa98444a3b75186cc42952421344
child 519043 1bf4fb5973f8681e49cf8fe051d7a92b79c6cb28
push id110273
push usertcampbell@mozilla.com
push dateMon, 16 Mar 2020 20:09:27 +0000
treeherderautoland@cc99b4449f14 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmgaudet
bugs1620495
milestone76.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 1620495 - Remove type-overloads using LazyScript r=mgaudet Cleanup up code in the Debugger and in PublicIterators that only used the LazyScript for overload resolution. This changes are largely mechanical and there is room to improve implementations in future Differential Revision: https://phabricator.services.mozilla.com/D66848
js/src/debugger/Debugger.cpp
js/src/gc/PublicIterators.cpp
--- a/js/src/debugger/Debugger.cpp
+++ b/js/src/debugger/Debugger.cpp
@@ -5143,18 +5143,17 @@ class MOZ_STACK_CLASS Debugger::ScriptQu
                              const JS::AutoRequireNoGC& nogc) {
     ScriptQuery* self = static_cast<ScriptQuery*>(data);
     self->consider(script->asJSScript(), nogc);
   }
 
   static void considerLazyScript(JSRuntime* rt, void* data, BaseScript* script,
                                  const JS::AutoRequireNoGC& nogc) {
     ScriptQuery* self = static_cast<ScriptQuery*>(data);
-    LazyScript* lazy = static_cast<LazyScript*>(script);
-    self->consider(lazy, nogc);
+    self->considerLazy(script, nogc);
   }
 
   bool needsDelazifyBeforeQuery() const {
     // * innermost
     //   Currently not supported, since this is not used outside of test.
     //
     // * hasLine
     //   Only JSScript supports GetScriptLineExtent.
@@ -5252,17 +5251,17 @@ class MOZ_STACK_CLASS Debugger::ScriptQu
       // Record this matching script in the results scriptVector.
       if (!scriptVector.append(script)) {
         oom = true;
         return;
       }
     }
   }
 
-  void consider(LazyScript* lazyScript, const JS::AutoRequireNoGC& nogc) {
+  void considerLazy(BaseScript* lazyScript, const JS::AutoRequireNoGC& nogc) {
     MOZ_ASSERT(!needsDelazifyBeforeQuery());
 
     if (oom) {
       return;
     }
     Realm* realm = lazyScript->realm();
     if (!realms.has(realm)) {
       return;
@@ -5408,18 +5407,17 @@ class MOZ_STACK_CLASS Debugger::SourceQu
                              const JS::AutoRequireNoGC& nogc) {
     SourceQuery* self = static_cast<SourceQuery*>(data);
     self->consider(script->asJSScript(), nogc);
   }
 
   static void considerLazyScript(JSRuntime* rt, void* data, BaseScript* script,
                                  const JS::AutoRequireNoGC& nogc) {
     SourceQuery* self = static_cast<SourceQuery*>(data);
-    LazyScript* lazy = static_cast<LazyScript*>(script);
-    self->consider(lazy, nogc);
+    self->considerLazy(script, nogc);
   }
 
   void consider(JSScript* script, const JS::AutoRequireNoGC& nogc) {
     if (oom || script->selfHosted()) {
       return;
     }
     Realm* realm = script->realm();
     if (!realms.has(realm)) {
@@ -5432,17 +5430,17 @@ class MOZ_STACK_CLASS Debugger::SourceQu
 
     ScriptSourceObject* source =
         &UncheckedUnwrap(script->sourceObject())->as<ScriptSourceObject>();
     if (!sources.put(source)) {
       oom = true;
     }
   }
 
-  void consider(LazyScript* lazyScript, const JS::AutoRequireNoGC& nogc) {
+  void considerLazy(BaseScript* lazyScript, const JS::AutoRequireNoGC& nogc) {
     if (oom) {
       return;
     }
     Realm* realm = lazyScript->realm();
     if (!realms.has(realm)) {
       return;
     }
 
--- a/js/src/gc/PublicIterators.cpp
+++ b/js/src/gc/PublicIterators.cpp
@@ -106,89 +106,87 @@ static void TraverseInnerLazyScriptsForL
     lazyScriptCallback(cx->runtime(), data, script, nogc);
 
     TraverseInnerLazyScriptsForLazyScript(cx, data, script, lazyScriptCallback,
                                           nogc);
   }
 }
 
 static inline void DoScriptCallback(JSContext* cx, void* data,
-                                    LazyScript* lazyScript,
-                                    IterateScriptCallback lazyScriptCallback,
+                                    BaseScript* script,
+                                    IterateScriptCallback callback,
                                     const JS::AutoRequireNoGC& nogc) {
-  // We call the callback only for the LazyScript that:
-  //   (a) its enclosing script has ever been fully compiled and
-  //       itself is delazifyable (handled in this function)
-  //   (b) it is contained in the (a)'s inner function tree
-  //       (handled in TraverseInnerLazyScriptsForLazyScript)
-  if (!lazyScript->enclosingScriptHasEverBeenCompiled()) {
-    return;
+  if (script->isLazyScript()) {
+    // We call the callback only for the LazyScript that:
+    //   (a) its enclosing script has ever been fully compiled and
+    //       itself is delazifyable (handled in this function)
+    //   (b) it is contained in the (a)'s inner function tree
+    //       (handled in TraverseInnerLazyScriptsForLazyScript)
+    if (!script->enclosingScriptHasEverBeenCompiled()) {
+      return;
+    }
+  } else {
+    // We check for presence of script->isUncompleted() because it is possible
+    // that the script was created and thus exposed to GC, but *not* fully
+    // initialized from fullyInitFromStencil due to errors.
+    if (static_cast<JSScript*>(script)->isUncompleted()) {
+      return;
+    }
   }
 
-  lazyScriptCallback(cx->runtime(), data, lazyScript, nogc);
+  // Invoke callback.
+  callback(cx->runtime(), data, script, nogc);
 
-  TraverseInnerLazyScriptsForLazyScript(cx, data, lazyScript,
-                                        lazyScriptCallback, nogc);
+  // Recursively visit inner lazy scripts. See the filter above for
+  // enclosingScriptHasEverBeenCompiled.
+  if (script->isLazyScript()) {
+    TraverseInnerLazyScriptsForLazyScript(cx, data, script, callback, nogc);
+  }
 }
 
-static inline void DoScriptCallback(JSContext* cx, void* data, JSScript* script,
-                                    IterateScriptCallback scriptCallback,
-                                    const JS::AutoRequireNoGC& nogc) {
-  // We check for presence of script->isUncompleted() because it is
-  // possible that the script was created and thus exposed to GC, but *not*
-  // fully initialized from fullyInit{FromEmitter,Trivial} due to errors.
-  if (script->isUncompleted()) {
-    return;
-  }
-
-  scriptCallback(cx->runtime(), data, script, nogc);
-}
-
-template <typename T>
+template <bool MatchLazy>
 static void IterateScriptsImpl(JSContext* cx, Realm* realm, void* data,
                                IterateScriptCallback scriptCallback) {
   MOZ_ASSERT(!cx->suppressGC);
   AutoEmptyNurseryAndPrepareForTracing prep(cx);
   JS::AutoSuppressGCAnalysis nogc;
 
   if (realm) {
     Zone* zone = realm->zone();
     for (auto iter = zone->cellIter<BaseScript>(prep); !iter.done();
          iter.next()) {
-      if (mozilla::IsSame<T, LazyScript>::value != iter->isLazyScript()) {
+      if (MatchLazy != iter->isLazyScript()) {
         continue;
       }
-      T* script = static_cast<T*>(iter.get());
-      if (script->realm() != realm) {
+      if (iter->realm() != realm) {
         continue;
       }
-      DoScriptCallback(cx, data, script, scriptCallback, nogc);
+      DoScriptCallback(cx, data, iter.get(), scriptCallback, nogc);
     }
   } else {
     for (ZonesIter zone(cx->runtime(), SkipAtoms); !zone.done(); zone.next()) {
       for (auto iter = zone->cellIter<BaseScript>(prep); !iter.done();
            iter.next()) {
-        if (mozilla::IsSame<T, LazyScript>::value != iter->isLazyScript()) {
+        if (MatchLazy != iter->isLazyScript()) {
           continue;
         }
-        T* script = static_cast<T*>(iter.get());
-        DoScriptCallback(cx, data, script, scriptCallback, nogc);
+        DoScriptCallback(cx, data, iter.get(), scriptCallback, nogc);
       }
     }
   }
 }
 
 void js::IterateScripts(JSContext* cx, Realm* realm, void* data,
                         IterateScriptCallback scriptCallback) {
-  IterateScriptsImpl<JSScript>(cx, realm, data, scriptCallback);
+  IterateScriptsImpl</* MatchLazy = */ false>(cx, realm, data, scriptCallback);
 }
 
 void js::IterateLazyScripts(JSContext* cx, Realm* realm, void* data,
                             IterateScriptCallback scriptCallback) {
-  IterateScriptsImpl<LazyScript>(cx, realm, data, scriptCallback);
+  IterateScriptsImpl</* MatchLazy = */ true>(cx, realm, data, scriptCallback);
 }
 
 static void IterateGrayObjects(Zone* zone, GCThingCallback cellCallback,
                                void* data) {
   for (auto kind : ObjectAllocKinds()) {
     for (GrayObjectIter obj(zone, kind); !obj.done(); obj.next()) {
       if (obj->asTenured().isMarkedGray()) {
         cellCallback(data, JS::GCCellPtr(obj.get()));