Bug 790338 - Improve debugger find edges code r=billm

--HG--
extra : rebase_source : 25574a7ca88533ce78ab06e18c4b1625df0fa70d
This commit is contained in:
Jon Coppeard 2012-11-06 17:45:58 +00:00
parent 8d898ef7c3
commit 33e1b47edf
2 changed files with 14 additions and 18 deletions

View File

@ -1568,9 +1568,14 @@ Debugger::findCompartmentEdges(JSCompartment *comp, js::gc::ComponentFinder &fin
JSRuntime *rt = comp->rt;
for (JSCList *p = &rt->debuggerList; (p = JS_NEXT_LINK(p)) != &rt->debuggerList;) {
Debugger *dbg = Debugger::fromLinks(p);
dbg->scripts.findCompartmentEdges(comp, finder);
dbg->objects.findCompartmentEdges(comp, finder);
dbg->environments.findCompartmentEdges(comp, finder);
JSCompartment *w = dbg->object->compartment();
if (w == comp || !w->isGCMarking())
continue;
if (dbg->scripts.hasKeyInCompartment(comp) ||
dbg->objects.hasKeyInCompartment(comp) ||
dbg->environments.hasKeyInCompartment(comp)) {
finder.addEdgeTo(w);
}
}
}

View File

@ -50,13 +50,12 @@ class DebuggerWeakMap : private WeakMap<Key, Value, DefaultHasher<Key> >
DefaultHasher<JSCompartment *>,
RuntimeAllocPolicy> CountMap;
JSCompartment *valueCompartment;
CountMap compartmentCounts;
public:
typedef WeakMap<Key, Value, DefaultHasher<Key> > Base;
explicit DebuggerWeakMap(JSContext *cx)
: Base(cx), valueCompartment(NULL), compartmentCounts(cx) { }
: Base(cx), compartmentCounts(cx) { }
public:
/* Expose those parts of HashMap public interface that are used by Debugger methods. */
@ -77,9 +76,7 @@ class DebuggerWeakMap : private WeakMap<Key, Value, DefaultHasher<Key> >
template<typename KeyInput, typename ValueInput>
bool relookupOrAdd(AddPtr &p, const KeyInput &k, const ValueInput &v) {
if (!valueCompartment)
valueCompartment = v->compartment();
JS_ASSERT(v->compartment() == valueCompartment);
JS_ASSERT(v->compartment() == Base::compartment);
if (!incCompartmentCount(k->compartment()))
return false;
bool ok = Base::relookupOrAdd(p, k, v);
@ -95,8 +92,6 @@ class DebuggerWeakMap : private WeakMap<Key, Value, DefaultHasher<Key> >
void remove(const Lookup &l) {
Base::remove(l);
decCompartmentCount(l->compartment());
if (Base::count() == 0)
valueCompartment = NULL;
}
public:
@ -114,14 +109,10 @@ class DebuggerWeakMap : private WeakMap<Key, Value, DefaultHasher<Key> >
}
}
void findCompartmentEdges(JSCompartment *v, js::gc::ComponentFinder &finder) {
if (!valueCompartment || valueCompartment == v || !valueCompartment->isGCMarking())
return;
CountMap::Ptr p = compartmentCounts.lookup(v);
if (!p)
return;
JS_ASSERT(p->value > 0);
finder.addEdgeTo(valueCompartment);
bool hasKeyInCompartment(JSCompartment *c) {
CountMap::Ptr p = compartmentCounts.lookup(c);
JS_ASSERT_IF(p, p->value > 0);
return p;
}
private: