Bug 1736021 - Convert the unique ID table to use traceWeak during sweeping r=sfink
authorJon Coppeard <jcoppeard@mozilla.com>
Fri, 15 Oct 2021 16:21:24 +0000
changeset 596019 e49fe5b9c09bb5ad74edef082768d18dc835ed37
parent 596018 a7de14d905e903c90d07f203b0bb1785363a4af3
child 596020 abd389d9d91309740bfbf927a4c50738be39ff84
push id38881
push userimoraru@mozilla.com
push dateFri, 15 Oct 2021 21:35:21 +0000
treeherdermozilla-central@ff6d6594f7b0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssfink
bugs1736021
milestone95.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 1736021 - Convert the unique ID table to use traceWeak during sweeping r=sfink In this case we know that we only ever do this in sweeping, so we can optimize by ignoring the tracer and checking the mark bits directly. This avoids dispatching on the (known) tracer kind, and dispatching on the (irrelevant) cell kind to call IsAboutToBeFinalized. Differential Revision: https://phabricator.services.mozilla.com/D128602
js/src/gc/GC.cpp
js/src/gc/Sweeping.cpp
js/src/gc/Zone.h
--- a/js/src/gc/GC.cpp
+++ b/js/src/gc/GC.cpp
@@ -1812,31 +1812,16 @@ void GCRuntime::queueBuffersForFreeAfter
     MOZ_ASSERT(!freeTask.isIdle(lock));
     freeTask.joinWithLockHeld(lock);
   }
 
   MOZ_ASSERT(buffersToFreeAfterMinorGC.ref().empty());
   std::swap(buffersToFreeAfterMinorGC.ref(), buffers);
 }
 
-/* static */
-bool UniqueIdGCPolicy::needsSweep(Cell** cellp, uint64_t*) {
-  Cell* cell = *cellp;
-  return MapGCThingTyped(cell, cell->getTraceKind(), [](auto t) {
-    mozilla::DebugOnly<const Cell*> prior = t;
-    bool result = IsAboutToBeFinalizedUnbarriered(&t);
-    // Sweep should not have to deal with moved pointers, since moving GC
-    // handles updating the UID table manually.
-    MOZ_ASSERT(t == prior);
-    return result;
-  });
-}
-
-void JS::Zone::sweepUniqueIds() { uniqueIds().sweep(); }
-
 void Realm::destroy(JSFreeOp* fop) {
   JSRuntime* rt = fop->runtime();
   if (auto callback = rt->destroyRealmCallback) {
     callback(fop, this);
   }
   if (principals()) {
     JS_DropPrincipals(rt->mainContextFromOwnThread(), principals());
   }
--- a/js/src/gc/Sweeping.cpp
+++ b/js/src/gc/Sweeping.cpp
@@ -1252,16 +1252,29 @@ void GCRuntime::sweepWeakMaps() {
 
 void GCRuntime::sweepUniqueIds() {
   for (SweepGroupZonesIter zone(this); !zone.done(); zone.next()) {
     AutoSetThreadIsSweeping threadIsSweeping(zone);
     zone->sweepUniqueIds();
   }
 }
 
+void JS::Zone::sweepUniqueIds() {
+  SweepingTracer trc(runtimeFromAnyThread());
+  uniqueIds().traceWeak(&trc);
+}
+
+/* static */
+bool UniqueIdGCPolicy::traceWeak(JSTracer* trc, Cell** keyp, uint64_t* valuep) {
+  // Since this is only ever used for sweeping, we can optimize it for that
+  // case. (Compacting GC updates this table manually when it moves a cell.)
+  MOZ_ASSERT(trc->kind() == JS::TracerKind::Sweeping);
+  return (*keyp)->isMarkedAny();
+}
+
 void GCRuntime::sweepWeakRefs() {
   for (SweepGroupZonesIter zone(this); !zone.done(); zone.next()) {
     AutoSetThreadIsSweeping threadIsSweeping(zone);
     zone->weakRefMap().sweep(&storeBuffer());
   }
 }
 
 void GCRuntime::sweepFinalizationRegistriesOnMainThread() {
--- a/js/src/gc/Zone.h
+++ b/js/src/gc/Zone.h
@@ -37,17 +37,17 @@ class JitZone;
 
 namespace gc {
 
 class ZoneList;
 
 using ZoneComponentFinder = ComponentFinder<JS::Zone>;
 
 struct UniqueIdGCPolicy {
-  static bool needsSweep(Cell** cell, uint64_t* value);
+  static bool traceWeak(JSTracer* trc, Cell** keyp, uint64_t* valuep);
 };
 
 // Maps a Cell* to a unique, 64bit id.
 using UniqueIdMap = GCHashMap<Cell*, uint64_t, PointerHasher<Cell*>,
                               SystemAllocPolicy, UniqueIdGCPolicy>;
 
 extern uint64_t NextCellUniqueId(JSRuntime* rt);