Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit d9c74c8

Browse files
committed
Bug 1735296 - Part 6: Add minor sweeping tracer r=sfink
Analagous to the sweeping tracer, this checks whether nursery things have been moved and updates the edge as necessary. Differential Revision: https://phabricator.services.mozilla.com/D128262
1 parent d8fe7c9 commit d9c74c8

File tree

7 files changed

+46
-11
lines changed

7 files changed

+46
-11
lines changed

js/public/TracingAPI.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ enum class TracerKind {
4444
GrayBuffering,
4545
ClearEdges,
4646
Sweeping,
47+
MinorSweeping,
4748
Barrier,
4849

4950
// Callback tracers: General-purpose tracers that have a single virtual

js/src/gc/GCInternals.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,16 @@ struct SweepingTracer final : public GenericTracerImpl<SweepingTracer> {
288288
friend class GenericTracerImpl<SweepingTracer>;
289289
};
290290

291+
struct MinorSweepingTracer final
292+
: public GenericTracerImpl<MinorSweepingTracer> {
293+
explicit MinorSweepingTracer(JSRuntime* rt);
294+
295+
private:
296+
template <typename T>
297+
T* onEdge(T* thingp);
298+
friend class GenericTracerImpl<MinorSweepingTracer>;
299+
};
300+
291301
extern void DelayCrossCompartmentGrayMarking(JSObject* src);
292302

293303
inline bool IsOOMReason(JS::GCReason reason) {

js/src/gc/Marking.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,10 @@ void js::CheckTracedThing(JSTracer* trc, T* thing) {
179179
MOZ_ASSERT(thing);
180180

181181
if (IsForwarded(thing)) {
182-
MOZ_ASSERT(IsTracerKind(trc, JS::TracerKind::Moving) ||
183-
trc->isTenuringTracer());
182+
JS::TracerKind kind = trc->kind();
183+
MOZ_ASSERT(kind == JS::TracerKind::Tenuring ||
184+
kind == JS::TracerKind::MinorSweeping ||
185+
kind == JS::TracerKind::Moving);
184186
thing = Forwarded(thing);
185187
}
186188

js/src/gc/Nursery.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,7 +1236,7 @@ js::Nursery::CollectionResult js::Nursery::doCollection(JS::GCReason reason) {
12361236
// Sweep to update any pointers to nursery objects that have now been
12371237
// tenured.
12381238
startProfile(ProfileKey::Sweep);
1239-
sweep(&mover);
1239+
sweep();
12401240
endProfile(ProfileKey::Sweep);
12411241

12421242
// Update any slot or element pointers whose destination has been tenured.
@@ -1431,7 +1431,9 @@ bool js::Nursery::registerMallocedBuffer(void* buffer, size_t nbytes) {
14311431
return true;
14321432
}
14331433

1434-
void js::Nursery::sweep(JSTracer* trc) {
1434+
void js::Nursery::sweep() {
1435+
MinorSweepingTracer trc(runtime());
1436+
14351437
// Sweep unique IDs first before we sweep any tables that may be keyed based
14361438
// on them.
14371439
for (Cell* cell : cellsWithUid_) {
@@ -1445,12 +1447,8 @@ void js::Nursery::sweep(JSTracer* trc) {
14451447
}
14461448
cellsWithUid_.clear();
14471449

1448-
for (CompartmentsIter c(runtime()); !c.done(); c.next()) {
1449-
c->sweepAfterMinorGC(trc);
1450-
}
1451-
1452-
for (ZonesIter zone(trc->runtime(), SkipAtoms); !zone.done(); zone.next()) {
1453-
zone->sweepAfterMinorGC(trc);
1450+
for (ZonesIter zone(runtime(), SkipAtoms); !zone.done(); zone.next()) {
1451+
zone->sweepAfterMinorGC(&trc);
14541452
}
14551453

14561454
sweepMapAndSetObjects();

js/src/gc/Nursery.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ class Nursery {
677677

678678
// Updates pointers to nursery objects that have been tenured and discards
679679
// pointers to objects that have been freed.
680-
void sweep(JSTracer* trc);
680+
void sweep();
681681

682682
// Reset the current chunk and position after a minor collection. Also poison
683683
// the nursery on debug & nightly builds.

js/src/gc/Tenuring.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -975,3 +975,23 @@ size_t js::TenuringTracer::moveBigIntToTenured(JS::BigInt* dst, JS::BigInt* src,
975975

976976
return size;
977977
}
978+
979+
MinorSweepingTracer::MinorSweepingTracer(JSRuntime* rt)
980+
: GenericTracerImpl(rt, JS::TracerKind::MinorSweeping,
981+
JS::WeakMapTraceAction::TraceKeysAndValues) {
982+
MOZ_ASSERT(CurrentThreadCanAccessRuntime(runtime()));
983+
MOZ_ASSERT(JS::RuntimeHeapIsMinorCollecting());
984+
}
985+
986+
template <typename T>
987+
inline T* MinorSweepingTracer::onEdge(T* thing) {
988+
if (thing->isTenured()) {
989+
return thing;
990+
}
991+
992+
if (IsForwarded(thing)) {
993+
return Forwarded(thing);
994+
}
995+
996+
return nullptr;
997+
}

js/src/gc/Zone.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,10 @@ static void SweepEphemeronEdgesWhileMinorSweeping(
266266
void Zone::sweepAfterMinorGC(JSTracer* trc) {
267267
sweepEphemeronTablesAfterMinorGC();
268268
crossZoneStringWrappers().sweepAfterMinorGC(trc);
269+
270+
for (CompartmentsInZoneIter comp(this); !comp.done(); comp.next()) {
271+
comp->sweepAfterMinorGC(trc);
272+
}
269273
}
270274

271275
void Zone::sweepEphemeronTablesAfterMinorGC() {

0 commit comments

Comments
 (0)