зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1668825 - Rename WeakMapTraceKind to WeakMapTraceAction and make it an enum class r=sfink
The instances of this are called 'actions' everywhere and I think it makes sense that the type should be called that. Also make it an enum class and move it into the JS namespace. Differential Revision: https://phabricator.services.mozilla.com/D92252
This commit is contained in:
Родитель
065d1d7e84
Коммит
f2905d4d6e
|
@ -26,41 +26,41 @@ JS_FRIEND_API const char* GCTraceKindToAscii(JS::TraceKind kind);
|
|||
/** Returns the base size in bytes of the GC thing of kind |kind|. */
|
||||
JS_FRIEND_API size_t GCTraceKindSize(JS::TraceKind kind);
|
||||
|
||||
} // namespace JS
|
||||
|
||||
enum WeakMapTraceKind {
|
||||
enum class WeakMapTraceAction {
|
||||
/**
|
||||
* Do not trace into weak map keys or values during traversal. Users must
|
||||
* handle weak maps manually.
|
||||
*/
|
||||
DoNotTraceWeakMaps,
|
||||
Skip,
|
||||
|
||||
/**
|
||||
* Do true ephemeron marking with a weak key lookup marking phase. This is
|
||||
* the default for GCMarker.
|
||||
*/
|
||||
ExpandWeakMaps,
|
||||
Expand,
|
||||
|
||||
/**
|
||||
* Trace through to all values, irrespective of whether the keys are live
|
||||
* or not. Used for non-marking tracers.
|
||||
*/
|
||||
TraceWeakMapValues,
|
||||
TraceValues,
|
||||
|
||||
/**
|
||||
* Trace through to all keys and values, irrespective of whether the keys
|
||||
* are live or not. Used for non-marking tracers.
|
||||
*/
|
||||
TraceWeakMapKeysValues
|
||||
TraceKeysAndValues
|
||||
};
|
||||
|
||||
} // namespace JS
|
||||
|
||||
class JS_PUBLIC_API JSTracer {
|
||||
public:
|
||||
// Return the runtime set on the tracer.
|
||||
JSRuntime* runtime() const { return runtime_; }
|
||||
|
||||
// Return the weak map tracing behavior currently set on this tracer.
|
||||
WeakMapTraceKind weakMapAction() const { return weakMapAction_; }
|
||||
JS::WeakMapTraceAction weakMapAction() const { return weakMapAction_; }
|
||||
|
||||
enum class TracerKindTag {
|
||||
// Marking path: a tracer used only for marking liveness of cells, not
|
||||
|
@ -92,9 +92,10 @@ class JS_PUBLIC_API JSTracer {
|
|||
|
||||
protected:
|
||||
JSTracer(JSRuntime* rt, TracerKindTag tag,
|
||||
WeakMapTraceKind weakTraceKind = TraceWeakMapValues)
|
||||
JS::WeakMapTraceAction weakMapAction =
|
||||
JS::WeakMapTraceAction::TraceValues)
|
||||
: runtime_(rt),
|
||||
weakMapAction_(weakTraceKind),
|
||||
weakMapAction_(weakMapAction),
|
||||
tag_(tag),
|
||||
traceWeakEdges_(true),
|
||||
#ifdef DEBUG
|
||||
|
@ -112,7 +113,7 @@ class JS_PUBLIC_API JSTracer {
|
|||
|
||||
private:
|
||||
JSRuntime* const runtime_;
|
||||
const WeakMapTraceKind weakMapAction_;
|
||||
const JS::WeakMapTraceAction weakMapAction_;
|
||||
const TracerKindTag tag_;
|
||||
|
||||
// Whether the tracer should trace weak edges. GCMarker sets this to false.
|
||||
|
@ -134,14 +135,14 @@ class AutoTracingCallback;
|
|||
|
||||
class JS_PUBLIC_API CallbackTracer : public JSTracer {
|
||||
public:
|
||||
CallbackTracer(JSRuntime* rt,
|
||||
WeakMapTraceKind weakTraceKind = TraceWeakMapValues)
|
||||
: JSTracer(rt, JSTracer::TracerKindTag::Callback, weakTraceKind),
|
||||
CallbackTracer(JSRuntime* rt, JS::WeakMapTraceAction weakMapAction =
|
||||
JS::WeakMapTraceAction::TraceValues)
|
||||
: JSTracer(rt, JSTracer::TracerKindTag::Callback, weakMapAction),
|
||||
contextName_(nullptr),
|
||||
contextIndex_(InvalidIndex),
|
||||
contextFunctor_(nullptr) {}
|
||||
CallbackTracer(JSContext* cx,
|
||||
WeakMapTraceKind weakTraceKind = TraceWeakMapValues);
|
||||
CallbackTracer(JSContext* cx, JS::WeakMapTraceAction weakMapAction =
|
||||
JS::WeakMapTraceAction::TraceValues);
|
||||
|
||||
// Override these methods to receive notification when an edge is visited
|
||||
// with the type contained in the callback. The default implementation
|
||||
|
|
|
@ -1882,7 +1882,7 @@ class HasChildTracer final : public JS::CallbackTracer {
|
|||
|
||||
public:
|
||||
HasChildTracer(JSContext* cx, HandleValue child)
|
||||
: JS::CallbackTracer(cx, TraceWeakMapKeysValues),
|
||||
: JS::CallbackTracer(cx, JS::WeakMapTraceAction::TraceKeysAndValues),
|
||||
child_(cx, child),
|
||||
found_(false) {}
|
||||
|
||||
|
|
|
@ -8893,7 +8893,7 @@ extern JS_PUBLIC_API bool js::gc::detail::ObjectIsMarkedBlack(
|
|||
#endif
|
||||
|
||||
js::gc::ClearEdgesTracer::ClearEdgesTracer(JSRuntime* rt)
|
||||
: CallbackTracer(rt, TraceWeakMapKeysValues) {}
|
||||
: CallbackTracer(rt, JS::WeakMapTraceAction::TraceKeysAndValues) {}
|
||||
|
||||
js::gc::ClearEdgesTracer::ClearEdgesTracer()
|
||||
: ClearEdgesTracer(TlsContext.get()->runtime()) {}
|
||||
|
|
|
@ -220,7 +220,7 @@ void CheckHeapAfterGC(JSRuntime* rt);
|
|||
|
||||
struct MovingTracer final : public JS::CallbackTracer {
|
||||
explicit MovingTracer(JSRuntime* rt)
|
||||
: CallbackTracer(rt, TraceWeakMapKeysValues) {}
|
||||
: CallbackTracer(rt, JS::WeakMapTraceAction::TraceKeysAndValues) {}
|
||||
|
||||
bool onObjectEdge(JSObject** objp) override;
|
||||
bool onShapeEdge(Shape** shapep) override;
|
||||
|
@ -247,7 +247,7 @@ struct MovingTracer final : public JS::CallbackTracer {
|
|||
|
||||
struct SweepingTracer final : public JS::CallbackTracer {
|
||||
explicit SweepingTracer(JSRuntime* rt)
|
||||
: CallbackTracer(rt, TraceWeakMapKeysValues) {}
|
||||
: CallbackTracer(rt, JS::WeakMapTraceAction::TraceKeysAndValues) {}
|
||||
|
||||
bool onObjectEdge(JSObject** objp) override;
|
||||
bool onShapeEdge(Shape** shapep) override;
|
||||
|
|
|
@ -2454,13 +2454,14 @@ inline void MarkStackIter::nextArray() {
|
|||
/*** GCMarker ***************************************************************/
|
||||
|
||||
/*
|
||||
* ExpandWeakMaps: the GC is recomputing the liveness of WeakMap entries by
|
||||
* expanding each live WeakMap into its constituent key->value edges, a table
|
||||
* of which will be consulted in a later phase whenever marking a potential
|
||||
* key.
|
||||
* WeakMapTraceAction::Expand: the GC is recomputing the liveness of WeakMap
|
||||
* entries by expanding each live WeakMap into its constituent key->value edges,
|
||||
* a table of which will be consulted in a later phase whenever marking a
|
||||
* potential key.
|
||||
*/
|
||||
GCMarker::GCMarker(JSRuntime* rt)
|
||||
: JSTracer(rt, JSTracer::TracerKindTag::Marking, ExpandWeakMaps),
|
||||
: JSTracer(rt, JSTracer::TracerKindTag::Marking,
|
||||
JS::WeakMapTraceAction::Expand),
|
||||
stack(),
|
||||
auxStack(),
|
||||
mainStackColor(MarkColor::Black),
|
||||
|
@ -2611,7 +2612,7 @@ void GCMarker::repush(JSObject* obj) {
|
|||
}
|
||||
|
||||
bool GCMarker::enterWeakMarkingMode() {
|
||||
MOZ_ASSERT(weakMapAction() == ExpandWeakMaps);
|
||||
MOZ_ASSERT(weakMapAction() == JS::WeakMapTraceAction::Expand);
|
||||
MOZ_ASSERT(state != MarkingState::WeakMarking);
|
||||
if (state == MarkingState::IterativeMarking) {
|
||||
return false;
|
||||
|
@ -4055,10 +4056,10 @@ struct AssertNonGrayTracer final : public JS::CallbackTracer {
|
|||
|
||||
class UnmarkGrayTracer final : public JS::CallbackTracer {
|
||||
public:
|
||||
// We set weakMapAction to DoNotTraceWeakMaps because the cycle collector
|
||||
// will fix up any color mismatches involving weakmaps when it runs.
|
||||
// We set weakMapAction to WeakMapTraceAction::Skip because the cycle
|
||||
// collector will fix up any color mismatches involving weakmaps when it runs.
|
||||
explicit UnmarkGrayTracer(JSRuntime* rt)
|
||||
: JS::CallbackTracer(rt, DoNotTraceWeakMaps),
|
||||
: JS::CallbackTracer(rt, JS::WeakMapTraceAction::Skip),
|
||||
unmarkedAny(false),
|
||||
oom(false),
|
||||
stack(rt->gc.unmarkGrayStack) {}
|
||||
|
|
|
@ -739,7 +739,8 @@ void js::Nursery::forwardBufferPointer(uintptr_t* pSlotsElems) {
|
|||
}
|
||||
|
||||
js::TenuringTracer::TenuringTracer(JSRuntime* rt, Nursery* nursery)
|
||||
: JSTracer(rt, JSTracer::TracerKindTag::Tenuring, TraceWeakMapKeysValues),
|
||||
: JSTracer(rt, JSTracer::TracerKindTag::Tenuring,
|
||||
JS::WeakMapTraceAction::TraceKeysAndValues),
|
||||
nursery_(*nursery),
|
||||
tenuredSize(0),
|
||||
tenuredCells(0),
|
||||
|
|
|
@ -448,7 +448,7 @@ class AssertNoRootsTracer final : public JS::CallbackTracer {
|
|||
|
||||
public:
|
||||
explicit AssertNoRootsTracer(JSRuntime* rt)
|
||||
: JS::CallbackTracer(rt, TraceWeakMapKeysValues) {}
|
||||
: JS::CallbackTracer(rt, JS::WeakMapTraceAction::TraceKeysAndValues) {}
|
||||
};
|
||||
#endif // DEBUG
|
||||
|
||||
|
|
|
@ -366,8 +366,8 @@ JS_PUBLIC_API void JS_GetTraceThingInfo(char* buf, size_t bufsize,
|
|||
}
|
||||
|
||||
JS::CallbackTracer::CallbackTracer(JSContext* cx,
|
||||
WeakMapTraceKind weakTraceKind)
|
||||
: CallbackTracer(cx->runtime(), weakTraceKind) {}
|
||||
WeakMapTraceAction weakMapAction)
|
||||
: CallbackTracer(cx->runtime(), weakMapAction) {}
|
||||
|
||||
uint32_t JSTracer::gcNumberForMarking() const {
|
||||
MOZ_ASSERT(isMarkingTracer());
|
||||
|
|
|
@ -760,7 +760,8 @@ void GCRuntime::finishMarkingValidation() {
|
|||
|
||||
class HeapCheckTracerBase : public JS::CallbackTracer {
|
||||
public:
|
||||
explicit HeapCheckTracerBase(JSRuntime* rt, WeakMapTraceKind weakTraceKind);
|
||||
explicit HeapCheckTracerBase(JSRuntime* rt,
|
||||
JS::WeakMapTraceAction weakMapAction);
|
||||
bool traceHeap(AutoTraceSession& session);
|
||||
virtual void checkCell(Cell* cell) = 0;
|
||||
|
||||
|
@ -798,8 +799,8 @@ class HeapCheckTracerBase : public JS::CallbackTracer {
|
|||
};
|
||||
|
||||
HeapCheckTracerBase::HeapCheckTracerBase(JSRuntime* rt,
|
||||
WeakMapTraceKind weakTraceKind)
|
||||
: CallbackTracer(rt, weakTraceKind),
|
||||
JS::WeakMapTraceAction weakMapAction)
|
||||
: CallbackTracer(rt, weakMapAction),
|
||||
failures(0),
|
||||
rt(rt),
|
||||
oom(false),
|
||||
|
@ -903,7 +904,8 @@ class CheckHeapTracer final : public HeapCheckTracerBase {
|
|||
};
|
||||
|
||||
CheckHeapTracer::CheckHeapTracer(JSRuntime* rt, GCType type)
|
||||
: HeapCheckTracerBase(rt, TraceWeakMapKeysValues), gcType(type) {}
|
||||
: HeapCheckTracerBase(rt, JS::WeakMapTraceAction::TraceKeysAndValues),
|
||||
gcType(type) {}
|
||||
|
||||
inline static bool IsValidGCThingPointer(Cell* cell) {
|
||||
return (uintptr_t(cell) & CellAlignMask) == 0;
|
||||
|
@ -955,7 +957,7 @@ class CheckGrayMarkingTracer final : public HeapCheckTracerBase {
|
|||
};
|
||||
|
||||
CheckGrayMarkingTracer::CheckGrayMarkingTracer(JSRuntime* rt)
|
||||
: HeapCheckTracerBase(rt, DoNotTraceWeakMaps) {
|
||||
: HeapCheckTracerBase(rt, JS::WeakMapTraceAction::Skip) {
|
||||
// Weak gray->black edges are allowed.
|
||||
setTraceWeakEdges(false);
|
||||
}
|
||||
|
|
|
@ -208,7 +208,7 @@ void WeakMap<K, V>::trace(JSTracer* trc) {
|
|||
TraceNullableEdge(trc, &memberOf, "WeakMap owner");
|
||||
|
||||
if (trc->isMarkingTracer()) {
|
||||
MOZ_ASSERT(trc->weakMapAction() == ExpandWeakMaps);
|
||||
MOZ_ASSERT(trc->weakMapAction() == JS::WeakMapTraceAction::Expand);
|
||||
auto marker = GCMarker::fromTracer(trc);
|
||||
|
||||
// Don't downgrade the map color from black to gray. This can happen when a
|
||||
|
@ -221,20 +221,19 @@ void WeakMap<K, V>::trace(JSTracer* trc) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (trc->weakMapAction() == DoNotTraceWeakMaps) {
|
||||
if (trc->weakMapAction() == JS::WeakMapTraceAction::Skip) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Trace keys only if weakMapAction() says to.
|
||||
if (trc->weakMapAction() == TraceWeakMapKeysValues) {
|
||||
if (trc->weakMapAction() == JS::WeakMapTraceAction::TraceKeysAndValues) {
|
||||
for (Enum e(*this); !e.empty(); e.popFront()) {
|
||||
TraceWeakMapKeyEdge(trc, zone(), &e.front().mutableKey(),
|
||||
"WeakMap entry key");
|
||||
}
|
||||
}
|
||||
|
||||
// Always trace all values (unless weakMapAction() is
|
||||
// DoNotTraceWeakMaps).
|
||||
// Always trace all values (unless weakMapAction() is Skip).
|
||||
for (Range r = Base::all(); !r.empty(); r.popFront()) {
|
||||
TraceEdge(trc, &r.front().value(), "WeakMap entry value");
|
||||
}
|
||||
|
@ -305,7 +304,7 @@ bool WeakMap<K, V>::markEntries(GCMarker* marker) {
|
|||
// So we only need to populate the table if the key is less marked than the
|
||||
// map, to catch later updates in the key's mark color.
|
||||
if (keyColor < mapColor) {
|
||||
MOZ_ASSERT(marker->weakMapAction() == ExpandWeakMaps);
|
||||
MOZ_ASSERT(marker->weakMapAction() == JS::WeakMapTraceAction::Expand);
|
||||
// The final color of the key is not yet known. Record this weakmap and
|
||||
// the lookup key in the list of weak keys. If the key has a delegate,
|
||||
// then the lookup key is the delegate (because marking the key will end
|
||||
|
|
|
@ -45,7 +45,7 @@ void WeakMapBase::unmarkZone(JS::Zone* zone) {
|
|||
}
|
||||
|
||||
void WeakMapBase::traceZone(JS::Zone* zone, JSTracer* tracer) {
|
||||
MOZ_ASSERT(tracer->weakMapAction() != DoNotTraceWeakMaps);
|
||||
MOZ_ASSERT(tracer->weakMapAction() != JS::WeakMapTraceAction::Skip);
|
||||
for (WeakMapBase* m : zone->gcWeakMapList()) {
|
||||
m->trace(tracer);
|
||||
TraceNullableEdge(tracer, &m->memberOf, "memberOf");
|
||||
|
|
|
@ -501,7 +501,7 @@ struct DumpHeapTracer final : public JS::CallbackTracer, public WeakMapTracer {
|
|||
mozilla::MallocSizeOf mallocSizeOf;
|
||||
|
||||
DumpHeapTracer(FILE* fp, JSContext* cx, mozilla::MallocSizeOf mallocSizeOf)
|
||||
: JS::CallbackTracer(cx, DoNotTraceWeakMaps),
|
||||
: JS::CallbackTracer(cx, JS::WeakMapTraceAction::Skip),
|
||||
WeakMapTracer(cx->runtime()),
|
||||
prefix(""),
|
||||
output(fp),
|
||||
|
|
|
@ -390,7 +390,7 @@ JSZoneParticipant::TraverseNative(void* aPtr,
|
|||
|
||||
struct TraversalTracer : public JS::CallbackTracer {
|
||||
TraversalTracer(JSRuntime* aRt, nsCycleCollectionTraversalCallback& aCb)
|
||||
: JS::CallbackTracer(aRt, DoNotTraceWeakMaps), mCb(aCb) {
|
||||
: JS::CallbackTracer(aRt, JS::WeakMapTraceAction::Skip), mCb(aCb) {
|
||||
setCanSkipJsids(true);
|
||||
}
|
||||
bool onChild(const JS::GCCellPtr& aThing) override;
|
||||
|
@ -713,7 +713,8 @@ CycleCollectedJSRuntime::CycleCollectedJSRuntime(JSContext* aCx)
|
|||
class JSLeakTracer : public JS::CallbackTracer {
|
||||
public:
|
||||
explicit JSLeakTracer(JSRuntime* aRuntime)
|
||||
: JS::CallbackTracer(aRuntime, TraceWeakMapKeysValues) {}
|
||||
: JS::CallbackTracer(aRuntime,
|
||||
JS::WeakMapTraceAction::TraceKeysAndValues) {}
|
||||
|
||||
private:
|
||||
bool onChild(const JS::GCCellPtr& thing) override {
|
||||
|
|
Загрузка…
Ссылка в новой задаче