mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 03:45:46 +00:00
Bug 1265483
- Use WeakCache to automate sweeping of ObjectGroupCompartment::NewTable; r=jonco
This commit is contained in:
parent
c09452f2f6
commit
da3a863a84
@ -31,6 +31,7 @@ class WeakCache : public js::WeakCacheBase<T>,
|
|||||||
friend class mozilla::LinkedListElement<WeakCache<T>>;
|
friend class mozilla::LinkedListElement<WeakCache<T>>;
|
||||||
friend class mozilla::LinkedList<WeakCache<T>>;
|
friend class mozilla::LinkedList<WeakCache<T>>;
|
||||||
|
|
||||||
|
WeakCache() = delete;
|
||||||
WeakCache(const WeakCache&) = delete;
|
WeakCache(const WeakCache&) = delete;
|
||||||
|
|
||||||
using SweepFn = void (*)(T*);
|
using SweepFn = void (*)(T*);
|
||||||
@ -38,6 +39,8 @@ class WeakCache : public js::WeakCacheBase<T>,
|
|||||||
T cache;
|
T cache;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
using Type = T;
|
||||||
|
|
||||||
template <typename U>
|
template <typename U>
|
||||||
WeakCache(Zone* zone, U&& initial)
|
WeakCache(Zone* zone, U&& initial)
|
||||||
: cache(mozilla::Forward<U>(initial))
|
: cache(mozilla::Forward<U>(initial))
|
||||||
|
@ -412,6 +412,16 @@ struct ObjectGroupCompartment::NewEntry
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class ObjectGroupCompartment::NewTable : public JS::WeakCache<js::GCHashSet<NewEntry, NewEntry,
|
||||||
|
SystemAllocPolicy>>
|
||||||
|
{
|
||||||
|
using Table = js::GCHashSet<NewEntry, NewEntry, SystemAllocPolicy>;
|
||||||
|
using Base = JS::WeakCache<Table>;
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit NewTable(Zone* zone) : Base(zone, Table()) {}
|
||||||
|
};
|
||||||
|
|
||||||
/* static */ ObjectGroup*
|
/* static */ ObjectGroup*
|
||||||
ObjectGroup::defaultNewGroup(ExclusiveContext* cx, const Class* clasp,
|
ObjectGroup::defaultNewGroup(ExclusiveContext* cx, const Class* clasp,
|
||||||
TaggedProto proto, JSObject* associated)
|
TaggedProto proto, JSObject* associated)
|
||||||
@ -429,7 +439,7 @@ ObjectGroup::defaultNewGroup(ExclusiveContext* cx, const Class* clasp,
|
|||||||
ObjectGroupCompartment::NewTable*& table = cx->compartment()->objectGroups.defaultNewTable;
|
ObjectGroupCompartment::NewTable*& table = cx->compartment()->objectGroups.defaultNewTable;
|
||||||
|
|
||||||
if (!table) {
|
if (!table) {
|
||||||
table = cx->new_<ObjectGroupCompartment::NewTable>();
|
table = cx->new_<ObjectGroupCompartment::NewTable>(cx->zone());
|
||||||
if (!table || !table->init()) {
|
if (!table || !table->init()) {
|
||||||
js_delete(table);
|
js_delete(table);
|
||||||
table = nullptr;
|
table = nullptr;
|
||||||
@ -551,7 +561,7 @@ ObjectGroup::lazySingletonGroup(ExclusiveContext* cx, const Class* clasp, Tagged
|
|||||||
ObjectGroupCompartment::NewTable*& table = cx->compartment()->objectGroups.lazyTable;
|
ObjectGroupCompartment::NewTable*& table = cx->compartment()->objectGroups.lazyTable;
|
||||||
|
|
||||||
if (!table) {
|
if (!table) {
|
||||||
table = cx->new_<ObjectGroupCompartment::NewTable>();
|
table = cx->new_<ObjectGroupCompartment::NewTable>(cx->zone());
|
||||||
if (!table || !table->init()) {
|
if (!table || !table->init()) {
|
||||||
ReportOutOfMemory(cx);
|
ReportOutOfMemory(cx);
|
||||||
js_delete(table);
|
js_delete(table);
|
||||||
@ -593,8 +603,8 @@ ObjectGroup::setDefaultNewGroupUnknown(JSContext* cx, const Class* clasp, Handle
|
|||||||
ObjectGroupCompartment::NewTable* table = cx->compartment()->objectGroups.defaultNewTable;
|
ObjectGroupCompartment::NewTable* table = cx->compartment()->objectGroups.defaultNewTable;
|
||||||
if (table) {
|
if (table) {
|
||||||
Rooted<TaggedProto> taggedProto(cx, TaggedProto(obj));
|
Rooted<TaggedProto> taggedProto(cx, TaggedProto(obj));
|
||||||
ObjectGroupCompartment::NewTable::Ptr p =
|
auto lookup = ObjectGroupCompartment::NewEntry::Lookup(clasp, taggedProto, nullptr);
|
||||||
table->lookup(ObjectGroupCompartment::NewEntry::Lookup(clasp, taggedProto, nullptr));
|
auto p = table->lookup(lookup);
|
||||||
if (p)
|
if (p)
|
||||||
MarkObjectGroupUnknownProperties(cx, p->group);
|
MarkObjectGroupUnknownProperties(cx, p->group);
|
||||||
}
|
}
|
||||||
@ -607,8 +617,8 @@ ObjectGroup::hasDefaultNewGroup(JSObject* proto, const Class* clasp, ObjectGroup
|
|||||||
ObjectGroupCompartment::NewTable* table = proto->compartment()->objectGroups.defaultNewTable;
|
ObjectGroupCompartment::NewTable* table = proto->compartment()->objectGroups.defaultNewTable;
|
||||||
|
|
||||||
if (table) {
|
if (table) {
|
||||||
ObjectGroupCompartment::NewTable::Ptr p =
|
auto lookup = ObjectGroupCompartment::NewEntry::Lookup(clasp, TaggedProto(proto), nullptr);
|
||||||
table->lookup(ObjectGroupCompartment::NewEntry::Lookup(clasp, TaggedProto(proto), nullptr));
|
auto p = table->lookup(lookup);
|
||||||
return p && p->group == group;
|
return p && p->group == group;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -1614,10 +1624,10 @@ void
|
|||||||
ObjectGroupCompartment::removeDefaultNewGroup(const Class* clasp, TaggedProto proto,
|
ObjectGroupCompartment::removeDefaultNewGroup(const Class* clasp, TaggedProto proto,
|
||||||
JSObject* associated)
|
JSObject* associated)
|
||||||
{
|
{
|
||||||
NewTable::Ptr p = defaultNewTable->lookup(NewEntry::Lookup(clasp, proto, associated));
|
auto p = defaultNewTable->lookup(NewEntry::Lookup(clasp, proto, associated));
|
||||||
MOZ_RELEASE_ASSERT(p);
|
MOZ_RELEASE_ASSERT(p);
|
||||||
|
|
||||||
defaultNewTable->remove(p);
|
defaultNewTable->get().remove(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -1626,9 +1636,9 @@ ObjectGroupCompartment::replaceDefaultNewGroup(const Class* clasp, TaggedProto p
|
|||||||
{
|
{
|
||||||
NewEntry::Lookup lookup(clasp, proto, associated);
|
NewEntry::Lookup lookup(clasp, proto, associated);
|
||||||
|
|
||||||
NewTable::Ptr p = defaultNewTable->lookup(lookup);
|
auto p = defaultNewTable->lookup(lookup);
|
||||||
MOZ_RELEASE_ASSERT(p);
|
MOZ_RELEASE_ASSERT(p);
|
||||||
defaultNewTable->remove(p);
|
defaultNewTable->get().remove(p);
|
||||||
{
|
{
|
||||||
AutoEnterOOMUnsafeRegion oomUnsafe;
|
AutoEnterOOMUnsafeRegion oomUnsafe;
|
||||||
if (!defaultNewTable->putNew(lookup, NewEntry(group, associated)))
|
if (!defaultNewTable->putNew(lookup, NewEntry(group, associated)))
|
||||||
@ -1734,10 +1744,6 @@ ObjectGroupCompartment::sweep(FreeOp* fop)
|
|||||||
plainObjectTable->sweep();
|
plainObjectTable->sweep();
|
||||||
if (allocationSiteTable)
|
if (allocationSiteTable)
|
||||||
allocationSiteTable->sweep();
|
allocationSiteTable->sweep();
|
||||||
if (defaultNewTable)
|
|
||||||
defaultNewTable->sweep();
|
|
||||||
if (lazyTable)
|
|
||||||
lazyTable->sweep();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -1794,7 +1800,7 @@ ObjectGroupCompartment::checkNewTableAfterMovingGC(NewTable* table)
|
|||||||
clasp = nullptr;
|
clasp = nullptr;
|
||||||
|
|
||||||
NewEntry::Lookup lookup(clasp, proto, entry.associated);
|
NewEntry::Lookup lookup(clasp, proto, entry.associated);
|
||||||
NewTable::Ptr ptr = table->lookup(lookup);
|
auto ptr = table->lookup(lookup);
|
||||||
MOZ_RELEASE_ASSERT(ptr.found() && &*ptr == &e.front());
|
MOZ_RELEASE_ASSERT(ptr.found() && &*ptr == &e.front());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -540,7 +540,7 @@ class ObjectGroupCompartment
|
|||||||
friend class ObjectGroup;
|
friend class ObjectGroup;
|
||||||
|
|
||||||
struct NewEntry;
|
struct NewEntry;
|
||||||
using NewTable = js::GCHashSet<NewEntry, NewEntry, SystemAllocPolicy>;
|
class NewTable;
|
||||||
|
|
||||||
// Set of default 'new' or lazy groups in the compartment.
|
// Set of default 'new' or lazy groups in the compartment.
|
||||||
NewTable* defaultNewTable;
|
NewTable* defaultNewTable;
|
||||||
|
Loading…
Reference in New Issue
Block a user