Bug 1756568 - Part 2: Rename FinalizationRegistry support data structures to FinalizationObservers r=sfink

Depends on D139691

Differential Revision: https://phabricator.services.mozilla.com/D139692
This commit is contained in:
Jon Coppeard 2022-02-28 10:33:10 +00:00
Родитель ad8b149a7f
Коммит 417893e4d2
5 изменённых файлов: 43 добавлений и 43 удалений

Просмотреть файл

@ -21,7 +21,7 @@
* | | | | | |
* | | v | v |
* | | +-------------+-------------+ | +-------------+------------+ |
* | | | Registrations | | | FinalizationRegistryZone | |
* | | | Registrations | | | FinalizationObservers | |
* | | | weak map | | +-------------+------------+ |
* | | +---------------------------+ | | |
* | | | Unregister : Records | | v |
@ -116,7 +116,7 @@ using RootedFinalizationQueueObject = Rooted<FinalizationQueueObject*>;
//
// Finalization records are added to a per-zone record map. They are removed
// when the record is queued for cleanup, or if the interest in finalization is
// cancelled. See FinalizationRegistryZone::shouldRemoveRecord for the possible
// cancelled. See FinalizationObservers::shouldRemoveRecord for the possible
// reasons.
class FinalizationRecordObject : public NativeObject {

Просмотреть файл

@ -26,10 +26,10 @@
using namespace js;
using namespace js::gc;
FinalizationRegistryZone::FinalizationRegistryZone(Zone* zone)
FinalizationObservers::FinalizationObservers(Zone* zone)
: zone(zone), registries(zone), recordMap(zone), crossZoneWrappers(zone) {}
FinalizationRegistryZone::~FinalizationRegistryZone() {
FinalizationObservers::~FinalizationObservers() {
MOZ_ASSERT(registries.empty());
MOZ_ASSERT(recordMap.empty());
MOZ_ASSERT(crossZoneWrappers.empty());
@ -37,8 +37,8 @@ FinalizationRegistryZone::~FinalizationRegistryZone() {
bool GCRuntime::addFinalizationRegistry(
JSContext* cx, Handle<FinalizationRegistryObject*> registry) {
if (!cx->zone()->ensureFinalizationRegistryZone() ||
!cx->zone()->finalizationRegistryZone()->addRegistry(registry)) {
if (!cx->zone()->ensureFinalizationObservers() ||
!cx->zone()->finalizationObservers()->addRegistry(registry)) {
ReportOutOfMemory(cx);
return false;
}
@ -46,7 +46,7 @@ bool GCRuntime::addFinalizationRegistry(
return true;
}
bool FinalizationRegistryZone::addRegistry(
bool FinalizationObservers::addRegistry(
Handle<FinalizationRegistryObject*> registry) {
return registries.put(registry);
}
@ -60,8 +60,8 @@ bool GCRuntime::registerWithFinalizationRegistry(JSContext* cx,
MOZ_ASSERT(target->compartment() == record->compartment());
Zone* zone = cx->zone();
if (!zone->ensureFinalizationRegistryZone() ||
!zone->finalizationRegistryZone()->addRecord(target, record)) {
if (!zone->ensureFinalizationObservers() ||
!zone->finalizationObservers()->addRecord(target, record)) {
ReportOutOfMemory(cx);
return false;
}
@ -69,8 +69,8 @@ bool GCRuntime::registerWithFinalizationRegistry(JSContext* cx,
return true;
}
bool FinalizationRegistryZone::addRecord(HandleObject target,
HandleObject record) {
bool FinalizationObservers::addRecord(HandleObject target,
HandleObject record) {
// Add a record to the record map and clean up on failure.
//
// The following must be updated and kept in sync:
@ -118,7 +118,7 @@ bool FinalizationRegistryZone::addRecord(HandleObject target,
return true;
}
bool FinalizationRegistryZone::addCrossZoneWrapper(JSObject* wrapper) {
bool FinalizationObservers::addCrossZoneWrapper(JSObject* wrapper) {
MOZ_ASSERT(IsCrossCompartmentWrapper(wrapper));
MOZ_ASSERT(UncheckedUnwrapWithoutExpose(wrapper)->zone() != zone);
@ -127,7 +127,7 @@ bool FinalizationRegistryZone::addCrossZoneWrapper(JSObject* wrapper) {
return crossZoneWrappers.add(ptr, wrapper, UndefinedValue());
}
void FinalizationRegistryZone::removeCrossZoneWrapper(JSObject* wrapper) {
void FinalizationObservers::removeCrossZoneWrapper(JSObject* wrapper) {
MOZ_ASSERT(IsCrossCompartmentWrapper(wrapper));
MOZ_ASSERT(UncheckedUnwrapWithoutExpose(wrapper)->zone() != zone);
@ -147,7 +147,7 @@ static FinalizationRecordObject* UnwrapFinalizationRecord(JSObject* obj) {
return &obj->as<FinalizationRecordObject>();
}
void FinalizationRegistryZone::clearRecords() {
void FinalizationObservers::clearRecords() {
#ifdef DEBUG
// Check crossZoneWrappers was correct before clearing.
for (RecordMap::Enum e(recordMap); !e.empty(); e.popFront()) {
@ -166,19 +166,19 @@ void FinalizationRegistryZone::clearRecords() {
}
void GCRuntime::traceWeakFinalizationRegistryEdges(JSTracer* trc, Zone* zone) {
FinalizationRegistryZone* frzone = zone->finalizationRegistryZone();
if (frzone) {
frzone->traceWeakEdges(trc);
FinalizationObservers* observers = zone->finalizationObservers();
if (observers) {
observers->traceWeakEdges(trc);
}
}
void FinalizationRegistryZone::traceRoots(JSTracer* trc) {
void FinalizationObservers::traceRoots(JSTracer* trc) {
// The crossZoneWrappers weak map is traced as a root; this does not keep any
// of its entries alive by itself.
crossZoneWrappers.trace(trc);
}
void FinalizationRegistryZone::traceWeakEdges(JSTracer* trc) {
void FinalizationObservers::traceWeakEdges(JSTracer* trc) {
// Sweep finalization registry data and queue finalization records for cleanup
// for any entries whose target is dying and remove them from the map.
@ -237,7 +237,7 @@ void FinalizationRegistryZone::traceWeakEdges(JSTracer* trc) {
}
// static
bool FinalizationRegistryZone::shouldRemoveRecord(
bool FinalizationObservers::shouldRemoveRecord(
FinalizationRecordObject* record) {
// Records are removed from the target's vector for the following reasons:
return !record || // Nuked CCW to record.
@ -245,7 +245,7 @@ bool FinalizationRegistryZone::shouldRemoveRecord(
!record->queue()->hasRegistry(); // Dead finalization registry.
}
void FinalizationRegistryZone::updateForRemovedRecord(
void FinalizationObservers::updateForRemovedRecord(
JSObject* wrapper, FinalizationRecordObject* record) {
// Remove other references to a record when it has been removed from the
// zone's record map. See addRecord().
@ -270,8 +270,8 @@ void GCRuntime::nukeFinalizationRecordWrapper(
JSObject* wrapper, FinalizationRecordObject* record) {
if (record->isInRecordMap()) {
FinalizationRegistryObject::unregisterRecord(record);
wrapper->zone()->finalizationRegistryZone()->updateForRemovedRecord(wrapper,
record);
wrapper->zone()->finalizationObservers()->updateForRemovedRecord(wrapper,
record);
}
}

Просмотреть файл

@ -20,8 +20,8 @@ class FinalizationRecordObject;
namespace gc {
// Per-zone data structures to support FinalizationRegistry.
class FinalizationRegistryZone {
// Per-zone data structures to support FinalizationRegistry and WeakRef.
class FinalizationObservers {
Zone* const zone;
// The set of all finalization registries in the associated zone. These are
@ -49,8 +49,8 @@ class FinalizationRegistryZone {
WrapperWeakSet crossZoneWrappers;
public:
explicit FinalizationRegistryZone(Zone* zone);
~FinalizationRegistryZone();
explicit FinalizationObservers(Zone* zone);
~FinalizationObservers();
bool addRegistry(Handle<FinalizationRegistryObject*> registry);
bool addRecord(HandleObject target, HandleObject record);

Просмотреть файл

@ -174,7 +174,7 @@ JS::Zone::Zone(JSRuntime* rt, Kind kind)
externalStringCache_(this),
functionToStringCache_(this),
shapeZone_(this, this),
finalizationRegistryZone_(this),
finalizationObservers_(this),
jitZone_(this, nullptr),
gcScheduled_(false),
gcScheduledSaved_(false),
@ -198,7 +198,7 @@ Zone::~Zone() {
MOZ_ASSERT_IF(regExps_.ref(), regExps().empty());
DebugAPI::deleteDebugScriptMap(debugScriptMap);
js_delete(finalizationRegistryZone_.ref().release());
js_delete(finalizationObservers_.ref().release());
MOZ_ASSERT(gcWeakMapList().isEmpty());
@ -770,8 +770,8 @@ void Zone::traceRootsInMajorGC(JSTracer* trc) {
// calling this only during major (non-nursery) collections.
traceScriptTableRoots(trc);
if (FinalizationRegistryZone* frzone = finalizationRegistryZone()) {
frzone->traceRoots(trc);
if (FinalizationObservers* observers = finalizationObservers()) {
observers->traceRoots(trc);
}
}
@ -917,8 +917,8 @@ void Zone::clearScriptLCov(Realm* realm) {
void Zone::clearRootsForShutdownGC() {
// Finalization callbacks are not called if we're shutting down.
if (finalizationRegistryZone()) {
finalizationRegistryZone()->clearRecords();
if (finalizationObservers()) {
finalizationObservers()->clearRecords();
}
clearKeptObjects();
@ -938,11 +938,11 @@ bool Zone::keepDuringJob(HandleObject target) {
void Zone::clearKeptObjects() { keptObjects.ref().clear(); }
bool Zone::ensureFinalizationRegistryZone() {
if (finalizationRegistryZone_.ref()) {
bool Zone::ensureFinalizationObservers() {
if (finalizationObservers_.ref()) {
return true;
}
finalizationRegistryZone_ = js::MakeUnique<FinalizationRegistryZone>(this);
return bool(finalizationRegistryZone_.ref());
finalizationObservers_ = js::MakeUnique<FinalizationObservers>(this);
return bool(finalizationObservers_.ref());
}

Просмотреть файл

@ -37,7 +37,7 @@ class JitZone;
namespace gc {
class FinalizationRegistryZone;
class FinalizationObservers;
class ZoneList;
using ZoneComponentFinder = ComponentFinder<JS::Zone>;
@ -285,8 +285,8 @@ class Zone : public js::ZoneAllocator, public js::gc::GraphNodeBase<JS::Zone> {
js::ZoneData<js::ShapeZone> shapeZone_;
// Information about finalization registries, created on demand.
js::ZoneOrGCTaskData<js::UniquePtr<js::gc::FinalizationRegistryZone>>
finalizationRegistryZone_;
js::ZoneOrGCTaskData<js::UniquePtr<js::gc::FinalizationObservers>>
finalizationObservers_;
js::ZoneOrGCTaskData<js::jit::JitZone*> jitZone_;
@ -624,10 +624,10 @@ class Zone : public js::ZoneAllocator, public js::gc::GraphNodeBase<JS::Zone> {
void sweepEphemeronTablesAfterMinorGC();
js::gc::FinalizationRegistryZone* finalizationRegistryZone() {
return finalizationRegistryZone_.ref().get();
js::gc::FinalizationObservers* finalizationObservers() {
return finalizationObservers_.ref().get();
}
bool ensureFinalizationRegistryZone();
bool ensureFinalizationObservers();
bool isOnList() const;
Zone* nextZone() const;