Bug 1223853 - Use stable hashing for ObjectValueMap; r=jonco

--HG--
extra : rebase_source : 70ef64bca2e6c5e1cc0883b25fc3453b2966257c
This commit is contained in:
Terrence Cole 2015-11-12 13:43:30 -08:00
Родитель dcd352d66d
Коммит e90202ab51
4 изменённых файлов: 23 добавлений и 15 удалений

Просмотреть файл

@ -148,13 +148,6 @@ TryPreserveReflector(JSContext* cx, HandleObject obj)
return true;
}
static inline void
WeakMapPostWriteBarrier(JSRuntime* rt, ObjectValueMap* weakMap, JSObject* key)
{
if (key && IsInsideNursery(key))
rt->gc.storeBuffer.putGeneric(gc::HashKeyRef<ObjectValueMap, JSObject*>(weakMap, key));
}
static MOZ_ALWAYS_INLINE bool
SetWeakMapEntryInternal(JSContext* cx, Handle<WeakMapObject*> mapObj,
HandleObject key, HandleValue value)
@ -189,7 +182,6 @@ SetWeakMapEntryInternal(JSContext* cx, Handle<WeakMapObject*> mapObj,
JS_ReportOutOfMemory(cx);
return false;
}
WeakMapPostWriteBarrier(cx->runtime(), map, key.get());
return true;
}

Просмотреть файл

@ -482,7 +482,9 @@ class RelocatablePtr : public WriteBarrieredBase<T>
{
public:
RelocatablePtr() : WriteBarrieredBase<T>(GCMethods<T>::initial()) {}
explicit RelocatablePtr(T v) : WriteBarrieredBase<T>(v) {
// Implicitly adding barriers is a reasonable default.
MOZ_IMPLICIT RelocatablePtr(const T& v) : WriteBarrieredBase<T>(v) {
this->post(GCMethods<T>::initial(), this->value);
}
@ -560,14 +562,18 @@ class ReadBarriered : public ReadBarrieredBase<T>
public:
ReadBarriered() : ReadBarrieredBase<T>(GCMethods<T>::initial()) {}
// It is okay to add barriers implicitly.
MOZ_IMPLICIT ReadBarriered(const T& v) : ReadBarrieredBase<T>(v) {
this->post(GCMethods<T>::initial(), v);
}
// Copy is creating a new edge, so we must read barrier the source edge.
explicit ReadBarriered(const ReadBarriered& v) : ReadBarrieredBase<T>(v) {
this->post(GCMethods<T>::initial(), v.get());
}
// Move retains the lifetime status of the source edge, so does not fire
// the read barrier of the defunct edge.
ReadBarriered(ReadBarriered&& v)
: ReadBarrieredBase<T>(mozilla::Forward<ReadBarriered<T>>(v))
{
@ -799,6 +805,17 @@ struct MovableCellHasher
static void rekey(Key& k, const Key& newKey) { k = newKey; }
};
template <typename T>
struct MovableCellHasher<RelocatablePtr<T>>
{
using Key = RelocatablePtr<T>;
using Lookup = T;
static HashNumber hash(const Lookup& l) { return MovableCellHasher<T>::hash(l); }
static bool match(const Key& k, const Lookup& l) { return MovableCellHasher<T>::match(k, l); }
static void rekey(Key& k, const Key& newKey) { k.unsafeSet(newKey); }
};
/* Useful for hashtables with a HeapPtr as key. */
template <class T>
struct HeapPtrHasher

Просмотреть файл

@ -188,8 +188,6 @@ ObjectWeakMap::add(JSContext* cx, JSObject* obj, JSObject* target)
ReportOutOfMemory(cx);
return false;
}
if (IsInsideNursery(obj))
cx->runtime()->gc.storeBuffer.putGeneric(StoreBufferRef(&map, obj));
return true;
}

Просмотреть файл

@ -392,11 +392,14 @@ extern JSObject*
InitWeakMapClass(JSContext* cx, HandleObject obj);
class ObjectValueMap : public WeakMap<PreBarrieredObject, RelocatableValue>
class ObjectValueMap : public WeakMap<RelocatablePtrObject, RelocatableValue,
MovableCellHasher<RelocatablePtrObject>>
{
public:
ObjectValueMap(JSContext* cx, JSObject* obj)
: WeakMap<PreBarrieredObject, RelocatableValue>(cx, obj) {}
: WeakMap<RelocatablePtrObject, RelocatableValue,
MovableCellHasher<RelocatablePtrObject>>(cx, obj)
{}
virtual bool findZoneEdges();
};
@ -405,9 +408,7 @@ class ObjectValueMap : public WeakMap<PreBarrieredObject, RelocatableValue>
// Generic weak map for mapping objects to other objects.
class ObjectWeakMap
{
private:
ObjectValueMap map;
typedef gc::HashKeyRef<ObjectValueMap, JSObject*> StoreBufferRef;
public:
explicit ObjectWeakMap(JSContext* cx);