Bug 1225650 - Use stable hashing for JSObject2WrappedJSMap; r=jonco
authorTerrence Cole <terrence@mozilla.com>
Tue, 17 Nov 2015 13:40:55 -0800
changeset 277924 3119ae778211ff35d5a8c3d5bdc26589bf8a9452
parent 277923 5075dc8f0dfa20f8fa0b7ab3d7c5e8db7ff774d0
child 277925 e7a9bcc4b922cfb1d8d87f299dda9ee4f492ef24
push id29838
push userkwierso@gmail.com
push dateThu, 31 Dec 2015 01:36:02 +0000
treeherdermozilla-central@22f51211915b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjonco
bugs1225650
milestone46.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 1225650 - Use stable hashing for JSObject2WrappedJSMap; r=jonco
js/xpconnect/src/XPCMaps.cpp
js/xpconnect/src/XPCMaps.h
--- a/js/xpconnect/src/XPCMaps.cpp
+++ b/js/xpconnect/src/XPCMaps.cpp
@@ -114,22 +114,21 @@ JSObject2WrappedJSMap::UpdateWeakPointer
                 if (!wrapper->GetJSObjectPreserveColor())
                     dying.AppendElement(dont_AddRef(wrapper));
             }
             wrapper = wrapper->GetNextWrapper();
         }
 
         // Remove or update the JSObject key in the table if necessary.
         JSObject* obj = e.front().key();
-        JSObject* prior = obj;
         JS_UpdateWeakPointerAfterGCUnbarriered(&obj);
         if (!obj)
             e.removeFront();
-        else if (obj != prior)
-            e.rekeyFront(obj);
+        else
+            e.front().mutableKey() = obj;
     }
 }
 
 void
 JSObject2WrappedJSMap::ShutdownMarker()
 {
     for (Map::Range r = mTable.all(); !r.empty(); r.popFront()) {
         nsXPCWrappedJS* wrapper = r.front().value();
--- a/js/xpconnect/src/XPCMaps.h
+++ b/js/xpconnect/src/XPCMaps.h
@@ -22,18 +22,20 @@
 
 // no virtuals in the maps - all the common stuff inlined
 // templates could be used to good effect here.
 
 /*************************/
 
 class JSObject2WrappedJSMap
 {
-    typedef js::HashMap<JSObject*, nsXPCWrappedJS*, js::PointerHasher<JSObject*, 3>,
-                        js::SystemAllocPolicy> Map;
+    using Map = js::HashMap<JS::Heap<JSObject*>,
+                            nsXPCWrappedJS*,
+                            js::MovableCellHasher<JS::Heap<JSObject*>>,
+                            js::SystemAllocPolicy>;
 
 public:
     static JSObject2WrappedJSMap* newMap(int length) {
         JSObject2WrappedJSMap* map = new JSObject2WrappedJSMap();
         if (!map->mTable.init(length)) {
             // This is a decent estimate of the size of the hash table's
             // entry storage. The |2| is because on average the capacity is
             // twice the requested length.
@@ -61,17 +63,16 @@ public:
     inline nsXPCWrappedJS* Add(JSContext* cx, nsXPCWrappedJS* wrapper) {
         NS_PRECONDITION(wrapper,"bad param");
         JSObject* obj = wrapper->GetJSObjectPreserveColor();
         Map::AddPtr p = mTable.lookupForAdd(obj);
         if (p)
             return p->value();
         if (!mTable.add(p, obj, wrapper))
             return nullptr;
-        JS_StoreObjectPostBarrierCallback(cx, KeyMarkCallback, obj, this);
         return wrapper;
     }
 
     inline void Remove(nsXPCWrappedJS* wrapper) {
         NS_PRECONDITION(wrapper,"bad param");
         mTable.remove(wrapper->GetJSObjectPreserveColor());
     }
 
@@ -90,27 +91,16 @@ public:
 
     // Report the sum of SizeOfIncludingThis() for all wrapped JS in the map.
     // Each wrapped JS is only in one map.
     size_t SizeOfWrappedJS(mozilla::MallocSizeOf mallocSizeOf) const;
 
 private:
     JSObject2WrappedJSMap() {}
 
-    /*
-     * This function is called during minor GCs for each key in the HashMap that
-     * has been moved.
-     */
-    static void KeyMarkCallback(JSTracer* trc, JSObject* key, void* data) {
-        JSObject2WrappedJSMap* self = static_cast<JSObject2WrappedJSMap*>(data);
-        JSObject* prior = key;
-        JS_CallUnbarrieredObjectTracer(trc, &key, "XPCJSRuntime::mWrappedJSMap key");
-        self->mTable.rekeyIfMoved(prior, key);
-    }
-
     Map mTable;
 };
 
 /*************************/
 
 class Native2WrappedNativeMap
 {
 public: