Bug 1225233 - Make MovableCellHasher a public interface, usable by embedders; r=jonco
☠☠ backed out by 84d1c56d6983 ☠ ☠
authorTerrence Cole <terrence@mozilla.com>
Tue, 17 Nov 2015 11:31:52 -0800
changeset 273035 02919b7d57d7f8206328f53ac0f7b2b9fe334c9b
parent 273034 f3d2ddb4979c9909e012adafd607fc4463e32e6b
child 273036 0899a0ebe6977940c9f702a02883eaa084281518
push id29693
push usercbook@mozilla.com
push dateWed, 18 Nov 2015 13:50:33 +0000
treeherdermozilla-central@1d6155d7e6c9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjonco
bugs1225233
milestone45.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1225233 - Make MovableCellHasher a public interface, usable by embedders; r=jonco
js/public/RootingAPI.h
js/src/gc/Barrier.h
--- a/js/public/RootingAPI.h
+++ b/js/public/RootingAPI.h
@@ -558,16 +558,38 @@ struct GCMethods<JSFunction*>
     static JSFunction* initial() { return nullptr; }
     static void postBarrier(JSFunction** vp, JSFunction* prev, JSFunction* next) {
         JS::HeapObjectPostBarrier(reinterpret_cast<JSObject**>(vp),
                                   reinterpret_cast<JSObject*>(prev),
                                   reinterpret_cast<JSObject*>(next));
     }
 };
 
+// Provide hash codes for Cell kinds that may be relocated and, thus, not have
+// a stable address to use as the base for a hash code. Instead of the address,
+// this hasher uses Cell::getUniqueId to provide exact matches and as a base
+// for generating hash codes.
+//
+// Note: this hasher, like PointerHasher can "hash" a nullptr. While a nullptr
+// would not likely be a useful key, there are some cases where being able to
+// hash a nullptr is useful, either on purpose or because of bugs:
+// (1) existence checks where the key may happen to be null and (2) some
+// aggregate Lookup kinds embed a JSObject* that is frequently null and do not
+// null test before dispatching to the hasher.
+template <typename T>
+struct JS_PUBLIC_API(MovableCellHasher)
+{
+    using Key = T;
+    using Lookup = T;
+
+    static HashNumber hash(const Lookup& l);
+    static bool match(const Key& k, const Lookup& l);
+    static void rekey(Key& k, const Key& newKey) { k = newKey; }
+};
+
 } /* namespace js */
 
 namespace JS {
 
 // Non pointer types -- structs or classes that contain GC pointers, either as
 // a member or in a more complex container layout -- can also be stored in a
 // [Persistent]Rooted if it derives from JS::Traceable. A JS::Traceable stored
 // in a [Persistent]Rooted must implement the method:
--- a/js/src/gc/Barrier.h
+++ b/js/src/gc/Barrier.h
@@ -779,38 +779,16 @@ class ImmutableTenuredPtr
         MOZ_ASSERT(ptr->isTenured());
         value = ptr;
     }
 
     T get() const { return value; }
     const T* address() { return &value; }
 };
 
-// Provide hash codes for Cell kinds that may be relocated and, thus, not have
-// a stable address to use as the base for a hash code. Instead of the address,
-// this hasher uses Cell::getUniqueId to provide exact matches and as a base
-// for generating hash codes.
-//
-// Note: this hasher, like PointerHasher can "hash" a nullptr. While a nullptr
-// would not likely be a useful key, there are some cases where being able to
-// hash a nullptr is useful, either on purpose or because of bugs:
-// (1) existence checks where the key may happen to be null and (2) some
-// aggregate Lookup kinds embed a JSObject* that is frequently null and do not
-// null test before dispatching to the hasher.
-template <typename T>
-struct MovableCellHasher
-{
-    using Key = T;
-    using Lookup = T;
-
-    static HashNumber hash(const Lookup& l);
-    static bool match(const Key& k, const Lookup& l);
-    static void rekey(Key& k, const Key& newKey) { k = newKey; }
-};
-
 template <typename T>
 struct MovableCellHasher<PreBarriered<T>>
 {
     using Key = PreBarriered<T>;
     using Lookup = T;
 
     static HashNumber hash(const Lookup& l) { return MovableCellHasher<T>::hash(l); }
     static bool match(const Key& k, const Lookup& l) { return MovableCellHasher<T>::match(k, l); }