/* static */ bool MovableCellHasher<T>::match(const Key& k, const Lookup& l) { // Return true if both are null or false if only one is null. if (!k) return !l; if (!l) return false; MOZ_ASSERT(k); MOZ_ASSERT(l); MOZ_ASSERT(CurrentThreadCanAccessZone(l->zoneFromAnyThread()) || l->zoneFromAnyThread()->isSelfHostingZone()); Zone* zone = k->zoneFromAnyThread(); if (zone != l->zoneFromAnyThread()) return false; MOZ_ASSERT(zone->hasUniqueId(k)); MOZ_ASSERT(zone->hasUniqueId(l)); // Since both already have a uid (from hash), the get is infallible. uint64_t uidK, uidL; MOZ_ALWAYS_TRUE(zone->getUniqueId(k, &uidK)); MOZ_ALWAYS_TRUE(zone->getUniqueId(l, &uidL)); return uidK == uidL; }
/* static */ HashNumber MovableCellHasher<T>::hash(const Lookup& l) { if (!l) return 0; // We have to access the zone from-any-thread here: a worker thread may be // cloning a self-hosted object from the main-thread-runtime-owned self- // hosting zone into the off-main-thread runtime. The zone's uid lock will // protect against multiple workers doing this simultaneously. MOZ_ASSERT(CurrentThreadCanAccessZone(l->zoneFromAnyThread()) || l->zoneFromAnyThread()->isSelfHostingZone()); return l->zoneFromAnyThread()->getHashCodeInfallible(l); }
/* static */ bool MovableCellHasher<T>::hasHash(const Lookup& l) { if (!l) return true; return l->zoneFromAnyThread()->hasUniqueId(l); }
/* static */ bool MovableCellHasher<T>::ensureHash(const Lookup& l) { if (!l) return true; uint64_t unusedId; return l->zoneFromAnyThread()->getUniqueId(l, &unusedId); }
/* static */ HashNumber MovableCellHasher<T>::hash(const Lookup& l) { if (!l) return 0; // We have to access the zone from-any-thread here: a worker thread may be // cloning a self-hosted object from the main-thread-runtime-owned self- // hosting zone into the off-main-thread runtime. The zone's uid lock will // protect against multiple workers doing this simultaneously. MOZ_ASSERT(CurrentThreadCanAccessZone(l->zoneFromAnyThread()) || l->zoneFromAnyThread()->isSelfHostingZone()); HashNumber hn; AutoEnterOOMUnsafeRegion oomUnsafe; if (!l->zoneFromAnyThread()->getHashCode(l, &hn)) oomUnsafe.crash("failed to get a stable hash code"); return hn; }
/* static */ bool MovableCellHasher<T>::match(const Key& k, const Lookup& l) { // Return true if both are null or false if only one is null. if (!k) return !l; if (!l) return false; MOZ_ASSERT(k); MOZ_ASSERT(l); MOZ_ASSERT(CurrentThreadCanAccessZone(l->zoneFromAnyThread()) || l->zoneFromAnyThread()->isSelfHostingZone()); Zone* zone = k->zoneFromAnyThread(); if (zone != l->zoneFromAnyThread()) return false; #ifdef DEBUG // Incremental table sweeping means that existing table entries may no // longer have unique IDs. We fail the match in that case and the entry is // removed from the table later on. if (!zone->hasUniqueId(k)) { Key key = k; MOZ_ASSERT(IsAboutToBeFinalizedUnbarriered(&key)); } MOZ_ASSERT(zone->hasUniqueId(l)); #endif uint64_t keyId; if (!zone->maybeGetUniqueId(k, &keyId)) { // Key is dead and cannot match lookup which must be live. return false; } return keyId == zone->getUniqueIdInfallible(l); }