From 38daeffb9bc525be4da4c30de618f1be3ea3583d Mon Sep 17 00:00:00 2001 From: Moonchild Date: Thu, 16 Jan 2025 23:11:37 +0100 Subject: [PATCH] Issue #2678 - Avoid QIing for NoteXPCOMRoot. This callback is only used in very limited ways, so just require that the caller passes in the canonical supports pointer plus the participant. This probably won't affect performance much. --- js/xpconnect/src/XPCJSContext.cpp | 5 +++-- xpcom/base/nsCycleCollector.cpp | 13 +++++++------ xpcom/glue/nsCycleCollectionNoteRootCallback.h | 4 +++- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/js/xpconnect/src/XPCJSContext.cpp b/js/xpconnect/src/XPCJSContext.cpp index 168dd5bf13..0a5d248185 100644 --- a/js/xpconnect/src/XPCJSContext.cpp +++ b/js/xpconnect/src/XPCJSContext.cpp @@ -629,11 +629,12 @@ XPCJSContext::TraverseAdditionalNativeRoots(nsCycleCollectionNoteRootCallback& c if (val.isObject() && !JS::ObjectIsMarkedGray(&val.toObject())) continue; } - cb.NoteXPCOMRoot(v); + cb.NoteXPCOMRoot(v, XPCTraceableVariant::NS_CYCLE_COLLECTION_INNERCLASS::GetParticipant()); } for (XPCRootSetElem* e = mWrappedJSRoots; e ; e = e->GetNextRoot()) { - cb.NoteXPCOMRoot(ToSupports(static_cast(e))); + cb.NoteXPCOMRoot(ToSupports(static_cast(e)), + nsXPCWrappedJS::NS_CYCLE_COLLECTION_INNERCLASS::GetParticipant()); } } diff --git a/xpcom/base/nsCycleCollector.cpp b/xpcom/base/nsCycleCollector.cpp index 257f36cf5f..0efde15312 100644 --- a/xpcom/base/nsCycleCollector.cpp +++ b/xpcom/base/nsCycleCollector.cpp @@ -2088,7 +2088,7 @@ private: public: // nsCycleCollectionNoteRootCallback methods. - NS_IMETHOD_(void) NoteXPCOMRoot(nsISupports* aRoot); + NS_IMETHOD_(void) NoteXPCOMRoot(nsISupports* aRoot, nsCycleCollectionParticipant* aParticipant); NS_IMETHOD_(void) NoteJSRoot(JSObject* aRoot); NS_IMETHOD_(void) NoteNativeRoot(void* aRoot, nsCycleCollectionParticipant* aParticipant); @@ -2281,16 +2281,17 @@ CCGraphBuilder::BuildGraph(SliceBudget& aBudget) } NS_IMETHODIMP_(void) -CCGraphBuilder::NoteXPCOMRoot(nsISupports* aRoot) +CCGraphBuilder::NoteXPCOMRoot(nsISupports* aRoot, nsCycleCollectionParticipant* aParticipant) { - aRoot = CanonicalizeXPCOMParticipant(aRoot); - NS_ASSERTION(aRoot, - "Don't add objects that don't participate in collection!"); + MOZ_ASSERT(aRoot == CanonicalizeXPCOMParticipant(aRoot)); +#ifdef DEBUG nsXPCOMCycleCollectionParticipant* cp; ToParticipant(aRoot, &cp); + MOZ_ASSERT(aParticipant == cp); +#endif - NoteRoot(aRoot, cp); + NoteRoot(aRoot, aParticipant); } NS_IMETHODIMP_(void) diff --git a/xpcom/glue/nsCycleCollectionNoteRootCallback.h b/xpcom/glue/nsCycleCollectionNoteRootCallback.h index 1f0b5c589f..45efd3e2c0 100644 --- a/xpcom/glue/nsCycleCollectionNoteRootCallback.h +++ b/xpcom/glue/nsCycleCollectionNoteRootCallback.h @@ -12,7 +12,9 @@ class nsISupports; class nsCycleCollectionNoteRootCallback { public: - NS_IMETHOD_(void) NoteXPCOMRoot(nsISupports* aRoot) = 0; + // aRoot must be canonical (ie the result of QIing to nsCycleCollectionISupports). + NS_IMETHOD_(void) NoteXPCOMRoot(nsISupports* aRoot, + nsCycleCollectionParticipant* aParticipant) = 0; NS_IMETHOD_(void) NoteJSRoot(JSObject* aRoot) = 0; NS_IMETHOD_(void) NoteNativeRoot(void* aRoot, nsCycleCollectionParticipant* aParticipant) = 0;