Bug 1226687 - Part 2: Use stable hashing and builtin sweep for JSObject2JSObjectMap; r=mccr8

--HG--
extra : rebase_source : e3c5c05bead56da0dab01a3fdfb16a1f02fe862d
This commit is contained in:
Terrence Cole 2015-11-20 13:54:35 -08:00
parent 2f587b2fc3
commit 79de7574c1

View File

@ -11,6 +11,7 @@
#include "mozilla/MemoryReporting.h" #include "mozilla/MemoryReporting.h"
#include "js/GCHashTable.h"
// Maps... // Maps...
@ -593,8 +594,10 @@ private:
class JSObject2JSObjectMap class JSObject2JSObjectMap
{ {
typedef js::HashMap<JSObject*, JS::Heap<JSObject*>, js::PointerHasher<JSObject*, 3>, using Map = js::GCHashMap<JS::Heap<JSObject*>,
js::SystemAllocPolicy> Map; JS::Heap<JSObject*>,
js::MovableCellHasher<JS::Heap<JSObject*>>,
js::SystemAllocPolicy>;
public: public:
static JSObject2JSObjectMap* newMap(int length) { static JSObject2JSObjectMap* newMap(int length) {
@ -624,7 +627,6 @@ public:
if (!mTable.add(p, key, value)) if (!mTable.add(p, key, value))
return nullptr; return nullptr;
MOZ_ASSERT(xpc::CompartmentPrivate::Get(key)->scope->mWaiverWrapperMap == this); MOZ_ASSERT(xpc::CompartmentPrivate::Get(key)->scope->mWaiverWrapperMap == this);
JS_StoreObjectPostBarrierCallback(cx, KeyMarkCallback, key, this);
return value; return value;
} }
@ -636,41 +638,12 @@ public:
inline uint32_t Count() { return mTable.count(); } inline uint32_t Count() { return mTable.count(); }
void Sweep() { void Sweep() {
for (Map::Enum e(mTable); !e.empty(); e.popFront()) { mTable.sweep();
JSObject* key = e.front().key();
JS::Heap<JSObject*>* valuep = &e.front().value();
JS_UpdateWeakPointerAfterGCUnbarriered(&key);
JS_UpdateWeakPointerAfterGC(valuep);
if (!key || !*valuep)
e.removeFront();
else if (key != e.front().key())
e.rekeyFront(key);
}
} }
private: private:
JSObject2JSObjectMap() {} JSObject2JSObjectMap() {}
/*
* 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) {
/*
* To stop the barriers on the values of mTable firing while we are
* marking the store buffer, we cast the table to one that is
* binary-equivatlent but without the barriers, and update that.
*/
typedef js::HashMap<JSObject*, JSObject*, js::PointerHasher<JSObject*, 3>,
js::SystemAllocPolicy> UnbarrieredMap;
JSObject2JSObjectMap* self = static_cast<JSObject2JSObjectMap*>(data);
UnbarrieredMap& table = reinterpret_cast<UnbarrieredMap&>(self->mTable);
JSObject* prior = key;
JS_CallUnbarrieredObjectTracer(trc, &key, "XPCWrappedNativeScope::mWaiverWrapperMap key");
table.rekeyIfMoved(prior, key);
}
Map mTable; Map mTable;
}; };