Commit 5ed380a9 authored by Jon Coppeard's avatar Jon Coppeard
Browse files

Bug 1832044 - Part 2: Move hashing of unique IDs into the hasher r=sfink

There's no need to expose this as generic functionality.

Depends on D177525

Differential Revision: https://phabricator.services.mozilla.com/D177526
parent fc47d693
Loading
Loading
Loading
Loading
+19 −3
Original line number Diff line number Diff line
@@ -67,6 +67,10 @@ bool CurrentThreadIsIonCompiling() {

#endif  // DEBUG

static inline js::HashNumber UniqueIdToHash(uint64_t uid) {
  return mozilla::HashGeneric(uid);
}

template <typename T>
/* static */ bool StableCellHasher<T>::maybeGetHash(const Lookup& l,
                                                    HashNumber* hashOut) {
@@ -75,7 +79,13 @@ template <typename T>
    return true;
  }

  return l->zoneFromAnyThread()->maybeGetHashCode(l, hashOut);
  uint64_t uid;
  if (!l->zoneFromAnyThread()->maybeGetUniqueId(l, &uid)) {
    return false;
  }

  *hashOut = UniqueIdToHash(uid);
  return true;
}

template <typename T>
@@ -86,7 +96,13 @@ template <typename T>
    return true;
  }

  return l->zoneFromAnyThread()->getOrCreateHashCode(l, hashOut);
  uint64_t uid;
  if (!l->zoneFromAnyThread()->getOrCreateUniqueId(l, &uid)) {
    return false;
  }

  *hashOut = UniqueIdToHash(uid);
  return true;
}

template <typename T>
@@ -102,7 +118,7 @@ template <typename T>
  MOZ_ASSERT(CurrentThreadCanAccessZone(l->zoneFromAnyThread()) ||
             CurrentThreadIsPerformingGC());

  return l->zoneFromAnyThread()->getHashCodeInfallible(l);
  return UniqueIdToHash(l->zoneFromAnyThread()->getUniqueIdInfallible(l));
}

template <typename T>
+0 −30
Original line number Diff line number Diff line
@@ -11,21 +11,6 @@

#include "vm/Runtime.h"

static inline js::HashNumber UniqueIdToHash(uint64_t uid) {
  return mozilla::HashGeneric(uid);
}

inline bool JS::Zone::maybeGetHashCode(js::gc::Cell* cell,
                                       js::HashNumber* hashOut) {
  uint64_t uid;
  if (!maybeGetUniqueId(cell, &uid)) {
    return false;
  }

  *hashOut = UniqueIdToHash(uid);
  return true;
}

inline bool JS::Zone::maybeGetUniqueId(js::gc::Cell* cell, uint64_t* uidp) {
  MOZ_ASSERT(uidp);
  MOZ_ASSERT(js::CurrentThreadCanAccessZone(this) ||
@@ -55,17 +40,6 @@ inline bool JS::Zone::maybeGetUniqueId(js::gc::Cell* cell, uint64_t* uidp) {
  return true;
}

inline bool JS::Zone::getOrCreateHashCode(js::gc::Cell* cell,
                                          js::HashNumber* hashOut) {
  uint64_t uid;
  if (!getOrCreateUniqueId(cell, &uid)) {
    return false;
  }

  *hashOut = UniqueIdToHash(uid);
  return true;
}

inline bool JS::Zone::getOrCreateUniqueId(js::gc::Cell* cell, uint64_t* uidp) {
  MOZ_ASSERT(uidp);
  MOZ_ASSERT(js::CurrentThreadCanAccessZone(this) ||
@@ -136,10 +110,6 @@ inline bool JS::Zone::setOrUpdateUniqueId(JSContext* cx, js::gc::Cell* cell,
  return uniqueIds().put(cell, uid);
}

inline js::HashNumber JS::Zone::getHashCodeInfallible(js::gc::Cell* cell) {
  return UniqueIdToHash(getUniqueIdInfallible(cell));
}

inline uint64_t JS::Zone::getUniqueIdInfallible(js::gc::Cell* cell) {
  uint64_t uid;
  js::AutoEnterOOMUnsafeRegion oomUnsafe;
+0 −6
Original line number Diff line number Diff line
@@ -549,16 +549,10 @@ class Zone : public js::ZoneAllocator, public js::gc::GraphNodeBase<JS::Zone> {
  // Gets an existing UID in |uidp| if one exists.
  [[nodiscard]] bool maybeGetUniqueId(js::gc::Cell* cell, uint64_t* uidp);

  [[nodiscard]] bool maybeGetHashCode(js::gc::Cell* cell,
                                      js::HashNumber* hashOut);

  // Puts an existing UID in |uidp|, or creates a new UID for this Cell and
  // puts that into |uidp|. Returns false on OOM.
  [[nodiscard]] bool getOrCreateUniqueId(js::gc::Cell* cell, uint64_t* uidp);
  [[nodiscard]] bool getOrCreateHashCode(js::gc::Cell* cell,
                                         js::HashNumber* hashOut);

  js::HashNumber getHashCodeInfallible(js::gc::Cell* cell);
  uint64_t getUniqueIdInfallible(js::gc::Cell* cell);

  // Return true if this cell has a UID associated with it.