diff --git a/js/src/gc/GCRuntime.h b/js/src/gc/GCRuntime.h index 6941e621b65f..f8d525996b00 100644 --- a/js/src/gc/GCRuntime.h +++ b/js/src/gc/GCRuntime.h @@ -1038,7 +1038,6 @@ class GCRuntime // accumulate these roots in each zone's gcGrayRoots vector and then mark // them later, after black marking is complete for each compartment. This // accumulation can fail, but in that case we switch to non-incremental GC. - friend class js::GCMarker; enum class GrayBufferState { Unused, Okay, diff --git a/js/src/gc/RootMarking.cpp b/js/src/gc/RootMarking.cpp index 2e12c389cec4..13493b664b16 100644 --- a/js/src/gc/RootMarking.cpp +++ b/js/src/gc/RootMarking.cpp @@ -574,3 +574,62 @@ js::gc::GCRuntime::bufferGrayRoots() grayBufferState = GrayBufferState::Okay; } } + +void +BufferGrayRootsTracer::appendGrayRoot(void *thing, JSGCTraceKind kind) +{ + MOZ_ASSERT(runtime()->isHeapBusy()); + + if (bufferingGrayRootsFailed) + return; + + GrayRoot root(thing, kind); +#ifdef DEBUG + root.debugPrinter = debugPrinter(); + root.debugPrintArg = debugPrintArg(); + root.debugPrintIndex = debugPrintIndex(); +#endif + + Zone *zone = TenuredCell::fromPointer(thing)->zone(); + if (zone->isCollecting()) { + // See the comment on SetMaybeAliveFlag to see why we only do this for + // objects and scripts. We rely on gray root buffering for this to work, + // but we only need to worry about uncollected dead compartments during + // incremental GCs (when we do gray root buffering). + switch (kind) { + case JSTRACE_OBJECT: + static_cast(thing)->compartment()->maybeAlive = true; + break; + case JSTRACE_SCRIPT: + static_cast(thing)->compartment()->maybeAlive = true; + break; + default: + break; + } + if (!zone->gcGrayRoots.append(root)) + bufferingGrayRootsFailed = true; + } +} + +void +GCRuntime::markBufferedGrayRoots(JS::Zone *zone) +{ + MOZ_ASSERT(grayBufferState == GrayBufferState::Okay); + MOZ_ASSERT(zone->isGCMarkingGray() || zone->isGCCompacting()); + + for (GrayRoot *elem = zone->gcGrayRoots.begin(); elem != zone->gcGrayRoots.end(); elem++) { +#ifdef DEBUG + marker.setTracingDetails(elem->debugPrinter, elem->debugPrintArg, elem->debugPrintIndex); +#endif + MarkKind(&marker, &elem->thing, elem->kind); + } +} + +void +GCRuntime::resetBufferedGrayRoots() const +{ + MOZ_ASSERT(grayBufferState != GrayBufferState::Okay, + "Do not clear the gray buffers unless we are Failed or becoming Unused"); + for (GCZonesIter zone(rt); !zone.done(); zone.next()) + zone->gcGrayRoots.clearAndFree(); +} diff --git a/js/src/gc/Tracer.cpp b/js/src/gc/Tracer.cpp index 042798c7b503..79a71764d8b4 100644 --- a/js/src/gc/Tracer.cpp +++ b/js/src/gc/Tracer.cpp @@ -643,65 +643,6 @@ GCMarker::checkZone(void *p) } #endif -void -GCRuntime::resetBufferedGrayRoots() const -{ - MOZ_ASSERT(grayBufferState != GrayBufferState::Okay, - "Do not clear the gray buffers unless we are Failed or becoming Unused"); - for (GCZonesIter zone(rt); !zone.done(); zone.next()) - zone->gcGrayRoots.clearAndFree(); -} - -void -GCRuntime::markBufferedGrayRoots(JS::Zone *zone) -{ - MOZ_ASSERT(grayBufferState == GrayBufferState::Okay); - MOZ_ASSERT(zone->isGCMarkingGray() || zone->isGCCompacting()); - - for (GrayRoot *elem = zone->gcGrayRoots.begin(); elem != zone->gcGrayRoots.end(); elem++) { -#ifdef DEBUG - marker.setTracingDetails(elem->debugPrinter, elem->debugPrintArg, elem->debugPrintIndex); -#endif - MarkKind(&marker, &elem->thing, elem->kind); - } -} - -void -BufferGrayRootsTracer::appendGrayRoot(void *thing, JSGCTraceKind kind) -{ - MOZ_ASSERT(runtime()->isHeapBusy()); - - if (bufferingGrayRootsFailed) - return; - - GrayRoot root(thing, kind); -#ifdef DEBUG - root.debugPrinter = debugPrinter(); - root.debugPrintArg = debugPrintArg(); - root.debugPrintIndex = debugPrintIndex(); -#endif - - Zone *zone = TenuredCell::fromPointer(thing)->zone(); - if (zone->isCollecting()) { - // See the comment on SetMaybeAliveFlag to see why we only do this for - // objects and scripts. We rely on gray root buffering for this to work, - // but we only need to worry about uncollected dead compartments during - // incremental GCs (when we do gray root buffering). - switch (kind) { - case JSTRACE_OBJECT: - static_cast(thing)->compartment()->maybeAlive = true; - break; - case JSTRACE_SCRIPT: - static_cast(thing)->compartment()->maybeAlive = true; - break; - default: - break; - } - if (!zone->gcGrayRoots.append(root)) - bufferingGrayRootsFailed = true; - } -} - size_t GCMarker::sizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) const { @@ -716,4 +657,3 @@ js::SetMarkStackLimit(JSRuntime *rt, size_t limit) { rt->gc.setMarkStackLimit(limit); } -