Bug 1372569 - Skip sweeping empty weak caches r=sfink

This commit is contained in:
Jon Coppeard 2017-06-16 10:06:28 +01:00
parent 52665ac9e7
commit 995284e0a4
5 changed files with 24 additions and 0 deletions

View File

@ -69,6 +69,10 @@ class GCHashMap : public js::HashMap<Key, Value, HashPolicy, AllocPolicy>
}
}
bool needsSweep() const {
return this->initialized() && !this->empty();
}
void sweep() {
if (!this->initialized())
return;
@ -246,6 +250,10 @@ class GCHashSet : public js::HashSet<T, HashPolicy, AllocPolicy>
GCPolicy<T>::trace(trc, &e.mutableFront(), "hashset element");
}
bool needsSweep() const {
return this->initialized() && !this->empty();
}
void sweep() {
if (!this->initialized())
return;

View File

@ -135,6 +135,10 @@ class GCVector
GCPolicy<T>::trace(trc, &elem, "vector element");
}
bool needsSweep() const {
return !this->empty();
}
void sweep() {
uint32_t src, dst = 0;
for (src = 0; src < length(); src++) {

View File

@ -38,6 +38,7 @@ class WeakCacheBase : public mozilla::LinkedListElement<WeakCacheBase>
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<T>::sweep(&cache);
}
bool needsSweep() override {
return cache.needsSweep();
}
};
} // namespace JS

View File

@ -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);
});

View File

@ -599,6 +599,10 @@ class InnerViewTable
void sweep();
void sweepAfterMinorGC();
bool needsSweep() const {
return map.needsSweep();
}
bool needsSweepAfterMinorGC() const {
return !nurseryKeys.empty() || !nurseryKeysValid;
}