Bug 1226732 - Use stable hashing and builtin sweeping for ipc::ObjectIdMap; r=billm

--HG--
extra : rebase_source : 9dc40a8f2573fd190d9c86a5a88b57dcb41e0771
This commit is contained in:
Terrence Cole 2015-11-25 11:59:09 -08:00
parent 9c36f99a19
commit 020b367913
2 changed files with 10 additions and 35 deletions

View File

@ -104,25 +104,13 @@ ObjectToIdMap::init()
void
ObjectToIdMap::trace(JSTracer* trc)
{
for (Table::Enum e(table_); !e.empty(); e.popFront()) {
JSObject* obj = e.front().key();
JS_CallUnbarrieredObjectTracer(trc, &obj, "ipc-object");
if (obj != e.front().key())
e.rekeyFront(obj);
}
table_.trace(trc);
}
void
ObjectToIdMap::sweep()
{
for (Table::Enum e(table_); !e.empty(); e.popFront()) {
JSObject* obj = e.front().key();
JS_UpdateWeakPointerAfterGCUnbarriered(&obj);
if (!obj)
e.removeFront();
else if (obj != e.front().key())
e.rekeyFront(obj);
}
table_.sweep();
}
ObjectId
@ -137,23 +125,7 @@ ObjectToIdMap::find(JSObject* obj)
bool
ObjectToIdMap::add(JSContext* cx, JSObject* obj, ObjectId id)
{
if (!table_.put(obj, id))
return false;
JS_StoreObjectPostBarrierCallback(cx, keyMarkCallback, obj, &table_);
return true;
}
/*
* This function is called during minor GCs for each key in the HashMap that has
* been moved.
*/
/* static */ void
ObjectToIdMap::keyMarkCallback(JSTracer* trc, JSObject* key, void* data)
{
Table* table = static_cast<Table*>(data);
JSObject* prior = key;
JS_CallUnbarrieredObjectTracer(trc, &key, "ObjectIdCache::table_ key");
table->rekeyIfMoved(prior, key);
return table_.put(obj, id);
}
void

View File

@ -11,6 +11,7 @@
#include "mozilla/dom/DOMTypes.h"
#include "mozilla/jsipc/CrossProcessObjectWrappers.h"
#include "mozilla/jsipc/PJavaScript.h"
#include "js/GCHashTable.h"
#include "nsJSUtils.h"
namespace mozilla {
@ -51,6 +52,10 @@ class ObjectId {
return ObjectId(data >> FLAG_BITS, data & 1);
}
// For use with StructGCPolicy.
void trace(JSTracer*) const {}
bool needsSweep() const { return false; }
private:
ObjectId() : serialNumber_(0), hasXrayWaiver_(false) {}
@ -103,8 +108,8 @@ class IdToObjectMap
// Map JSObjects -> ids
class ObjectToIdMap
{
typedef js::PointerHasher<JSObject*, 3> Hasher;
typedef js::HashMap<JSObject*, ObjectId, Hasher, js::SystemAllocPolicy> Table;
using Hasher = js::MovableCellHasher<JS::Heap<JSObject*>>;
using Table = js::GCHashMap<JS::Heap<JSObject*>, ObjectId, Hasher, js::SystemAllocPolicy>;
public:
explicit ObjectToIdMap(JSRuntime* rt);
@ -120,8 +125,6 @@ class ObjectToIdMap
void clear();
private:
static void keyMarkCallback(JSTracer* trc, JSObject* key, void* data);
JSRuntime* rt_;
Table table_;
};