diff --git a/js/src/gc/Barrier.cpp b/js/src/gc/Barrier.cpp index 699bc3aec21..9c019f9f308 100644 --- a/js/src/gc/Barrier.cpp +++ b/js/src/gc/Barrier.cpp @@ -123,11 +123,7 @@ MovableCellHasher::hash(const Lookup& l) 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; + return l->zoneFromAnyThread()->getHashCodeInfallible(l); } template @@ -152,10 +148,7 @@ MovableCellHasher::match(const Key& k, const Lookup& l) 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; + return zone->getUniqueIdInfallible(k) == zone->getUniqueIdInfallible(l); } template struct MovableCellHasher; diff --git a/js/src/gc/Zone.h b/js/src/gc/Zone.h index 5519823ada2..65edd43d810 100644 --- a/js/src/gc/Zone.h +++ b/js/src/gc/Zone.h @@ -359,12 +359,16 @@ struct Zone : public JS::shadow::Zone, mozilla::DebugOnly gcLastZoneGroupIndex; + static js::HashNumber UniqueIdToHash(uint64_t uid) { + return js::HashNumber(uid >> 32) ^ js::HashNumber(uid & 0xFFFFFFFF); + } + // Creates a HashNumber based on getUniqueId. Returns false on OOM. bool getHashCode(js::gc::Cell* cell, js::HashNumber* hashp) { uint64_t uid; if (!getUniqueId(cell, &uid)) return false; - *hashp = js::HashNumber(uid >> 32) ^ js::HashNumber(uid & 0xFFFFFFFF); + *hashp = UniqueIdToHash(uid); return true; } @@ -389,10 +393,19 @@ struct Zone : public JS::shadow::Zone, // If the cell was in the nursery, hopefully unlikely, then we need to // tell the nursery about it so that it can sweep the uid if the thing // does not get tenured. + return runtimeFromAnyThread()->gc.nursery.addedUniqueIdToCell(cell); + } + + js::HashNumber getHashCodeInfallible(js::gc::Cell* cell) { + return UniqueIdToHash(getUniqueIdInfallible(cell)); + } + + uint64_t getUniqueIdInfallible(js::gc::Cell* cell) { + uint64_t uid; js::AutoEnterOOMUnsafeRegion oomUnsafe; - if (!runtimeFromAnyThread()->gc.nursery.addedUniqueIdToCell(cell)) - oomUnsafe.crash("failed to allocate tracking data for a nursery uid"); - return true; + if (!getUniqueId(cell, &uid)) + oomUnsafe.crash("failed to allocate uid"); + return uid; } // Return true if this cell has a UID associated with it.