Bug 1785804 - Part 5: Merge GenericTracer into JSTracer r=sfink

All tracers are now GenericTracers so there's no reason for this to be a
separate thing.

Depends on D156562

Differential Revision: https://phabricator.services.mozilla.com/D156563
This commit is contained in:
Jon Coppeard 2022-09-07 09:49:59 +00:00
parent 7c85e1f4ff
commit 14eb214402
5 changed files with 30 additions and 54 deletions

View File

@ -30,11 +30,6 @@ JS_PUBLIC_API size_t GCTraceKindSize(JS::TraceKind kind);
enum class TracerKind {
// Generic tracers: Internal tracers that have a different virtual method
// called for each edge kind.
//
// Order is important. All generic kinds must follow this one.
Generic,
// Specific kinds of generic tracer.
Marking,
Tenuring,
Moving,
@ -153,22 +148,17 @@ class TracingContext {
} // namespace JS
namespace js {
class GenericTracer;
} // namespace js
class JS_PUBLIC_API JSTracer {
public:
// Return the runtime set on the tracer.
JSRuntime* runtime() const { return runtime_; }
JS::TracerKind kind() const { return kind_; }
bool isGenericTracer() const { return kind_ < JS::TracerKind::Callback; }
bool isCallbackTracer() const { return kind_ >= JS::TracerKind::Callback; }
bool isMarkingTracer() const { return kind_ == JS::TracerKind::Marking; }
bool isTenuringTracer() const { return kind_ == JS::TracerKind::Tenuring; }
bool isGenericTracer() const { return kind_ >= JS::TracerKind::Generic; }
bool isCallbackTracer() const { return kind_ >= JS::TracerKind::Callback; }
inline js::GenericTracer* asGenericTracer();
inline JS::CallbackTracer* asCallbackTracer();
JS::WeakMapTraceAction weakMapAction() const {
@ -180,28 +170,6 @@ class JS_PUBLIC_API JSTracer {
JS::TracingContext& context() { return context_; }
protected:
JSTracer(JSRuntime* rt, JS::TracerKind kind,
JS::TraceOptions options = JS::TraceOptions())
: runtime_(rt), kind_(kind), options_(options) {}
private:
JSRuntime* const runtime_;
const JS::TracerKind kind_;
const JS::TraceOptions options_;
JS::TracingContext context_;
};
namespace js {
class GenericTracer : public JSTracer {
public:
GenericTracer(JSRuntime* rt, JS::TracerKind kind = JS::TracerKind::Generic,
JS::TraceOptions options = JS::TraceOptions())
: JSTracer(rt, kind, options) {
MOZ_ASSERT(isGenericTracer());
}
// These methods are called when the tracer encounters an edge. Clients should
// override them to receive notifications when an edge of each type is
// visited.
@ -217,16 +185,29 @@ class GenericTracer : public JSTracer {
virtual void on##name##Edge(type** thingp, const char* name) = 0;
JS_FOR_EACH_TRACEKIND(DEFINE_ON_EDGE_METHOD)
#undef DEFINE_ON_EDGE_METHOD
protected:
JSTracer(JSRuntime* rt, JS::TracerKind kind,
JS::TraceOptions options = JS::TraceOptions())
: runtime_(rt), kind_(kind), options_(options) {}
private:
JSRuntime* const runtime_;
const JS::TracerKind kind_;
const JS::TraceOptions options_;
JS::TracingContext context_;
};
// A helper class that implements a GenericTracer by calling template method
// on a derived type for each edge kind.
namespace js {
// A CRTP helper class that implements a JSTracer by calling a template method
// on the derived tracer type for each edge kind.
template <typename T>
class GenericTracerImpl : public GenericTracer {
class GenericTracerImpl : public JSTracer {
public:
GenericTracerImpl(JSRuntime* rt, JS::TracerKind kind,
JS::TraceOptions options)
: GenericTracer(rt, kind, options) {}
: JSTracer(rt, kind, options) {}
private:
T* derived() { return static_cast<T*>(this); }
@ -318,11 +299,6 @@ class MOZ_RAII AutoClearTracingContext {
} // namespace JS
js::GenericTracer* JSTracer::asGenericTracer() {
MOZ_ASSERT(isGenericTracer());
return static_cast<js::GenericTracer*>(this);
}
JS::CallbackTracer* JSTracer::asCallbackTracer() {
MOZ_ASSERT(isCallbackTracer());
return static_cast<JS::CallbackTracer*>(this);

View File

@ -643,14 +643,14 @@ void js::TraceGCCellPtrRoot(JSTracer* trc, JS::GCCellPtr* thingp,
}
template <typename T>
inline bool DoCallback(GenericTracer* trc, T** thingp, const char* name) {
inline bool DoCallback(JSTracer* trc, T** thingp, const char* name) {
CheckTracedThing(trc, *thingp);
DispatchToOnEdge(trc, thingp, name);
return *thingp;
}
template <typename T>
inline bool DoCallback(GenericTracer* trc, T* thingp, const char* name) {
inline bool DoCallback(JSTracer* trc, T* thingp, const char* name) {
// Return true by default. For some types the lambda below won't be called.
bool ret = true;
auto thing = MapGCThingTyped(*thingp, [&](auto thing) {
@ -685,7 +685,7 @@ bool js::gc::TraceEdgeInternal(JSTracer* trc, T* thingp, const char* name) {
"marking/tracing internals");
#undef IS_SAME_TYPE_OR
return DoCallback(trc->asGenericTracer(), thingp, name);
return DoCallback(trc, thingp, name);
}
template <typename T>
@ -2724,7 +2724,7 @@ static bool CellMayHaveChildren(JS::GCCellPtr cell) {
/* static */
BarrierTracer* BarrierTracer::fromTracer(JSTracer* trc) {
MOZ_ASSERT(trc->kind() == JS::TracerKind::Barrier);
return static_cast<BarrierTracer*>(trc->asGenericTracer());
return static_cast<BarrierTracer*>(trc);
}
BarrierTracer::BarrierTracer(JSRuntime* rt)

View File

@ -44,8 +44,8 @@ using mozilla::PodCopy;
constexpr size_t MAX_DEDUPLICATABLE_STRING_LENGTH = 500;
TenuringTracer::TenuringTracer(JSRuntime* rt, Nursery* nursery)
: GenericTracer(rt, JS::TracerKind::Tenuring,
JS::WeakMapTraceAction::TraceKeysAndValues),
: JSTracer(rt, JS::TracerKind::Tenuring,
JS::WeakMapTraceAction::TraceKeysAndValues),
nursery_(*nursery) {}
size_t TenuringTracer::getTenuredSize() const {

View File

@ -21,7 +21,7 @@ class RelocationOverlay;
class StringRelocationOverlay;
} // namespace gc
class TenuringTracer final : public GenericTracer {
class TenuringTracer final : public JSTracer {
Nursery& nursery_;
// Amount of data moved to the tenured generation during collection.

View File

@ -355,10 +355,10 @@ void GetTraceThingInfo(char* buf, size_t bufsize, void* thing,
// Overloaded function to call the correct GenericTracer method based on the
// argument type.
#define DEFINE_DISPATCH_FUNCTION(name, type, _1, _2) \
inline void DispatchToOnEdge(GenericTracer* trc, type** thingp, \
const char* name) { \
trc->on##name##Edge(thingp, name); \
#define DEFINE_DISPATCH_FUNCTION(name, type, _1, _2) \
inline void DispatchToOnEdge(JSTracer* trc, type** thingp, \
const char* name) { \
trc->on##name##Edge(thingp, name); \
}
JS_FOR_EACH_TRACEKIND(DEFINE_DISPATCH_FUNCTION)
#undef DEFINE_DISPATCH_FUNCTION