1380030 fully.

1380030 - Remove color constants from public API and replace with an internal MarkColor enum.

1380030 - Simplify and refactor use of isMarked*() methods.

I only had one part of this before: Refactor isMarked() methods into separate methods for each color and any.
This commit is contained in:
win7-7 2026-01-16 06:53:16 +02:00 committed by wuggy
commit 9eede345ec
6 changed files with 25 additions and 23 deletions

View file

@ -74,9 +74,7 @@ const size_t ArenaHeaderSize = sizeof(size_t) + 2 * sizeof(uintptr_t) +
* depends on the size of the GCThing. Objects marked gray are eligible for
* cycle collection.
*/
static const uint32_t BLACK = 0;
static const uint32_t GRAY = 1;
/*
* Two bits determine the mark color as follows:
* BlackBit GrayOrBlackBit color

View file

@ -622,7 +622,7 @@ struct VisitGrayCallbackFunctor {
template <class T>
void operator()(T tp) const {
if ((*tp)->isTenured() && (*tp)->asTenured().isMarkedGray())
if ((*tp)->isMarkedGray())
callback_(closure_, JS::GCCellPtr(*tp));
}
};
@ -1083,10 +1083,13 @@ static char
MarkDescriptor(void* thing)
{
gc::TenuredCell* cell = gc::TenuredCell::fromPointer(thing);
if (cell->isMarkedBlack())
return 'B';
if (cell->isMarkedGray())
return 'G';
if (cell->isMarkedAny())
return cell->isMarkedGray() ? 'G' : 'B';
else
return cell->isMarkedGray() ? 'X' : 'W';
return 'X';
return 'W';
}
static void

View file

@ -2009,7 +2009,7 @@ RelocateArena(Arena* arena, SliceBudget& sliceBudget)
TenuredCell* src = i.getCell();
MOZ_ASSERT(RelocationOverlay::isCellForwarded(src));
TenuredCell* dest = Forwarded(src);
MOZ_ASSERT(src->isMarkedAny() == dest->isMarkedAny());
MOZ_ASSERT(src->isMarkedBlack() == dest->isMarkedBlack());
MOZ_ASSERT(src->isMarkedGray() == dest->isMarkedGray());
}
#endif
@ -4452,7 +4452,7 @@ js::gc::MarkingValidator::validate()
uintptr_t thing = arena->thingsStart();
uintptr_t end = arena->thingsEnd();
while (thing < end) {
Cell* cell = (Cell*)thing;
auto cell = reinterpret_cast<TenuredCell*>(thing);
/*
* If a non-incremental GC wouldn't have collected a cell, then
@ -4572,7 +4572,7 @@ JSCompartment::findOutgoingEdges(ZoneComponentFinder& finder)
bool needsEdge = true;
if (key.is<JSObject*>()) {
TenuredCell& other = key.as<JSObject*>()->asTenured();
needsEdge = !other.isMarkedAny() || other.isMarkedGray();
needsEdge = !other.isMarkedBlack();
}
key.applyToWrapped(AddOutgoingEdgeFunctor(needsEdge, finder));
}
@ -4815,21 +4815,22 @@ js::gc::DelayCrossCompartmentGrayMarking(JSObject* src)
}
static void
MarkIncomingCrossCompartmentPointers(JSRuntime* rt, const uint32_t color)
MarkIncomingCrossCompartmentPointers(JSRuntime* rt, MarkColor color)
{
MOZ_ASSERT(color == BLACK || color == GRAY);
MOZ_ASSERT(color == MarkColor::Black || color == MarkColor::Gray);
static const gcstats::Phase statsPhases[] = {
gcstats::PHASE_SWEEP_MARK_INCOMING_BLACK,
gcstats::PHASE_SWEEP_MARK_INCOMING_GRAY
};
gcstats::AutoPhase ap1(rt->gc.stats, statsPhases[color]);
bool unlinkList = color == GRAY;
gcstats::AutoPhase ap1(rt->gc.stats(), statsPhases[unsigned(color)]);
bool unlinkList = color == MarkColor::Gray;
for (SweepGroupCompartmentsIter c(rt); !c.done(); c.next()) {
MOZ_ASSERT_IF(color == GRAY, c->zone()->isGCMarkingGray());
MOZ_ASSERT_IF(color == BLACK, c->zone()->isGCMarkingBlack());
MOZ_ASSERT_IF(color == MarkColor::Gray, c->zone()->isGCMarkingGray());
MOZ_ASSERT_IF(color == MarkColor::Black, c->zone()->isGCMarkingBlack());
MOZ_ASSERT_IF(c->gcIncomingGrayPointers, IsGrayListObject(c->gcIncomingGrayPointers));
for (JSObject* src = c->gcIncomingGrayPointers;
@ -4839,7 +4840,7 @@ MarkIncomingCrossCompartmentPointers(JSRuntime* rt, const uint32_t color)
JSObject* dst = CrossCompartmentPointerReferent(src);
MOZ_ASSERT(dst->compartment() == c);
if (color == GRAY) {
if (color == MarkColor::Gray) {
if (IsMarkedUnbarriered(rt, &src) && src->asTenured().isMarkedGray())
TraceManuallyBarrieredEdge(&rt->gc.marker, &dst,
"cross-compartment gray pointer");
@ -4950,7 +4951,7 @@ GCRuntime::endMarkingSweepGroup(FreeOp* fop, SliceBudget& budget)
* whose referents are not marked. This can occur when gray cells become
* black by the action of UnmarkGray.
*/
MarkIncomingCrossCompartmentPointers(rt, BLACK);
MarkIncomingCrossCompartmentPointers(rt, MarkColor::Black);
markWeakReferencesInCurrentGroup(gcstats::PHASE_SWEEP_MARK_WEAK);
/*
@ -4966,7 +4967,7 @@ GCRuntime::endMarkingSweepGroup(FreeOp* fop, SliceBudget& budget)
marker.setMarkColorGray();
/* Mark incoming gray pointers from previously swept compartments. */
MarkIncomingCrossCompartmentPointers(rt, GRAY);
MarkIncomingCrossCompartmentPointers(rt, MarkColor::Gray);
/* Mark gray roots and mark transitively inside the current compartment group. */
markGrayReferencesInCurrentGroup(gcstats::PHASE_SWEEP_MARK_GRAY);
@ -7199,7 +7200,7 @@ GCRuntime::maybeDoCycleCollection()
for (CompartmentsIter c(rt, SkipAtoms); !c.done(); c.next()) {
++compartmentsTotal;
GlobalObject* global = c->unsafeUnbarrieredMaybeGlobal();
if (global && global->asTenured().isMarkedGray())
if (global && global->isMarkedGray())
++compartmentsGray;
}
double grayFraction = double(compartmentsGray) / double(compartmentsTotal);

View file

@ -3419,7 +3419,7 @@ js::detail::CopyScript(JSContext* cx, HandleScript src, HandleScript dst,
/* NB: Keep this in sync with XDRScript. */
/* Some embeddings are not careful to use ExposeObjectToActiveJS as needed. */
MOZ_ASSERT(!src->sourceObject()->asTenured().isMarkedGray());
MOZ_ASSERT(!src->sourceObject()->isMarkedGray());
uint32_t nconsts = src->hasConsts() ? src->consts()->length : 0;
uint32_t nobjects = src->hasObjects() ? src->objects()->length : 0;

View file

@ -137,7 +137,7 @@ ObjectValueMap::findZoneEdges()
JS::AutoSuppressGCAnalysis nogc;
for (Range r = all(); !r.empty(); r.popFront()) {
JSObject* key = r.front().key();
if (key->asTenured().isMarkedAny() && !key->asTenured().isMarkedGray())
if (key->asTenured().isMarkedBlack())
continue;
JSObject* delegate = getDelegate(key);
if (!delegate)

View file

@ -335,7 +335,7 @@ Wrapper::wrappedObject(JSObject* wrapper)
// of black wrappers black but while it is in progress we can observe gray
// targets. Expose rather than returning a gray object in this case.
if (target) {
if (wrapper->isMarkedAny() && !wrapper->isMarkedGray())
if (wrapper->isMarkedBlack())
MOZ_ASSERT(JS::ObjectIsNotGray(target));
if (!wrapper->isMarkedGray())
JS::ExposeObjectToActiveJS(target);