From da3a863a847381fc83e625b86bae98449b8e62f6 Mon Sep 17 00:00:00 2001 From: Terrence Cole Date: Wed, 20 Apr 2016 15:17:25 -0700 Subject: [PATCH] Bug 1265483 - Use WeakCache to automate sweeping of ObjectGroupCompartment::NewTable; r=jonco --- js/public/SweepingAPI.h | 3 +++ js/src/vm/ObjectGroup.cpp | 36 +++++++++++++++++++++--------------- js/src/vm/ObjectGroup.h | 2 +- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/js/public/SweepingAPI.h b/js/public/SweepingAPI.h index f6d98da954f3..f730f64e1eb8 100644 --- a/js/public/SweepingAPI.h +++ b/js/public/SweepingAPI.h @@ -31,6 +31,7 @@ class WeakCache : public js::WeakCacheBase, friend class mozilla::LinkedListElement>; friend class mozilla::LinkedList>; + WeakCache() = delete; WeakCache(const WeakCache&) = delete; using SweepFn = void (*)(T*); @@ -38,6 +39,8 @@ class WeakCache : public js::WeakCacheBase, T cache; public: + using Type = T; + template WeakCache(Zone* zone, U&& initial) : cache(mozilla::Forward(initial)) diff --git a/js/src/vm/ObjectGroup.cpp b/js/src/vm/ObjectGroup.cpp index edb167f40e9e..b316a74688f6 100644 --- a/js/src/vm/ObjectGroup.cpp +++ b/js/src/vm/ObjectGroup.cpp @@ -412,6 +412,16 @@ struct ObjectGroupCompartment::NewEntry } }; +class ObjectGroupCompartment::NewTable : public JS::WeakCache> +{ + using Table = js::GCHashSet; + using Base = JS::WeakCache; + + public: + explicit NewTable(Zone* zone) : Base(zone, Table()) {} +}; + /* static */ ObjectGroup* ObjectGroup::defaultNewGroup(ExclusiveContext* cx, const Class* clasp, TaggedProto proto, JSObject* associated) @@ -429,7 +439,7 @@ ObjectGroup::defaultNewGroup(ExclusiveContext* cx, const Class* clasp, ObjectGroupCompartment::NewTable*& table = cx->compartment()->objectGroups.defaultNewTable; if (!table) { - table = cx->new_(); + table = cx->new_(cx->zone()); if (!table || !table->init()) { js_delete(table); table = nullptr; @@ -551,7 +561,7 @@ ObjectGroup::lazySingletonGroup(ExclusiveContext* cx, const Class* clasp, Tagged ObjectGroupCompartment::NewTable*& table = cx->compartment()->objectGroups.lazyTable; if (!table) { - table = cx->new_(); + table = cx->new_(cx->zone()); if (!table || !table->init()) { ReportOutOfMemory(cx); js_delete(table); @@ -593,8 +603,8 @@ ObjectGroup::setDefaultNewGroupUnknown(JSContext* cx, const Class* clasp, Handle ObjectGroupCompartment::NewTable* table = cx->compartment()->objectGroups.defaultNewTable; if (table) { Rooted taggedProto(cx, TaggedProto(obj)); - ObjectGroupCompartment::NewTable::Ptr p = - table->lookup(ObjectGroupCompartment::NewEntry::Lookup(clasp, taggedProto, nullptr)); + auto lookup = ObjectGroupCompartment::NewEntry::Lookup(clasp, taggedProto, nullptr); + auto p = table->lookup(lookup); if (p) MarkObjectGroupUnknownProperties(cx, p->group); } @@ -607,8 +617,8 @@ ObjectGroup::hasDefaultNewGroup(JSObject* proto, const Class* clasp, ObjectGroup ObjectGroupCompartment::NewTable* table = proto->compartment()->objectGroups.defaultNewTable; if (table) { - ObjectGroupCompartment::NewTable::Ptr p = - table->lookup(ObjectGroupCompartment::NewEntry::Lookup(clasp, TaggedProto(proto), nullptr)); + auto lookup = ObjectGroupCompartment::NewEntry::Lookup(clasp, TaggedProto(proto), nullptr); + auto p = table->lookup(lookup); return p && p->group == group; } return false; @@ -1614,10 +1624,10 @@ void ObjectGroupCompartment::removeDefaultNewGroup(const Class* clasp, TaggedProto proto, 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); - defaultNewTable->remove(p); + defaultNewTable->get().remove(p); } void @@ -1626,9 +1636,9 @@ ObjectGroupCompartment::replaceDefaultNewGroup(const Class* clasp, TaggedProto p { NewEntry::Lookup lookup(clasp, proto, associated); - NewTable::Ptr p = defaultNewTable->lookup(lookup); + auto p = defaultNewTable->lookup(lookup); MOZ_RELEASE_ASSERT(p); - defaultNewTable->remove(p); + defaultNewTable->get().remove(p); { AutoEnterOOMUnsafeRegion oomUnsafe; if (!defaultNewTable->putNew(lookup, NewEntry(group, associated))) @@ -1734,10 +1744,6 @@ ObjectGroupCompartment::sweep(FreeOp* fop) plainObjectTable->sweep(); if (allocationSiteTable) allocationSiteTable->sweep(); - if (defaultNewTable) - defaultNewTable->sweep(); - if (lazyTable) - lazyTable->sweep(); } void @@ -1794,7 +1800,7 @@ ObjectGroupCompartment::checkNewTableAfterMovingGC(NewTable* table) clasp = nullptr; 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()); } } diff --git a/js/src/vm/ObjectGroup.h b/js/src/vm/ObjectGroup.h index 350c9c6530ad..1fd8f3b792ef 100644 --- a/js/src/vm/ObjectGroup.h +++ b/js/src/vm/ObjectGroup.h @@ -540,7 +540,7 @@ class ObjectGroupCompartment friend class ObjectGroup; struct NewEntry; - using NewTable = js::GCHashSet; + class NewTable; // Set of default 'new' or lazy groups in the compartment. NewTable* defaultNewTable;