diff --git a/js/public/GCHashTable.h b/js/public/GCHashTable.h index 0776201c01eb..ff59cf1b5554 100644 --- a/js/public/GCHashTable.h +++ b/js/public/GCHashTable.h @@ -69,6 +69,10 @@ class GCHashMap : public js::HashMap } } + bool needsSweep() const { + return this->initialized() && !this->empty(); + } + void sweep() { if (!this->initialized()) return; @@ -246,6 +250,10 @@ class GCHashSet : public js::HashSet GCPolicy::trace(trc, &e.mutableFront(), "hashset element"); } + bool needsSweep() const { + return this->initialized() && !this->empty(); + } + void sweep() { if (!this->initialized()) return; diff --git a/js/public/GCVector.h b/js/public/GCVector.h index fd2608967f0f..67ffc51ee93d 100644 --- a/js/public/GCVector.h +++ b/js/public/GCVector.h @@ -135,6 +135,10 @@ class GCVector GCPolicy::trace(trc, &elem, "vector element"); } + bool needsSweep() const { + return !this->empty(); + } + void sweep() { uint32_t src, dst = 0; for (src = 0; src < length(); src++) { diff --git a/js/public/SweepingAPI.h b/js/public/SweepingAPI.h index 627b27a5843c..27fd59883ed5 100644 --- a/js/public/SweepingAPI.h +++ b/js/public/SweepingAPI.h @@ -38,6 +38,7 @@ class WeakCacheBase : public mozilla::LinkedListElement virtual ~WeakCacheBase() {} virtual void sweep() = 0; + virtual bool needsSweep() = 0; }; } // namespace detail @@ -69,6 +70,10 @@ class WeakCache : protected detail::WeakCacheBase, void sweep() override { GCPolicy::sweep(&cache); } + + bool needsSweep() override { + return cache.needsSweep(); + } }; } // namespace JS diff --git a/js/src/jsgc.cpp b/js/src/jsgc.cpp index d1fc124f3723..3c048dd0a529 100644 --- a/js/src/jsgc.cpp +++ b/js/src/jsgc.cpp @@ -5233,6 +5233,9 @@ PrepareWeakCacheTasks(JSRuntime* rt) // Build a vector of sweep tasks to run on a helper thread. WeakCacheTaskVector tasks; bool ok = IterateWeakCaches(rt, [&] (JS::detail::WeakCacheBase* cache) { + if (!cache->needsSweep()) + return true; + return tasks.emplaceBack(rt, *cache); }); diff --git a/js/src/vm/ArrayBufferObject.h b/js/src/vm/ArrayBufferObject.h index d3d70eec910c..43170885fadc 100644 --- a/js/src/vm/ArrayBufferObject.h +++ b/js/src/vm/ArrayBufferObject.h @@ -599,6 +599,10 @@ class InnerViewTable void sweep(); void sweepAfterMinorGC(); + bool needsSweep() const { + return map.needsSweep(); + } + bool needsSweepAfterMinorGC() const { return !nurseryKeys.empty() || !nurseryKeysValid; }