Bug 785666 - Remove old-style CC Suspect and Forget functions. r=smaug,bsmedberg
authorAndrew McCreight <amccreight@mozilla.com>
Mon, 27 Aug 2012 10:28:38 -0700
changeset 105761 0a5dee7e43fa274074ab02ac87633ec45a83459a
parent 105760 3e6ed8c7aaa63c8533c5e4612bec1131ac895298
child 105762 f24546b76f3e8b3d462c7df75a11f203e4ee1592
push id55
push usershu@rfrn.org
push dateThu, 30 Aug 2012 01:33:09 +0000
reviewerssmaug, bsmedberg
bugs785666
milestone18.0a1
Bug 785666 - Remove old-style CC Suspect and Forget functions. r=smaug,bsmedberg
xpcom/base/nsCycleCollector.cpp
xpcom/build/nsXPCOM.h
xpcom/build/nsXPCOMPrivate.h
xpcom/stub/nsXPComStub.cpp
--- a/xpcom/base/nsCycleCollector.cpp
+++ b/xpcom/base/nsCycleCollector.cpp
@@ -739,39 +739,35 @@ public:
     // buffer.
 
     nsCycleCollectorParams &mParams;
     uint32_t mNumBlocksAlloced;
     uint32_t mCount;
     Block mFirstBlock;
     nsPurpleBufferEntry *mFreeList;
 
-    // For objects compiled against Gecko 1.9 and 1.9.1.
-    PointerSet mCompatObjects;
 #ifdef DEBUG_CC
     PointerSet mNormalObjects; // duplicates our blocks
     nsCycleCollectorStats &mStats;
 #endif
     
 #ifdef DEBUG_CC
     nsPurpleBuffer(nsCycleCollectorParams &params,
                    nsCycleCollectorStats &stats) 
         : mParams(params),
           mStats(stats)
     {
         InitBlocks();
         mNormalObjects.Init();
-        mCompatObjects.Init();
     }
 #else
     nsPurpleBuffer(nsCycleCollectorParams &params) 
         : mParams(params)
     {
         InitBlocks();
-        mCompatObjects.Init();
     }
 #endif
 
     ~nsPurpleBuffer()
     {
         FreeBlocks();
     }
 
@@ -845,17 +841,17 @@ public:
     // If removeChildlessNodes is true, then any nodes in the purple buffer
     // that will have no children in the cycle collector graph will also be
     // removed. CanSkip() may be run on these children.
     void RemoveSkippable(bool removeChildlessNodes);
 
 #ifdef DEBUG_CC
     bool Exists(void *p) const
     {
-        return mNormalObjects.GetEntry(p) || mCompatObjects.GetEntry(p);
+        return mNormalObjects.GetEntry(p);
     }
 #endif
 
     nsPurpleBufferEntry* NewEntry()
     {
         if (!mFreeList) {
             Block *b = new Block;
             if (!b) {
@@ -905,67 +901,31 @@ public:
 
         e->mNextInFreeList =
             (nsPurpleBufferEntry*)(uintptr_t(mFreeList) | uintptr_t(1));
         mFreeList = e;
 
         --mCount;
     }
 
-    bool PutCompatObject(nsISupports *p)
-    {
-        ++mCount;
-        return !!mCompatObjects.PutEntry(p);
-    }
-
-    void RemoveCompatObject(nsISupports *p)
-    {
-        --mCount;
-        mCompatObjects.RemoveEntry(p);
-    }
-
     uint32_t Count() const
     {
         return mCount;
     }
 
     size_t BlocksSize() const
     {
         return sizeof(Block) * mNumBlocksAlloced;
     }
 
 };
 
 static bool
 AddPurpleRoot(GCGraphBuilder &builder, void *root, nsCycleCollectionParticipant *cp);
 
-struct CallbackClosure
-{
-    CallbackClosure(nsPurpleBuffer *aPurpleBuffer, GCGraphBuilder &aBuilder)
-        : mPurpleBuffer(aPurpleBuffer),
-          mBuilder(aBuilder)
-    {
-    }
-    nsPurpleBuffer *mPurpleBuffer;
-    GCGraphBuilder &mBuilder;
-};
-
-static PLDHashOperator
-selectionCallback(nsPtrHashKey<const void>* key, void* userArg)
-{
-    CallbackClosure *closure = static_cast<CallbackClosure*>(userArg);
-    if (AddPurpleRoot(closure->mBuilder,
-                      static_cast<nsISupports *>(
-                        const_cast<void*>(key->GetKey())),
-                      nullptr))
-        return PL_DHASH_REMOVE;
-
-    return PL_DHASH_NEXT;
-}
-
 void
 nsPurpleBuffer::SelectPointers(GCGraphBuilder &aBuilder)
 {
 #ifdef DEBUG_CC
     // Can't use mCount here, since it may include null entries.
     uint32_t realCount = 0;
     for (Block *b = &mFirstBlock; b; b = b->mNext) {
         for (nsPurpleBufferEntry *e = b->mEntries,
@@ -974,28 +934,20 @@ nsPurpleBuffer::SelectPointers(GCGraphBu
             if (!(uintptr_t(e->mObject) & uintptr_t(1))) {
                 if (e->mObject) {
                     ++realCount;
                 }
             }
         }
     }
 
-    NS_ABORT_IF_FALSE(mCompatObjects.Count() + mNormalObjects.Count() ==
-                          realCount,
+    NS_ABORT_IF_FALSE(mNormalObjects.Count() == realCount,
                       "count out of sync");
 #endif
 
-    if (mCompatObjects.Count()) {
-        mCount -= mCompatObjects.Count();
-        CallbackClosure closure(this, aBuilder);
-        mCompatObjects.EnumerateEntries(selectionCallback, &closure);
-        mCount += mCompatObjects.Count(); // in case of allocation failure
-    }
-
     // Walk through all the blocks.
     for (Block *b = &mFirstBlock; b; b = b->mNext) {
         for (nsPurpleBufferEntry *e = b->mEntries,
                               *eEnd = ArrayEnd(b->mEntries);
             e != eEnd; ++e) {
             if (!(uintptr_t(e->mObject) & uintptr_t(1))) {
                 // This is a real entry (rather than something on the
                 // free list).
@@ -1057,20 +1009,16 @@ struct nsCycleCollector
     void ForgetSkippable(bool removeChildlessNodes);
 
     // returns whether anything was collected
     bool CollectWhite(nsICycleCollectorListener *aListener);
 
     nsCycleCollector();
     ~nsCycleCollector();
 
-    // The first pair of Suspect and Forget functions are only used by
-    // old XPCOM binary components.
-    bool Suspect(nsISupports *n);
-    bool Forget(nsISupports *n);
     nsPurpleBufferEntry* Suspect2(void *n, nsCycleCollectionParticipant *cp);
     bool Forget2(nsPurpleBufferEntry *e);
 
     void Collect(bool aMergeCompartments,
                  nsCycleCollectorResults *aResults,
                  uint32_t aTryCollections,
                  nsICycleCollectorListener *aListener);
 
@@ -2463,80 +2411,16 @@ nsCycleCollector_isScanSafe(void *s, nsC
 
     nsXPCOMCycleCollectionParticipant *xcp;
     ToParticipant(static_cast<nsISupports*>(s), &xcp);
 
     return xcp != nullptr;
 }
 #endif
 
-bool
-nsCycleCollector::Suspect(nsISupports *n)
-{
-    AbortIfOffMainThreadIfCheckFast();
-
-    // Re-entering ::Suspect during collection used to be a fault, but
-    // we are canonicalizing nsISupports pointers using QI, so we will
-    // see some spurious refcount traffic here. 
-
-    if (mScanInProgress)
-        return false;
-
-    NS_ASSERTION(nsCycleCollector_isScanSafe(n, nullptr),
-                 "suspected a non-scansafe pointer");
-
-    if (mParams.mDoNothing)
-        return false;
-
-#ifdef DEBUG_CC
-    mStats.mSuspectNode++;
-
-    if (nsCycleCollector_shouldSuppress(n))
-        return false;
-
-    if (mParams.mLogPointers) {
-        if (!mPtrLog)
-            mPtrLog = fopen("pointer_log", "w");
-        fprintf(mPtrLog, "S %p\n", static_cast<void*>(n));
-    }
-#endif
-
-    return mPurpleBuf.PutCompatObject(n);
-}
-
-
-bool
-nsCycleCollector::Forget(nsISupports *n)
-{
-    AbortIfOffMainThreadIfCheckFast();
-
-    // Re-entering ::Forget during collection used to be a fault, but
-    // we are canonicalizing nsISupports pointers using QI, so we will
-    // see some spurious refcount traffic here. 
-
-    if (mScanInProgress)
-        return false;
-
-    if (mParams.mDoNothing)
-        return true; // it's as good as forgotten
-
-#ifdef DEBUG_CC
-    mStats.mForgetNode++;
-
-    if (mParams.mLogPointers) {
-        if (!mPtrLog)
-            mPtrLog = fopen("pointer_log", "w");
-        fprintf(mPtrLog, "F %p\n", static_cast<void*>(n));
-    }
-#endif
-
-    mPurpleBuf.RemoveCompatObject(n);
-    return true;
-}
-
 nsPurpleBufferEntry*
 nsCycleCollector::Suspect2(void *n, nsCycleCollectionParticipant *cp)
 {
     AbortIfOffMainThreadIfCheckFast();
 
     // Re-entering ::Suspect during collection used to be a fault, but
     // we are canonicalizing nsISupports pointers using QI, so we will
     // see some spurious refcount traffic here. 
@@ -2984,31 +2868,16 @@ nsCycleCollector_registerJSRuntime(nsCyc
 
 void 
 nsCycleCollector_forgetJSRuntime()
 {
     if (sCollector)
         sCollector->ForgetJSRuntime();
 }
 
-
-bool
-NS_CycleCollectorSuspect(nsISupports *n)
-{
-    if (sCollector)
-        return sCollector->Suspect(n);
-    return false;
-}
-
-bool
-NS_CycleCollectorForget(nsISupports *n)
-{
-    return sCollector ? sCollector->Forget(n) : true;
-}
-
 nsPurpleBufferEntry*
 NS_CycleCollectorSuspect2(void *n, nsCycleCollectionParticipant *cp)
 {
     if (sCollector)
         return sCollector->Suspect2(n, cp);
     return nullptr;
 }
 
--- a/xpcom/build/nsXPCOM.h
+++ b/xpcom/build/nsXPCOM.h
@@ -25,18 +25,16 @@
 # define NS_LogInit                  NS_LogInit_P
 # define NS_LogTerm                  NS_LogTerm_P
 # define NS_LogAddRef                NS_LogAddRef_P
 # define NS_LogRelease               NS_LogRelease_P
 # define NS_LogCtor                  NS_LogCtor_P
 # define NS_LogDtor                  NS_LogDtor_P
 # define NS_LogCOMPtrAddRef          NS_LogCOMPtrAddRef_P
 # define NS_LogCOMPtrRelease         NS_LogCOMPtrRelease_P
-# define NS_CycleCollectorSuspect    NS_CycleCollectorSuspect_P
-# define NS_CycleCollectorForget     NS_CycleCollectorForget_P
 # define NS_CycleCollectorSuspect2   NS_CycleCollectorSuspect2_P
 # define NS_CycleCollectorForget2    NS_CycleCollectorForget2_P
 #endif
 
 #include "nscore.h"
 #include "nsXPCOMCID.h"
 
 #ifdef __cplusplus
@@ -355,22 +353,16 @@ NS_LogCOMPtrRelease(void *aCOMPtr, nsISu
  * The first two functions below exist only to support binary components
  * that were compiled for older XPCOM versions.
  */
 
 #ifdef __cplusplus
 
 class nsCycleCollectionParticipant;
 
-XPCOM_API(bool)
-NS_CycleCollectorSuspect(nsISupports *n);
-
-XPCOM_API(bool)
-NS_CycleCollectorForget(nsISupports *n);
-
 XPCOM_API(nsPurpleBufferEntry*)
 NS_CycleCollectorSuspect2(void *n, nsCycleCollectionParticipant *p);
 
 XPCOM_API(bool)
 NS_CycleCollectorForget2(nsPurpleBufferEntry *e);
 
 #endif
 
--- a/xpcom/build/nsXPCOMPrivate.h
+++ b/xpcom/build/nsXPCOMPrivate.h
@@ -152,18 +152,18 @@ typedef struct XPCOMFunctions{
     LogReleaseFunc logReleaseFunc;
     LogCtorFunc logCtorFunc;
     LogCtorFunc logDtorFunc;
     LogCOMPtrFunc logCOMPtrAddRefFunc;
     LogCOMPtrFunc logCOMPtrReleaseFunc;
     GetXPTCallStubFunc getXPTCallStubFunc;
     DestroyXPTCallStubFunc destroyXPTCallStubFunc;
     InvokeByIndexFunc invokeByIndexFunc;
-    CycleCollectorFunc cycleSuspectFunc;
-    CycleCollectorFunc cycleForgetFunc;
+    CycleCollectorFunc cycleSuspectFunc; // obsolete: use cycleSuspect2Func
+    CycleCollectorFunc cycleForgetFunc; // obsolete: use cycleForget2Func
     StringSetIsVoidFunc stringSetIsVoid;
     StringGetIsVoidFunc stringGetIsVoid;
     CStringSetIsVoidFunc cstringSetIsVoid;
     CStringGetIsVoidFunc cstringGetIsVoid;
 
     // Added for Mozilla 1.9.1
     CycleCollectorSuspect2Func cycleSuspect2Func;
     CycleCollectorForget2Func cycleForget2Func;
--- a/xpcom/stub/nsXPComStub.cpp
+++ b/xpcom/stub/nsXPComStub.cpp
@@ -77,18 +77,18 @@ static const XPCOMFunctions kFrozenFunct
     &NS_LogRelease_P,
     &NS_LogCtor_P,
     &NS_LogDtor_P,
     &NS_LogCOMPtrAddRef_P,
     &NS_LogCOMPtrRelease_P,
     &NS_GetXPTCallStub_P,
     &NS_DestroyXPTCallStub_P,
     &NS_InvokeByIndex_P,
-    &NS_CycleCollectorSuspect_P,
-    &NS_CycleCollectorForget_P,
+    nullptr,
+    nullptr,
     &NS_StringSetIsVoid_P,
     &NS_StringGetIsVoid_P,
     &NS_CStringSetIsVoid_P,
     &NS_CStringGetIsVoid_P,
 
     // these functions were added post 1.9
     &NS_CycleCollectorSuspect2_P,
     &NS_CycleCollectorForget2_P
@@ -494,30 +494,16 @@ NS_CStringToUTF16(const nsACString &aSrc
 
 #undef NS_UTF16ToCString
 EXPORT_XPCOM_API(nsresult)
 NS_UTF16ToCString(const nsAString &aSrc, nsCStringEncoding aDestEncoding, nsACString &aDest)
 {
   return NS_UTF16ToCString_P(aSrc, aDestEncoding, aDest);
 }
 
-#undef NS_CycleCollectorSuspect
-EXPORT_XPCOM_API(bool)
-NS_CycleCollectorSuspect(nsISupports* obj)
-{
-  return NS_CycleCollectorSuspect_P(obj);
-}
-
-#undef NS_CycleCollectorForget
-EXPORT_XPCOM_API(bool)
-NS_CycleCollectorForget(nsISupports* obj)
-{
-  return NS_CycleCollectorForget_P(obj);
-}
-
 #undef NS_CycleCollectorSuspect2
 EXPORT_XPCOM_API(nsPurpleBufferEntry*)
 NS_CycleCollectorSuspect2(void *obj, nsCycleCollectionParticipant *p)
 {
   return NS_CycleCollectorSuspect2_P(obj, p);
 }
 
 #undef NS_CycleCollectorForget2