Bug 1225237 - Use stable hashing for DOMExpandoSet; r=jonco

This commit is contained in:
Terrence Cole 2015-11-17 11:32:53 -08:00
parent 46a8a4f3d1
commit 4885ef86f6
4 changed files with 16 additions and 15 deletions

View File

@ -585,6 +585,17 @@ struct JS_PUBLIC_API(MovableCellHasher)
static void rekey(Key& k, const Key& newKey) { k = newKey; }
};
template <typename T>
struct MovableCellHasher<JS::Heap<T>>
{
using Key = JS::Heap<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); }
};
} /* namespace js */
namespace JS {

View File

@ -329,16 +329,6 @@ JS_CallUnbarrieredStringTracer(JSTracer* trc, JSString** strp, const char* name)
extern JS_PUBLIC_API(void)
JS_CallUnbarrieredScriptTracer(JSTracer* trc, JSScript** scriptp, const char* name);
template <typename HashSetEnum>
inline void
JS_CallHashSetObjectTracer(JSTracer* trc, HashSetEnum& e, JSObject* const& key, const char* name)
{
JSObject* updated = key;
JS_CallUnbarrieredObjectTracer(trc, &updated, name);
if (updated != key)
e.rekeyFront(updated);
}
/**
* Trace an object that is known to always be tenured. No post barriers are
* required in this case.

View File

@ -479,7 +479,7 @@ XPCWrappedNativeScope::TraceWrappedNativesInAllScopes(JSTracer* trc, XPCJSRuntim
if (cur->mDOMExpandoSet) {
for (DOMExpandoSet::Enum e(*cur->mDOMExpandoSet); !e.empty(); e.popFront())
JS_CallHashSetObjectTracer(trc, e, e.front(), "DOM expando object");
JS_CallObjectTracer(trc, &e.mutableFront(), "DOM expando object");
}
}
}

View File

@ -1119,8 +1119,8 @@ public:
static bool
IsDyingScope(XPCWrappedNativeScope* scope);
typedef js::HashSet<JSObject*,
js::PointerHasher<JSObject*, 3>,
typedef js::HashSet<JS::Heap<JSObject*>,
js::MovableCellHasher<JS::Heap<JSObject*>>,
js::SystemAllocPolicy> DOMExpandoSet;
bool RegisterDOMExpandoObject(JSObject* expando) {
@ -1130,11 +1130,11 @@ public:
mDOMExpandoSet = new DOMExpandoSet();
mDOMExpandoSet->init(8);
}
return mDOMExpandoSet->put(expando);
return mDOMExpandoSet->put(JS::Heap<JSObject*>(expando));
}
void RemoveDOMExpandoObject(JSObject* expando) {
if (mDOMExpandoSet) {
DOMExpandoSet::Ptr p = mDOMExpandoSet->lookup(expando);
DOMExpandoSet::Ptr p = mDOMExpandoSet->lookup(JS::Heap<JSObject*>(expando));
MOZ_ASSERT(p.found());
mDOMExpandoSet->remove(p);
}