Bug 1714561 - Allow single-zone JS holders to contain pointers into the atoms zone r=mccr8,sfink

Differential Revision: https://phabricator.services.mozilla.com/D116848
This commit is contained in:
Jon Coppeard 2021-06-07 15:19:29 +00:00
parent 6de5f47867
commit 39dcc0ea21
4 changed files with 32 additions and 7 deletions

View File

@ -1172,6 +1172,8 @@ extern JS_PUBLIC_API void SetHostCleanupFinalizationRegistryCallback(
extern JS_PUBLIC_API void ClearKeptObjects(JSContext* cx);
extern JS_PUBLIC_API bool ZoneIsCollecting(Zone* zone);
extern JS_PUBLIC_API bool AtomsZoneIsCollecting(JSRuntime* runtime);
extern JS_PUBLIC_API bool IsAtomsZone(Zone* zone);
} // namespace JS

View File

@ -1368,6 +1368,14 @@ JS_PUBLIC_API bool JS::ZoneIsCollecting(JS::Zone* zone) {
return zone->wasGCStarted();
}
JS_PUBLIC_API bool JS::AtomsZoneIsCollecting(JSRuntime* runtime) {
return runtime->activeGCInAtomsZone();
}
JS_PUBLIC_API bool JS::IsAtomsZone(JS::Zone* zone) {
return zone->isAtomsZone();
}
JS_PUBLIC_API bool JS_AddWeakPointerZonesCallback(JSContext* cx,
JSWeakPointerZonesCallback cb,
void* data) {

View File

@ -971,7 +971,14 @@ void CycleCollectedJSRuntime::TraceGrayJS(JSTracer* aTracer, void* aData) {
CycleCollectedJSRuntime* self = static_cast<CycleCollectedJSRuntime*>(aData);
// Mark these roots as gray so the CC can walk them later.
self->TraceNativeGrayRoots(aTracer, JSHolderMap::HoldersInCollectingZones);
JSHolderMap::WhichHolders which = JSHolderMap::HoldersInCollectingZones;
if (JS::AtomsZoneIsCollecting(self->Runtime())) {
// Any holder may point into the atoms zone.
which = JSHolderMap::AllHolders;
}
self->TraceNativeGrayRoots(aTracer, which);
}
/* static */
@ -1268,6 +1275,11 @@ struct CheckZoneTracer : public TraceCallbacks {
: mClassName(aClassName), mZone(aZone) {}
void checkZone(JS::Zone* aZone, const char* aName) const {
if (JS::IsAtomsZone(aZone)) {
// Any holder may contain pointers into the atoms zone.
return;
}
if (!mZone) {
mZone = aZone;
return;
@ -1277,9 +1289,12 @@ struct CheckZoneTracer : public TraceCallbacks {
return;
}
// Most JS holders only contain pointers to GC things in a single zone. In
// the future this will allow us to improve GC performance by only tracing
// holders in zones that are being collected.
// Most JS holders only contain pointers to GC things in a single zone. We
// group holders by referent zone where possible, allowing us to improve GC
// performance by only tracing holders for zones that are being collected.
//
// Additionally, pointers from any holder into the atoms zone are allowed
// since all holders are traced when we collect the atoms zone.
//
// If you added a holder that has pointers into multiple zones please try to
// remedy this. Some options are:
@ -1306,7 +1321,7 @@ struct CheckZoneTracer : public TraceCallbacks {
void* aClosure) const override {
jsid id = aPtr->unbarrieredGet();
if (id.isGCThing()) {
checkZone(JS::GetTenuredGCThingZone(id.toGCCellPtr()), aName);
MOZ_ASSERT(JS::IsAtomsZone(JS::GetTenuredGCThingZone(id.toGCCellPtr())));
}
}
virtual void Trace(JS::Heap<JSObject*>* aPtr, const char* aName,

View File

@ -872,8 +872,8 @@ T* DowncastCCParticipant(void* aPtr) {
_class::NS_CYCLE_COLLECTION_INNERCLASS _class::NS_CYCLE_COLLECTION_INNERNAME;
// Most JS holder classes should only contain pointers to JS GC things in a
// single JS zone, but there are some exceptions. Such classes should use this
// macro to tell the system about this.
// single JS zone (excluding pointers into the atoms zone), but there are some
// exceptions. Such classes should use this macro to tell the system about this.
#define NS_IMPL_CYCLE_COLLECTION_MULTI_ZONE_JSHOLDER_CLASS(_class) \
_class::NS_CYCLE_COLLECTION_INNERCLASS \
_class::NS_CYCLE_COLLECTION_INNERNAME( \