Bug 865306 - Add assertions for the initialization of the cycle collector's EdgePool::Iterators. r=smaug
authorAndrew McCreight <amccreight@mozilla.com>
Thu, 25 Apr 2013 08:42:44 -0700
changeset 129878 c253479e2a2e54dbbda2365fa8eeb484a9d52769
parent 129877 2d8dfb7e10e66b5f24de933e514871efc1ff016a
child 129879 1296bb2e0445eccbdd494f1fba9360ef88183427
push id24590
push userryanvm@gmail.com
push dateFri, 26 Apr 2013 01:39:07 +0000
treeherdermozilla-central@7f68735fc8da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs865306
milestone23.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 865306 - Add assertions for the initialization of the cycle collector's EdgePool::Iterators. r=smaug
xpcom/base/nsCycleCollector.cpp
--- a/xpcom/base/nsCycleCollector.cpp
+++ b/xpcom/base/nsCycleCollector.cpp
@@ -144,16 +144,19 @@
 #include "mozilla/Mutex.h"
 #include "mozilla/StandardInteger.h"
 #include "mozilla/Telemetry.h"
 
 using namespace mozilla;
 
 //#define COLLECT_TIME_DEBUG
 
+// Enable assertions that are useful for diagnosing errors in graph construction.
+//#define DEBUG_CC_GRAPH
+
 #define DEFAULT_SHUTDOWN_COLLECTIONS 5
 #define SHUTDOWN_COLLECTIONS(params) DEFAULT_SHUTDOWN_COLLECTIONS
 
 #if defined(XP_WIN)
 // Defined in nsThreadManager.cpp.
 extern DWORD gTLSThreadIDIndex;
 #elif defined(NS_TLS)
 // Defined in nsThreadManager.cpp.
@@ -331,16 +334,23 @@ public:
             }
             return mPointer->ptrInfo;
         }
         bool operator==(const Iterator& aOther) const
             { return mPointer == aOther.mPointer; }
         bool operator!=(const Iterator& aOther) const
             { return mPointer != aOther.mPointer; }
 
+#ifdef DEBUG_CC_GRAPH
+        bool Initialized() const
+        {
+            return mPointer != nullptr;
+        }
+#endif
+
     private:
         PtrInfoOrBlock *mPointer;
     };
 
     class Builder;
     friend class Builder;
     class Builder {
     public:
@@ -380,16 +390,22 @@ public:
         while (b) {
             n += aMallocSizeOf(b);
             b = b->Next();
         }
         return n;
     }
 };
 
+#ifdef DEBUG_CC_GRAPH
+#define CC_GRAPH_ASSERT(b) MOZ_ASSERT(b)
+#else
+#define CC_GRAPH_ASSERT(b)
+#endif
+
 enum NodeColor { black, white, grey };
 
 // This structure should be kept as small as possible; we may expect
 // hundreds of thousands of them to be allocated and touched
 // repeatedly during each cycle collection.
 
 struct PtrInfo
 {
@@ -416,33 +432,37 @@ public:
 
     // Allow NodePool::Block's constructor to compile.
     PtrInfo() {
         NS_NOTREACHED("should never be called");
     }
 
     EdgePool::Iterator FirstChild()
     {
+        CC_GRAPH_ASSERT(mFirstChild.Initialized());
         return mFirstChild;
     }
 
     // this PtrInfo must be part of a NodePool
     EdgePool::Iterator LastChild()
     {
+        CC_GRAPH_ASSERT((this + 1)->mFirstChild.Initialized());
         return (this + 1)->mFirstChild;
     }
 
     void SetFirstChild(EdgePool::Iterator aFirstChild)
     {
+        CC_GRAPH_ASSERT(aFirstChild.Initialized());
         mFirstChild = aFirstChild;
     }
 
     // this PtrInfo must be part of a NodePool
     void SetLastChild(EdgePool::Iterator aLastChild)
     {
+        CC_GRAPH_ASSERT(aLastChild.Initialized());
         (this + 1)->mFirstChild = aLastChild;
     }
 };
 
 /**
  * A structure designed to be used like a linked list of PtrInfo, except
  * that allocates the PtrInfo 32K-at-a-time.
  */