Bug 1167291 - Generalize the marking tracer's cross-compartment check; r=jonco

This commit is contained in:
Terrence Cole 2015-05-21 11:30:01 -07:00
parent 12554cb2df
commit dc697a8108
6 changed files with 22 additions and 16 deletions

View File

@ -230,6 +230,9 @@ struct Cell
inline JSRuntime* runtimeFromAnyThread() const;
inline JS::shadow::Runtime* shadowRuntimeFromAnyThread() const;
// May be overridden by GC thing kinds that have a compartment pointer.
inline JSCompartment* maybeCompartment() const { return nullptr; }
inline StoreBuffer* storeBuffer() const;
inline JSGCTraceKind getTraceKind() const;

View File

@ -737,21 +737,23 @@ template <typename S, typename T>
void
js::GCMarker::traverseEdge(S source, T target)
{
// Atoms and Symbols do not have or mark their internal pointers, respectively.
MOZ_ASSERT(!ThingIsPermanentAtomOrWellKnownSymbol(source));
// The Zones must match, unless the target is an atom.
MOZ_ASSERT_IF(!ThingIsPermanentAtomOrWellKnownSymbol(target),
target->zone()->isAtomsZone() || target->zone() == source->zone());
traverse(target);
}
namespace js {
// Special-case JSObject->JSObject edges to check the compartment too.
template <>
void
GCMarker::traverseEdge(JSObject* source, JSObject* target)
{
MOZ_ASSERT(target->compartment() == source->compartment());
// Atoms and Symbols do not have access to a compartment pointer, or we'd need
// to adjust the subsequent check to catch that case.
MOZ_ASSERT_IF(ThingIsPermanentAtomOrWellKnownSymbol(target), !target->maybeCompartment());
MOZ_ASSERT_IF(target->zoneFromAnyThread()->isAtomsZone(), !target->maybeCompartment());
// If we have access to a compartment pointer for both things, they must match.
MOZ_ASSERT_IF(source->maybeCompartment() && target->maybeCompartment(),
source->maybeCompartment() == target->maybeCompartment());
traverse(target);
}
} // namespace js
template <typename V, typename S> struct TraverseEdgeFunctor : public VoidDefaultAdaptor<V> {
template <typename T> void operator()(T t, GCMarker* gcmarker, S s) {

View File

@ -155,9 +155,8 @@ class JSObject : public js::gc::Cell
return group_->lazy();
}
JSCompartment* compartment() const {
return group_->compartment();
}
JSCompartment* compartment() const { return group_->compartment(); }
JSCompartment* maybeCompartment() const { return compartment(); }
inline js::Shape* maybeShape() const;
inline js::Shape* ensureShape(js::ExclusiveContext* cx);

View File

@ -1061,6 +1061,7 @@ class JSScript : public js::gc::TenuredCell
inline JSPrincipals* principals();
JSCompartment* compartment() const { return compartment_; }
JSCompartment* maybeCompartment() const { return compartment(); }
void setVersion(JSVersion v) { version = v; }

View File

@ -216,9 +216,8 @@ class ObjectGroup : public gc::TenuredCell
return res;
}
JSCompartment* compartment() const {
return compartment_;
}
JSCompartment* compartment() const { return compartment_; }
JSCompartment* maybeCompartment() const { return compartment(); }
private:
/* Flags for this group. */

View File

@ -426,6 +426,7 @@ class BaseShape : public gc::TenuredCell
void setSlotSpan(uint32_t slotSpan) { MOZ_ASSERT(isOwned()); slotSpan_ = slotSpan; }
JSCompartment* compartment() const { return compartment_; }
JSCompartment* maybeCompartment() const { return compartment(); }
/*
* Lookup base shapes from the compartment's baseShapes table, adding if
@ -655,6 +656,7 @@ class Shape : public gc::TenuredCell
const HeapPtrShape& previous() const { return parent; }
JSCompartment* compartment() const { return base()->compartment(); }
JSCompartment* maybeCompartment() const { return compartment(); }
template <AllowGC allowGC>
class Range {