Bug 1736604 - Part 3: Rename MapSweepPolicy to MapEntryGCPolicy r=sfink

It's only used for traceWeak it's true, but it's like a GCPolicy for the map
entry itself.

Differential Revision: https://phabricator.services.mozilla.com/D128904
This commit is contained in:
Jon Coppeard 2021-11-09 09:17:35 +00:00
Родитель 4514fe83d3
Коммит be63f8d9df
3 изменённых файлов: 25 добавлений и 24 удалений

Просмотреть файл

@ -21,7 +21,7 @@ namespace JS {
// Define a reasonable default GC policy for GC-aware Maps.
template <typename Key, typename Value>
struct DefaultMapSweepPolicy {
struct DefaultMapEntryGCPolicy {
static bool traceWeak(JSTracer* trc, Key* key, Value* value) {
return GCPolicy<Key>::traceWeak(trc, key) &&
GCPolicy<Value>::traceWeak(trc, value);
@ -41,13 +41,13 @@ struct DefaultMapSweepPolicy {
// define your own GCPolicy specialization, generic helpers can be found in
// js/public/TracingAPI.h.
//
// The MapSweepPolicy template parameter controls how the table drops entries
// when edges are weakly held. GCHashMap::traceWeak applies the MapSweepPolicy's
// traceWeak method to each table entry; if it returns true, the entry is
// dropped. The default MapSweepPolicy drops the entry if either the key or
// value is about to be finalized, according to its GCPolicy<T>::traceWeak
// method. (This default is almost always fine: it's hard to imagine keeping
// such an entry around anyway.)
// The MapEntryGCPolicy template parameter controls how the table drops entries
// when edges are weakly held. GCHashMap::traceWeak applies the
// MapEntryGCPolicy's traceWeak method to each table entry; if it returns true,
// the entry is dropped. The default MapEntryGCPolicy drops the entry if either
// the key or value is about to be finalized, according to its
// GCPolicy<T>::traceWeak method. (This default is almost always fine: it's hard
// to imagine keeping such an entry around anyway.)
//
// Note that this HashMap only knows *how* to trace, but it does not itself
// cause tracing to be invoked. For tracing, it must be used as
@ -56,12 +56,12 @@ struct DefaultMapSweepPolicy {
template <typename Key, typename Value,
typename HashPolicy = js::DefaultHasher<Key>,
typename AllocPolicy = js::TempAllocPolicy,
typename MapSweepPolicy = DefaultMapSweepPolicy<Key, Value>>
typename MapEntryGCPolicy = DefaultMapEntryGCPolicy<Key, Value>>
class GCHashMap : public js::HashMap<Key, Value, HashPolicy, AllocPolicy> {
using Base = js::HashMap<Key, Value, HashPolicy, AllocPolicy>;
public:
using SweepPolicy = MapSweepPolicy;
using EntryGCPolicy = MapEntryGCPolicy;
explicit GCHashMap(AllocPolicy a = AllocPolicy()) : Base(std::move(a)) {}
explicit GCHashMap(size_t length) : Base(length) {}
@ -82,7 +82,7 @@ class GCHashMap : public js::HashMap<Key, Value, HashPolicy, AllocPolicy> {
void traceWeakEntries(JSTracer* trc, typename Base::Enum& e) {
for (typename Base::Enum e(*this); !e.empty(); e.popFront()) {
if (!MapSweepPolicy::traceWeak(trc, &e.front().mutableKey(),
if (!MapEntryGCPolicy::traceWeak(trc, &e.front().mutableKey(),
&e.front().value())) {
e.removeFront();
}
@ -114,9 +114,9 @@ namespace js {
template <typename Key, typename Value,
typename HashPolicy = DefaultHasher<Key>,
typename AllocPolicy = TempAllocPolicy,
typename MapSweepPolicy = JS::DefaultMapSweepPolicy<Key, Value>>
typename MapEntryGCPolicy = JS::DefaultMapEntryGCPolicy<Key, Value>>
class GCRekeyableHashMap : public JS::GCHashMap<Key, Value, HashPolicy,
AllocPolicy, MapSweepPolicy> {
AllocPolicy, MapEntryGCPolicy> {
using Base = JS::GCHashMap<Key, Value, HashPolicy, AllocPolicy>;
public:
@ -129,7 +129,7 @@ class GCRekeyableHashMap : public JS::GCHashMap<Key, Value, HashPolicy,
bool traceWeak(JSTracer* trc) {
for (typename Base::Enum e(*this); !e.empty(); e.popFront()) {
Key key(e.front().key());
if (!MapSweepPolicy::traceWeak(trc, &key, &e.front().value())) {
if (!MapEntryGCPolicy::traceWeak(trc, &key, &e.front().value())) {
e.removeFront();
} else if (!HashPolicy::match(key, e.front().key())) {
e.rekeyFront(key);
@ -373,10 +373,11 @@ namespace JS {
// Specialize WeakCache for GCHashMap to provide a barriered map that does not
// need to be swept immediately.
template <typename Key, typename Value, typename HashPolicy,
typename AllocPolicy, typename MapSweepPolicy>
class WeakCache<GCHashMap<Key, Value, HashPolicy, AllocPolicy, MapSweepPolicy>>
typename AllocPolicy, typename MapEntryGCPolicy>
class WeakCache<
GCHashMap<Key, Value, HashPolicy, AllocPolicy, MapEntryGCPolicy>>
final : protected detail::WeakCacheBase {
using Map = GCHashMap<Key, Value, HashPolicy, AllocPolicy, MapSweepPolicy>;
using Map = GCHashMap<Key, Value, HashPolicy, AllocPolicy, MapEntryGCPolicy>;
using Self = WeakCache<Map>;
Map map;
@ -426,7 +427,7 @@ class WeakCache<GCHashMap<Key, Value, HashPolicy, AllocPolicy, MapSweepPolicy>>
static bool entryNeedsSweep(JSTracer* barrierTracer, const Entry& prior) {
Key key(prior.key());
Value value(prior.value());
bool needsSweep = !MapSweepPolicy::traceWeak(barrierTracer, &key, &value);
bool needsSweep = !MapEntryGCPolicy::traceWeak(barrierTracer, &key, &value);
MOZ_ASSERT_IF(!needsSweep,
prior.key() == key); // We shouldn't update here.
MOZ_ASSERT_IF(!needsSweep,

Просмотреть файл

@ -1741,7 +1741,7 @@ void InnerViewTable::sweepAfterMinorGC(JSTracer* trc) {
JSObject* buffer = MaybeForwarded(nurseryKeys[i]);
Map::Ptr p = map.lookup(buffer);
if (p &&
!Map::SweepPolicy::traceWeak(trc, &p->mutableKey(), &p->value())) {
!Map::EntryGCPolicy::traceWeak(trc, &p->mutableKey(), &p->value())) {
map.remove(p);
}
}

Просмотреть файл

@ -612,7 +612,7 @@ class XPCJSRuntime final : public mozilla::CycleCollectedJSRuntime {
}
};
struct SweepPolicy {
struct MapEntryGCPolicy {
static bool traceWeak(JSTracer* trc,
RefPtr<mozilla::BasePrincipal>* /* unused */,
JS::Heap<JSObject*>* value) {
@ -621,7 +621,7 @@ class XPCJSRuntime final : public mozilla::CycleCollectedJSRuntime {
};
typedef JS::GCHashMap<RefPtr<mozilla::BasePrincipal>, JS::Heap<JSObject*>,
Hasher, js::SystemAllocPolicy, SweepPolicy>
Hasher, js::SystemAllocPolicy, MapEntryGCPolicy>
Principal2JSObjectMap;
mozilla::UniquePtr<JSObject2WrappedJSMap> mWrappedJSMap;
@ -2644,7 +2644,7 @@ class CompartmentPrivate {
size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf);
struct SweepPolicy {
struct MapEntryGCPolicy {
static bool traceWeak(JSTracer* trc, const void* /* unused */,
JS::Heap<JSObject*>* value) {
return JS::GCPolicy<JS::Heap<JSObject*>>::traceWeak(trc, value);
@ -2653,7 +2653,7 @@ class CompartmentPrivate {
typedef JS::GCHashMap<const void*, JS::Heap<JSObject*>,
mozilla::PointerHasher<const void*>,
js::SystemAllocPolicy, SweepPolicy>
js::SystemAllocPolicy, MapEntryGCPolicy>
RemoteProxyMap;
RemoteProxyMap& GetRemoteProxyMap() { return mRemoteProxies; }