Bug 1843477, remove main thread only CC macros, r=mccr8

Differential Revision: https://phabricator.services.mozilla.com/D187146
This commit is contained in:
Olli Pettay 2023-09-26 12:36:20 +00:00
parent 310f2406b1
commit b632508d71
8 changed files with 44 additions and 156 deletions

View file

@ -2434,9 +2434,8 @@ NS_INTERFACE_TABLE_HEAD(Document)
NS_INTERFACE_TABLE_TO_MAP_SEGUE_CYCLE_COLLECTION(Document) NS_INTERFACE_TABLE_TO_MAP_SEGUE_CYCLE_COLLECTION(Document)
NS_INTERFACE_MAP_END NS_INTERFACE_MAP_END
NS_IMPL_MAIN_THREAD_ONLY_CYCLE_COLLECTING_ADDREF(Document) NS_IMPL_CYCLE_COLLECTING_ADDREF(Document)
NS_IMPL_MAIN_THREAD_ONLY_CYCLE_COLLECTING_RELEASE_WITH_LAST_RELEASE( NS_IMPL_CYCLE_COLLECTING_RELEASE_WITH_LAST_RELEASE(Document, LastRelease())
Document, LastRelease())
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(Document) NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(Document)
if (Element::CanSkip(tmp, aRemovingAllowed)) { if (Element::CanSkip(tmp, aRemovingAllowed)) {

View file

@ -147,12 +147,13 @@ NS_INTERFACE_MAP_BEGIN(nsIContent)
NS_INTERFACE_MAP_ENTRY(nsISupports) NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END NS_INTERFACE_MAP_END
NS_IMPL_MAIN_THREAD_ONLY_CYCLE_COLLECTING_ADDREF(nsIContent) NS_IMPL_CYCLE_COLLECTING_ADDREF(nsIContent)
NS_IMPL_DOMARENA_DESTROY(nsIContent) NS_IMPL_DOMARENA_DESTROY(nsIContent)
NS_IMPL_MAIN_THREAD_ONLY_CYCLE_COLLECTING_RELEASE_WITH_LAST_RELEASE_AND_DESTROY( NS_IMPL_CYCLE_COLLECTING_RELEASE_WITH_LAST_RELEASE_AND_DESTROY(nsIContent,
nsIContent, LastRelease(), Destroy()) LastRelease(),
Destroy())
nsIContent* nsIContent::FindFirstNonChromeOnlyAccessContent() const { nsIContent* nsIContent::FindFirstNonChromeOnlyAccessContent() const {
// This handles also nested native anonymous content. // This handles also nested native anonymous content.

View file

@ -804,9 +804,8 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Selection)
NS_INTERFACE_MAP_ENTRY(nsISupports) NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END NS_INTERFACE_MAP_END
NS_IMPL_MAIN_THREAD_ONLY_CYCLE_COLLECTING_ADDREF(Selection) NS_IMPL_CYCLE_COLLECTING_ADDREF(Selection)
NS_IMPL_MAIN_THREAD_ONLY_CYCLE_COLLECTING_RELEASE_WITH_LAST_RELEASE( NS_IMPL_CYCLE_COLLECTING_RELEASE_WITH_LAST_RELEASE(Selection, Disconnect())
Selection, Disconnect())
const RangeBoundary& Selection::AnchorRef() const { const RangeBoundary& Selection::AnchorRef() const {
if (!mAnchorFocusRange) { if (!mAnchorFocusRange) {

View file

@ -46,8 +46,8 @@ template void StaticRange::DoSetRange(const RawRangeBoundary& aStartBoundary,
nsTArray<RefPtr<StaticRange>>* StaticRange::sCachedRanges = nullptr; nsTArray<RefPtr<StaticRange>>* StaticRange::sCachedRanges = nullptr;
NS_IMPL_MAIN_THREAD_ONLY_CYCLE_COLLECTING_ADDREF(StaticRange) NS_IMPL_CYCLE_COLLECTING_ADDREF(StaticRange)
NS_IMPL_MAIN_THREAD_ONLY_CYCLE_COLLECTING_RELEASE_WITH_INTERRUPTABLE_LAST_RELEASE( NS_IMPL_CYCLE_COLLECTING_RELEASE_WITH_INTERRUPTABLE_LAST_RELEASE(
StaticRange, DoSetRange(RawRangeBoundary(), RawRangeBoundary(), nullptr), StaticRange, DoSetRange(RawRangeBoundary(), RawRangeBoundary(), nullptr),
AbstractRange::MaybeCacheToReuse(*this)) AbstractRange::MaybeCacheToReuse(*this))

View file

@ -204,8 +204,8 @@ already_AddRefed<nsRange> nsRange::Create(
* nsISupports * nsISupports
******************************************************/ ******************************************************/
NS_IMPL_MAIN_THREAD_ONLY_CYCLE_COLLECTING_ADDREF(nsRange) NS_IMPL_CYCLE_COLLECTING_ADDREF(nsRange)
NS_IMPL_MAIN_THREAD_ONLY_CYCLE_COLLECTING_RELEASE_WITH_INTERRUPTABLE_LAST_RELEASE( NS_IMPL_CYCLE_COLLECTING_RELEASE_WITH_INTERRUPTABLE_LAST_RELEASE(
nsRange, DoSetRange(RawRangeBoundary(), RawRangeBoundary(), nullptr), nsRange, DoSetRange(RawRangeBoundary(), RawRangeBoundary(), nullptr),
MaybeInterruptLastRelease()) MaybeInterruptLastRelease())

View file

@ -77,7 +77,7 @@ struct RangeItem final {
return EditorDOMPointType(mEndContainer, mEndOffset); return EditorDOMPointType(mEndContainer, mEndOffset);
} }
NS_INLINE_DECL_MAIN_THREAD_ONLY_CYCLE_COLLECTING_NATIVE_REFCOUNTING(RangeItem) NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(RangeItem)
NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(RangeItem) NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(RangeItem)
nsCOMPtr<nsINode> mStartContainer; nsCOMPtr<nsINode> mStartContainer;

View file

@ -390,9 +390,9 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsComputedDOMStyle)
NS_INTERFACE_MAP_ENTRY(nsIMutationObserver) NS_INTERFACE_MAP_ENTRY(nsIMutationObserver)
NS_INTERFACE_MAP_END_INHERITING(nsDOMCSSDeclaration) NS_INTERFACE_MAP_END_INHERITING(nsDOMCSSDeclaration)
NS_IMPL_MAIN_THREAD_ONLY_CYCLE_COLLECTING_ADDREF(nsComputedDOMStyle) NS_IMPL_CYCLE_COLLECTING_ADDREF(nsComputedDOMStyle)
NS_IMPL_MAIN_THREAD_ONLY_CYCLE_COLLECTING_RELEASE_WITH_LAST_RELEASE( NS_IMPL_CYCLE_COLLECTING_RELEASE_WITH_LAST_RELEASE(nsComputedDOMStyle,
nsComputedDOMStyle, ClearComputedStyle()) ClearComputedStyle())
void nsComputedDOMStyle::GetPropertyValue(const nsCSSPropertyID aPropID, void nsComputedDOMStyle::GetPropertyValue(const nsCSSPropertyID aPropID,
nsACString& aValue) { nsACString& aValue) {

View file

@ -228,12 +228,10 @@ class nsCycleCollectingAutoRefCnt {
nsCycleCollectingAutoRefCnt(const nsCycleCollectingAutoRefCnt&) = delete; nsCycleCollectingAutoRefCnt(const nsCycleCollectingAutoRefCnt&) = delete;
void operator=(const nsCycleCollectingAutoRefCnt&) = delete; void operator=(const nsCycleCollectingAutoRefCnt&) = delete;
template <Suspect suspect = NS_CycleCollectorSuspect3>
MOZ_ALWAYS_INLINE uintptr_t incr(nsISupports* aOwner) { MOZ_ALWAYS_INLINE uintptr_t incr(nsISupports* aOwner) {
return incr<suspect>(aOwner, nullptr); return incr(aOwner, nullptr);
} }
template <Suspect suspect = NS_CycleCollectorSuspect3>
MOZ_ALWAYS_INLINE uintptr_t incr(void* aOwner, MOZ_ALWAYS_INLINE uintptr_t incr(void* aOwner,
nsCycleCollectionParticipant* aCp) { nsCycleCollectionParticipant* aCp) {
mRefCntAndFlags += NS_REFCOUNT_CHANGE; mRefCntAndFlags += NS_REFCOUNT_CHANGE;
@ -244,7 +242,7 @@ class nsCycleCollectingAutoRefCnt {
mRefCntAndFlags |= NS_IN_PURPLE_BUFFER; mRefCntAndFlags |= NS_IN_PURPLE_BUFFER;
// Refcount isn't zero, so Suspect won't delete anything. // Refcount isn't zero, so Suspect won't delete anything.
MOZ_ASSERT(get() > 0); MOZ_ASSERT(get() > 0);
suspect(aOwner, aCp, this, nullptr); NS_CycleCollectorSuspect3(aOwner, aCp, this, nullptr);
} }
return NS_REFCOUNT_VALUE(mRefCntAndFlags); return NS_REFCOUNT_VALUE(mRefCntAndFlags);
} }
@ -255,13 +253,11 @@ class nsCycleCollectingAutoRefCnt {
mRefCntAndFlags = NS_REFCOUNT_CHANGE | NS_IN_PURPLE_BUFFER; mRefCntAndFlags = NS_REFCOUNT_CHANGE | NS_IN_PURPLE_BUFFER;
} }
template <Suspect suspect = NS_CycleCollectorSuspect3>
MOZ_ALWAYS_INLINE uintptr_t decr(nsISupports* aOwner, MOZ_ALWAYS_INLINE uintptr_t decr(nsISupports* aOwner,
bool* aShouldDelete = nullptr) { bool* aShouldDelete = nullptr) {
return decr<suspect>(aOwner, nullptr, aShouldDelete); return decr(aOwner, nullptr, aShouldDelete);
} }
template <Suspect suspect = NS_CycleCollectorSuspect3>
MOZ_ALWAYS_INLINE uintptr_t decr(void* aOwner, MOZ_ALWAYS_INLINE uintptr_t decr(void* aOwner,
nsCycleCollectionParticipant* aCp, nsCycleCollectionParticipant* aCp,
bool* aShouldDelete = nullptr) { bool* aShouldDelete = nullptr) {
@ -271,7 +267,7 @@ class nsCycleCollectingAutoRefCnt {
mRefCntAndFlags |= (NS_IN_PURPLE_BUFFER | NS_IS_PURPLE); mRefCntAndFlags |= (NS_IN_PURPLE_BUFFER | NS_IS_PURPLE);
uintptr_t retval = NS_REFCOUNT_VALUE(mRefCntAndFlags); uintptr_t retval = NS_REFCOUNT_VALUE(mRefCntAndFlags);
// Suspect may delete 'aOwner' and 'this'! // Suspect may delete 'aOwner' and 'this'!
suspect(aOwner, aCp, this, aShouldDelete); NS_CycleCollectorSuspect3(aOwner, aCp, this, aShouldDelete);
return retval; return retval;
} }
mRefCntAndFlags -= NS_REFCOUNT_CHANGE; mRefCntAndFlags -= NS_REFCOUNT_CHANGE;
@ -498,16 +494,6 @@ class InterfaceNeedsThreadSafeRefCnt : public std::false_type {};
NS_LOG_ADDREF(this, count, #_class, sizeof(*this)); \ NS_LOG_ADDREF(this, count, #_class, sizeof(*this)); \
return count; return count;
#define NS_IMPL_CC_MAIN_THREAD_ONLY_NATIVE_ADDREF_BODY(_class) \
MOZ_ASSERT_TYPE_OK_FOR_REFCOUNTING(_class) \
MOZ_ASSERT(int32_t(mRefCnt) >= 0, "illegal refcnt"); \
NS_ASSERT_OWNINGTHREAD(_class); \
nsrefcnt count = mRefCnt.incr<NS_CycleCollectorSuspectUsingNursery>( \
static_cast<void*>(this), \
_class::NS_CYCLE_COLLECTION_INNERCLASS::GetParticipant()); \
NS_LOG_ADDREF(this, count, #_class, sizeof(*this)); \
return count;
#define NS_IMPL_CC_NATIVE_RELEASE_BODY(_class) \ #define NS_IMPL_CC_NATIVE_RELEASE_BODY(_class) \
MOZ_ASSERT(int32_t(mRefCnt) > 0, "dup release"); \ MOZ_ASSERT(int32_t(mRefCnt) > 0, "dup release"); \
NS_ASSERT_OWNINGTHREAD(_class); \ NS_ASSERT_OWNINGTHREAD(_class); \
@ -517,15 +503,6 @@ class InterfaceNeedsThreadSafeRefCnt : public std::false_type {};
NS_LOG_RELEASE(this, count, #_class); \ NS_LOG_RELEASE(this, count, #_class); \
return count; return count;
#define NS_IMPL_CC_MAIN_THREAD_ONLY_NATIVE_RELEASE_BODY(_class) \
MOZ_ASSERT(int32_t(mRefCnt) > 0, "dup release"); \
NS_ASSERT_OWNINGTHREAD(_class); \
nsrefcnt count = mRefCnt.decr<NS_CycleCollectorSuspectUsingNursery>( \
static_cast<void*>(this), \
_class::NS_CYCLE_COLLECTION_INNERCLASS::GetParticipant()); \
NS_LOG_RELEASE(this, count, #_class); \
return count;
#define NS_IMPL_CYCLE_COLLECTING_NATIVE_ADDREF(_class) \ #define NS_IMPL_CYCLE_COLLECTING_NATIVE_ADDREF(_class) \
NS_METHOD_(MozExternalRefCountType) _class::AddRef(void) { \ NS_METHOD_(MozExternalRefCountType) _class::AddRef(void) { \
NS_IMPL_CC_NATIVE_ADDREF_BODY(_class) \ NS_IMPL_CC_NATIVE_ADDREF_BODY(_class) \
@ -586,21 +563,6 @@ class InterfaceNeedsThreadSafeRefCnt : public std::false_type {};
NS_DECL_OWNINGTHREAD \ NS_DECL_OWNINGTHREAD \
public: public:
#define NS_INLINE_DECL_MAIN_THREAD_ONLY_CYCLE_COLLECTING_NATIVE_REFCOUNTING( \
_class) \
public: \
NS_METHOD_(MozExternalRefCountType) \
AddRef(void){NS_IMPL_CC_MAIN_THREAD_ONLY_NATIVE_ADDREF_BODY( \
_class)} NS_METHOD_(MozExternalRefCountType) Release(void) { \
NS_IMPL_CC_MAIN_THREAD_ONLY_NATIVE_RELEASE_BODY(_class) \
} \
using HasThreadSafeRefCnt = std::false_type; \
\
protected: \
nsCycleCollectingAutoRefCnt mRefCnt; \
NS_DECL_OWNINGTHREAD \
public:
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
/** /**
@ -956,17 +918,6 @@ void ProxyDeleteVoid(const char* aRunnableName,
return count; \ return count; \
} }
#define NS_IMPL_MAIN_THREAD_ONLY_CYCLE_COLLECTING_ADDREF(_class) \
NS_IMETHODIMP_(MozExternalRefCountType) _class::AddRef(void) { \
MOZ_ASSERT_TYPE_OK_FOR_REFCOUNTING(_class) \
MOZ_ASSERT(int32_t(mRefCnt) >= 0, "illegal refcnt"); \
NS_ASSERT_OWNINGTHREAD(_class); \
nsISupports* base = NS_CYCLE_COLLECTION_CLASSNAME(_class)::Upcast(this); \
nsrefcnt count = mRefCnt.incr<NS_CycleCollectorSuspectUsingNursery>(base); \
NS_LOG_ADDREF(this, count, #_class, sizeof(*this)); \
return count; \
}
#define NS_IMPL_CYCLE_COLLECTING_RELEASE_WITH_DESTROY(_class, _destroy) \ #define NS_IMPL_CYCLE_COLLECTING_RELEASE_WITH_DESTROY(_class, _destroy) \
NS_IMETHODIMP_(MozExternalRefCountType) _class::Release(void) { \ NS_IMETHODIMP_(MozExternalRefCountType) _class::Release(void) { \
MOZ_ASSERT(int32_t(mRefCnt) > 0, "dup release"); \ MOZ_ASSERT(int32_t(mRefCnt) > 0, "dup release"); \
@ -1028,42 +979,6 @@ void ProxyDeleteVoid(const char* aRunnableName,
} \ } \
NS_IMETHODIMP_(void) _class::DeleteCycleCollectable(void) { _destroy; } NS_IMETHODIMP_(void) _class::DeleteCycleCollectable(void) { _destroy; }
#define NS_IMPL_MAIN_THREAD_ONLY_CYCLE_COLLECTING_RELEASE(_class) \
NS_IMETHODIMP_(MozExternalRefCountType) _class::Release(void) { \
MOZ_ASSERT(int32_t(mRefCnt) > 0, "dup release"); \
NS_ASSERT_OWNINGTHREAD(_class); \
nsISupports* base = NS_CYCLE_COLLECTION_CLASSNAME(_class)::Upcast(this); \
nsrefcnt count = mRefCnt.decr<NS_CycleCollectorSuspectUsingNursery>(base); \
NS_LOG_RELEASE(this, count, #_class); \
return count; \
} \
NS_IMETHODIMP_(void) _class::DeleteCycleCollectable(void) { delete this; }
// _LAST_RELEASE can be useful when certain resources should be released
// as soon as we know the object will be deleted.
#define NS_IMPL_MAIN_THREAD_ONLY_CYCLE_COLLECTING_RELEASE_WITH_LAST_RELEASE( \
_class, _last) \
NS_IMETHODIMP_(MozExternalRefCountType) _class::Release(void) { \
MOZ_ASSERT(int32_t(mRefCnt) > 0, "dup release"); \
NS_ASSERT_OWNINGTHREAD(_class); \
bool shouldDelete = false; \
nsISupports* base = NS_CYCLE_COLLECTION_CLASSNAME(_class)::Upcast(this); \
nsrefcnt count = mRefCnt.decr<NS_CycleCollectorSuspectUsingNursery>( \
base, &shouldDelete); \
NS_LOG_RELEASE(this, count, #_class); \
if (count == 0) { \
mRefCnt.incr<NS_CycleCollectorSuspectUsingNursery>(base); \
_last; \
mRefCnt.decr<NS_CycleCollectorSuspectUsingNursery>(base); \
if (shouldDelete) { \
mRefCnt.stabilizeForDeletion(); \
DeleteCycleCollectable(); \
} \
} \
return count; \
} \
NS_IMETHODIMP_(void) _class::DeleteCycleCollectable(void) { delete this; }
// _WITH_INTERRUPTABLE_LAST_RELEASE can be useful when certain resources // _WITH_INTERRUPTABLE_LAST_RELEASE can be useful when certain resources
// should be released as soon as we know the object will be deleted and the // should be released as soon as we know the object will be deleted and the
// instance may be cached for reuse. // instance may be cached for reuse.
@ -1073,58 +988,32 @@ void ProxyDeleteVoid(const char* aRunnableName,
// during _last is performed.) // during _last is performed.)
// Therefore, when _maybeInterrupt returns true, the instance has to be grabbed // Therefore, when _maybeInterrupt returns true, the instance has to be grabbed
// by nsCOMPtr or RefPtr. // by nsCOMPtr or RefPtr.
#define NS_IMPL_MAIN_THREAD_ONLY_CYCLE_COLLECTING_RELEASE_WITH_INTERRUPTABLE_LAST_RELEASE( \ #define NS_IMPL_CYCLE_COLLECTING_RELEASE_WITH_INTERRUPTABLE_LAST_RELEASE( \
_class, _last, _maybeInterrupt) \ _class, _last, _maybeInterrupt) \
NS_IMETHODIMP_(MozExternalRefCountType) _class::Release(void) { \ NS_IMETHODIMP_(MozExternalRefCountType) _class::Release(void) { \
MOZ_ASSERT(int32_t(mRefCnt) > 0, "dup release"); \ MOZ_ASSERT(int32_t(mRefCnt) > 0, "dup release"); \
NS_ASSERT_OWNINGTHREAD(_class); \ NS_ASSERT_OWNINGTHREAD(_class); \
bool shouldDelete = false; \ bool shouldDelete = false; \
nsISupports* base = NS_CYCLE_COLLECTION_CLASSNAME(_class)::Upcast(this); \ nsISupports* base = NS_CYCLE_COLLECTION_CLASSNAME(_class)::Upcast(this); \
nsrefcnt count = mRefCnt.decr<NS_CycleCollectorSuspectUsingNursery>( \ nsrefcnt count = mRefCnt.decr(base, &shouldDelete); \
base, &shouldDelete); \ NS_LOG_RELEASE(this, count, #_class); \
NS_LOG_RELEASE(this, count, #_class); \ if (count == 0) { \
if (count == 0) { \ mRefCnt.incr(base); \
mRefCnt.incr<NS_CycleCollectorSuspectUsingNursery>(base); \ _last; \
_last; \ mRefCnt.decr(base); \
mRefCnt.decr<NS_CycleCollectorSuspectUsingNursery>(base); \ if (_maybeInterrupt) { \
if (_maybeInterrupt) { \ MOZ_ASSERT(mRefCnt.get() > 0); \
MOZ_ASSERT(mRefCnt.get() > 0); \ return mRefCnt.get(); \
return mRefCnt.get(); \ } \
} \ if (shouldDelete) { \
if (shouldDelete) { \ mRefCnt.stabilizeForDeletion(); \
mRefCnt.stabilizeForDeletion(); \ DeleteCycleCollectable(); \
DeleteCycleCollectable(); \ } \
} \ } \
} \ return count; \
return count; \ } \
} \
NS_IMETHODIMP_(void) _class::DeleteCycleCollectable(void) { delete this; } NS_IMETHODIMP_(void) _class::DeleteCycleCollectable(void) { delete this; }
// _LAST_RELEASE can be useful when certain resources should be released
// as soon as we know the object will be deleted.
#define NS_IMPL_MAIN_THREAD_ONLY_CYCLE_COLLECTING_RELEASE_WITH_LAST_RELEASE_AND_DESTROY( \
_class, _last, _destroy) \
NS_IMETHODIMP_(MozExternalRefCountType) _class::Release(void) { \
MOZ_ASSERT(int32_t(mRefCnt) > 0, "dup release"); \
NS_ASSERT_OWNINGTHREAD(_class); \
bool shouldDelete = false; \
nsISupports* base = NS_CYCLE_COLLECTION_CLASSNAME(_class)::Upcast(this); \
nsrefcnt count = mRefCnt.decr<NS_CycleCollectorSuspectUsingNursery>( \
base, &shouldDelete); \
NS_LOG_RELEASE(this, count, #_class); \
if (count == 0) { \
mRefCnt.incr<NS_CycleCollectorSuspectUsingNursery>(base); \
_last; \
mRefCnt.decr<NS_CycleCollectorSuspectUsingNursery>(base); \
if (shouldDelete) { \
mRefCnt.stabilizeForDeletion(); \
DeleteCycleCollectable(); \
} \
} \
return count; \
} \
NS_IMETHODIMP_(void) _class::DeleteCycleCollectable(void) { _destroy; }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
namespace mozilla::detail { namespace mozilla::detail {