1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef nsCycleCollectionParticipant_h__
8 #define nsCycleCollectionParticipant_h__
10 #include "mozilla/MacroArgs.h"
11 #include "mozilla/MacroForEach.h"
12 #include "nsCycleCollectionNoteChild.h"
13 #include "js/RootingAPI.h"
16 * Note: the following two IIDs only differ in one bit in the last byte. This
17 * is a hack and is intentional in order to speed up the comparison inside
18 * NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED.
20 #define NS_XPCOMCYCLECOLLECTIONPARTICIPANT_IID \
22 0xc61eac14, 0x5f7a, 0x4481, { \
23 0x96, 0x5e, 0x7e, 0xaa, 0x6e, 0xff, 0xa8, 0x5e \
28 * Special IID to get at the base nsISupports for a class. Usually this is the
29 * canonical nsISupports pointer, but in the case of tearoffs for example it is
30 * the base nsISupports pointer of the tearoff. This allow the cycle collector
31 * to have separate nsCycleCollectionParticipant's for tearoffs or aggregated
34 #define NS_CYCLECOLLECTIONISUPPORTS_IID \
36 0xc61eac14, 0x5f7a, 0x4481, { \
37 0x96, 0x5e, 0x7e, 0xaa, 0x6e, 0xff, 0xa8, 0x5f \
42 * Just holds the IID so NS_GET_IID works.
44 class nsCycleCollectionISupports
{
46 NS_DECLARE_STATIC_IID_ACCESSOR(NS_CYCLECOLLECTIONISUPPORTS_IID
)
49 NS_DEFINE_STATIC_IID_ACCESSOR(nsCycleCollectionISupports
,
50 NS_CYCLECOLLECTIONISUPPORTS_IID
)
60 * A struct defining pure virtual methods which are called when tracing cycle
61 * collection paticipants. The appropriate method is called depending on the
62 * type of JS GC thing.
64 struct TraceCallbacks
{
65 virtual void Trace(JS::Heap
<JS::Value
>* aPtr
, const char* aName
,
66 void* aClosure
) const = 0;
67 virtual void Trace(JS::Heap
<jsid
>* aPtr
, const char* aName
,
68 void* aClosure
) const = 0;
69 virtual void Trace(JS::Heap
<JSObject
*>* aPtr
, const char* aName
,
70 void* aClosure
) const = 0;
71 virtual void Trace(nsWrapperCache
* aPtr
, const char* aName
,
72 void* aClosure
) const = 0;
73 virtual void Trace(JS::TenuredHeap
<JSObject
*>* aPtr
, const char* aName
,
74 void* aClosure
) const = 0;
75 virtual void Trace(JS::Heap
<JSString
*>* aPtr
, const char* aName
,
76 void* aClosure
) const = 0;
77 virtual void Trace(JS::Heap
<JSScript
*>* aPtr
, const char* aName
,
78 void* aClosure
) const = 0;
79 virtual void Trace(JS::Heap
<JSFunction
*>* aPtr
, const char* aName
,
80 void* aClosure
) const = 0;
84 * An implementation of TraceCallbacks that calls a single function for all JS
85 * GC thing types encountered. Implemented in
86 * nsCycleCollectorTraceJSHelpers.cpp.
88 struct TraceCallbackFunc
: public TraceCallbacks
{
89 typedef void (*Func
)(JS::GCCellPtr aPtr
, const char* aName
, void* aClosure
);
91 explicit TraceCallbackFunc(Func aCb
) : mCallback(aCb
) {}
93 virtual void Trace(JS::Heap
<JS::Value
>* aPtr
, const char* aName
,
94 void* aClosure
) const override
;
95 virtual void Trace(JS::Heap
<jsid
>* aPtr
, const char* aName
,
96 void* aClosure
) const override
;
97 virtual void Trace(JS::Heap
<JSObject
*>* aPtr
, const char* aName
,
98 void* aClosure
) const override
;
99 virtual void Trace(nsWrapperCache
* aPtr
, const char* aName
,
100 void* aClosure
) const override
;
101 virtual void Trace(JS::TenuredHeap
<JSObject
*>* aPtr
, const char* aName
,
102 void* aClosure
) const override
;
103 virtual void Trace(JS::Heap
<JSString
*>* aPtr
, const char* aName
,
104 void* aClosure
) const override
;
105 virtual void Trace(JS::Heap
<JSScript
*>* aPtr
, const char* aName
,
106 void* aClosure
) const override
;
107 virtual void Trace(JS::Heap
<JSFunction
*>* aPtr
, const char* aName
,
108 void* aClosure
) const override
;
115 * Participant implementation classes
117 class NS_NO_VTABLE nsCycleCollectionParticipant
{
119 using Flags
= uint8_t;
120 static constexpr Flags FlagMightSkip
= 1u << 0;
121 static constexpr Flags FlagTraverseShouldTrace
= 1u << 1;
122 static constexpr Flags FlagMultiZoneJSHolder
= 1u << 2;
123 static constexpr Flags AllFlags
=
124 FlagMightSkip
| FlagTraverseShouldTrace
| FlagMultiZoneJSHolder
;
126 constexpr explicit nsCycleCollectionParticipant(Flags aFlags
)
128 MOZ_ASSERT((aFlags
& ~AllFlags
) == 0);
131 NS_IMETHOD
TraverseNative(void* aPtr
,
132 nsCycleCollectionTraversalCallback
& aCb
) = 0;
134 nsresult
TraverseNativeAndJS(void* aPtr
,
135 nsCycleCollectionTraversalCallback
& aCb
) {
136 nsresult rv
= TraverseNative(aPtr
, aCb
);
137 if (TraverseShouldTrace()) {
138 // Note, we always call Trace, even if Traverse returned
139 // NS_SUCCESS_INTERRUPTED_TRAVERSE.
140 TraceCallbackFunc
noteJsChild(&nsCycleCollectionParticipant::NoteJSChild
);
141 Trace(aPtr
, noteJsChild
, &aCb
);
146 // Implemented in nsCycleCollectorTraceJSHelpers.cpp.
147 static void NoteJSChild(JS::GCCellPtr aGCThing
, const char* aName
,
150 NS_IMETHOD_(void) Root(void* aPtr
) = 0;
151 NS_IMETHOD_(void) Unlink(void* aPtr
) = 0;
152 NS_IMETHOD_(void) Unroot(void* aPtr
) = 0;
153 NS_IMETHOD_(const char*) ClassName() = 0;
156 Trace(void* aPtr
, const TraceCallbacks
& aCb
, void* aClosure
) {}
158 // CanSkip is called during nsCycleCollector_forgetSkippable. If it returns
159 // true, aPtr is removed from the purple buffer and therefore might be left
160 // out from the cycle collector graph the next time that's constructed (unless
161 // it's reachable in some other way).
163 // CanSkip is allowed to expand the set of certainly-alive objects by removing
164 // other objects from the purple buffer, marking JS things black (in the GC
165 // sense), and so forth. Furthermore, if aRemovingAllowed is true, this call
166 // is allowed to remove aPtr itself from the purple buffer.
168 // Things can return true from CanSkip if either they know they have no
169 // outgoing edges at all in the cycle collection graph (because then they
170 // can't be parts of a cycle) or they know for sure they're alive.
171 bool CanSkip(void* aPtr
, bool aRemovingAllowed
) {
172 return MightSkip() ? CanSkipReal(aPtr
, aRemovingAllowed
) : false;
175 // CanSkipInCC is called during construction of the initial set of roots for
176 // the cycle collector graph. If it returns true, aPtr is left out of that
177 // set of roots. Note that the set of roots includes whatever is in the
178 // purple buffer (after earlier CanSkip calls) plus various other sources of
179 // roots, so an object can end up having CanSkipInCC called on it even if it
180 // returned true from CanSkip. One example of this would be an object that
181 // can potentially trace JS things.
183 // CanSkipInCC is allowed to remove other objects from the purple buffer but
184 // should not remove aPtr and should not mark JS things black. It should also
185 // not modify any reference counts.
187 // Things can return true from CanSkipInCC if either they know they have no
188 // outgoing edges at all in the cycle collection graph or they know for sure
189 // they're alive _and_ none of their outgoing edges are to gray (in the GC
190 // sense) gcthings. See also nsWrapperCache::HasNothingToTrace and
191 // nsWrapperCache::HasKnownLiveWrapperAndDoesNotNeedTracing. The restriction
192 // on not having outgoing edges to gray gcthings is because if we _do_ have
193 // them that means we have a "strong" edge to a JS thing and since we're alive
194 // we need to trace through it and mark keep them alive. Outgoing edges to
195 // C++ things don't matter here, because the criteria for when a CC
196 // participant is considered alive are slightly different for JS and C++
197 // things: JS things are only considered alive when reachable via an edge from
198 // a live thing, while C++ things are also considered alive when their
199 // refcount exceeds the number of edges via which they are reachable.
200 bool CanSkipInCC(void* aPtr
) {
201 return MightSkip() ? CanSkipInCCReal(aPtr
) : false;
204 // CanSkipThis is called during construction of the cycle collector graph,
205 // when we traverse an edge to aPtr and consider adding it to the graph. If
206 // it returns true, aPtr is not added to the graph.
208 // CanSkipThis is not allowed to change the liveness or reference count of any
211 // Things can return true from CanSkipThis if either they know they have no
212 // outgoing edges at all in the cycle collection graph or they know for sure
215 // Note that CanSkipThis doesn't have to worry about outgoing edges to gray GC
216 // things, because if this object could have those it already got added to the
217 // graph during root set construction. An object should never have
218 // CanSkipThis called on it if it has outgoing strong references to JS things.
219 bool CanSkipThis(void* aPtr
) {
220 return MightSkip() ? CanSkipThisReal(aPtr
) : false;
223 NS_IMETHOD_(void) DeleteCycleCollectable(void* aPtr
) = 0;
225 bool IsMultiZoneJSHolder() const { return mFlags
& FlagMultiZoneJSHolder
; }
228 NS_IMETHOD_(bool) CanSkipReal(void* aPtr
, bool aRemovingAllowed
) {
229 NS_ASSERTION(false, "Forgot to implement CanSkipReal?");
232 NS_IMETHOD_(bool) CanSkipInCCReal(void* aPtr
) {
233 NS_ASSERTION(false, "Forgot to implement CanSkipInCCReal?");
236 NS_IMETHOD_(bool) CanSkipThisReal(void* aPtr
) {
237 NS_ASSERTION(false, "Forgot to implement CanSkipThisReal?");
242 bool MightSkip() const { return mFlags
& FlagMightSkip
; }
243 bool TraverseShouldTrace() const { return mFlags
& FlagTraverseShouldTrace
; }
248 class NS_NO_VTABLE nsScriptObjectTracer
: public nsCycleCollectionParticipant
{
250 constexpr explicit nsScriptObjectTracer(Flags aFlags
)
251 : nsCycleCollectionParticipant(aFlags
| FlagTraverseShouldTrace
) {}
254 Trace(void* aPtr
, const TraceCallbacks
& aCb
, void* aClosure
) override
= 0;
257 class NS_NO_VTABLE nsXPCOMCycleCollectionParticipant
258 : public nsScriptObjectTracer
{
260 constexpr explicit nsXPCOMCycleCollectionParticipant(Flags aFlags
)
261 : nsScriptObjectTracer(aFlags
) {}
263 NS_DECLARE_STATIC_IID_ACCESSOR(NS_XPCOMCYCLECOLLECTIONPARTICIPANT_IID
)
265 NS_IMETHOD_(void) Root(void* aPtr
) override
;
266 NS_IMETHOD_(void) Unroot(void* aPtr
) override
;
269 Trace(void* aPtr
, const TraceCallbacks
& aCb
, void* aClosure
) override
;
271 static bool CheckForRightISupports(nsISupports
* aSupports
);
274 NS_DEFINE_STATIC_IID_ACCESSOR(nsXPCOMCycleCollectionParticipant
,
275 NS_XPCOMCYCLECOLLECTIONPARTICIPANT_IID
)
277 ///////////////////////////////////////////////////////////////////////////////
278 // Helpers for implementing a QI to nsXPCOMCycleCollectionParticipant
279 ///////////////////////////////////////////////////////////////////////////////
281 #define NS_CYCLE_COLLECTION_CLASSNAME(_class) \
282 _class::NS_CYCLE_COLLECTION_INNERCLASS
284 // The IIDs for nsXPCOMCycleCollectionParticipant and nsCycleCollectionISupports
285 // are special in that they only differ in their last byte. This allows for the
286 // optimization below where we first check the first three words of the IID and
287 // if we find a match we check the last word to decide which case we have to
289 #define NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(_class) \
290 if (TopThreeWordsEquals( \
291 aIID, NS_GET_IID(nsXPCOMCycleCollectionParticipant), \
293 nsCycleCollectionISupports)) && /* The calls to LowWordEquals \
294 here are repeated inside the \
295 if branch. This is due to the \
296 fact that we need to maintain \
297 the if/else chain for these \
298 macros, so that the control \
299 flow never enters the if \
300 branch unless if we're \
302 LowWordEquals() branches will \
304 (LowWordEquals(aIID, NS_GET_IID(nsXPCOMCycleCollectionParticipant)) || \
305 LowWordEquals(aIID, NS_GET_IID(nsCycleCollectionISupports)))) { \
306 if (LowWordEquals(aIID, NS_GET_IID(nsXPCOMCycleCollectionParticipant))) { \
307 *aInstancePtr = NS_CYCLE_COLLECTION_PARTICIPANT(_class); \
310 if (LowWordEquals(aIID, NS_GET_IID(nsCycleCollectionISupports))) { \
311 *aInstancePtr = NS_CYCLE_COLLECTION_CLASSNAME(_class)::Upcast(this); \
314 /* Avoid warnings about foundInterface being left uninitialized. */ \
315 foundInterface = nullptr; \
318 #define NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(_class) \
319 NS_INTERFACE_MAP_BEGIN(_class) \
320 NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(_class)
322 #define NS_INTERFACE_TABLE_TO_MAP_SEGUE_CYCLE_COLLECTION(_class) \
323 if (rv == NS_OK) return rv; \
324 nsISupports* foundInterface; \
325 NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(_class)
327 // The IIDs for nsXPCOMCycleCollectionParticipant and nsCycleCollectionISupports
328 // are special in that they only differ in their last byte. This allows for the
329 // optimization below where we first check the first three words of the IID and
330 // if we find a match we check the last word to decide which case we have to
332 #define NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(_class) \
333 NS_IMETHODIMP _class::QueryInterface(REFNSIID aIID, void** aInstancePtr) { \
334 MOZ_ASSERT(aInstancePtr, "null out param"); \
336 if (TopThreeWordsEquals(aIID, \
337 NS_GET_IID(nsXPCOMCycleCollectionParticipant), \
338 NS_GET_IID(nsCycleCollectionISupports))) { \
339 if (LowWordEquals(aIID, \
340 NS_GET_IID(nsXPCOMCycleCollectionParticipant))) { \
341 *aInstancePtr = NS_CYCLE_COLLECTION_PARTICIPANT(_class); \
344 if (LowWordEquals(aIID, NS_GET_IID(nsCycleCollectionISupports))) { \
345 *aInstancePtr = NS_CYCLE_COLLECTION_CLASSNAME(_class)::Upcast(this); \
349 nsresult rv = NS_ERROR_FAILURE;
351 #define NS_CYCLE_COLLECTION_UPCAST(obj, clazz) \
352 NS_CYCLE_COLLECTION_CLASSNAME(clazz)::Upcast(obj)
355 # define NS_CHECK_FOR_RIGHT_PARTICIPANT(_ptr) _ptr->CheckForRightParticipant()
357 # define NS_CHECK_FOR_RIGHT_PARTICIPANT(_ptr)
360 // The default implementation of this class template is empty, because it
361 // should never be used: see the partial specializations below.
362 template <typename T
, bool IsXPCOM
= std::is_base_of
<nsISupports
, T
>::value
>
363 struct DowncastCCParticipantImpl
{};
365 // Specialization for XPCOM CC participants
366 template <typename T
>
367 struct DowncastCCParticipantImpl
<T
, true> {
368 static T
* Run(void* aPtr
) {
369 nsISupports
* s
= static_cast<nsISupports
*>(aPtr
);
370 MOZ_ASSERT(NS_CYCLE_COLLECTION_CLASSNAME(T
)::CheckForRightISupports(s
),
371 "not the nsISupports pointer we expect");
372 T
* rval
= NS_CYCLE_COLLECTION_CLASSNAME(T
)::Downcast(s
);
373 NS_CHECK_FOR_RIGHT_PARTICIPANT(rval
);
378 // Specialization for native CC participants
379 template <typename T
>
380 struct DowncastCCParticipantImpl
<T
, false> {
381 static T
* Run(void* aPtr
) { return static_cast<T
*>(aPtr
); }
384 template <typename T
>
385 T
* DowncastCCParticipant(void* aPtr
) {
386 return DowncastCCParticipantImpl
<T
>::Run(aPtr
);
389 ///////////////////////////////////////////////////////////////////////////////
390 // Helpers for implementing CanSkip methods
391 ///////////////////////////////////////////////////////////////////////////////
393 // See documentation for nsCycleCollectionParticipant::CanSkip for documentation
394 // about this method.
395 #define NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(_class) \
396 NS_IMETHODIMP_(bool) \
397 NS_CYCLE_COLLECTION_CLASSNAME(_class)::CanSkipReal(void* p, \
398 bool aRemovingAllowed) { \
399 _class* tmp = DowncastCCParticipant<_class>(p);
401 #define NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_END \
406 // See documentation for nsCycleCollectionParticipant::CanSkipInCC for
407 // documentation about this method.
408 #define NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_IN_CC_BEGIN(_class) \
409 NS_IMETHODIMP_(bool) \
410 NS_CYCLE_COLLECTION_CLASSNAME(_class)::CanSkipInCCReal(void* p) { \
411 _class* tmp = DowncastCCParticipant<_class>(p);
413 #define NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_IN_CC_END \
418 // See documentation for nsCycleCollectionParticipant::CanSkipThis for
419 // documentation about this method.
420 #define NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_THIS_BEGIN(_class) \
421 NS_IMETHODIMP_(bool) \
422 NS_CYCLE_COLLECTION_CLASSNAME(_class)::CanSkipThisReal(void* p) { \
423 _class* tmp = DowncastCCParticipant<_class>(p);
425 #define NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_THIS_END \
430 ///////////////////////////////////////////////////////////////////////////////
431 // Helpers for implementing nsCycleCollectionParticipant::Unlink
433 // You need to use NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED if you want
434 // the base class Unlink version to be called before your own implementation.
435 // You can use NS_IMPL_CYCLE_COLLECTION_UNLINK_END_INHERITED if you want the
436 // base class Unlink to get called after your own implementation. You should
437 // never use them together.
438 ///////////////////////////////////////////////////////////////////////////////
440 #define NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(_class) \
441 NS_IMETHODIMP_(void) \
442 NS_CYCLE_COLLECTION_CLASSNAME(_class)::Unlink(void* p) { \
443 _class* tmp = DowncastCCParticipant<_class>(p);
445 #define NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(_class, _base_class) \
446 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(_class) \
447 nsISupports* s = static_cast<nsISupports*>(p); \
448 NS_CYCLE_COLLECTION_CLASSNAME(_base_class)::Unlink(s);
450 #define NS_IMPL_CYCLE_COLLECTION_UNLINK_HELPER(_field) \
451 ImplCycleCollectionUnlink(tmp->_field);
453 #define NS_IMPL_CYCLE_COLLECTION_UNLINK(...) \
454 MOZ_FOR_EACH(NS_IMPL_CYCLE_COLLECTION_UNLINK_HELPER, (), (__VA_ARGS__))
456 #define NS_IMPL_CYCLE_COLLECTION_UNLINK_END \
460 #define NS_IMPL_CYCLE_COLLECTION_UNLINK_END_INHERITED(_base_class) \
461 nsISupports* s = static_cast<nsISupports*>(p); \
462 NS_CYCLE_COLLECTION_CLASSNAME(_base_class)::Unlink(s); \
466 #define NS_IMPL_CYCLE_COLLECTION_UNLINK_0(_class) \
467 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(_class) \
468 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
470 ///////////////////////////////////////////////////////////////////////////////
471 // Helpers for implementing nsCycleCollectionParticipant::Traverse
472 ///////////////////////////////////////////////////////////////////////////////
474 #define NS_IMPL_CYCLE_COLLECTION_DESCRIBE(_class, _refcnt) \
475 cb.DescribeRefCountedNode(_refcnt, #_class);
477 #define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(_class) \
479 NS_CYCLE_COLLECTION_CLASSNAME(_class)::TraverseNative( \
480 void* p, nsCycleCollectionTraversalCallback& cb) { \
481 _class* tmp = DowncastCCParticipant<_class>(p);
483 #define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(_class) \
484 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(_class) \
485 NS_IMPL_CYCLE_COLLECTION_DESCRIBE(_class, tmp->mRefCnt.get())
487 // Base class' CC participant should return NS_SUCCESS_INTERRUPTED_TRAVERSE
488 // from Traverse if it wants derived classes to not traverse anything from
489 // their CC participant.
491 #define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(_class, _base_class) \
492 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(_class) \
493 nsISupports* s = static_cast<nsISupports*>(p); \
494 if (NS_CYCLE_COLLECTION_CLASSNAME(_base_class)::TraverseNative(s, cb) == \
495 NS_SUCCESS_INTERRUPTED_TRAVERSE) { \
496 return NS_SUCCESS_INTERRUPTED_TRAVERSE; \
499 #define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_HELPER(_field) \
500 ImplCycleCollectionTraverse(cb, tmp->_field, #_field, 0);
502 #define NS_IMPL_CYCLE_COLLECTION_TRAVERSE(...) \
503 MOZ_FOR_EACH(NS_IMPL_CYCLE_COLLECTION_TRAVERSE_HELPER, (), (__VA_ARGS__))
505 #define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_RAWPTR(_field) \
506 CycleCollectionNoteChild(cb, tmp->_field, #_field);
508 #define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END \
513 ///////////////////////////////////////////////////////////////////////////////
514 // Helpers for implementing nsScriptObjectTracer::Trace
515 ///////////////////////////////////////////////////////////////////////////////
517 #define NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(_class) \
518 void NS_CYCLE_COLLECTION_CLASSNAME(_class)::Trace( \
519 void* p, const TraceCallbacks& aCallbacks, void* aClosure) { \
520 _class* tmp = DowncastCCParticipant<_class>(p);
522 #define NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(_class, _base_class) \
523 NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(_class) \
524 nsISupports* s = static_cast<nsISupports*>(p); \
525 NS_CYCLE_COLLECTION_CLASSNAME(_base_class)::Trace(s, aCallbacks, aClosure);
527 #define NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(_field) \
528 aCallbacks.Trace(&tmp->_field, #_field, aClosure);
530 // NB: The (void)tmp; hack in the TRACE_END macro exists to support
531 // implementations that don't need to do anything in their Trace method.
532 // Without this hack, some compilers warn about the unused tmp local.
533 #define NS_IMPL_CYCLE_COLLECTION_TRACE_END \
537 ///////////////////////////////////////////////////////////////////////////////
538 // Helpers for implementing a concrete nsCycleCollectionParticipant
539 ///////////////////////////////////////////////////////////////////////////////
541 // If a class defines a participant, then QIing an instance of that class to
542 // nsXPCOMCycleCollectionParticipant should produce that participant.
544 # define NS_CHECK_FOR_RIGHT_PARTICIPANT_BASE \
545 virtual void CheckForRightParticipant()
546 # define NS_CHECK_FOR_RIGHT_PARTICIPANT_DERIVED \
547 virtual void CheckForRightParticipant() override
548 # define NS_CHECK_FOR_RIGHT_PARTICIPANT_BODY(_class) \
550 nsXPCOMCycleCollectionParticipant* p; \
551 CallQueryInterface(this, &p); \
552 MOZ_ASSERT(p == &NS_CYCLE_COLLECTION_INNERNAME, \
553 #_class " should QI to its own CC participant"); \
555 # define NS_CHECK_FOR_RIGHT_PARTICIPANT_IMPL(_class) \
556 NS_CHECK_FOR_RIGHT_PARTICIPANT_BASE \
557 NS_CHECK_FOR_RIGHT_PARTICIPANT_BODY(_class)
558 # define NS_CHECK_FOR_RIGHT_PARTICIPANT_IMPL_INHERITED(_class) \
559 NS_CHECK_FOR_RIGHT_PARTICIPANT_DERIVED \
560 NS_CHECK_FOR_RIGHT_PARTICIPANT_BODY(_class)
562 # define NS_CHECK_FOR_RIGHT_PARTICIPANT_IMPL(_class)
563 # define NS_CHECK_FOR_RIGHT_PARTICIPANT_IMPL_INHERITED(_class)
566 #define NS_DECL_CYCLE_COLLECTION_CLASS_NAME_METHOD(_class) \
567 NS_IMETHOD_(const char*) ClassName() override { return #_class; };
569 #define NS_DECL_CYCLE_COLLECTION_CLASS_BODY_NO_UNLINK(_class, _base) \
571 NS_IMETHOD TraverseNative(void* p, nsCycleCollectionTraversalCallback& cb) \
573 NS_DECL_CYCLE_COLLECTION_CLASS_NAME_METHOD(_class) \
574 NS_IMETHOD_(void) DeleteCycleCollectable(void* p) override { \
575 DowncastCCParticipant<_class>(p)->DeleteCycleCollectable(); \
577 static _class* Downcast(nsISupports* s) { \
578 return static_cast<_class*>(static_cast<_base*>(s)); \
580 static nsISupports* Upcast(_class* p) { \
581 return NS_ISUPPORTS_CAST(_base*, p); \
583 template <typename T> \
584 friend nsISupports* ToSupports(T* p, NS_CYCLE_COLLECTION_INNERCLASS* dummy);
586 #define NS_DECL_CYCLE_COLLECTION_CLASS_BODY(_class, _base) \
587 NS_DECL_CYCLE_COLLECTION_CLASS_BODY_NO_UNLINK(_class, _base) \
588 NS_IMETHOD_(void) Unlink(void* p) override;
590 #define NS_PARTICIPANT_AS(type, participant) \
591 const_cast<type*>(reinterpret_cast<const type*>(participant))
593 #define NS_IMPL_GET_XPCOM_CYCLE_COLLECTION_PARTICIPANT(_class) \
594 static constexpr nsXPCOMCycleCollectionParticipant* GetParticipant() { \
595 return &_class::NS_CYCLE_COLLECTION_INNERNAME; \
599 * We use this macro to force that classes that inherit from a ccable class and
600 * declare their own participant declare themselves as inherited cc classes.
601 * To avoid possibly unnecessary vtables we only do this checking in debug
606 // Force this line to remain this way to make sure we don't trigger the
607 // lint cpp-virtual-final. see bug 1505943
608 #define NOT_INHERITED_CANT_OVERRIDE virtual void BaseCycleCollectable() final {}
611 # define NOT_INHERITED_CANT_OVERRIDE
614 #define NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(_class, _base) \
615 class NS_CYCLE_COLLECTION_INNERCLASS \
616 : public nsXPCOMCycleCollectionParticipant { \
618 constexpr explicit NS_CYCLE_COLLECTION_INNERCLASS(Flags aFlags = 0) \
619 : nsXPCOMCycleCollectionParticipant(aFlags) {} \
622 NS_DECL_CYCLE_COLLECTION_CLASS_BODY(_class, _base) \
623 NS_IMPL_GET_XPCOM_CYCLE_COLLECTION_PARTICIPANT(_class) \
625 NS_CHECK_FOR_RIGHT_PARTICIPANT_IMPL(_class) \
626 static NS_CYCLE_COLLECTION_INNERCLASS NS_CYCLE_COLLECTION_INNERNAME; \
627 NOT_INHERITED_CANT_OVERRIDE
629 #define NS_DECL_CYCLE_COLLECTION_CLASS(_class) \
630 NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(_class, _class)
632 // Cycle collector helper for ambiguous classes that can sometimes be skipped.
633 #define NS_DECL_CYCLE_COLLECTION_SKIPPABLE_CLASS_AMBIGUOUS(_class, _base) \
634 class NS_CYCLE_COLLECTION_INNERCLASS \
635 : public nsXPCOMCycleCollectionParticipant { \
637 constexpr explicit NS_CYCLE_COLLECTION_INNERCLASS( \
638 Flags aFlags = FlagMightSkip) /* We always want skippability. */ \
639 : nsXPCOMCycleCollectionParticipant(aFlags | FlagMightSkip) {} \
642 NS_DECL_CYCLE_COLLECTION_CLASS_BODY(_class, _base) \
643 NS_IMETHOD_(bool) CanSkipReal(void* p, bool aRemovingAllowed) override; \
644 NS_IMETHOD_(bool) CanSkipInCCReal(void* p) override; \
645 NS_IMETHOD_(bool) CanSkipThisReal(void* p) override; \
646 NS_IMPL_GET_XPCOM_CYCLE_COLLECTION_PARTICIPANT(_class) \
648 NS_CHECK_FOR_RIGHT_PARTICIPANT_IMPL(_class) \
649 static NS_CYCLE_COLLECTION_INNERCLASS NS_CYCLE_COLLECTION_INNERNAME; \
650 NOT_INHERITED_CANT_OVERRIDE
652 #define NS_DECL_CYCLE_COLLECTION_SKIPPABLE_CLASS(_class) \
653 NS_DECL_CYCLE_COLLECTION_SKIPPABLE_CLASS_AMBIGUOUS(_class, _class)
655 #define NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(_class, _base) \
656 class NS_CYCLE_COLLECTION_INNERCLASS \
657 : public nsXPCOMCycleCollectionParticipant { \
659 constexpr explicit NS_CYCLE_COLLECTION_INNERCLASS(Flags aFlags = 0) \
660 : nsXPCOMCycleCollectionParticipant(aFlags) {} \
663 NS_DECL_CYCLE_COLLECTION_CLASS_BODY(_class, _base) \
665 Trace(void* p, const TraceCallbacks& cb, void* closure) override; \
666 NS_IMPL_GET_XPCOM_CYCLE_COLLECTION_PARTICIPANT(_class) \
668 NS_CHECK_FOR_RIGHT_PARTICIPANT_IMPL(_class) \
669 static NS_CYCLE_COLLECTION_INNERCLASS NS_CYCLE_COLLECTION_INNERNAME; \
670 NOT_INHERITED_CANT_OVERRIDE
672 #define NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS_AMBIGUOUS( \
674 class NS_CYCLE_COLLECTION_INNERCLASS \
675 : public nsXPCOMCycleCollectionParticipant { \
677 constexpr explicit NS_CYCLE_COLLECTION_INNERCLASS( \
678 Flags aFlags = FlagMightSkip) /* We always want skippability. */ \
679 : nsXPCOMCycleCollectionParticipant(aFlags | FlagMightSkip) {} \
682 NS_DECL_CYCLE_COLLECTION_CLASS_BODY(_class, _base) \
684 Trace(void* p, const TraceCallbacks& cb, void* closure) override; \
685 NS_IMETHOD_(bool) CanSkipReal(void* p, bool aRemovingAllowed) override; \
686 NS_IMETHOD_(bool) CanSkipInCCReal(void* p) override; \
687 NS_IMETHOD_(bool) CanSkipThisReal(void* p) override; \
688 NS_IMPL_GET_XPCOM_CYCLE_COLLECTION_PARTICIPANT(_class) \
690 NS_CHECK_FOR_RIGHT_PARTICIPANT_IMPL(_class) \
691 static NS_CYCLE_COLLECTION_INNERCLASS NS_CYCLE_COLLECTION_INNERNAME; \
692 NOT_INHERITED_CANT_OVERRIDE
694 #define NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS(_class) \
695 NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS_AMBIGUOUS(_class, \
698 #define NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS_INHERITED( \
699 _class, _base_class) \
700 class NS_CYCLE_COLLECTION_INNERCLASS \
701 : public NS_CYCLE_COLLECTION_CLASSNAME(_base_class) { \
703 constexpr explicit NS_CYCLE_COLLECTION_INNERCLASS( \
704 Flags aFlags = FlagMightSkip) /* We always want skippability. */ \
705 : NS_CYCLE_COLLECTION_CLASSNAME(_base_class)(aFlags | FlagMightSkip) { \
709 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_BODY(_class, _base_class) \
711 Trace(void* p, const TraceCallbacks& cb, void* closure) override; \
712 NS_IMETHOD_(bool) CanSkipReal(void* p, bool aRemovingAllowed) override; \
713 NS_IMETHOD_(bool) CanSkipInCCReal(void* p) override; \
714 NS_IMETHOD_(bool) CanSkipThisReal(void* p) override; \
715 NS_IMPL_GET_XPCOM_CYCLE_COLLECTION_PARTICIPANT(_class) \
717 NS_CHECK_FOR_RIGHT_PARTICIPANT_IMPL_INHERITED(_class) \
718 static NS_CYCLE_COLLECTION_INNERCLASS NS_CYCLE_COLLECTION_INNERNAME;
720 #define NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(_class) \
721 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(_class, _class)
723 #define NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_BODY_NO_UNLINK(_class, \
726 NS_IMETHOD TraverseNative(void* p, nsCycleCollectionTraversalCallback& cb) \
728 NS_DECL_CYCLE_COLLECTION_CLASS_NAME_METHOD(_class) \
729 static _class* Downcast(nsISupports* s) { \
730 return static_cast<_class*>(static_cast<_base_class*>( \
731 NS_CYCLE_COLLECTION_CLASSNAME(_base_class)::Downcast(s))); \
734 #define NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_BODY(_class, _base_class) \
735 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_BODY_NO_UNLINK(_class, _base_class) \
736 NS_IMETHOD_(void) Unlink(void* p) override;
738 #define NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(_class, _base_class) \
739 class NS_CYCLE_COLLECTION_INNERCLASS \
740 : public NS_CYCLE_COLLECTION_CLASSNAME(_base_class) { \
742 constexpr explicit NS_CYCLE_COLLECTION_INNERCLASS(Flags aFlags = 0) \
743 : NS_CYCLE_COLLECTION_CLASSNAME(_base_class)(aFlags) {} \
746 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_BODY(_class, _base_class) \
747 NS_IMPL_GET_XPCOM_CYCLE_COLLECTION_PARTICIPANT(_class) \
749 NS_CHECK_FOR_RIGHT_PARTICIPANT_IMPL_INHERITED(_class) \
750 static NS_CYCLE_COLLECTION_INNERCLASS NS_CYCLE_COLLECTION_INNERNAME;
752 #define NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_NO_UNLINK(_class, \
754 class NS_CYCLE_COLLECTION_INNERCLASS \
755 : public NS_CYCLE_COLLECTION_CLASSNAME(_base_class) { \
757 constexpr explicit NS_CYCLE_COLLECTION_INNERCLASS(Flags aFlags = 0) \
758 : NS_CYCLE_COLLECTION_CLASSNAME(_base_class)(aFlags) {} \
761 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_BODY_NO_UNLINK(_class, \
763 NS_IMPL_GET_XPCOM_CYCLE_COLLECTION_PARTICIPANT(_class) \
765 NS_CHECK_FOR_RIGHT_PARTICIPANT_IMPL_INHERITED(_class) \
766 static NS_CYCLE_COLLECTION_INNERCLASS NS_CYCLE_COLLECTION_INNERNAME;
768 #define NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(_class, \
770 class NS_CYCLE_COLLECTION_INNERCLASS \
771 : public NS_CYCLE_COLLECTION_CLASSNAME(_base_class) { \
773 constexpr explicit NS_CYCLE_COLLECTION_INNERCLASS(Flags aFlags = 0) \
774 : NS_CYCLE_COLLECTION_CLASSNAME(_base_class)(aFlags) {} \
777 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_BODY(_class, _base_class) \
779 Trace(void* p, const TraceCallbacks& cb, void* closure) override; \
780 NS_IMPL_GET_XPCOM_CYCLE_COLLECTION_PARTICIPANT(_class) \
782 NS_CHECK_FOR_RIGHT_PARTICIPANT_IMPL_INHERITED(_class) \
783 static NS_CYCLE_COLLECTION_INNERCLASS NS_CYCLE_COLLECTION_INNERNAME;
785 // Cycle collector participant declarations.
787 #define NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS_BODY(_class) \
789 NS_IMETHOD_(void) Root(void* n) override; \
790 NS_IMETHOD_(void) Unlink(void* n) override; \
791 NS_IMETHOD_(void) Unroot(void* n) override; \
792 NS_IMETHOD TraverseNative(void* n, nsCycleCollectionTraversalCallback& cb) \
794 NS_DECL_CYCLE_COLLECTION_CLASS_NAME_METHOD(_class) \
795 NS_IMETHOD_(void) DeleteCycleCollectable(void* n) override { \
796 DowncastCCParticipant<_class>(n)->DeleteCycleCollectable(); \
798 static _class* Downcast(void* s) { \
799 return DowncastCCParticipant<_class>(s); \
801 static void* Upcast(_class* p) { return static_cast<void*>(p); }
803 #define NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(_class) \
804 void DeleteCycleCollectable(void) { delete this; } \
805 class NS_CYCLE_COLLECTION_INNERCLASS : public nsCycleCollectionParticipant { \
807 constexpr explicit NS_CYCLE_COLLECTION_INNERCLASS(Flags aFlags = 0) \
808 : nsCycleCollectionParticipant(aFlags) {} \
811 NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS_BODY(_class) \
812 static constexpr nsCycleCollectionParticipant* GetParticipant() { \
813 return &_class::NS_CYCLE_COLLECTION_INNERNAME; \
816 static NS_CYCLE_COLLECTION_INNERCLASS NS_CYCLE_COLLECTION_INNERNAME;
818 #define NS_DECL_CYCLE_COLLECTION_SKIPPABLE_NATIVE_CLASS(_class) \
819 void DeleteCycleCollectable(void) { delete this; } \
820 class NS_CYCLE_COLLECTION_INNERCLASS : public nsCycleCollectionParticipant { \
822 constexpr explicit NS_CYCLE_COLLECTION_INNERCLASS( \
823 Flags aFlags = FlagMightSkip) /* We always want skippability. */ \
824 : nsCycleCollectionParticipant(aFlags | FlagMightSkip) {} \
827 NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS_BODY(_class) \
828 NS_IMETHOD_(bool) CanSkipReal(void* p, bool aRemovingAllowed) override; \
829 NS_IMETHOD_(bool) CanSkipInCCReal(void* p) override; \
830 NS_IMETHOD_(bool) CanSkipThisReal(void* p) override; \
831 static nsCycleCollectionParticipant* GetParticipant() { \
832 return &_class::NS_CYCLE_COLLECTION_INNERNAME; \
835 static NS_CYCLE_COLLECTION_INNERCLASS NS_CYCLE_COLLECTION_INNERNAME;
837 #define NS_DECL_CYCLE_COLLECTION_SKIPPABLE_NATIVE_CLASS_WITH_CUSTOM_DELETE( \
839 class NS_CYCLE_COLLECTION_INNERCLASS : public nsCycleCollectionParticipant { \
841 constexpr NS_CYCLE_COLLECTION_INNERCLASS() \
842 : nsCycleCollectionParticipant(true) {} \
845 NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS_BODY(_class) \
846 NS_IMETHOD_(bool) CanSkipReal(void* p, bool aRemovingAllowed) override; \
847 NS_IMETHOD_(bool) CanSkipInCCReal(void* p) override; \
848 NS_IMETHOD_(bool) CanSkipThisReal(void* p) override; \
849 static nsCycleCollectionParticipant* GetParticipant() { \
850 return &_class::NS_CYCLE_COLLECTION_INNERNAME; \
853 static NS_CYCLE_COLLECTION_INNERCLASS NS_CYCLE_COLLECTION_INNERNAME;
855 #define NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(_class) \
856 void DeleteCycleCollectable(void) { delete this; } \
857 class NS_CYCLE_COLLECTION_INNERCLASS : public nsScriptObjectTracer { \
859 constexpr explicit NS_CYCLE_COLLECTION_INNERCLASS(Flags aFlags = 0) \
860 : nsScriptObjectTracer(aFlags) {} \
863 NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS_BODY(_class) \
865 Trace(void* p, const TraceCallbacks& cb, void* closure) override; \
866 static constexpr nsScriptObjectTracer* GetParticipant() { \
867 return &_class::NS_CYCLE_COLLECTION_INNERNAME; \
870 static NS_CYCLE_COLLECTION_INNERCLASS NS_CYCLE_COLLECTION_INNERNAME;
872 #define NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(_class, _root_function) \
873 NS_IMETHODIMP_(void) \
874 NS_CYCLE_COLLECTION_CLASSNAME(_class)::Root(void* p) { \
875 _class* tmp = static_cast<_class*>(p); \
876 tmp->_root_function(); \
879 #define NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(_class, _unroot_function) \
880 NS_IMETHODIMP_(void) \
881 NS_CYCLE_COLLECTION_CLASSNAME(_class)::Unroot(void* p) { \
882 _class* tmp = static_cast<_class*>(p); \
883 tmp->_unroot_function(); \
886 #define NS_IMPL_CYCLE_COLLECTION_CLASS(_class) \
887 _class::NS_CYCLE_COLLECTION_INNERCLASS _class::NS_CYCLE_COLLECTION_INNERNAME;
889 // Most JS holder classes should only contain pointers to JS GC things in a
890 // single JS zone, but there are some exceptions. Such classes should use this
891 // macro to tell the system about this.
892 #define NS_IMPL_CYCLE_COLLECTION_MULTI_ZONE_JSHOLDER_CLASS(_class) \
893 _class::NS_CYCLE_COLLECTION_INNERCLASS \
894 _class::NS_CYCLE_COLLECTION_INNERNAME( \
895 nsCycleCollectionParticipant::FlagMultiZoneJSHolder);
897 // NB: This is not something you usually want to use. It is here to allow
898 // adding things to the CC graph to help debugging via CC logs, but it does not
899 // traverse or unlink anything, so it is useless for anything else.
900 #define NS_IMPL_CYCLE_COLLECTION_0(_class) \
901 NS_IMPL_CYCLE_COLLECTION_CLASS(_class) \
902 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(_class) \
903 NS_IMPL_CYCLE_COLLECTION_UNLINK_END \
904 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(_class) \
905 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
907 #define NS_IMPL_CYCLE_COLLECTION(_class, ...) \
908 NS_IMPL_CYCLE_COLLECTION_CLASS(_class) \
909 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(_class) \
910 NS_IMPL_CYCLE_COLLECTION_UNLINK(__VA_ARGS__) \
911 NS_IMPL_CYCLE_COLLECTION_UNLINK_END \
912 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(_class) \
913 NS_IMPL_CYCLE_COLLECTION_TRAVERSE(__VA_ARGS__) \
914 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
916 // If you are looking for NS_IMPL_CYCLE_COLLECTION_INHERITED_0(_class, _base)
917 // you should instead not declare any cycle collected stuff in _class, so it
918 // will just inherit the CC declarations from _base.
920 #define NS_IMPL_CYCLE_COLLECTION_INHERITED(_class, _base, ...) \
921 NS_IMPL_CYCLE_COLLECTION_CLASS(_class) \
922 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(_class, _base) \
923 NS_IMPL_CYCLE_COLLECTION_UNLINK(__VA_ARGS__) \
924 NS_IMPL_CYCLE_COLLECTION_UNLINK_END \
925 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(_class, _base) \
926 NS_IMPL_CYCLE_COLLECTION_TRAVERSE(__VA_ARGS__) \
927 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
929 #define NS_CYCLE_COLLECTION_NOTE_EDGE_NAME CycleCollectionNoteEdgeName
932 * Convenience macros for defining nISupports methods in a cycle collected
936 #define NS_IMPL_QUERY_INTERFACE_CYCLE_COLLECTION_INHERITED(aClass, aSuper, \
938 NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(aClass) \
939 NS_INTERFACE_TABLE_INHERITED(aClass, __VA_ARGS__) \
940 NS_INTERFACE_TABLE_TAIL_INHERITING(aSuper)
942 #define NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED(aClass, aSuper, ...) \
943 NS_IMPL_QUERY_INTERFACE_CYCLE_COLLECTION_INHERITED(aClass, aSuper, \
945 NS_IMPL_ADDREF_INHERITED(aClass, aSuper) \
946 NS_IMPL_RELEASE_INHERITED(aClass, aSuper)
948 #define NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED_0(aClass, aSuper) \
949 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(aClass) \
950 NS_INTERFACE_MAP_END_INHERITING(aSuper) \
951 NS_IMPL_ADDREF_INHERITED(aClass, aSuper) \
952 NS_IMPL_RELEASE_INHERITED(aClass, aSuper)
955 * Equivalency of the high three words where two IIDs have the same
956 * top three words but not the same low word.
958 inline bool TopThreeWordsEquals(const nsID
& aID
, const nsID
& aOther1
,
959 const nsID
& aOther2
) {
960 MOZ_ASSERT((((uint32_t*)&aOther1
.m0
)[0] == ((uint32_t*)&aOther2
.m0
)[0]) &&
961 (((uint32_t*)&aOther1
.m0
)[1] == ((uint32_t*)&aOther2
.m0
)[1]) &&
962 (((uint32_t*)&aOther1
.m0
)[2] == ((uint32_t*)&aOther2
.m0
)[2]) &&
963 (((uint32_t*)&aOther1
.m0
)[3] != ((uint32_t*)&aOther2
.m0
)[3]));
965 return ((((uint32_t*)&aID
.m0
)[0] == ((uint32_t*)&aOther1
.m0
)[0]) &&
966 (((uint32_t*)&aID
.m0
)[1] == ((uint32_t*)&aOther1
.m0
)[1]) &&
967 (((uint32_t*)&aID
.m0
)[2] == ((uint32_t*)&aOther1
.m0
)[2]));
971 * Equivalency of the fourth word where the two IIDs have the same
972 * top three words but not the same low word.
974 inline bool LowWordEquals(const nsID
& aID
, const nsID
& aOther
) {
975 return (((uint32_t*)&aID
.m0
)[3] == ((uint32_t*)&aOther
.m0
)[3]);
978 #endif // nsCycleCollectionParticipant_h__