Bug 745322 - Make a relocatable version of HeapId; r=billm

We cannot put implicitly post-barriered items into memory managed outside the
GC.

--HG--
extra : rebase_source : 9d4c8db78d887642dd06e60788e9d514040e92e4
This commit is contained in:
Terrence Cole 2012-04-16 13:05:47 -07:00
parent c93591489a
commit 12a1ff7afb
4 changed files with 90 additions and 39 deletions

View File

@ -313,30 +313,8 @@ HeapSlot::post(JSCompartment *comp, JSObject *owner, uint32_t slot)
HeapSlot::writeBarrierPost(comp, owner, slot);
}
inline
HeapId::HeapId(jsid id)
: value(id)
{
JS_ASSERT(!IsPoisonedId(id));
post();
}
inline
HeapId::~HeapId()
{
pre();
}
inline void
HeapId::init(jsid id)
{
JS_ASSERT(!IsPoisonedId(id));
value = id;
post();
}
inline void
HeapId::pre()
EncapsulatedId::pre()
{
#ifdef JSGC_INCREMENTAL
if (JSID_IS_OBJECT(value)) {
@ -357,6 +335,54 @@ HeapId::pre()
#endif
}
inline
RelocatableId::~RelocatableId()
{
pre();
}
inline RelocatableId &
RelocatableId::operator=(jsid id)
{
if (id != value)
pre();
JS_ASSERT(!IsPoisonedId(id));
value = id;
return *this;
}
inline RelocatableId &
RelocatableId::operator=(const RelocatableId &v)
{
if (v.value != value)
pre();
JS_ASSERT(!IsPoisonedId(v.value));
value = v.value;
return *this;
}
inline
HeapId::HeapId(jsid id)
: EncapsulatedId(id)
{
JS_ASSERT(!IsPoisonedId(id));
post();
}
inline
HeapId::~HeapId()
{
pre();
}
inline void
HeapId::init(jsid id)
{
JS_ASSERT(!IsPoisonedId(id));
value = id;
post();
}
inline void
HeapId::post()
{

View File

@ -443,21 +443,20 @@ class HeapSlotArray
HeapSlotArray operator +(uint32_t offset) const { return HeapSlotArray(array + offset); }
};
class HeapId
class EncapsulatedId
{
protected:
jsid value;
explicit EncapsulatedId() : value(JSID_VOID) {}
explicit inline EncapsulatedId(jsid id) : value(id) {}
~EncapsulatedId() {}
private:
EncapsulatedId(const EncapsulatedId &v) MOZ_DELETE;
EncapsulatedId &operator=(const EncapsulatedId &v) MOZ_DELETE;
public:
explicit HeapId() : value(JSID_VOID) {}
explicit inline HeapId(jsid id);
inline ~HeapId();
inline void init(jsid id);
inline HeapId &operator=(jsid id);
inline HeapId &operator=(const HeapId &v);
bool operator==(jsid id) const { return value == id; }
bool operator!=(jsid id) const { return value != id; }
@ -465,11 +464,37 @@ class HeapId
jsid *unsafeGet() { return &value; }
operator jsid() const { return value; }
private:
protected:
inline void pre();
};
class RelocatableId : public EncapsulatedId
{
public:
explicit RelocatableId() : EncapsulatedId() {}
explicit inline RelocatableId(jsid id) : EncapsulatedId(id) {}
inline ~RelocatableId();
inline RelocatableId &operator=(jsid id);
inline RelocatableId &operator=(const RelocatableId &v);
};
class HeapId : public EncapsulatedId
{
public:
explicit HeapId() : EncapsulatedId() {}
explicit inline HeapId(jsid id);
inline ~HeapId();
inline void init(jsid id);
inline HeapId &operator=(jsid id);
inline HeapId &operator=(const HeapId &v);
private:
inline void post();
HeapId(const HeapId &v);
HeapId(const HeapId &v) MOZ_DELETE;
};
/*

View File

@ -283,7 +283,7 @@ MarkIdInternal(JSTracer *trc, jsid *id)
}
void
MarkId(JSTracer *trc, HeapId *id, const char *name)
MarkId(JSTracer *trc, EncapsulatedId *id, const char *name)
{
JS_SET_TRACING_NAME(trc, name);
MarkIdInternal(trc, id->unsafeGet());

View File

@ -84,13 +84,13 @@ MarkGCThingRoot(JSTracer *trc, void **thingp, const char *name);
/*** ID Marking ***/
void
MarkId(JSTracer *trc, HeapId *id, const char *name);
MarkId(JSTracer *trc, EncapsulatedId *id, const char *name);
void
MarkIdRoot(JSTracer *trc, jsid *id, const char *name);
void
MarkIdRange(JSTracer *trc, size_t len, js::HeapId *vec, const char *name);
MarkIdRange(JSTracer *trc, size_t len, HeapId *vec, const char *name);
void
MarkIdRootRange(JSTracer *trc, size_t len, jsid *vec, const char *name);