mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 14:22:01 +00:00
Bug 1226687
- Part 2: Use stable hashing and builtin sweep for JSObject2JSObjectMap; r=mccr8
--HG-- extra : rebase_source : e3c5c05bead56da0dab01a3fdfb16a1f02fe862d
This commit is contained in:
parent
2f587b2fc3
commit
79de7574c1
@ -11,6 +11,7 @@
|
||||
|
||||
#include "mozilla/MemoryReporting.h"
|
||||
|
||||
#include "js/GCHashTable.h"
|
||||
|
||||
// Maps...
|
||||
|
||||
@ -593,8 +594,10 @@ private:
|
||||
|
||||
class JSObject2JSObjectMap
|
||||
{
|
||||
typedef js::HashMap<JSObject*, JS::Heap<JSObject*>, js::PointerHasher<JSObject*, 3>,
|
||||
js::SystemAllocPolicy> Map;
|
||||
using Map = js::GCHashMap<JS::Heap<JSObject*>,
|
||||
JS::Heap<JSObject*>,
|
||||
js::MovableCellHasher<JS::Heap<JSObject*>>,
|
||||
js::SystemAllocPolicy>;
|
||||
|
||||
public:
|
||||
static JSObject2JSObjectMap* newMap(int length) {
|
||||
@ -624,7 +627,6 @@ public:
|
||||
if (!mTable.add(p, key, value))
|
||||
return nullptr;
|
||||
MOZ_ASSERT(xpc::CompartmentPrivate::Get(key)->scope->mWaiverWrapperMap == this);
|
||||
JS_StoreObjectPostBarrierCallback(cx, KeyMarkCallback, key, this);
|
||||
return value;
|
||||
}
|
||||
|
||||
@ -636,41 +638,12 @@ public:
|
||||
inline uint32_t Count() { return mTable.count(); }
|
||||
|
||||
void Sweep() {
|
||||
for (Map::Enum e(mTable); !e.empty(); e.popFront()) {
|
||||
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);
|
||||
}
|
||||
mTable.sweep();
|
||||
}
|
||||
|
||||
private:
|
||||
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;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user