Bug 1624810 - Replace individual nsCycleCollectionParticipant flags with a bit field to make it easier pass multiple flags through derived class oonstructors r=mccr8

Currently classes derived from nsCycleCollectionParicipant have one flag to pass and adding more makes the class delcaration macros get messy really quickly.  This patch replaces boolean flags with a bitfield which makes adding new flags easier.

Differential Revision: https://phabricator.services.mozilla.com/D68194

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Jon Coppeard 2020-03-26 10:48:17 +00:00
Родитель d66d0bdca0
Коммит ff40627b14
1 изменённых файлов: 133 добавлений и 128 удалений

Просмотреть файл

@ -116,9 +116,15 @@ struct TraceCallbackFunc : public TraceCallbacks {
*/
class NS_NO_VTABLE nsCycleCollectionParticipant {
public:
constexpr explicit nsCycleCollectionParticipant(
bool aMightSkip, bool aTraverseShouldTrace = false)
: mMightSkip(aMightSkip), mTraverseShouldTrace(aTraverseShouldTrace) {}
using Flags = uint8_t;
static constexpr Flags FlagMightSkip = 1u << 0;
static constexpr Flags FlagTraverseShouldTrace = 1u << 1;
static constexpr Flags AllFlags = FlagMightSkip | FlagTraverseShouldTrace;
constexpr explicit nsCycleCollectionParticipant(Flags aFlags)
: mFlags(aFlags) {
MOZ_ASSERT((aFlags & ~AllFlags) == 0);
}
NS_IMETHOD TraverseNative(void* aPtr,
nsCycleCollectionTraversalCallback& aCb) = 0;
@ -126,7 +132,7 @@ class NS_NO_VTABLE nsCycleCollectionParticipant {
nsresult TraverseNativeAndJS(void* aPtr,
nsCycleCollectionTraversalCallback& aCb) {
nsresult rv = TraverseNative(aPtr, aCb);
if (mTraverseShouldTrace) {
if (TraverseShouldTrace()) {
// Note, we always call Trace, even if Traverse returned
// NS_SUCCESS_INTERRUPTED_TRAVERSE.
TraceCallbackFunc noteJsChild(&nsCycleCollectionParticipant::NoteJSChild);
@ -161,7 +167,7 @@ class NS_NO_VTABLE nsCycleCollectionParticipant {
// outgoing edges at all in the cycle collection graph (because then they
// can't be parts of a cycle) or they know for sure they're alive.
bool CanSkip(void* aPtr, bool aRemovingAllowed) {
return mMightSkip ? CanSkipReal(aPtr, aRemovingAllowed) : false;
return MightSkip() ? CanSkipReal(aPtr, aRemovingAllowed) : false;
}
// CanSkipInCC is called during construction of the initial set of roots for
@ -190,7 +196,7 @@ class NS_NO_VTABLE nsCycleCollectionParticipant {
// a live thing, while C++ things are also considered alive when their
// refcount exceeds the number of edges via which they are reachable.
bool CanSkipInCC(void* aPtr) {
return mMightSkip ? CanSkipInCCReal(aPtr) : false;
return MightSkip() ? CanSkipInCCReal(aPtr) : false;
}
// CanSkipThis is called during construction of the cycle collector graph,
@ -209,7 +215,7 @@ class NS_NO_VTABLE nsCycleCollectionParticipant {
// graph during root set construction. An object should never have
// CanSkipThis called on it if it has outgoing strong references to JS things.
bool CanSkipThis(void* aPtr) {
return mMightSkip ? CanSkipThisReal(aPtr) : false;
return MightSkip() ? CanSkipThisReal(aPtr) : false;
}
NS_IMETHOD_(void) DeleteCycleCollectable(void* aPtr) = 0;
@ -229,14 +235,16 @@ class NS_NO_VTABLE nsCycleCollectionParticipant {
}
private:
const bool mMightSkip;
const bool mTraverseShouldTrace;
bool MightSkip() const { return mFlags & FlagMightSkip; }
bool TraverseShouldTrace() const { return mFlags & FlagTraverseShouldTrace; }
const Flags mFlags;
};
class NS_NO_VTABLE nsScriptObjectTracer : public nsCycleCollectionParticipant {
public:
constexpr explicit nsScriptObjectTracer(bool aMightSkip)
: nsCycleCollectionParticipant(aMightSkip, true) {}
constexpr explicit nsScriptObjectTracer(Flags aFlags)
: nsCycleCollectionParticipant(aFlags | FlagTraverseShouldTrace) {}
NS_IMETHOD_(void)
Trace(void* aPtr, const TraceCallbacks& aCb, void* aClosure) override = 0;
@ -245,8 +253,8 @@ class NS_NO_VTABLE nsScriptObjectTracer : public nsCycleCollectionParticipant {
class NS_NO_VTABLE nsXPCOMCycleCollectionParticipant
: public nsScriptObjectTracer {
public:
constexpr explicit nsXPCOMCycleCollectionParticipant(bool aMightSkip)
: nsScriptObjectTracer(aMightSkip) {}
constexpr explicit nsXPCOMCycleCollectionParticipant(Flags aFlags)
: nsScriptObjectTracer(aFlags) {}
NS_DECLARE_STATIC_IID_ACCESSOR(NS_XPCOMCYCLECOLLECTIONPARTICIPANT_IID)
@ -599,19 +607,19 @@ T* DowncastCCParticipant(void* aPtr) {
# define NOT_INHERITED_CANT_OVERRIDE
#endif
#define NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(_class, _base) \
class NS_CYCLE_COLLECTION_INNERCLASS \
: public nsXPCOMCycleCollectionParticipant { \
public: \
constexpr explicit NS_CYCLE_COLLECTION_INNERCLASS(bool aMightSkip = false) \
: nsXPCOMCycleCollectionParticipant(aMightSkip) {} \
\
private: \
NS_DECL_CYCLE_COLLECTION_CLASS_BODY(_class, _base) \
NS_IMPL_GET_XPCOM_CYCLE_COLLECTION_PARTICIPANT(_class) \
}; \
NS_CHECK_FOR_RIGHT_PARTICIPANT_IMPL(_class) \
static NS_CYCLE_COLLECTION_INNERCLASS NS_CYCLE_COLLECTION_INNERNAME; \
#define NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(_class, _base) \
class NS_CYCLE_COLLECTION_INNERCLASS \
: public nsXPCOMCycleCollectionParticipant { \
public: \
constexpr explicit NS_CYCLE_COLLECTION_INNERCLASS(Flags aFlags = 0) \
: nsXPCOMCycleCollectionParticipant(aFlags) {} \
\
private: \
NS_DECL_CYCLE_COLLECTION_CLASS_BODY(_class, _base) \
NS_IMPL_GET_XPCOM_CYCLE_COLLECTION_PARTICIPANT(_class) \
}; \
NS_CHECK_FOR_RIGHT_PARTICIPANT_IMPL(_class) \
static NS_CYCLE_COLLECTION_INNERCLASS NS_CYCLE_COLLECTION_INNERNAME; \
NOT_INHERITED_CANT_OVERRIDE
#define NS_DECL_CYCLE_COLLECTION_CLASS(_class) \
@ -623,9 +631,8 @@ T* DowncastCCParticipant(void* aPtr) {
: public nsXPCOMCycleCollectionParticipant { \
public: \
constexpr explicit NS_CYCLE_COLLECTION_INNERCLASS( \
bool aMightSkip = \
true) /* Ignore aMightSkip: we always want skippability. */ \
: nsXPCOMCycleCollectionParticipant(true) {} \
Flags aFlags = FlagMightSkip) /* We always want skippability. */ \
: nsXPCOMCycleCollectionParticipant(aFlags | FlagMightSkip) {} \
\
private: \
NS_DECL_CYCLE_COLLECTION_CLASS_BODY(_class, _base) \
@ -641,21 +648,21 @@ T* DowncastCCParticipant(void* aPtr) {
#define NS_DECL_CYCLE_COLLECTION_SKIPPABLE_CLASS(_class) \
NS_DECL_CYCLE_COLLECTION_SKIPPABLE_CLASS_AMBIGUOUS(_class, _class)
#define NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(_class, _base) \
class NS_CYCLE_COLLECTION_INNERCLASS \
: public nsXPCOMCycleCollectionParticipant { \
public: \
constexpr explicit NS_CYCLE_COLLECTION_INNERCLASS(bool aMightSkip = false) \
: nsXPCOMCycleCollectionParticipant(aMightSkip) {} \
\
private: \
NS_DECL_CYCLE_COLLECTION_CLASS_BODY(_class, _base) \
NS_IMETHOD_(void) \
Trace(void* p, const TraceCallbacks& cb, void* closure) override; \
NS_IMPL_GET_XPCOM_CYCLE_COLLECTION_PARTICIPANT(_class) \
}; \
NS_CHECK_FOR_RIGHT_PARTICIPANT_IMPL(_class) \
static NS_CYCLE_COLLECTION_INNERCLASS NS_CYCLE_COLLECTION_INNERNAME; \
#define NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(_class, _base) \
class NS_CYCLE_COLLECTION_INNERCLASS \
: public nsXPCOMCycleCollectionParticipant { \
public: \
constexpr explicit NS_CYCLE_COLLECTION_INNERCLASS(Flags aFlags = 0) \
: nsXPCOMCycleCollectionParticipant(aFlags) {} \
\
private: \
NS_DECL_CYCLE_COLLECTION_CLASS_BODY(_class, _base) \
NS_IMETHOD_(void) \
Trace(void* p, const TraceCallbacks& cb, void* closure) override; \
NS_IMPL_GET_XPCOM_CYCLE_COLLECTION_PARTICIPANT(_class) \
}; \
NS_CHECK_FOR_RIGHT_PARTICIPANT_IMPL(_class) \
static NS_CYCLE_COLLECTION_INNERCLASS NS_CYCLE_COLLECTION_INNERNAME; \
NOT_INHERITED_CANT_OVERRIDE
#define NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS_AMBIGUOUS( \
@ -664,9 +671,8 @@ T* DowncastCCParticipant(void* aPtr) {
: public nsXPCOMCycleCollectionParticipant { \
public: \
constexpr explicit NS_CYCLE_COLLECTION_INNERCLASS( \
bool aMightSkip = \
true) /* Ignore aMightSkip: we always want skippability. */ \
: nsXPCOMCycleCollectionParticipant(true) {} \
Flags aFlags = FlagMightSkip) /* We always want skippability. */ \
: nsXPCOMCycleCollectionParticipant(aFlags | FlagMightSkip) {} \
\
private: \
NS_DECL_CYCLE_COLLECTION_CLASS_BODY(_class, _base) \
@ -685,26 +691,26 @@ T* DowncastCCParticipant(void* aPtr) {
NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS_AMBIGUOUS(_class, \
_class)
#define NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS_INHERITED( \
_class, _base_class) \
class NS_CYCLE_COLLECTION_INNERCLASS \
: public NS_CYCLE_COLLECTION_CLASSNAME(_base_class) { \
public: \
constexpr explicit NS_CYCLE_COLLECTION_INNERCLASS( \
bool aMightSkip = \
true) /* Ignore aMightSkip: we always want skippability. */ \
: NS_CYCLE_COLLECTION_CLASSNAME(_base_class)(true) {} \
\
private: \
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_BODY(_class, _base_class) \
NS_IMETHOD_(void) \
Trace(void* p, const TraceCallbacks& cb, void* closure) override; \
NS_IMETHOD_(bool) CanSkipReal(void* p, bool aRemovingAllowed) override; \
NS_IMETHOD_(bool) CanSkipInCCReal(void* p) override; \
NS_IMETHOD_(bool) CanSkipThisReal(void* p) override; \
NS_IMPL_GET_XPCOM_CYCLE_COLLECTION_PARTICIPANT(_class) \
}; \
NS_CHECK_FOR_RIGHT_PARTICIPANT_IMPL_INHERITED(_class) \
#define NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS_INHERITED( \
_class, _base_class) \
class NS_CYCLE_COLLECTION_INNERCLASS \
: public NS_CYCLE_COLLECTION_CLASSNAME(_base_class) { \
public: \
constexpr explicit NS_CYCLE_COLLECTION_INNERCLASS( \
Flags aFlags = FlagMightSkip) /* We always want skippability. */ \
: NS_CYCLE_COLLECTION_CLASSNAME(_base_class)(aFlags | FlagMightSkip) { \
} \
\
private: \
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_BODY(_class, _base_class) \
NS_IMETHOD_(void) \
Trace(void* p, const TraceCallbacks& cb, void* closure) override; \
NS_IMETHOD_(bool) CanSkipReal(void* p, bool aRemovingAllowed) override; \
NS_IMETHOD_(bool) CanSkipInCCReal(void* p) override; \
NS_IMETHOD_(bool) CanSkipThisReal(void* p) override; \
NS_IMPL_GET_XPCOM_CYCLE_COLLECTION_PARTICIPANT(_class) \
}; \
NS_CHECK_FOR_RIGHT_PARTICIPANT_IMPL_INHERITED(_class) \
static NS_CYCLE_COLLECTION_INNERCLASS NS_CYCLE_COLLECTION_INNERNAME;
#define NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(_class) \
@ -725,51 +731,51 @@ T* DowncastCCParticipant(void* aPtr) {
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_BODY_NO_UNLINK(_class, _base_class) \
NS_IMETHOD_(void) Unlink(void* p) override;
#define NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(_class, _base_class) \
class NS_CYCLE_COLLECTION_INNERCLASS \
: public NS_CYCLE_COLLECTION_CLASSNAME(_base_class) { \
public: \
constexpr explicit NS_CYCLE_COLLECTION_INNERCLASS(bool aMightSkip = false) \
: NS_CYCLE_COLLECTION_CLASSNAME(_base_class)(aMightSkip) {} \
\
private: \
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_BODY(_class, _base_class) \
NS_IMPL_GET_XPCOM_CYCLE_COLLECTION_PARTICIPANT(_class) \
}; \
NS_CHECK_FOR_RIGHT_PARTICIPANT_IMPL_INHERITED(_class) \
#define NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(_class, _base_class) \
class NS_CYCLE_COLLECTION_INNERCLASS \
: public NS_CYCLE_COLLECTION_CLASSNAME(_base_class) { \
public: \
constexpr explicit NS_CYCLE_COLLECTION_INNERCLASS(Flags aFlags = 0) \
: NS_CYCLE_COLLECTION_CLASSNAME(_base_class)(aFlags) {} \
\
private: \
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_BODY(_class, _base_class) \
NS_IMPL_GET_XPCOM_CYCLE_COLLECTION_PARTICIPANT(_class) \
}; \
NS_CHECK_FOR_RIGHT_PARTICIPANT_IMPL_INHERITED(_class) \
static NS_CYCLE_COLLECTION_INNERCLASS NS_CYCLE_COLLECTION_INNERNAME;
#define NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_NO_UNLINK(_class, \
_base_class) \
class NS_CYCLE_COLLECTION_INNERCLASS \
: public NS_CYCLE_COLLECTION_CLASSNAME(_base_class) { \
public: \
constexpr explicit NS_CYCLE_COLLECTION_INNERCLASS(bool aMightSkip = false) \
: NS_CYCLE_COLLECTION_CLASSNAME(_base_class)(aMightSkip) {} \
\
private: \
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_BODY_NO_UNLINK(_class, \
_base_class) \
NS_IMPL_GET_XPCOM_CYCLE_COLLECTION_PARTICIPANT(_class) \
}; \
NS_CHECK_FOR_RIGHT_PARTICIPANT_IMPL_INHERITED(_class) \
#define NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_NO_UNLINK(_class, \
_base_class) \
class NS_CYCLE_COLLECTION_INNERCLASS \
: public NS_CYCLE_COLLECTION_CLASSNAME(_base_class) { \
public: \
constexpr explicit NS_CYCLE_COLLECTION_INNERCLASS(Flags aFlags = 0) \
: NS_CYCLE_COLLECTION_CLASSNAME(_base_class)(aFlags) {} \
\
private: \
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_BODY_NO_UNLINK(_class, \
_base_class) \
NS_IMPL_GET_XPCOM_CYCLE_COLLECTION_PARTICIPANT(_class) \
}; \
NS_CHECK_FOR_RIGHT_PARTICIPANT_IMPL_INHERITED(_class) \
static NS_CYCLE_COLLECTION_INNERCLASS NS_CYCLE_COLLECTION_INNERNAME;
#define NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(_class, \
_base_class) \
class NS_CYCLE_COLLECTION_INNERCLASS \
: public NS_CYCLE_COLLECTION_CLASSNAME(_base_class) { \
public: \
constexpr explicit NS_CYCLE_COLLECTION_INNERCLASS(bool aMightSkip = false) \
: NS_CYCLE_COLLECTION_CLASSNAME(_base_class)(aMightSkip) {} \
\
private: \
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_BODY(_class, _base_class) \
NS_IMETHOD_(void) \
Trace(void* p, const TraceCallbacks& cb, void* closure) override; \
NS_IMPL_GET_XPCOM_CYCLE_COLLECTION_PARTICIPANT(_class) \
}; \
NS_CHECK_FOR_RIGHT_PARTICIPANT_IMPL_INHERITED(_class) \
#define NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(_class, \
_base_class) \
class NS_CYCLE_COLLECTION_INNERCLASS \
: public NS_CYCLE_COLLECTION_CLASSNAME(_base_class) { \
public: \
constexpr explicit NS_CYCLE_COLLECTION_INNERCLASS(Flags aFlags = 0) \
: NS_CYCLE_COLLECTION_CLASSNAME(_base_class)(aFlags) {} \
\
private: \
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_BODY(_class, _base_class) \
NS_IMETHOD_(void) \
Trace(void* p, const TraceCallbacks& cb, void* closure) override; \
NS_IMPL_GET_XPCOM_CYCLE_COLLECTION_PARTICIPANT(_class) \
}; \
NS_CHECK_FOR_RIGHT_PARTICIPANT_IMPL_INHERITED(_class) \
static NS_CYCLE_COLLECTION_INNERCLASS NS_CYCLE_COLLECTION_INNERNAME;
// Cycle collector participant declarations.
@ -794,8 +800,8 @@ T* DowncastCCParticipant(void* aPtr) {
void DeleteCycleCollectable(void) { delete this; } \
class NS_CYCLE_COLLECTION_INNERCLASS : public nsCycleCollectionParticipant { \
public: \
constexpr explicit NS_CYCLE_COLLECTION_INNERCLASS(bool aMightSkip = false) \
: nsCycleCollectionParticipant(aMightSkip) {} \
constexpr explicit NS_CYCLE_COLLECTION_INNERCLASS(Flags aFlags = 0) \
: nsCycleCollectionParticipant(aFlags) {} \
\
private: \
NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS_BODY(_class) \
@ -810,9 +816,8 @@ T* DowncastCCParticipant(void* aPtr) {
class NS_CYCLE_COLLECTION_INNERCLASS : public nsCycleCollectionParticipant { \
public: \
constexpr explicit NS_CYCLE_COLLECTION_INNERCLASS( \
bool aMightSkip = \
true) /* Ignore aMightSkip: we always want skippability. */ \
: nsCycleCollectionParticipant(true) {} \
Flags aFlags = FlagMightSkip) /* We always want skippability. */ \
: nsCycleCollectionParticipant(aFlags | FlagMightSkip) {} \
\
private: \
NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS_BODY(_class) \
@ -843,21 +848,21 @@ T* DowncastCCParticipant(void* aPtr) {
}; \
static NS_CYCLE_COLLECTION_INNERCLASS NS_CYCLE_COLLECTION_INNERNAME;
#define NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(_class) \
void DeleteCycleCollectable(void) { delete this; } \
class NS_CYCLE_COLLECTION_INNERCLASS : public nsScriptObjectTracer { \
public: \
constexpr explicit NS_CYCLE_COLLECTION_INNERCLASS(bool aMightSkip = false) \
: nsScriptObjectTracer(aMightSkip) {} \
\
private: \
NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS_BODY(_class) \
NS_IMETHOD_(void) \
Trace(void* p, const TraceCallbacks& cb, void* closure) override; \
static constexpr nsScriptObjectTracer* GetParticipant() { \
return &_class::NS_CYCLE_COLLECTION_INNERNAME; \
} \
}; \
#define NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(_class) \
void DeleteCycleCollectable(void) { delete this; } \
class NS_CYCLE_COLLECTION_INNERCLASS : public nsScriptObjectTracer { \
public: \
constexpr explicit NS_CYCLE_COLLECTION_INNERCLASS(Flags aFlags = 0) \
: nsScriptObjectTracer(aFlags) {} \
\
private: \
NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS_BODY(_class) \
NS_IMETHOD_(void) \
Trace(void* p, const TraceCallbacks& cb, void* closure) override; \
static constexpr nsScriptObjectTracer* GetParticipant() { \
return &_class::NS_CYCLE_COLLECTION_INNERNAME; \
} \
}; \
static NS_CYCLE_COLLECTION_INNERCLASS NS_CYCLE_COLLECTION_INNERNAME;
#define NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(_class, _root_function) \