Bug 1224404 - Use stable hashing for WeakMapPtr; r=jonco
authorTerrence Cole <terrence@mozilla.com>
Fri, 13 Nov 2015 08:41:39 -0800
changeset 273033 a621c6d49da11548244ba40ba131db239195c43c
parent 273032 40a37cb11607a03baa857eb41095956923676e5c
child 273034 f3d2ddb4979c9909e012adafd607fc4463e32e6b
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
bugs1224404
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 1224404 - Use stable hashing for WeakMapPtr; r=jonco
js/public/WeakMapPtr.h
js/src/vm/WeakMapPtr.cpp
--- a/js/public/WeakMapPtr.h
+++ b/js/public/WeakMapPtr.h
@@ -28,18 +28,16 @@ class JS_PUBLIC_API(WeakMapPtr)
     bool initialized() { return ptr != nullptr; }
     void destroy();
     virtual ~WeakMapPtr() { MOZ_ASSERT(!initialized()); }
     void trace(JSTracer* tracer);
 
     V lookup(const K& key);
     bool put(JSContext* cx, const K& key, const V& value);
 
-    static void keyMarkCallback(JSTracer* trc, K key, void* data);
-
   private:
     void* ptr;
 
     // WeakMapPtr is neither copyable nor assignable.
     WeakMapPtr(const WeakMapPtr& wmp) = delete;
     WeakMapPtr& operator=(const WeakMapPtr& wmp) = delete;
 };
 
--- a/js/src/vm/WeakMapPtr.cpp
+++ b/js/src/vm/WeakMapPtr.cpp
@@ -20,33 +20,35 @@ namespace {
 template<typename T>
 struct DataType
 {
 };
 
 template<>
 struct DataType<JSObject*>
 {
-    typedef PreBarrieredObject PreBarriered;
+    using BarrieredType = RelocatablePtrObject;
+    using HasherType = MovableCellHasher<BarrieredType>;
     static JSObject* NullValue() { return nullptr; }
 };
 
 template<>
 struct DataType<JS::Value>
 {
-    typedef PreBarrieredValue PreBarriered;
+    using BarrieredType = RelocatablePtr<Value>;
     static JS::Value NullValue() { return JS::UndefinedValue(); }
 };
 
 template <typename K, typename V>
 struct Utils
 {
-    typedef typename DataType<K>::PreBarriered KeyType;
-    typedef typename DataType<V>::PreBarriered ValueType;
-    typedef WeakMap<KeyType, ValueType> Type;
+    typedef typename DataType<K>::BarrieredType KeyType;
+    typedef typename DataType<K>::HasherType HasherType;
+    typedef typename DataType<V>::BarrieredType ValueType;
+    typedef WeakMap<KeyType, ValueType, HasherType> Type;
     typedef Type* PtrType;
     static PtrType cast(void* ptr) { return static_cast<PtrType>(ptr); }
 };
 
 } /* namespace */
 
 template <typename K, typename V>
 void
@@ -84,36 +86,21 @@ JS::WeakMapPtr<K, V>::lookup(const K& ke
     MOZ_ASSERT(initialized());
     typename Utils<K, V>::Type::Ptr result = Utils<K, V>::cast(ptr)->lookup(key);
     if (!result)
         return DataType<V>::NullValue();
     return result->value();
 }
 
 template <typename K, typename V>
-/* static */ void
-JS::WeakMapPtr<K, V>::keyMarkCallback(JSTracer* trc, K key, void* data)
-{
-    auto map = static_cast< JS::WeakMapPtr<K, V>* >(data);
-    K prior = key;
-    JS_CallUnbarrieredObjectTracer(trc, &key, "WeakMapPtr key");
-    return Utils<K, V>::cast(map->ptr)->rekeyIfMoved(prior, key);
-}
-
-template <typename K, typename V>
 bool
 JS::WeakMapPtr<K, V>::put(JSContext* cx, const K& key, const V& value)
 {
     MOZ_ASSERT(initialized());
-    if (!Utils<K, V>::cast(ptr)->put(key, value))
-        return false;
-    JS_StoreObjectPostBarrierCallback(cx, keyMarkCallback, key, this);
-    // Values do not need to be barriered because only put() is supported,
-    // which is always an initializing write.
-    return true;
+    return Utils<K, V>::cast(ptr)->put(key, value);
 }
 
 //
 // Supported specializations of JS::WeakMap:
 //
 
 template class JS_PUBLIC_API(JS::WeakMapPtr)<JSObject*, JSObject*>;