remove-cycle
author Benjamin Smedberg <benjamin@smedbergs.us>
Sat, 26 Jul 2008 22:49:39 -0400
changeset 167 a4da40849f5436e629c5732f4368c6c48189637f
parent 153 cd96178a2e472dc6cd10443a56a3cedf9e8e1140
permissions -rw-r--r--
State as of now

Get rid of the cycle collector.
* * *

diff --git a/content/base/public/nsContentUtils.h b/content/base/public/nsContentUtils.h
--- a/content/base/public/nsContentUtils.h
+++ b/content/base/public/nsContentUtils.h
@@ -881,20 +881,6 @@ public:
   static PRUint32 GetEventId(nsIAtom* aName);
 
   /**
-   * Used only during traversal of the XPCOM graph by the cycle
-   * collector: push a pointer to the listener manager onto the
-   * children deque, if it exists. Do nothing if there is no listener
-   * manager.
-   *
-   * Crucially: does not perform any refcounting operations.
-   *
-   * @param aNode The node to traverse.
-   * @param children The buffer to push a listener manager pointer into.
-   */
-  static void TraverseListenerManager(nsINode *aNode,
-                                      nsCycleCollectionTraversalCallback &cb);
-
-  /**
    * Get the eventlistener manager for aNode. If a new eventlistener manager
    * was created, aCreated is set to PR_TRUE.
    *
@@ -1040,74 +1026,6 @@ public:
    * Unbinds the content from the tree and nulls it out if it's not null.
    */
   static void DestroyAnonymousContent(nsCOMPtr<nsIContent>* aContent);
-
-  /**
-   * Keep script object aNewObject, held by aScriptObjectHolder, alive.
-   *
-   * NOTE: This currently only supports objects that hold script objects of one
-   *       scripting language.
-   *
-   * @param aLangID script language ID of aNewObject
-   * @param aScriptObjectHolder the object that holds aNewObject
-   * @param aTracer the tracer for aScriptObject
-   * @param aNewObject the script object to hold
-   * @param aWasHoldingObjects whether aScriptObjectHolder was already holding
-   *                           script objects (ie. HoldScriptObject was called
-   *                           on it before, without a corresponding call to
-   *                           DropScriptObjects)
-   */
-  static nsresult HoldScriptObject(PRUint32 aLangID, void* aScriptObjectHolder,
-                                   nsScriptObjectTracer* aTracer,
-                                   void* aNewObject, PRBool aWasHoldingObjects)
-  {
-    if (aLangID == nsIProgrammingLanguage::JAVASCRIPT) {
-      return aWasHoldingObjects ? NS_OK :
-                                  HoldJSObjects(aScriptObjectHolder, aTracer);
-    }
-
-    return HoldScriptObject(aLangID, aNewObject);
-  }
-
-  /**
-   * Drop any script objects that aScriptObjectHolder is holding.
-   *
-   * NOTE: This currently only supports objects that hold script objects of one
-   *       scripting language.
-   *
-   * @param aLangID script language ID of the objects that 
-   * @param aScriptObjectHolder the object that holds script object that we want
-   *                            to drop
-   * @param aTracer the tracer for aScriptObject
-   */
-  static nsresult DropScriptObjects(PRUint32 aLangID, void* aScriptObjectHolder,
-                                    nsScriptObjectTracer* aTracer)
-  {
-    if (aLangID == nsIProgrammingLanguage::JAVASCRIPT) {
-      return DropJSObjects(aScriptObjectHolder);
-    }
-
-    aTracer->Trace(aScriptObjectHolder, DropScriptObject, nsnull);
-
-    return NS_OK;
-  }
-
-  /**
-   * Keep the JS objects held by aScriptObjectHolder alive.
-   *
-   * @param aScriptObjectHolder the object that holds JS objects that we want to
-   *                            keep alive
-   * @param aTracer the tracer for aScriptObject
-   */
-  static nsresult HoldJSObjects(void* aScriptObjectHolder,
-                                nsScriptObjectTracer* aTracer);
-
-  /**
-   * Drop the JS objects held by aScriptObjectHolder.
-   *
-   * @param aScriptObjectHolder the object that holds JS objects that we want to
-   *                            drop
-   */
-  static nsresult DropJSObjects(void* aScriptObjectHolder);
 
   /**
    * Convert nsIContent::IME_STATUS_* to nsIKBStateControll::IME_STATUS_*
@@ -1385,13 +1303,8 @@ private:
   static PRUint32 sRunnersCountAtFirstBlocker;
 };
 
-#define NS_HOLD_JS_OBJECTS(obj, clazz)                                         \
-  nsContentUtils::HoldJSObjects(NS_CYCLE_COLLECTION_UPCAST(obj, clazz),        \
-                                &NS_CYCLE_COLLECTION_NAME(clazz))
-
-#define NS_DROP_JS_OBJECTS(obj, clazz)                                         \
-  nsContentUtils::DropJSObjects(NS_CYCLE_COLLECTION_UPCAST(obj, clazz))
-
+#define NS_HOLD_JS_OBJECTS(obj, clazz) NS_OK
+#define NS_DROP_JS_OBJECTS(obj, clazz) NS_OK
 
 class NS_STACK_CLASS nsCxPusher
 {
diff --git a/content/base/public/nsIContent.h b/content/base/public/nsIContent.h
--- a/content/base/public/nsIContent.h
+++ b/content/base/public/nsIContent.h
@@ -856,39 +856,11 @@ NS_DEFINE_STATIC_IID_ACCESSOR(nsIContent
 
 // Some cycle-collecting helper macros for nsIContent subclasses
 
-#define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_LISTENERMANAGER \
-  if (tmp->HasFlag(NODE_HAS_LISTENERMANAGER)) {           \
-    nsContentUtils::TraverseListenerManager(tmp, cb);     \
-  }
-
-#define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_PRESERVED_WRAPPER      \
-  {                                                              \
-    nsISupports *preservedWrapper = nsnull;                      \
-    if (tmp->GetOwnerDoc())                                      \
-      preservedWrapper = tmp->GetOwnerDoc()->GetReference(tmp);  \
-    NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "[preserved wrapper]");\
-    cb.NoteXPCOMChild(preservedWrapper);                         \
-  }
-
-#define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_USERDATA \
-  if (tmp->HasProperties()) {                      \
-    nsNodeUtils::TraverseUserData(tmp, cb);        \
-  }
-
-#define NS_IMPL_CYCLE_COLLECTION_UNLINK_LISTENERMANAGER \
-  if (tmp->HasFlag(NODE_HAS_LISTENERMANAGER)) {         \
-    nsContentUtils::RemoveListenerManager(tmp);         \
-    tmp->UnsetFlags(NODE_HAS_LISTENERMANAGER);          \
-  }
-
-#define NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER \
-  if (tmp->GetOwnerDoc())                                 \
-    tmp->GetOwnerDoc()->RemoveReference(tmp);
-
-#define NS_IMPL_CYCLE_COLLECTION_UNLINK_USERDATA \
-  if (tmp->HasProperties()) {                    \
-    nsNodeUtils::UnlinkUserData(tmp);            \
-  }
-
+#define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_LISTENERMANAGER
+#define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_PRESERVED_WRAPPER
+#define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_USERDATA
+#define NS_IMPL_CYCLE_COLLECTION_UNLINK_LISTENERMANAGER
+#define NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
+#define NS_IMPL_CYCLE_COLLECTION_UNLINK_USERDATA
 
 #endif /* nsIContent_h___ */
diff --git a/content/base/public/nsReferencedElement.h b/content/base/public/nsReferencedElement.h
--- a/content/base/public/nsReferencedElement.h
+++ b/content/base/public/nsReferencedElement.h
@@ -69,7 +69,6 @@ public:
 public:
   nsReferencedElement() {}
   ~nsReferencedElement() {
-    Unlink();
     if (mPendingNotification) {
       mPendingNotification->Clear();
     }
@@ -91,13 +90,6 @@ public:
    * value, the current element for the ID.
    */
   void Reset(nsIContent* aFrom, nsIURI* aURI, PRBool aWatch = PR_TRUE);
-  /**
-   * Clears the reference. ContentChanged is not triggered. get() will return
-   * null.
-   */
-  void Unlink();
-
-  void Traverse(nsCycleCollectionTraversalCallback* aCB);
   
 protected:
   /**
diff --git a/content/base/src/nsContentSink.cpp b/content/base/src/nsContentSink.cpp
--- a/content/base/src/nsContentSink.cpp
+++ b/content/base/src/nsContentSink.cpp
@@ -160,23 +160,6 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(
   NS_INTERFACE_MAP_ENTRY(nsITimerCallback)
   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIScriptLoaderObserver)
 NS_INTERFACE_MAP_END
-
-NS_IMPL_CYCLE_COLLECTION_CLASS(nsContentSink)
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsContentSink)
-  if (tmp->mDocument) {
-    tmp->mDocument->RemoveObserver(tmp);
-  }
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mDocument)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mParser)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mNodeInfoManager)
-NS_IMPL_CYCLE_COLLECTION_UNLINK_END
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsContentSink)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mDocument)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mParser)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_MEMBER(mNodeInfoManager,
-                                                  nsNodeInfoManager)
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
-
 
 nsContentSink::nsContentSink()
 {
diff --git a/content/base/src/nsContentUtils.cpp b/content/base/src/nsContentUtils.cpp
--- a/content/base/src/nsContentUtils.cpp
+++ b/content/base/src/nsContentUtils.cpp
@@ -3245,26 +3245,6 @@ nsContentUtils::HasMutationListeners(nsI
   return PR_FALSE;
 }
 
-/* static */
-void
-nsContentUtils::TraverseListenerManager(nsINode *aNode,
-                                        nsCycleCollectionTraversalCallback &cb)
-{
-  if (!sEventListenerManagersHash.ops) {
-    // We're already shut down, just return.
-    return;
-  }
-
-  EventListenerManagerMapEntry *entry =
-    static_cast<EventListenerManagerMapEntry *>
-               (PL_DHashTableOperate(&sEventListenerManagersHash, aNode,
-                                        PL_DHASH_LOOKUP));
-  if (PL_DHASH_ENTRY_IS_BUSY(entry)) {
-    NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "[via hash] mListenerManager");
-    cb.NoteXPCOMChild(entry->mListenerManager);
-  }
-}
-
 nsresult
 nsContentUtils::GetListenerManager(nsINode *aNode,
                                    PRBool aCreateIfNotFound,
@@ -3762,33 +3742,6 @@ nsContentUtils::DropScriptObject(PRUint3
   if (--sScriptRootCount[langIndex] == 0) {
     NS_RELEASE(sScriptRuntimes[langIndex]);
   }
-}
-
-/* static */
-nsresult
-nsContentUtils::HoldJSObjects(void* aScriptObjectHolder,
-                              nsScriptObjectTracer* aTracer)
-{
-  nsresult rv = sXPConnect->AddJSHolder(aScriptObjectHolder, aTracer);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  ++sJSGCThingRootCount;
-  NS_LOG_ADDREF(sXPConnect, sJSGCThingRootCount, "HoldJSObjects",
-                sizeof(void*));
-
-  return NS_OK;
-}
-
-/* static */
-nsresult
-nsContentUtils::DropJSObjects(void* aScriptObjectHolder)
-{
-  NS_LOG_RELEASE(sXPConnect, sJSGCThingRootCount - 1, "HoldJSObjects");
-  nsresult rv = sXPConnect->RemoveJSHolder(aScriptObjectHolder);
-  if (--sJSGCThingRootCount == 0 && !sInitialized) {
-    NS_RELEASE(sXPConnect);
-  }
-  return rv;
 }
 
 /* static */
diff --git a/content/base/src/nsDOMAttributeMap.cpp b/content/base/src/nsDOMAttributeMap.cpp
--- a/content/base/src/nsDOMAttributeMap.cpp
+++ b/content/base/src/nsDOMAttributeMap.cpp
@@ -84,36 +84,6 @@ nsDOMAttributeMap::~nsDOMAttributeMap()
 {
   mAttributeCache.Enumerate(RemoveMapRef, nsnull);
 }
-
-void
-nsDOMAttributeMap::DropReference()
-{
-  mAttributeCache.Enumerate(RemoveMapRef, nsnull);
-  mContent = nsnull;
-}
-
-NS_IMPL_CYCLE_COLLECTION_CLASS(nsDOMAttributeMap)
-
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsDOMAttributeMap)
-  tmp->DropReference();
-NS_IMPL_CYCLE_COLLECTION_UNLINK_END
-
-
-PLDHashOperator
-TraverseMapEntry(nsAttrHashKey::KeyType aKey, nsCOMPtr<nsIDOMNode>& aData, void* aUserArg)
-{
-  nsCycleCollectionTraversalCallback *cb = 
-    static_cast<nsCycleCollectionTraversalCallback*>(aUserArg);
-
-  cb->NoteXPCOMChild(aData.get());
-
-  return PL_DHASH_NEXT;
-}
-
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsDOMAttributeMap)
-  tmp->mAttributeCache.Enumerate(TraverseMapEntry, &cb);
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
-
 
 // QueryInterface implementation for nsDOMAttributeMap
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsDOMAttributeMap)
diff --git a/content/base/src/nsDOMAttributeMap.h b/content/base/src/nsDOMAttributeMap.h
--- a/content/base/src/nsDOMAttributeMap.h
+++ b/content/base/src/nsDOMAttributeMap.h
@@ -131,8 +131,6 @@ public:
   // nsIDOMNamedNodeMap interface
   NS_DECL_NSIDOMNAMEDNODEMAP
 
-  void DropReference();
-
   nsIContent* GetContent()
   {
     return mContent;
diff --git a/content/base/src/nsDocument.cpp b/content/base/src/nsDocument.cpp
--- a/content/base/src/nsDocument.cpp
+++ b/content/base/src/nsDocument.cpp
@@ -154,7 +154,6 @@ static NS_DEFINE_CID(kDOMEventGroupCID, 
 
 #include "nsIJSContextStack.h"
 #include "nsIXPConnect.h"
-#include "nsCycleCollector.h"
 #include "nsCCUncollectableMarker.h"
 #include "nsIContentPolicy.h"
 
@@ -296,15 +295,6 @@ nsIdentifierMapEntry::~nsIdentifierMapEn
   if (mNameContentList && mNameContentList != NAME_NOT_VALID) {
     NS_RELEASE(mNameContentList);
   }
-}
-
-void
-nsIdentifierMapEntry::Traverse(nsCycleCollectionTraversalCallback* aCallback)
-{
-  if (mNameContentList != NAME_NOT_VALID)
-    aCallback->NoteXPCOMChild(mNameContentList);
-
-  aCallback->NoteXPCOMChild(static_cast<nsIDOMNodeList*>(mDocAllList));
 }
 
 void
@@ -1024,10 +1014,6 @@ nsDocument::~nsDocument()
   if (gDocumentLeakPRLog)
     PR_LOG(gDocumentLeakPRLog, PR_LOG_DEBUG,
            ("DOCUMENT %p destroyed", this));
-#endif
-
-#ifdef DEBUG
-  nsCycleCollector_DEBUG_wasFreed(static_cast<nsIDocument*>(this));
 #endif
 
   mInDestructor = PR_TRUE;
@@ -1170,184 +1156,6 @@ NS_IMPL_CYCLE_COLLECTING_RELEASE_AMBIGUO
                                                         nsIDocument,
                                                         nsNodeUtils::LastRelease(this))
 
-
-PR_STATIC_CALLBACK(PLDHashOperator)
-SubDocTraverser(PLDHashTable *table, PLDHashEntryHdr *hdr, PRUint32 number,
-                void *arg)
-{
-  SubDocMapEntry *entry = static_cast<SubDocMapEntry*>(hdr);
-  nsCycleCollectionTraversalCallback *cb = 
-    static_cast<nsCycleCollectionTraversalCallback*>(arg);
-
-  NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(*cb, "mSubDocuments entry->mKey");
-  cb->NoteXPCOMChild(entry->mKey);
-  NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(*cb, "mSubDocuments entry->mSubDocument");
-  cb->NoteXPCOMChild(entry->mSubDocument);
-
-  return PL_DHASH_NEXT;
-}
-
-PR_STATIC_CALLBACK(PLDHashOperator)
-RadioGroupsTraverser(const nsAString& aKey, nsAutoPtr<nsRadioGroupStruct>& aData, void* aClosure)
-{
-  nsCycleCollectionTraversalCallback *cb = 
-    static_cast<nsCycleCollectionTraversalCallback*>(aClosure);
-
-  NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(*cb,
-                                   "mRadioGroups entry->mSelectedRadioButton");
-  cb->NoteXPCOMChild(aData->mSelectedRadioButton);
-
-  PRUint32 i, count = aData->mRadioButtons.Count();
-  for (i = 0; i < count; ++i) {
-    NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(*cb,
-                                       "mRadioGroups entry->mRadioButtons[i]");
-    cb->NoteXPCOMChild(aData->mRadioButtons[i]);
-  }
-
-  return PL_DHASH_NEXT;
-}
-
-PR_STATIC_CALLBACK(PLDHashOperator)
-BoxObjectTraverser(const void* key, nsPIBoxObject* boxObject, void* userArg)
-{
-  nsCycleCollectionTraversalCallback *cb = 
-    static_cast<nsCycleCollectionTraversalCallback*>(userArg);
- 
-  NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(*cb, "mBoxObjectTable entry");
-  cb->NoteXPCOMChild(boxObject);
-
-  return PL_DHASH_NEXT;
-}
-
-class LinkMapTraversalVisitor : public nsUint32ToContentHashEntry::Visitor
-{
-public:
-  nsCycleCollectionTraversalCallback *mCb;
-  virtual void Visit(nsIContent* aContent)
-  {
-    mCb->NoteXPCOMChild(aContent);
-  }
-};
-
-PR_STATIC_CALLBACK(PLDHashOperator)
-LinkMapTraverser(nsUint32ToContentHashEntry* aEntry, void* userArg)
-{
-  LinkMapTraversalVisitor visitor;
-  visitor.mCb = static_cast<nsCycleCollectionTraversalCallback*>(userArg);
-  NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(*visitor.mCb, "mLinkMap entry");
-  aEntry->VisitContent(&visitor);
-  return PL_DHASH_NEXT;
-}
-
-PR_STATIC_CALLBACK(PLDHashOperator)
-IdentifierMapEntryTraverse(nsIdentifierMapEntry *aEntry, void *aArg)
-{
-  nsCycleCollectionTraversalCallback *cb =
-    static_cast<nsCycleCollectionTraversalCallback*>(aArg);
-  aEntry->Traverse(cb);
-  return PL_DHASH_NEXT;
-}
-
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsDocument)
-  if (nsCCUncollectableMarker::InGeneration(tmp->GetMarkedCCGeneration())) {
-    return NS_OK;
-  }
-
-  tmp->mIdentifierMap.EnumerateEntries(IdentifierMapEntryTraverse, &cb);
-
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mNodeInfo)
-
-  // Traverse the mChildren nsAttrAndChildArray.
-  for (PRInt32 indx = PRInt32(tmp->mChildren.ChildCount()); indx > 0; --indx) {
-    NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mChildren[i]");
-    cb.NoteXPCOMChild(tmp->mChildren.ChildAt(indx - 1));
-  }
-
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_USERDATA
-
-  // Traverse all nsIDocument pointer members.
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mCachedRootContent)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_MEMBER(mNodeInfoManager,
-                                                  nsNodeInfoManager)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mSecurityInfo)
-
-  // Traverse all nsDocument nsCOMPtrs.
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mParser)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mScriptGlobalObject)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mListenerManager)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mDOMStyleSheets)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mScriptLoader)
-
-  tmp->mRadioGroups.Enumerate(RadioGroupsTraverser, &cb);
-
-  // The boxobject for an element will only exist as long as it's in the
-  // document, so we'll traverse the table here instead of from the element.
-  if (tmp->mBoxObjectTable) {
-    tmp->mBoxObjectTable->EnumerateRead(BoxObjectTraverser, &cb);
-  }
-
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mChannel)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mStyleAttrStyleSheet)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mScriptEventManager)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mXPathEvaluatorTearoff)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mLayoutHistoryState)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOnloadBlocker)
-
-  // An element will only be in the linkmap as long as it's in the
-  // document, so we'll traverse the table here instead of from the element.
-  if (tmp->mLinkMap.IsInitialized()) {
-    tmp->mLinkMap.EnumerateEntries(LinkMapTraverser, &cb);
-  }
-
-  // Traverse all our nsCOMArrays.
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMARRAY(mStyleSheets)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMARRAY(mCatalogSheets)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMARRAY(mVisitednessChangedURIs)
-
-  // Traverse any associated preserved wrapper.
-  NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "[preserved wrapper]");
-  cb.NoteXPCOMChild(tmp->GetReference(tmp));
-
-  if (tmp->mSubDocuments && tmp->mSubDocuments->ops) {
-    PL_DHashTableEnumerate(tmp->mSubDocuments, SubDocTraverser, &cb);
-  }
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
-
-
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsDocument)
-  // Tear down linkmap. This is a performance optimization so that we
-  // don't waste time removing links one by one as they are removed
-  // from the doc.
-  tmp->DestroyLinkMap();
-
-  nsAutoScriptBlocker scriptBlocker;
-
-  // Unlink the mChildren nsAttrAndChildArray.
-  for (PRInt32 indx = PRInt32(tmp->mChildren.ChildCount()) - 1; 
-       indx >= 0; --indx) {
-    tmp->mChildren.ChildAt(indx)->UnbindFromTree();
-    tmp->mChildren.RemoveChildAt(indx);
-  }
-
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mCachedRootContent)
-
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_USERDATA
-
-  // Drop the content hash.
-  delete tmp->mContentWrapperHash;
-  tmp->mContentWrapperHash = nsnull;
-
-  tmp->mParentDocument = nsnull;
-
-  // nsDocument has a pretty complex destructor, so we're going to
-  // assume that *most* cycles you actually want to break somewhere
-  // else, and not unlink an awful lot here.
-  //
-  // In rare cases where you think an unlink will help here, add one
-  // manually.
-NS_IMPL_CYCLE_COLLECTION_UNLINK_END
-
-
 nsresult
 nsDocument::Init()
 {
diff --git a/content/base/src/nsDocument.h b/content/base/src/nsDocument.h
--- a/content/base/src/nsDocument.h
+++ b/content/base/src/nsDocument.h
@@ -273,8 +273,6 @@ public:
   PRBool HasContentChangeCallback() { return mChangeCallbacks != nsnull; }
   void AddContentChangeCallback(nsIDocument::IDTargetObserver aCallback, void* aData);
   void RemoveContentChangeCallback(nsIDocument::IDTargetObserver aCallback, void* aData);
-
-  void Traverse(nsCycleCollectionTraversalCallback* aCallback);
 
   void SetDocAllList(nsContentList* aContentList) { mDocAllList = aContentList; }
   nsContentList* GetDocAllList() { return mDocAllList; }
diff --git a/content/base/src/nsGenericDOMDataNode.cpp b/content/base/src/nsGenericDOMDataNode.cpp
--- a/content/base/src/nsGenericDOMDataNode.cpp
+++ b/content/base/src/nsGenericDOMDataNode.cpp
@@ -79,31 +79,6 @@ nsGenericDOMDataNode::~nsGenericDOMDataN
 }
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(nsGenericDOMDataNode)
-
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsGenericDOMDataNode)
-  nsIDocument* currentDoc = tmp->GetCurrentDoc();
-  if (currentDoc && nsCCUncollectableMarker::InGeneration(
-                      currentDoc->GetMarkedCCGeneration())) {
-    return NS_OK;
-  }
-
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mNodeInfo)
-
-  nsIDocument* ownerDoc = tmp->GetOwnerDoc();
-  if (ownerDoc) {
-    ownerDoc->BindingManager()->Traverse(tmp, cb);
-  }
-
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_LISTENERMANAGER
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_USERDATA
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_PRESERVED_WRAPPER
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
-
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsGenericDOMDataNode)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_LISTENERMANAGER
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_USERDATA
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
-NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsGenericDOMDataNode)
   NS_INTERFACE_MAP_ENTRY(nsIContent)
diff --git a/content/base/src/nsGenericElement.cpp b/content/base/src/nsGenericElement.cpp
--- a/content/base/src/nsGenericElement.cpp
+++ b/content/base/src/nsGenericElement.cpp
@@ -1167,13 +1167,6 @@ nsGenericElement::nsDOMSlots::nsDOMSlots
 
 nsGenericElement::nsDOMSlots::~nsDOMSlots()
 {
-  if (mStyle) {
-    mStyle->DropReference();
-  }
-
-  if (mAttributeMap) {
-    mAttributeMap->DropReference();
-  }
 }
 
 nsGenericElement::nsGenericElement(nsINodeInfo *aNodeInfo)
@@ -3472,103 +3465,6 @@ nsGenericElement::doRemoveChild(nsIDOMNo
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(nsGenericElement)
 
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsGenericElement)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_LISTENERMANAGER
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_USERDATA
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
-
-  if (tmp->HasProperties() && tmp->IsNodeOfType(nsINode::eXUL)) {
-    tmp->DeleteProperty(nsGkAtoms::contextmenulistener);
-    tmp->DeleteProperty(nsGkAtoms::popuplistener);
-  }
-
-  // Unlink child content (and unbind our subtree).
-  {
-    PRUint32 childCount = tmp->mAttrsAndChildren.ChildCount();
-    if (childCount) {
-      // Don't allow script to run while we're unbinding everything.
-      nsAutoScriptBlocker scriptBlocker;
-      while (childCount-- > 0) {
-        // Once we have XPCOMGC we shouldn't need to call UnbindFromTree.
-        // We could probably do a non-deep unbind here when IsInDoc is false
-        // for better performance.
-        tmp->mAttrsAndChildren.ChildAt(childCount)->UnbindFromTree();
-        tmp->mAttrsAndChildren.RemoveChildAt(childCount);
-      }
-    }
-  }  
-
-  // Unlink any DOM slots of interest.
-  {
-    nsDOMSlots *slots = tmp->GetExistingDOMSlots();
-    if (slots) {
-      if (slots->mAttributeMap) {
-        slots->mAttributeMap->DropReference();
-        slots->mAttributeMap = nsnull;
-      }
-      if (tmp->IsNodeOfType(nsINode::eXUL))
-        NS_IF_RELEASE(slots->mControllers);
-    }
-  }
-NS_IMPL_CYCLE_COLLECTION_UNLINK_END
-
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsGenericElement)
-  nsIDocument* currentDoc = tmp->GetCurrentDoc();
-  if (currentDoc && nsCCUncollectableMarker::InGeneration(
-                      currentDoc->GetMarkedCCGeneration())) {
-    return NS_OK;
-  }
-
-  nsIDocument* ownerDoc = tmp->GetOwnerDoc();
-  if (ownerDoc) {
-    ownerDoc->BindingManager()->Traverse(tmp, cb);
-  }
-
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_LISTENERMANAGER
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_USERDATA
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_PRESERVED_WRAPPER
-
-  if (tmp->HasProperties() && tmp->IsNodeOfType(nsINode::eXUL)) {
-    nsISupports* property =
-      static_cast<nsISupports*>
-                 (tmp->GetProperty(nsGkAtoms::contextmenulistener));
-    cb.NoteXPCOMChild(property);
-    property = static_cast<nsISupports*>
-                          (tmp->GetProperty(nsGkAtoms::popuplistener));
-    cb.NoteXPCOMChild(property);
-  }
-
-  // Traverse attribute names and child content.
-  {
-    PRUint32 i;
-    PRUint32 attrs = tmp->mAttrsAndChildren.AttrCount();
-    for (i = 0; i < attrs; i++) {
-      const nsAttrName* name = tmp->mAttrsAndChildren.AttrNameAt(i);
-      if (!name->IsAtom())
-        cb.NoteXPCOMChild(name->NodeInfo());
-    }
-
-    PRUint32 kids = tmp->mAttrsAndChildren.ChildCount();
-    for (i = 0; i < kids; i++) {
-      NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mAttrsAndChildren[i]");
-      cb.NoteXPCOMChild(tmp->mAttrsAndChildren.GetSafeChildAt(i));
-    }
-  }
-
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mNodeInfo)
-
-  // Traverse any DOM slots of interest.
-  {
-    nsDOMSlots *slots = tmp->GetExistingDOMSlots();
-    if (slots) {
-      cb.NoteXPCOMChild(slots->mAttributeMap.get());
-      if (tmp->IsNodeOfType(nsINode::eXUL))
-        cb.NoteXPCOMChild(slots->mControllers);
-    }
-  }
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
-
-
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsGenericElement)
   NS_INTERFACE_MAP_ENTRY(nsIContent)
   NS_INTERFACE_MAP_ENTRY(nsINode)
diff --git a/content/base/src/nsNodeUtils.cpp b/content/base/src/nsNodeUtils.cpp
--- a/content/base/src/nsNodeUtils.cpp
+++ b/content/base/src/nsNodeUtils.cpp
@@ -386,31 +386,6 @@ nsNodeUtils::CallUserDataHandlers(nsCOMA
   return NS_OK;
 }
 
-static void
-NoteUserData(void *aObject, nsIAtom *aKey, void *aXPCOMChild, void *aData)
-{
-  nsCycleCollectionTraversalCallback* cb =
-    static_cast<nsCycleCollectionTraversalCallback*>(aData);
-  NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(*cb, "[user data (or handler)]");
-  cb->NoteXPCOMChild(static_cast<nsISupports*>(aXPCOMChild));
-}
-
-/* static */
-void
-nsNodeUtils::TraverseUserData(nsINode* aNode,
-                              nsCycleCollectionTraversalCallback &aCb)
-{
-  nsIDocument* ownerDoc = aNode->GetOwnerDoc();
-  if (!ownerDoc) {
-    return;
-  }
-
-  nsPropertyTable *table = ownerDoc->PropertyTable();
-
-  table->Enumerate(aNode, DOM_USER_DATA, NoteUserData, &aCb);
-  table->Enumerate(aNode, DOM_USER_DATA_HANDLER, NoteUserData, &aCb);
-}
-
 /* static */
 nsresult
 nsNodeUtils::CloneNodeImpl(nsINode *aNode, PRBool aDeep, nsIDOMNode **aResult)
diff --git a/content/base/src/nsNodeUtils.h b/content/base/src/nsNodeUtils.h
--- a/content/base/src/nsNodeUtils.h
+++ b/content/base/src/nsNodeUtils.h
@@ -242,16 +242,6 @@ public:
                                        PRUint16 aOperation, PRBool aCloned);
 
   /**
-   * Helper for the cycle collector to traverse the DOM UserData and
-   * UserDataHandlers for aNode.
-   *
-   * @param aNode the node to traverse UserData and UserDataHandlers for
-   * @param aCb the cycle collection callback
-   */
-  static void TraverseUserData(nsINode* aNode,
-                               nsCycleCollectionTraversalCallback &aCb);
-
-  /**
    * A basic implementation of the DOM cloneNode method. Calls nsINode::Clone to
    * do the actual cloning of the node.
    *
diff --git a/content/base/src/nsObjectLoadingContent.cpp b/content/base/src/nsObjectLoadingContent.cpp
--- a/content/base/src/nsObjectLoadingContent.cpp
+++ b/content/base/src/nsObjectLoadingContent.cpp
@@ -1335,12 +1335,6 @@ nsObjectLoadingContent::RemovedFromDocum
   }
 }
 
-void
-nsObjectLoadingContent::Traverse(nsCycleCollectionTraversalCallback &cb)
-{
-  cb.NoteXPCOMChild(mFrameLoader);
-}
-
 // <private>
 /* static */ PRBool
 nsObjectLoadingContent::IsSuccessfulRequest(nsIRequest* aRequest)
diff --git a/content/base/src/nsReferencedElement.cpp b/content/base/src/nsReferencedElement.cpp
--- a/content/base/src/nsReferencedElement.cpp
+++ b/content/base/src/nsReferencedElement.cpp
@@ -77,8 +77,6 @@ void
 void
 nsReferencedElement::Reset(nsIContent* aFromContent, nsIURI* aURI, PRBool aWatch)
 {
-  Unlink();
-
   nsCOMPtr<nsIURL> url = do_QueryInterface(aURI);
   if (!url)
     return;
@@ -173,24 +171,6 @@ nsReferencedElement::Reset(nsIContent* a
   }
 }
 
-void
-nsReferencedElement::Traverse(nsCycleCollectionTraversalCallback* aCB)
-{
-  aCB->NoteXPCOMChild(mWatchDocument);
-  aCB->NoteXPCOMChild(mContent);
-}
-
-void
-nsReferencedElement::Unlink()
-{
-  if (mWatchDocument && mWatchID) {
-    mWatchDocument->RemoveIDTargetObserver(mWatchID, Observe, this);
-  }
-  mWatchDocument = nsnull;
-  mWatchID = nsnull;
-  mContent = nsnull;
-}
-
 PRBool
 nsReferencedElement::Observe(nsIContent* aOldContent,
                              nsIContent* aNewContent, void* aData)
diff --git a/content/base/src/nsXMLHttpRequest.cpp b/content/base/src/nsXMLHttpRequest.cpp
--- a/content/base/src/nsXMLHttpRequest.cpp
+++ b/content/base/src/nsXMLHttpRequest.cpp
@@ -1663,7 +1663,7 @@ nsXMLHttpRequest::RequestCompleted()
     ChangeState(XML_HTTP_REQUEST_OPENED);
   }
 
-  nsJSContext::MaybeCC(PR_FALSE);
+  nsJSContext::MaybeCC();
   return rv;
 }
 
@@ -2187,7 +2187,7 @@ nsXMLHttpRequest::Error(nsIDOMEvent* aEv
     NotifyEventListeners(errorEventListeners, event);
   }
 
-  nsJSContext::MaybeCC(PR_FALSE);
+  nsJSContext::MaybeCC();
   return NS_OK;
 }
 
diff --git a/content/events/src/nsDOMDataContainerEvent.cpp b/content/events/src/nsDOMDataContainerEvent.cpp
--- a/content/events/src/nsDOMDataContainerEvent.cpp
+++ b/content/events/src/nsDOMDataContainerEvent.cpp
@@ -49,17 +49,6 @@ nsDOMDataContainerEvent::nsDOMDataContai
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(nsDOMDataContainerEvent)
 
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsDOMDataContainerEvent,
-                                                nsDOMEvent)
-  if (tmp->mData.IsInitialized())
-    tmp->mData.Clear();
-NS_IMPL_CYCLE_COLLECTION_UNLINK_END
-
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsDOMDataContainerEvent,
-                                                  nsDOMEvent)
-  tmp->mData.EnumerateRead(TraverseEntry, &cb);
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
-
 NS_IMPL_ADDREF_INHERITED(nsDOMDataContainerEvent, nsDOMEvent)
 NS_IMPL_RELEASE_INHERITED(nsDOMDataContainerEvent, nsDOMEvent)
 
@@ -102,15 +91,3 @@ NS_NewDOMDataContainerEvent(nsIDOMEvent*
   return CallQueryInterface(it, aInstancePtrResult);
 }
 
-PLDHashOperator
-nsDOMDataContainerEvent::TraverseEntry(const nsAString& aKey,
-                                       nsIVariant *aDataItem,
-                                       void* aUserArg)
-{
-  nsCycleCollectionTraversalCallback *cb =
-    static_cast<nsCycleCollectionTraversalCallback*>(aUserArg);
-  cb->NoteXPCOMChild(aDataItem);
-
-  return PL_DHASH_NEXT;
-}
-
diff --git a/content/events/src/nsDOMDataContainerEvent.h b/content/events/src/nsDOMDataContainerEvent.h
--- a/content/events/src/nsDOMDataContainerEvent.h
+++ b/content/events/src/nsDOMDataContainerEvent.h
@@ -57,9 +57,6 @@ public:
   NS_DECL_NSIDOMDATACONTAINEREVENT
 
 private:
-  static PLDHashOperator PR_CALLBACK
-    TraverseEntry(const nsAString& aKey, nsIVariant *aDataItem, void* aUserArg);
-
   nsInterfaceHashtable<nsStringHashKey, nsIVariant> mData;
 };
 
diff --git a/content/events/src/nsDOMEvent.cpp b/content/events/src/nsDOMEvent.cpp
--- a/content/events/src/nsDOMEvent.cpp
+++ b/content/events/src/nsDOMEvent.cpp
@@ -163,59 +163,6 @@ NS_INTERFACE_MAP_END
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF(nsDOMEvent)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(nsDOMEvent)
-
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsDOMEvent)
-  if (tmp->mEventIsInternal) {
-    tmp->mEvent->target = nsnull;
-    tmp->mEvent->currentTarget = nsnull;
-    tmp->mEvent->originalTarget = nsnull;
-    switch (tmp->mEvent->eventStructType) {
-      case NS_MOUSE_EVENT:
-      case NS_MOUSE_SCROLL_EVENT:
-        static_cast<nsMouseEvent_base*>(tmp->mEvent)->relatedTarget = nsnull;
-        break;
-      case NS_XUL_COMMAND_EVENT:
-        static_cast<nsXULCommandEvent*>(tmp->mEvent)->sourceEvent = nsnull;
-        break;
-      case NS_MUTATION_EVENT:
-        static_cast<nsMutationEvent*>(tmp->mEvent)->mRelatedNode = nsnull;
-        break;
-      default:
-        break;
-    }
-  }
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mPresContext);
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mTmpRealOriginalTarget)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mExplicitOriginalTarget)
-NS_IMPL_CYCLE_COLLECTION_UNLINK_END
-
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsDOMEvent)
-  if (tmp->mEventIsInternal) {
-    cb.NoteXPCOMChild(tmp->mEvent->target);
-    cb.NoteXPCOMChild(tmp->mEvent->currentTarget);
-    cb.NoteXPCOMChild(tmp->mEvent->originalTarget);
-    switch (tmp->mEvent->eventStructType) {
-      case NS_MOUSE_EVENT:
-      case NS_MOUSE_SCROLL_EVENT:
-        cb.NoteXPCOMChild(
-          static_cast<nsMouseEvent_base*>(tmp->mEvent)->relatedTarget);
-        break;
-      case NS_XUL_COMMAND_EVENT:
-        cb.NoteXPCOMChild(
-          static_cast<nsXULCommandEvent*>(tmp->mEvent)->sourceEvent);
-        break;
-      case NS_MUTATION_EVENT:
-        cb.NoteXPCOMChild(
-          static_cast<nsMutationEvent*>(tmp->mEvent)->mRelatedNode);
-        break;
-      default:
-        break;
-    }
-  }
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mPresContext)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mTmpRealOriginalTarget)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mExplicitOriginalTarget)
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 // nsIDOMEventInterface
 NS_METHOD nsDOMEvent::GetType(nsAString& aType)
diff --git a/content/events/src/nsEventListenerManager.cpp b/content/events/src/nsEventListenerManager.cpp
--- a/content/events/src/nsEventListenerManager.cpp
+++ b/content/events/src/nsEventListenerManager.cpp
@@ -388,18 +388,6 @@ NS_INTERFACE_MAP_END
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF_AMBIGUOUS(nsEventListenerManager, nsIEventListenerManager)
 NS_IMPL_CYCLE_COLLECTING_RELEASE_AMBIGUOUS(nsEventListenerManager, nsIEventListenerManager)
-
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsEventListenerManager)
-  PRUint32 count = tmp->mListeners.Length();
-  for (PRUint32 i = 0; i < count; i++) {
-    cb.NoteXPCOMChild(tmp->mListeners.ElementAt(i).mListener.get());
-  }  
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
-
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsEventListenerManager)
-  tmp->Disconnect();
-NS_IMPL_CYCLE_COLLECTION_UNLINK_END
-
 
 const EventTypeData*
 nsEventListenerManager::GetTypeDataForIID(const nsIID& aIID)
diff --git a/content/events/src/nsEventStateManager.cpp b/content/events/src/nsEventStateManager.cpp
--- a/content/events/src/nsEventStateManager.cpp
+++ b/content/events/src/nsEventStateManager.cpp
@@ -678,53 +678,6 @@ NS_IMPL_CYCLE_COLLECTING_ADDREF_AMBIGUOU
 NS_IMPL_CYCLE_COLLECTING_ADDREF_AMBIGUOUS(nsEventStateManager, nsIEventStateManager)
 NS_IMPL_CYCLE_COLLECTING_RELEASE_AMBIGUOUS(nsEventStateManager, nsIEventStateManager)
 
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsEventStateManager)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mCurrentTargetContent);
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mLastMouseOverElement);
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mGestureDownContent);
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mGestureDownFrameOwner);
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mLastLeftMouseDownContent);
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mLastMiddleMouseDownContent);
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mLastRightMouseDownContent);
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mActiveContent);
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mHoverContent);
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mDragOverContent);
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mURLTargetContent);
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mCurrentFocus);
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mLastFocus);
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mLastContentFocus);
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mFirstBlurEvent);
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mFirstFocusEvent);
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mFirstMouseOverEventElement);
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mFirstMouseOutEventElement);
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mDocument);
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMARRAY(mAccessKeys);
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
-
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsEventStateManager)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mCurrentTargetContent);
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mLastMouseOverElement);
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mGestureDownContent);
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mGestureDownFrameOwner);
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mLastLeftMouseDownContent);
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mLastMiddleMouseDownContent);
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mLastRightMouseDownContent);
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mActiveContent);
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mHoverContent);
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mDragOverContent);
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mURLTargetContent);
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mCurrentFocus);
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mLastFocus);
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mLastContentFocus);
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mFirstBlurEvent);
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mFirstFocusEvent);
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mFirstMouseOverEventElement);
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mFirstMouseOutEventElement);
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mDocument);
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMARRAY(mAccessKeys);
-NS_IMPL_CYCLE_COLLECTION_UNLINK_END
-
-
 NS_IMETHODIMP
 nsEventStateManager::PreHandleEvent(nsPresContext* aPresContext,
                                     nsEvent *aEvent,
diff --git a/content/html/content/src/nsHTMLFormElement.cpp b/content/html/content/src/nsHTMLFormElement.cpp
--- a/content/html/content/src/nsHTMLFormElement.cpp
+++ b/content/html/content/src/nsHTMLFormElement.cpp
@@ -528,25 +528,6 @@ nsHTMLFormElement::Init()
 
 
 // nsISupports
-
-PR_STATIC_CALLBACK(PLDHashOperator)
-ElementTraverser(const nsAString& key, nsIDOMHTMLInputElement* element,
-                 void* userArg)
-{
-  nsCycleCollectionTraversalCallback *cb = 
-    static_cast<nsCycleCollectionTraversalCallback*>(userArg);
- 
-  cb->NoteXPCOMChild(element);
-  return PL_DHASH_NEXT;
-}
-
-NS_IMPL_CYCLE_COLLECTION_CLASS(nsHTMLFormElement)
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsHTMLFormElement,
-                                                  nsGenericHTMLElement)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mControls,
-                                                       nsIDOMHTMLCollection)
-  tmp->mSelectedRadioButtons.EnumerateRead(ElementTraverser, &cb);
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_IMPL_ADDREF_INHERITED(nsHTMLFormElement, nsGenericElement) 
 NS_IMPL_RELEASE_INHERITED(nsHTMLFormElement, nsGenericElement) 
@@ -2094,23 +2075,7 @@ nsFormControlList::FlushPendingNotificat
   }
 }
 
-PR_STATIC_CALLBACK(PLDHashOperator)
-ControlTraverser(const nsAString& key, nsISupports* control, void* userArg)
-{
-  nsCycleCollectionTraversalCallback *cb = 
-    static_cast<nsCycleCollectionTraversalCallback*>(userArg);
- 
-  cb->NoteXPCOMChild(control);
-  return PL_DHASH_NEXT;
-}
-
 NS_IMPL_CYCLE_COLLECTION_CLASS(nsFormControlList)
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsFormControlList)
-  tmp->Clear();
-NS_IMPL_CYCLE_COLLECTION_UNLINK_END
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsFormControlList)
-  tmp->mNameLookupTable.EnumerateRead(ControlTraverser, &cb);
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 // XPConnect interface list for nsFormControlList
 NS_INTERFACE_TABLE_HEAD(nsFormControlList)
diff --git a/content/html/content/src/nsHTMLObjectElement.cpp b/content/html/content/src/nsHTMLObjectElement.cpp
--- a/content/html/content/src/nsHTMLObjectElement.cpp
+++ b/content/html/content/src/nsHTMLObjectElement.cpp
@@ -168,10 +168,6 @@ nsHTMLObjectElement::DoneAddingChildren(
 }
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(nsHTMLObjectElement)
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsHTMLObjectElement,
-                                                  nsGenericHTMLFormElement)
-  tmp->Traverse(cb);
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_IMPL_ADDREF_INHERITED(nsHTMLObjectElement, nsGenericElement) 
 NS_IMPL_RELEASE_INHERITED(nsHTMLObjectElement, nsGenericElement) 
diff --git a/content/html/content/src/nsHTMLSharedObjectElement.cpp b/content/html/content/src/nsHTMLSharedObjectElement.cpp
--- a/content/html/content/src/nsHTMLSharedObjectElement.cpp
+++ b/content/html/content/src/nsHTMLSharedObjectElement.cpp
@@ -202,10 +202,6 @@ nsHTMLSharedObjectElement::DoneAddingChi
 }
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(nsHTMLSharedObjectElement)
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsHTMLSharedObjectElement,
-                                                  nsGenericHTMLElement)
-  tmp->Traverse(cb);
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_IMPL_ADDREF_INHERITED(nsHTMLSharedObjectElement, nsGenericElement) 
 NS_IMPL_RELEASE_INHERITED(nsHTMLSharedObjectElement, nsGenericElement) 
diff --git a/content/html/document/src/nsHTMLDocument.cpp b/content/html/document/src/nsHTMLDocument.cpp
--- a/content/html/document/src/nsHTMLDocument.cpp
+++ b/content/html/document/src/nsHTMLDocument.cpp
@@ -234,19 +234,6 @@ nsHTMLDocument::nsHTMLDocument()
 }
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(nsHTMLDocument)
-
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsHTMLDocument, nsDocument)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMARRAY(mImageMaps)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mImages)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mApplets)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mEmbeds)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mLinks)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mAnchors)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mFragmentParser)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mForms, nsIDOMNodeList)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mFormControls,
-                                                       nsIDOMNodeList)
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_IMPL_ADDREF_INHERITED(nsHTMLDocument, nsDocument)
 NS_IMPL_RELEASE_INHERITED(nsHTMLDocument, nsDocument)
diff --git a/content/html/document/src/nsHTMLFragmentContentSink.cpp b/content/html/document/src/nsHTMLFragmentContentSink.cpp
--- a/content/html/document/src/nsHTMLFragmentContentSink.cpp
+++ b/content/html/document/src/nsHTMLFragmentContentSink.cpp
@@ -238,27 +238,6 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(
   NS_INTERFACE_MAP_ENTRY(nsIContentSink)
   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIContentSink)
 NS_INTERFACE_MAP_END
-
-NS_IMPL_CYCLE_COLLECTION_CLASS(nsHTMLFragmentContentSink)
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsHTMLFragmentContentSink)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mParser)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mTargetDocument)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mRoot)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mNodeInfoManager)
-NS_IMPL_CYCLE_COLLECTION_UNLINK_END
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsHTMLFragmentContentSink)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mParser)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mTargetDocument)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mRoot)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_MEMBER(mNodeInfoManager,
-                                                  nsNodeInfoManager)
-  {
-    PRUint32 i;
-    for (i = 0; i < NS_ARRAY_LENGTH(tmp->mNodeInfoCache); ++i) {
-      cb.NoteXPCOMChild(tmp->mNodeInfoCache[i]);
-    }
-  }
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_IMETHODIMP
 nsHTMLFragmentContentSink::WillBuildModel(void)
diff --git a/content/svg/content/src/nsSVGUseElement.cpp b/content/svg/content/src/nsSVGUseElement.cpp
--- a/content/svg/content/src/nsSVGUseElement.cpp
+++ b/content/svg/content/src/nsSVGUseElement.cpp
@@ -64,21 +64,6 @@ NS_IMPL_NS_NEW_SVG_ELEMENT(Use)
 //----------------------------------------------------------------------
 // nsISupports methods
 
-NS_IMPL_CYCLE_COLLECTION_CLASS(nsSVGUseElement)
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsSVGUseElement,
-                                                nsSVGUseElementBase)
-  nsAutoScriptBlocker scriptBlocker;
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOriginal)
-  tmp->DestroyAnonymousContent();
-  tmp->UnlinkSource();
-NS_IMPL_CYCLE_COLLECTION_UNLINK_END
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsSVGUseElement,
-                                                  nsSVGUseElementBase)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOriginal)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mClone)
-  tmp->mSource.Traverse(&cb);
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
-
 NS_IMPL_ADDREF_INHERITED(nsSVGUseElement,nsSVGUseElementBase)
 NS_IMPL_RELEASE_INHERITED(nsSVGUseElement,nsSVGUseElementBase)
 
@@ -105,7 +90,6 @@ nsSVGUseElement::nsSVGUseElement(nsINode
 
 nsSVGUseElement::~nsSVGUseElement()
 {
-  UnlinkSource();
 }
 
 //----------------------------------------------------------------------
@@ -232,7 +216,6 @@ void
 void
 nsSVGUseElement::NodeWillBeDestroyed(const nsINode *aNode)
 {
-  UnlinkSource();
 }
 
 //----------------------------------------------------------------------
@@ -434,15 +417,6 @@ nsSVGUseElement::TriggerReclone()
   presShell->PostRecreateFramesFor(this);
 }
 
-void
-nsSVGUseElement::UnlinkSource()
-{
-  if (mSource.get()) {
-    mSource.get()->RemoveMutationObserver(this);
-  }
-  mSource.Unlink();
-}
-
 //----------------------------------------------------------------------
 // nsSVGElement methods
 
diff --git a/content/svg/content/src/nsSVGUseElement.h b/content/svg/content/src/nsSVGUseElement.h
--- a/content/svg/content/src/nsSVGUseElement.h
+++ b/content/svg/content/src/nsSVGUseElement.h
@@ -127,7 +127,6 @@ protected:
   void SyncWidthHeight(PRUint8 aAttrEnum);
   void LookupHref();
   void TriggerReclone();
-  void UnlinkSource();
 
   enum { X, Y, WIDTH, HEIGHT };
   nsSVGLength2 mLengthAttributes[4];
diff --git a/content/xbl/src/nsBindingManager.cpp b/content/xbl/src/nsBindingManager.cpp
--- a/content/xbl/src/nsBindingManager.cpp
+++ b/content/xbl/src/nsBindingManager.cpp
@@ -143,15 +143,6 @@ NS_INTERFACE_MAP_END
 NS_INTERFACE_MAP_END
 
 NS_IMPL_CYCLE_COLLECTION_UNLINK_0(nsAnonymousContentList)
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsAnonymousContentList)
-  {
-    PRInt32 i, count = tmp->mElements->Length();
-    for (i = 0; i < count; ++i) {
-      NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_MEMBER(mElements->ElementAt(i),
-                                                      nsXBLInsertionPoint);
-    }
-  }
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_IMETHODIMP
 nsAnonymousContentList::GetLength(PRUint32* aLength)
@@ -326,72 +317,6 @@ SetOrRemoveObject(PLDHashTable& table, n
 // Static member variable initialization
 
 // Implement our nsISupports methods
-
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsBindingManager)
-  tmp->mDestroyed = PR_TRUE;
-
-  if (tmp->mBindingTable.IsInitialized())
-    tmp->mBindingTable.Clear();
-
-  if (tmp->mDocumentTable.IsInitialized())
-    tmp->mDocumentTable.Clear();
-
-  if (tmp->mLoadingDocTable.IsInitialized())
-    tmp->mLoadingDocTable.Clear();
-
-  if (tmp->mContentListTable.ops)
-    PL_DHashTableFinish(&(tmp->mContentListTable));
-  tmp->mContentListTable.ops = nsnull;
-
-  if (tmp->mAnonymousNodesTable.ops)
-    PL_DHashTableFinish(&(tmp->mAnonymousNodesTable));
-  tmp->mAnonymousNodesTable.ops = nsnull;
-
-  if (tmp->mInsertionParentTable.ops)
-    PL_DHashTableFinish(&(tmp->mInsertionParentTable));
-  tmp->mInsertionParentTable.ops = nsnull;
-
-  if (tmp->mWrapperTable.ops)
-    PL_DHashTableFinish(&(tmp->mWrapperTable));
-  tmp->mWrapperTable.ops = nsnull;
-
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSTARRAY(mAttachedStack)
-NS_IMPL_CYCLE_COLLECTION_UNLINK_END
-
-
-static PLDHashOperator
-DocumentInfoHashtableTraverser(nsIURI* key,
-                               nsIXBLDocumentInfo* di,
-                               void* userArg)
-{
-  nsCycleCollectionTraversalCallback *cb = 
-    static_cast<nsCycleCollectionTraversalCallback*>(userArg);
-  cb->NoteXPCOMChild(di);
-  return PL_DHASH_NEXT;
-}
-
-static PLDHashOperator
-LoadingDocHashtableTraverser(nsIURI* key,
-                             nsIStreamListener* sl,
-                             void* userArg)
-{
-  nsCycleCollectionTraversalCallback *cb = 
-    static_cast<nsCycleCollectionTraversalCallback*>(userArg);
-  cb->NoteXPCOMChild(sl);
-  return PL_DHASH_NEXT;
-}
-
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsBindingManager)
-  // The hashes keyed on nsIContent are traversed from the nsIContent itself.
-  if (tmp->mDocumentTable.IsInitialized())
-      tmp->mDocumentTable.EnumerateRead(&DocumentInfoHashtableTraverser, &cb);
-  if (tmp->mLoadingDocTable.IsInitialized())
-      tmp->mLoadingDocTable.EnumerateRead(&LoadingDocHashtableTraverser, &cb);
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSTARRAY_MEMBER(mAttachedStack,
-                                                    nsXBLBinding)
-  // No need to traverse mProcessAttachedQueueEvent, since it'll just
-  // fire at some point.
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(nsBindingManager)
 
@@ -1474,57 +1399,6 @@ nsBindingManager::DropDocumentReference(
 }
 
 void
-nsBindingManager::Traverse(nsIContent *aContent,
-                           nsCycleCollectionTraversalCallback &cb)
-{
-  if (!aContent->HasFlag(NODE_MAY_BE_IN_BINDING_MNGR)) {
-    return;
-  }
-
-  nsISupports *value;
-  if (mInsertionParentTable.ops &&
-      (value = LookupObject(mInsertionParentTable, aContent))) {
-    NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "[via binding manager] mInsertionParentTable key");
-    cb.NoteXPCOMChild(aContent);
-    NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "[via binding manager] mInsertionParentTable value");
-    cb.NoteXPCOMChild(value);
-  }
-
-  if (!aContent->IsNodeOfType(nsINode::eELEMENT)) {
-    return;
-  }
-
-  nsXBLBinding *binding = GetBinding(aContent);
-  if (binding) {
-    NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "[via binding manager] mBindingTable key");
-    cb.NoteXPCOMChild(aContent);
-    NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_PTR(binding, nsXBLBinding,
-                                  "[via binding manager] mBindingTable value")
-  }
-  if (mContentListTable.ops &&
-      (value = LookupObject(mContentListTable, aContent))) {
-    NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "[via binding manager] mContentListTable key");
-    cb.NoteXPCOMChild(aContent);
-    NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "[via binding manager] mContentListTable value");
-    cb.NoteXPCOMChild(value);
-  }
-  if (mAnonymousNodesTable.ops &&
-      (value = LookupObject(mAnonymousNodesTable, aContent))) {
-    NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "[via binding manager] mAnonymousNodesTable key");
-    cb.NoteXPCOMChild(aContent);
-    NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "[via binding manager] mAnonymousNodesTable value");
-    cb.NoteXPCOMChild(value);
-  }
-  if (mWrapperTable.ops &&
-      (value = LookupObject(mWrapperTable, aContent))) {
-    NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "[via binding manager] mWrapperTable key");
-    cb.NoteXPCOMChild(aContent);
-    NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "[via binding manager] mWrapperTable value");
-    cb.NoteXPCOMChild(value);
-  }
-}
-
-void
 nsBindingManager::BeginOutermostUpdate()
 {
   mAttachedStackSizeOnOutermost = mAttachedStack.Length();
diff --git a/content/xbl/src/nsBindingManager.h b/content/xbl/src/nsBindingManager.h
--- a/content/xbl/src/nsBindingManager.h
+++ b/content/xbl/src/nsBindingManager.h
@@ -189,9 +189,6 @@ public:
                      RuleProcessorData* aData,
                      PRBool* aCutOffInheritance);
 
-  NS_HIDDEN_(void) Traverse(nsIContent *aContent,
-                            nsCycleCollectionTraversalCallback &cb);
-
   NS_DECL_CYCLE_COLLECTION_CLASS(nsBindingManager)
 
   // Notify the binding manager when an outermost update begins and
diff --git a/content/xbl/src/nsXBLBinding.cpp b/content/xbl/src/nsXBLBinding.cpp
--- a/content/xbl/src/nsXBLBinding.cpp
+++ b/content/xbl/src/nsXBLBinding.cpp
@@ -286,38 +286,6 @@ nsXBLBinding::~nsXBLBinding(void)
   nsIXBLDocumentInfo* info = mPrototypeBinding->XBLDocumentInfo();
   NS_RELEASE(info);
 }
-
-PR_STATIC_CALLBACK(PLDHashOperator)
-TraverseKey(nsISupports* aKey, nsInsertionPointList* aData, void* aClosure)
-{
-  nsCycleCollectionTraversalCallback &cb = 
-    *static_cast<nsCycleCollectionTraversalCallback*>(aClosure);
-
-  NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mInsertionPointTable key");
-  cb.NoteXPCOMChild(aKey);
-  if (aData) {
-    NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSTARRAY(*aData, nsXBLInsertionPoint,
-                                               "mInsertionPointTable value")
-  }
-  return PL_DHASH_NEXT;
-}
-
-NS_IMPL_CYCLE_COLLECTION_CLASS(nsXBLBinding)
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_NATIVE(nsXBLBinding)
-  // XXX Probably can't unlink mPrototypeBinding->XBLDocumentInfo(), because
-  //     mPrototypeBinding is weak.
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mContent)
-  // XXX What about mNextBinding and mInsertionPointTable?
-NS_IMPL_CYCLE_COLLECTION_UNLINK_END
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_BEGIN(nsXBLBinding)
-  cb.NoteXPCOMChild(tmp->mPrototypeBinding->XBLDocumentInfo());
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mContent)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_MEMBER(mNextBinding, nsXBLBinding)
-  if (tmp->mInsertionPointTable)
-    tmp->mInsertionPointTable->EnumerateRead(TraverseKey, &cb);
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
-NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(nsXBLBinding, AddRef)
-NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(nsXBLBinding, Release)
 
 void
 nsXBLBinding::SetBaseBinding(nsXBLBinding* aBinding)
diff --git a/content/xbl/src/nsXBLDocumentInfo.cpp b/content/xbl/src/nsXBLDocumentInfo.cpp
--- a/content/xbl/src/nsXBLDocumentInfo.cpp
+++ b/content/xbl/src/nsXBLDocumentInfo.cpp
@@ -434,64 +434,6 @@ static PRBool IsChromeURI(nsIURI* aURI)
 
 /* Implementation file */
 
-static PRIntn PR_CALLBACK
-TraverseProtos(nsHashKey *aKey, void *aData, void* aClosure)
-{
-  nsCycleCollectionTraversalCallback *cb = 
-    static_cast<nsCycleCollectionTraversalCallback*>(aClosure);
-  nsXBLPrototypeBinding *proto = static_cast<nsXBLPrototypeBinding*>(aData);
-  proto->Traverse(*cb);
-  return kHashEnumerateNext;
-}
-
-static PRIntn PR_CALLBACK
-UnlinkProtoJSObjects(nsHashKey *aKey, void *aData, void* aClosure)
-{
-  nsXBLPrototypeBinding *proto = static_cast<nsXBLPrototypeBinding*>(aData);
-  proto->UnlinkJSObjects();
-  return kHashEnumerateNext;
-}
-
-struct ProtoTracer
-{
-  TraceCallback mCallback;
-  void *mClosure;
-};
-
-static PRIntn PR_CALLBACK
-TraceProtos(nsHashKey *aKey, void *aData, void* aClosure)
-{
-  ProtoTracer* closure = static_cast<ProtoTracer*>(aClosure);
-  nsXBLPrototypeBinding *proto = static_cast<nsXBLPrototypeBinding*>(aData);
-  proto->Trace(closure->mCallback, closure->mClosure);
-  return kHashEnumerateNext;
-}
-
-NS_IMPL_CYCLE_COLLECTION_CLASS(nsXBLDocumentInfo)
-NS_IMPL_CYCLE_COLLECTION_ROOT_BEGIN(nsXBLDocumentInfo)
-  if (tmp->mBindingTable) {
-    tmp->mBindingTable->Enumerate(UnlinkProtoJSObjects, nsnull);
-  }
-NS_IMPL_CYCLE_COLLECTION_ROOT_END
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsXBLDocumentInfo)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mDocument)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mGlobalObject)
-NS_IMPL_CYCLE_COLLECTION_UNLINK_END
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsXBLDocumentInfo)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mDocument)
-  if (tmp->mBindingTable) {
-    tmp->mBindingTable->Enumerate(TraverseProtos, &cb);
-  }
-  cb.NoteXPCOMChild(static_cast<nsIScriptGlobalObject*>(tmp->mGlobalObject));
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
-NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(nsXBLDocumentInfo)
-  if (tmp->mBindingTable) {
-    ProtoTracer closure = { aCallback, aClosure };
-    tmp->mBindingTable->Enumerate(TraceProtos, &closure);
-  }
-NS_IMPL_CYCLE_COLLECTION_TRACE_END
-
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsXBLDocumentInfo)
   NS_INTERFACE_MAP_ENTRY(nsIXBLDocumentInfo)
   NS_INTERFACE_MAP_ENTRY(nsIScriptGlobalObjectOwner)
diff --git a/content/xbl/src/nsXBLProtoImpl.cpp b/content/xbl/src/nsXBLProtoImpl.cpp
--- a/content/xbl/src/nsXBLProtoImpl.cpp
+++ b/content/xbl/src/nsXBLProtoImpl.cpp
@@ -212,30 +212,6 @@ nsXBLProtoImpl::CompilePrototypeMembers(
   return NS_OK;
 }
 
-void
-nsXBLProtoImpl::Trace(TraceCallback aCallback, void *aClosure) const
-{
-  // If we don't have a class object then we either didn't compile members
-  // or we only have fields, in both cases there are no cycles through our
-  // members.
-  if (!mClassObject) {
-    return;
-  }
-
-  nsXBLProtoImplMember *member;
-  for (member = mMembers; member; member = member->GetNext()) {
-    member->Trace(aCallback, aClosure);
-  }
-}
-
-void
-nsXBLProtoImpl::UnlinkJSObjects()
-{
-  if (mClassObject) {
-    DestroyMembers();
-  }
-}
-
 nsXBLProtoImplField*
 nsXBLProtoImpl::FindField(const nsString& aFieldName) const
 {
diff --git a/content/xbl/src/nsXBLProtoImpl.h b/content/xbl/src/nsXBLProtoImpl.h
--- a/content/xbl/src/nsXBLProtoImpl.h
+++ b/content/xbl/src/nsXBLProtoImpl.h
@@ -88,9 +88,6 @@ public:
     mFields = aFieldList;
   }
 
-  void Trace(TraceCallback aCallback, void *aClosure) const;
-  void UnlinkJSObjects();
-
   nsXBLProtoImplField* FindField(const nsString& aFieldName) const;
 
   // Resolve all the fields for this implementation on the object |obj| False
diff --git a/content/xbl/src/nsXBLProtoImplMember.h b/content/xbl/src/nsXBLProtoImplMember.h
--- a/content/xbl/src/nsXBLProtoImplMember.h
+++ b/content/xbl/src/nsXBLProtoImplMember.h
@@ -113,8 +113,6 @@ public:
                                  const nsCString& aClassStr,
                                  void* aClassObject)=0;
 
-  virtual void Trace(TraceCallback aCallback, void *aClosure) const = 0;
-
 protected:
   friend class nsAutoGCRoot;
   
diff --git a/content/xbl/src/nsXBLProtoImplMethod.cpp b/content/xbl/src/nsXBLProtoImplMethod.cpp
--- a/content/xbl/src/nsXBLProtoImplMethod.cpp
+++ b/content/xbl/src/nsXBLProtoImplMethod.cpp
@@ -257,14 +257,6 @@ nsXBLProtoImplMethod::CompileMember(nsIS
   return NS_OK;
 }
 
-void
-nsXBLProtoImplMethod::Trace(TraceCallback aCallback, void *aClosure) const
-{
-  if (IsCompiled() && mJSMethodObject) {
-    aCallback(nsIProgrammingLanguage::JAVASCRIPT, mJSMethodObject, aClosure);
-  }
-}
-
 nsresult
 nsXBLProtoImplAnonymousMethod::Execute(nsIContent* aBoundElement)
 {
diff --git a/content/xbl/src/nsXBLProtoImplMethod.h b/content/xbl/src/nsXBLProtoImplMethod.h
--- a/content/xbl/src/nsXBLProtoImplMethod.h
+++ b/content/xbl/src/nsXBLProtoImplMethod.h
@@ -128,8 +128,6 @@ public:
                                  const nsCString& aClassStr,
                                  void* aClassObject);
 
-  virtual void Trace(TraceCallback aCallback, void *aClosure) const;
-
   PRBool IsCompiled() const
   {
     return !(mUncompiledMethod & BIT_UNCOMPILED);
diff --git a/content/xbl/src/nsXBLProtoImplProperty.cpp b/content/xbl/src/nsXBLProtoImplProperty.cpp
--- a/content/xbl/src/nsXBLProtoImplProperty.cpp
+++ b/content/xbl/src/nsXBLProtoImplProperty.cpp
@@ -324,15 +324,3 @@ nsXBLProtoImplProperty::CompileMember(ns
   
   return rv;
 }
-
-void
-nsXBLProtoImplProperty::Trace(TraceCallback aCallback, void *aClosure) const
-{
-  if (mJSAttributes & JSPROP_GETTER) {
-    aCallback(nsIProgrammingLanguage::JAVASCRIPT, mJSGetterObject, aClosure);
-  }
-
-  if (mJSAttributes & JSPROP_SETTER) {
-    aCallback(nsIProgrammingLanguage::JAVASCRIPT, mJSSetterObject, aClosure);
-  }
-}
diff --git a/content/xbl/src/nsXBLProtoImplProperty.h b/content/xbl/src/nsXBLProtoImplProperty.h
--- a/content/xbl/src/nsXBLProtoImplProperty.h
+++ b/content/xbl/src/nsXBLProtoImplProperty.h
@@ -71,8 +71,6 @@ public:
                                  const nsCString& aClassStr,
                                  void* aClassObject);
 
-  virtual void Trace(TraceCallback aCallback, void *aClosure) const;
-
 protected:
   union {
     // The raw text for the getter (prior to compilation).
diff --git a/content/xbl/src/nsXBLPrototypeBinding.cpp b/content/xbl/src/nsXBLPrototypeBinding.cpp
--- a/content/xbl/src/nsXBLPrototypeBinding.cpp
+++ b/content/xbl/src/nsXBLPrototypeBinding.cpp
@@ -245,18 +245,6 @@ PRUint32 nsXBLInsertionPointEntry::gRefC
 PRUint32 nsXBLInsertionPointEntry::gRefCnt = 0;
 nsFixedSizeAllocator* nsXBLInsertionPointEntry::kPool;
 
-NS_IMPL_CYCLE_COLLECTION_CLASS(nsXBLInsertionPointEntry)
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_NATIVE(nsXBLInsertionPointEntry)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mInsertionParent)
-  if (tmp->mDefaultContent) {
-    nsAutoScriptBlocker scriptBlocker;
-    // mDefaultContent is a sort of anonymous content within the XBL
-    // document, and we own and manage it.  Unhook it here, since we're going
-    // away.
-    tmp->mDefaultContent->UnbindFromTree();
-    tmp->mDefaultContent = nsnull;
-  }      
-NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_BEGIN(nsXBLInsertionPointEntry)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mInsertionParent)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mDefaultContent)
@@ -330,54 +318,6 @@ nsXBLPrototypeBinding::Init(const nsACSt
 
   SetBindingElement(aElement);
   return NS_OK;
-}
-
-PR_STATIC_CALLBACK(PRIntn)
-TraverseInsertionPoint(nsHashKey* aKey, void* aData, void* aClosure)
-{
-  nsCycleCollectionTraversalCallback &cb = 
-    *static_cast<nsCycleCollectionTraversalCallback*>(aClosure);
-  nsXBLInsertionPointEntry* entry =
-    static_cast<nsXBLInsertionPointEntry*>(aData);
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_PTR(entry,
-                                               nsXBLInsertionPointEntry,
-                                               "[insertion point table] value")
-  return kHashEnumerateNext;
-}
-
-PR_STATIC_CALLBACK(PRBool)
-TraverseBinding(nsHashKey *aKey, void *aData, void* aClosure)
-{
-  nsCycleCollectionTraversalCallback *cb = 
-    static_cast<nsCycleCollectionTraversalCallback*>(aClosure);
-  cb->NoteXPCOMChild(static_cast<nsISupports*>(aData));
-  return kHashEnumerateNext;
-}
-
-void
-nsXBLPrototypeBinding::Traverse(nsCycleCollectionTraversalCallback &cb) const
-{
-  cb.NoteXPCOMChild(mBinding);
-  if (mResources)
-    cb.NoteXPCOMChild(mResources->mLoader);
-  if (mInsertionPointTable)
-    mInsertionPointTable->Enumerate(TraverseInsertionPoint, &cb);
-  if (mInterfaceTable)
-    mInterfaceTable->Enumerate(TraverseBinding, &cb);
-}
-
-void
-nsXBLPrototypeBinding::UnlinkJSObjects()
-{
-  if (mImplementation)
-    mImplementation->UnlinkJSObjects();
-}
-
-void
-nsXBLPrototypeBinding::Trace(TraceCallback aCallback, void *aClosure) const
-{
-  if (mImplementation)
-    mImplementation->Trace(aCallback, aClosure);
 }
 
 void
diff --git a/content/xbl/src/nsXBLPrototypeBinding.h b/content/xbl/src/nsXBLPrototypeBinding.h
--- a/content/xbl/src/nsXBLPrototypeBinding.h
+++ b/content/xbl/src/nsXBLPrototypeBinding.h
@@ -196,10 +196,6 @@ public:
                 nsIXBLDocumentInfo* aInfo,
                 nsIContent* aElement);
 
-  void Traverse(nsCycleCollectionTraversalCallback &cb) const;
-  void UnlinkJSObjects();
-  void Trace(TraceCallback aCallback, void *aClosure) const;
-
 // Static members
   static PRUint32 gRefCnt;
  
diff --git a/content/xml/document/src/nsXMLContentSink.cpp b/content/xml/document/src/nsXMLContentSink.cpp
--- a/content/xml/document/src/nsXMLContentSink.cpp
+++ b/content/xml/document/src/nsXMLContentSink.cpp
@@ -190,18 +190,6 @@ NS_INTERFACE_MAP_END_INHERITING(nsConten
 
 NS_IMPL_ADDREF_INHERITED(nsXMLContentSink, nsContentSink)
 NS_IMPL_RELEASE_INHERITED(nsXMLContentSink, nsContentSink)
-
-NS_IMPL_CYCLE_COLLECTION_CLASS(nsXMLContentSink)
-
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsXMLContentSink,
-                                                  nsContentSink)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mCurrentHead)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_RAWPTR(mDocElement)
-  for (PRUint32 i = 0, count = tmp->mContentStack.Length(); i < count; i++) {
-    const StackNode& node = tmp->mContentStack.ElementAt(i);
-    cb.NoteXPCOMChild(node.mContent);
-  }
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 // nsIContentSink
 NS_IMETHODIMP
diff --git a/content/xslt/src/xpath/nsXPathResult.cpp b/content/xslt/src/xpath/nsXPathResult.cpp
--- a/content/xslt/src/xpath/nsXPathResult.cpp
+++ b/content/xslt/src/xpath/nsXPathResult.cpp
@@ -76,18 +76,6 @@ nsXPathResult::~nsXPathResult()
 {
     RemoveObserver();
 }
-
-NS_IMPL_CYCLE_COLLECTION_CLASS(nsXPathResult)
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsXPathResult)
-    {
-        tmp->RemoveObserver();
-    }
-    NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mDocument)
-NS_IMPL_CYCLE_COLLECTION_UNLINK_END
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsXPathResult)
-    NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mDocument)
-    NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMARRAY(mResultNodes)
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF_AMBIGUOUS(nsXPathResult, nsIDOMXPathResult)
 NS_IMPL_CYCLE_COLLECTING_RELEASE_AMBIGUOUS(nsXPathResult, nsIDOMXPathResult)
diff --git a/content/xslt/src/xslt/txMozillaXSLTProcessor.cpp b/content/xslt/src/xslt/txMozillaXSLTProcessor.cpp
--- a/content/xslt/src/xslt/txMozillaXSLTProcessor.cpp
+++ b/content/xslt/src/xslt/txMozillaXSLTProcessor.cpp
@@ -291,23 +291,6 @@ private:
 /**
  * txMozillaXSLTProcessor
  */
-
-NS_IMPL_CYCLE_COLLECTION_CLASS(txMozillaXSLTProcessor)
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(txMozillaXSLTProcessor)
-    NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mEmbeddedStylesheetRoot)
-    NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mSource)
-    NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mPrincipal)
-    tmp->mVariables.clear();
-NS_IMPL_CYCLE_COLLECTION_UNLINK_END
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(txMozillaXSLTProcessor)
-    NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mEmbeddedStylesheetRoot)
-    NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mSource)
-    NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mPrincipal)
-    txOwningExpandedNameMap<txIGlobalParameter>::iterator iter(tmp->mVariables);
-    while (iter.next()) {
-        cb.NoteXPCOMChild(static_cast<txVariable*>(iter.value())->getValue());
-    }
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF(txMozillaXSLTProcessor)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(txMozillaXSLTProcessor)
diff --git a/content/xul/content/src/nsXULElement.cpp b/content/xul/content/src/nsXULElement.cpp
--- a/content/xul/content/src/nsXULElement.cpp
+++ b/content/xul/content/src/nsXULElement.cpp
@@ -389,11 +389,6 @@ nsXULElement::QueryInterface(REFNSIID aI
 {
     NS_PRECONDITION(aInstancePtr, "null out param");
 
-    if (aIID.Equals(NS_GET_IID(nsXPCOMCycleCollectionParticipant))) {
-      *aInstancePtr = &NS_CYCLE_COLLECTION_NAME(nsXULElement);
-      return NS_OK;
-    }
-
     nsresult rv = nsGenericElement::QueryInterface(aIID, aInstancePtr);
     if (NS_SUCCEEDED(rv))
         return rv;
@@ -714,12 +709,6 @@ nsXULElement::PerformAccesskey(PRBool aK
 // nsIScriptEventHandlerOwner interface
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(nsScriptEventHandlerOwnerTearoff)
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsScriptEventHandlerOwnerTearoff)
-  tmp->mElement = nsnull;
-NS_IMPL_CYCLE_COLLECTION_UNLINK_END
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsScriptEventHandlerOwnerTearoff)
-  cb.NoteXPCOMChild(static_cast<nsIContent*>(tmp->mElement));
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsScriptEventHandlerOwnerTearoff)
   NS_INTERFACE_MAP_ENTRY(nsIScriptEventHandlerOwner)
@@ -821,15 +810,6 @@ nsScriptEventHandlerOwnerTearoff::Compil
         // take a copy of the event handler, and tell the language about it.
         if (aHandler) {
             NS_ASSERTION(!attr->mEventHandler, "Leaking handler.");
-
-            rv = nsContentUtils::HoldScriptObject(aContext->GetScriptTypeID(),
-                                                  elem,
-                                                  &NS_CYCLE_COLLECTION_NAME(nsXULPrototypeNode),
-                                                  aHandler,
-                                                  elem->mHoldsScriptObject);
-            if (NS_FAILED(rv)) return rv;
-
-            elem->mHoldsScriptObject = PR_TRUE;
         }
         attr->mEventHandler = (void *)aHandler;
     }
@@ -2562,62 +2542,6 @@ nsXULElement::RecompileScriptEventListen
     }
 }
 
-NS_IMPL_CYCLE_COLLECTION_CLASS(nsXULPrototypeNode)
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_NATIVE(nsXULPrototypeNode)
-    if (tmp->mType == nsXULPrototypeNode::eType_Element) {
-        static_cast<nsXULPrototypeElement*>(tmp)->Unlink();
-    }
-NS_IMPL_CYCLE_COLLECTION_UNLINK_END
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_BEGIN(nsXULPrototypeNode)
-    if (tmp->mType == nsXULPrototypeNode::eType_Element) {
-        nsXULPrototypeElement *elem =
-            static_cast<nsXULPrototypeElement*>(tmp);
-        cb.NoteXPCOMChild(elem->mNodeInfo);
-        PRUint32 i;
-        for (i = 0; i < elem->mNumAttributes; ++i) {
-            const nsAttrName& name = elem->mAttributes[i].mName;
-            if (!name.IsAtom())
-                cb.NoteXPCOMChild(name.NodeInfo());
-        }
-        for (i = 0; i < elem->mNumChildren; ++i) {
-            NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_PTR(elem->mChildren[i],
-                                                         nsXULPrototypeNode,
-                                                         "mChildren[i]")
-        }
-    }
-    NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
-NS_IMPL_CYCLE_COLLECTION_TRACE_NATIVE_BEGIN(nsXULPrototypeNode)
-    if (tmp->mType == nsXULPrototypeNode::eType_Element) {
-        nsXULPrototypeElement *elem =
-            static_cast<nsXULPrototypeElement*>(tmp);
-        if (elem->mHoldsScriptObject) {
-            PRUint32 i;
-            for (i = 0; i < elem->mNumAttributes; ++i) {
-                void *handler = elem->mAttributes[i].mEventHandler;
-                NS_IMPL_CYCLE_COLLECTION_TRACE_CALLBACK(elem->mScriptTypeID,
-                                                        handler)
-            }
-        }
-    }
-    else if (tmp->mType == nsXULPrototypeNode::eType_Script) {
-        nsXULPrototypeScript *script =
-            static_cast<nsXULPrototypeScript*>(tmp);
-        NS_IMPL_CYCLE_COLLECTION_TRACE_CALLBACK(script->mScriptObject.mLangID,
-                                                script->mScriptObject.mObject)
-    }
-NS_IMPL_CYCLE_COLLECTION_TRACE_END
-NS_IMPL_CYCLE_COLLECTION_ROOT_BEGIN_NATIVE(nsXULPrototypeNode, AddRef)
-    if (tmp->mType == nsXULPrototypeNode::eType_Element) {
-        static_cast<nsXULPrototypeElement*>(tmp)->UnlinkJSObjects();
-    }
-    else if (tmp->mType == nsXULPrototypeNode::eType_Script) {
-        static_cast<nsXULPrototypeScript*>(tmp)->UnlinkJSObjects();
-    }
-NS_IMPL_CYCLE_COLLECTION_ROOT_END
-//NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(nsXULPrototypeNode, AddRef)
-NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(nsXULPrototypeNode, Release)
-
 //----------------------------------------------------------------------
 //
 // nsXULPrototypeAttribute
@@ -2912,24 +2836,6 @@ nsXULPrototypeElement::SetAttrAt(PRUint3
     return NS_OK;
 }
 
-void
-nsXULPrototypeElement::UnlinkJSObjects()
-{
-    if (mHoldsScriptObject) {
-        nsContentUtils::DropScriptObjects(mScriptTypeID, this,
-                                          &NS_CYCLE_COLLECTION_NAME(nsXULPrototypeNode));
-        mHoldsScriptObject = PR_FALSE;
-    }
-}
-
-void
-nsXULPrototypeElement::Unlink()
-{
-    mNumAttributes = 0;
-    delete[] mAttributes;
-    mAttributes = nsnull;
-}
-
 //----------------------------------------------------------------------
 //
 // nsXULPrototypeScript
@@ -2952,7 +2858,6 @@ nsXULPrototypeScript::nsXULPrototypeScri
 
 nsXULPrototypeScript::~nsXULPrototypeScript()
 {
-    UnlinkJSObjects();
 }
 
 nsresult
diff --git a/content/xul/content/src/nsXULElement.h b/content/xul/content/src/nsXULElement.h
--- a/content/xul/content/src/nsXULElement.h
+++ b/content/xul/content/src/nsXULElement.h
@@ -247,7 +247,6 @@ public:
           mHasIdAttribute(PR_FALSE),
           mHasClassAttribute(PR_FALSE),
           mHasStyleAttribute(PR_FALSE),
-          mHoldsScriptObject(PR_FALSE),
           mScriptTypeID(nsIProgrammingLanguage::UNKNOWN)
     {
         NS_LOG_ADDREF(this, 1, ClassName(), ClassSize());
@@ -255,8 +254,6 @@ public:
 
     virtual ~nsXULPrototypeElement()
     {
-        UnlinkJSObjects();
-        Unlink();
         NS_ASSERTION(!mChildren && mNumChildren == 0,
                      "ReleaseSubtree not called");
     }
@@ -291,9 +288,6 @@ public:
 
     nsresult SetAttrAt(PRUint32 aPos, const nsAString& aValue, nsIURI* aDocumentURI);
 
-    void UnlinkJSObjects();
-    void Unlink();
-
     PRUint32                 mNumChildren;
     nsXULPrototypeNode**     mChildren;           // [OWNER]
 
@@ -305,7 +299,6 @@ public:
     PRPackedBool             mHasIdAttribute:1;
     PRPackedBool             mHasClassAttribute:1;
     PRPackedBool             mHasStyleAttribute:1;
-    PRPackedBool             mHoldsScriptObject:1;
 
     // The language ID can not be set on a per-node basis, but is tracked
     // so that the language ID from the originating root can be used
@@ -362,15 +355,6 @@ public:
                      nsIDocument* aDocument,
                      nsIScriptGlobalObjectOwner* aGlobalOwner);
 
-    void UnlinkJSObjects()
-    {
-        if (mScriptObject.mObject) {
-            nsContentUtils::DropScriptObjects(mScriptObject.mLangID, this,
-                                              &NS_CYCLE_COLLECTION_NAME(nsXULPrototypeNode));
-            mScriptObject.mObject = nsnull;
-        }
-    }
-
     void Set(nsScriptObjectHolder &aHolder)
     {
         NS_ASSERTION(mScriptObject.mLangID == aHolder.getScriptTypeID(),
@@ -383,13 +367,7 @@ public:
     {
         NS_ASSERTION(!mScriptObject.mObject, "Leaking script object.");
 
-        nsresult rv = nsContentUtils::HoldScriptObject(mScriptObject.mLangID,
-                                                       this,
-                                                       &NS_CYCLE_COLLECTION_NAME(nsXULPrototypeNode),
-                                                       aObject, PR_FALSE);
-        if (NS_SUCCEEDED(rv)) {
-            mScriptObject.mObject = aObject;
-        }
+        mScriptObject.mObject = aObject;
     }
 
     struct ScriptObjectHolder
diff --git a/content/xul/document/src/nsXULCommandDispatcher.cpp b/content/xul/document/src/nsXULCommandDispatcher.cpp
--- a/content/xul/document/src/nsXULCommandDispatcher.cpp
+++ b/content/xul/document/src/nsXULCommandDispatcher.cpp
@@ -104,19 +104,6 @@ NS_INTERFACE_MAP_END
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF(nsXULCommandDispatcher)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(nsXULCommandDispatcher)
-
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsXULCommandDispatcher)
-  tmp->Disconnect();
-NS_IMPL_CYCLE_COLLECTION_UNLINK_END
-
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsXULCommandDispatcher)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mDocument)
-  Updater* updater = tmp->mUpdaters;
-  while (updater) {
-    cb.NoteXPCOMChild(updater->mElement);
-    updater = updater->mNext;
-  }
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 void
 nsXULCommandDispatcher::Disconnect()
diff --git a/content/xul/document/src/nsXULControllers.cpp b/content/xul/document/src/nsXULControllers.cpp
--- a/content/xul/document/src/nsXULControllers.cpp
+++ b/content/xul/document/src/nsXULControllers.cpp
@@ -98,21 +98,6 @@ NS_NewXULControllers(nsISupports* aOuter
 }
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(nsXULControllers)
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsXULControllers)
-  tmp->DeleteControllers();
-NS_IMPL_CYCLE_COLLECTION_UNLINK_END
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsXULControllers)
-  {
-    PRUint32 i, count = tmp->mControllers.Count();
-    for (i = 0; i < count; ++i) {
-      nsXULControllerData*  controllerData =
-        static_cast<nsXULControllerData*>(tmp->mControllers[i]);
-      if (controllerData) {
-        cb.NoteXPCOMChild(controllerData->mController);
-      }
-    }
-  }
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsXULControllers)
   NS_INTERFACE_MAP_ENTRY(nsIControllers)
diff --git a/content/xul/document/src/nsXULDocument.cpp b/content/xul/document/src/nsXULDocument.cpp
--- a/content/xul/document/src/nsXULDocument.cpp
+++ b/content/xul/document/src/nsXULDocument.cpp
@@ -315,60 +315,6 @@ NS_NewXULDocument(nsIXULDocument** resul
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(nsXULDocument)
 
-static PLDHashOperator PR_CALLBACK
-TraverseTemplateBuilders(nsISupports* aKey, nsIXULTemplateBuilder* aData,
-                         void* aContext)
-{
-    nsCycleCollectionTraversalCallback *cb =
-        static_cast<nsCycleCollectionTraversalCallback*>(aContext);
-
-    cb->NoteXPCOMChild(aKey);
-    cb->NoteXPCOMChild(aData);
-
-    return PL_DHASH_NEXT;
-}
-
-static PLDHashOperator PR_CALLBACK
-TraverseObservers(nsIURI* aKey, nsIObserver* aData, void* aContext)
-{
-    nsCycleCollectionTraversalCallback *cb =
-        static_cast<nsCycleCollectionTraversalCallback*>(aContext);
-
-    cb->NoteXPCOMChild(aData);
-
-    return PL_DHASH_NEXT;
-}
-
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsXULDocument, nsXMLDocument)
-    // XXX tmp->mForwardReferences?
-    // XXX tmp->mContextStack?
-
-    // An element will only have a template builder as long as it's in the
-    // document, so we'll traverse the table here instead of from the element.
-    if (tmp->mTemplateBuilderTable)
-        tmp->mTemplateBuilderTable->EnumerateRead(TraverseTemplateBuilders, &cb);
-        
-    NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mCurrentPrototype,
-                                                     nsIScriptGlobalObjectOwner)
-    NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mMasterPrototype,
-                                                     nsIScriptGlobalObjectOwner)
-    NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mCommandDispatcher,
-                                                     nsIDOMXULCommandDispatcher)
-
-    PRUint32 i, count = tmp->mPrototypes.Length();
-    for (i = 0; i < count; ++i) {
-        cb.NoteXPCOMChild(static_cast<nsIScriptGlobalObjectOwner*>(tmp->mPrototypes[i]));
-    }
-
-    NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mTooltipNode)
-    NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mLocalStore)
-
-    if (tmp->mOverlayLoadObservers.IsInitialized())
-        tmp->mOverlayLoadObservers.EnumerateRead(TraverseObservers, &cb);
-    if (tmp->mPendingOverlayLoadNotifications.IsInitialized())
-        tmp->mPendingOverlayLoadNotifications.EnumerateRead(TraverseObservers, &cb);
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
-
 NS_IMPL_ADDREF_INHERITED(nsXULDocument, nsXMLDocument)
 NS_IMPL_RELEASE_INHERITED(nsXULDocument, nsXMLDocument)
 
diff --git a/content/xul/document/src/nsXULPrototypeDocument.cpp b/content/xul/document/src/nsXULPrototypeDocument.cpp
--- a/content/xul/document/src/nsXULPrototypeDocument.cpp
+++ b/content/xul/document/src/nsXULPrototypeDocument.cpp
@@ -196,13 +196,6 @@ nsXULPrototypeDocument::~nsXULPrototypeD
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(nsXULPrototypeDocument)
 NS_IMPL_CYCLE_COLLECTION_UNLINK_0(nsXULPrototypeDocument)
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsXULPrototypeDocument)
-    NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_MEMBER(mRoot,
-                                                    nsXULPrototypeElement)
-    cb.NoteXPCOMChild(static_cast<nsIScriptGlobalObject*>(tmp->mGlobalObject));
-    NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_MEMBER(mNodeInfoManager,
-                                                    nsNodeInfoManager)
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsXULPrototypeDocument)
     NS_INTERFACE_MAP_ENTRY(nsIScriptGlobalObjectOwner)
@@ -628,14 +621,6 @@ nsXULPDGlobalObject::~nsXULPDGlobalObjec
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(nsXULPDGlobalObject)
 NS_IMPL_CYCLE_COLLECTION_UNLINK_0(nsXULPDGlobalObject)
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsXULPDGlobalObject)
-  {
-    PRUint32 lang_index;
-    NS_STID_FOR_INDEX(lang_index) {
-      cb.NoteXPCOMChild(tmp->mScriptContexts[lang_index]);
-    }
-  }
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsXULPDGlobalObject)
   NS_INTERFACE_MAP_ENTRY(nsIScriptGlobalObject)
diff --git a/content/xul/templates/src/nsTemplateRule.h b/content/xul/templates/src/nsTemplateRule.h
--- a/content/xul/templates/src/nsTemplateRule.h
+++ b/content/xul/templates/src/nsTemplateRule.h
@@ -225,12 +225,6 @@ public:
     nsresult
     AddBindingsToQueryProcessor(nsIXULTemplateQueryProcessor* aProcessor);
 
-    void Traverse(nsCycleCollectionTraversalCallback &cb) const
-    {
-        cb.NoteXPCOMChild(mRuleNode);
-        cb.NoteXPCOMChild(mAction);
-    }
-
 protected:
 
     struct Binding {
diff --git a/content/xul/templates/src/nsXULContentBuilder.cpp b/content/xul/templates/src/nsXULContentBuilder.cpp
--- a/content/xul/templates/src/nsXULContentBuilder.cpp
+++ b/content/xul/templates/src/nsXULContentBuilder.cpp
@@ -147,11 +147,6 @@ protected:
     NS_NewXULContentBuilder(nsISupports* aOuter, REFNSIID aIID, void** aResult);
 
     nsXULContentBuilder();
-
-    void Traverse(nsCycleCollectionTraversalCallback &cb) const
-    {
-        mSortState.Traverse(cb);
-    }
 
     virtual void Uninit(PRBool aIsFinal);
 
diff --git a/content/xul/templates/src/nsXULSortService.h b/content/xul/templates/src/nsXULSortService.h
--- a/content/xul/templates/src/nsXULSortService.h
+++ b/content/xul/templates/src/nsXULSortService.h
@@ -91,11 +91,6 @@ struct nsSortState
   nsSortState()
     : initialized(PR_FALSE)
   {
-  }
-  void Traverse(nsCycleCollectionTraversalCallback &cb) const
-  {
-    cb.NoteXPCOMChild(processor);
-    cb.NoteXPCOMChild(lastContainer);
   }
 };
 
diff --git a/content/xul/templates/src/nsXULTemplateBuilder.cpp b/content/xul/templates/src/nsXULTemplateBuilder.cpp
--- a/content/xul/templates/src/nsXULTemplateBuilder.cpp
+++ b/content/xul/templates/src/nsXULTemplateBuilder.cpp
@@ -244,53 +244,12 @@ nsXULTemplateBuilder::Uninit(PRBool aIsF
     mQueriesCompiled = PR_FALSE;
 }
 
-static PLDHashOperator
-TraverseMatchList(nsISupports* aKey, nsTemplateMatch* aMatch, void* aContext)
-{
-    nsCycleCollectionTraversalCallback *cb =
-        static_cast<nsCycleCollectionTraversalCallback*>(aContext);
-
-    cb->NoteXPCOMChild(aKey);
-    nsTemplateMatch* match = aMatch;
-    while (match) {
-        cb->NoteXPCOMChild(match->GetContainer());
-        cb->NoteXPCOMChild(match->mResult);
-        match = match->mNext;
-    }
-
-    return PL_DHASH_NEXT;
-}
-
 NS_IMPL_CYCLE_COLLECTION_CLASS(nsXULTemplateBuilder)
 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsXULTemplateBuilder)
     NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mDataSource)
     NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mDB)
     NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mCompDB)
 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsXULTemplateBuilder)
-    NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mDataSource)
-    NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mDB)
-    NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mCompDB)
-    NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mRoot)
-    NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mRootResult)
-    NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMARRAY(mListeners)
-    NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mQueryProcessor)
-    if (tmp->mMatchMap.IsInitialized())
-        tmp->mMatchMap.EnumerateRead(TraverseMatchList, &cb);
-    {
-      PRUint32 i, count = tmp->mQuerySets.Length();
-      for (i = 0; i < count; ++i) {
-        nsTemplateQuerySet *set = tmp->mQuerySets[i];
-        cb.NoteXPCOMChild(set->mQueryNode);
-        cb.NoteXPCOMChild(set->mCompiledQuery);
-        PRUint16 j, rulesCount = set->RuleCount();
-        for (j = 0; j < rulesCount; ++j) {
-          set->GetRuleAt(j)->Traverse(cb);
-        }
-      }
-    }
-    tmp->Traverse(cb);
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF_AMBIGUOUS(nsXULTemplateBuilder,
                                           nsIXULTemplateBuilder)
diff --git a/content/xul/templates/src/nsXULTemplateQueryProcessorRDF.cpp b/content/xul/templates/src/nsXULTemplateQueryProcessorRDF.cpp
--- a/content/xul/templates/src/nsXULTemplateQueryProcessorRDF.cpp
+++ b/content/xul/templates/src/nsXULTemplateQueryProcessorRDF.cpp
@@ -87,66 +87,6 @@ nsIRDFResource*           nsXULTemplateQ
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(nsXULTemplateQueryProcessorRDF)
 NS_IMPL_CYCLE_COLLECTION_UNLINK_0(nsXULTemplateQueryProcessorRDF)
-
-PR_STATIC_CALLBACK(PLDHashOperator)
-BindingDependenciesTraverser(nsISupports* key,
-                             nsCOMArray<nsXULTemplateResultRDF>* array,
-                             void* userArg)
-{
-    nsCycleCollectionTraversalCallback *cb = 
-        static_cast<nsCycleCollectionTraversalCallback*>(userArg);
-
-    PRInt32 i, count = array->Count();
-    for (i = 0; i < count; ++i) {
-        cb->NoteXPCOMChild(array->ObjectAt(i));
-    }
-
-    return PL_DHASH_NEXT;
-}
-
-PR_STATIC_CALLBACK(PLDHashOperator)
-MemoryElementTraverser(const PRUint32& key,
-                       nsCOMArray<nsXULTemplateResultRDF>* array,
-                       void* userArg)
-{
-    nsCycleCollectionTraversalCallback *cb = 
-        static_cast<nsCycleCollectionTraversalCallback*>(userArg);
-
-    PRInt32 i, count = array->Count();
-    for (i = 0; i < count; ++i) {
-        cb->NoteXPCOMChild(array->ObjectAt(i));
-    }
-
-    return PL_DHASH_NEXT;
-}
-
-PR_STATIC_CALLBACK(PLDHashOperator)
-RuleToBindingTraverser(nsISupports* key, RDFBindingSet* binding, void* userArg)
-{
-    nsCycleCollectionTraversalCallback *cb = 
-        static_cast<nsCycleCollectionTraversalCallback*>(userArg);
-
-    cb->NoteXPCOMChild(key);
-
-    return PL_DHASH_NEXT;
-}
-
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsXULTemplateQueryProcessorRDF)
-    NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mDB)
-    NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mLastRef)
-    if (tmp->mBindingDependencies.IsInitialized()) {
-        tmp->mBindingDependencies.EnumerateRead(BindingDependenciesTraverser,
-                                                &cb);
-    }
-    if (tmp->mMemoryElementToResultMap.IsInitialized()) {
-        tmp->mMemoryElementToResultMap.EnumerateRead(MemoryElementTraverser,
-                                                     &cb);
-    }
-    if (tmp->mRuleToBindingsMap.IsInitialized()) {
-        tmp->mRuleToBindingsMap.EnumerateRead(RuleToBindingTraverser, &cb);
-    }
-    NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMARRAY(mQueries)
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF_AMBIGUOUS(nsXULTemplateQueryProcessorRDF,
                                           nsIXULTemplateQueryProcessor)
diff --git a/dom/src/base/nsGlobalWindow.cpp b/dom/src/base/nsGlobalWindow.cpp
--- a/dom/src/base/nsGlobalWindow.cpp
+++ b/dom/src/base/nsGlobalWindow.cpp
@@ -79,7 +79,6 @@
 #endif
 #include "nsContentCID.h"
 #include "nsLayoutStatics.h"
-#include "nsCycleCollector.h"
 #include "nsCCUncollectableMarker.h"
 
 // Interfaces Needed
@@ -752,10 +751,6 @@ nsGlobalWindow::~nsGlobalWindow()
 
   CleanUp();
 
-#ifdef DEBUG
-  nsCycleCollector_DEBUG_wasFreed(static_cast<nsIScriptGlobalObject*>(this));
-#endif
-
   delete mPendingStorageEvents;
 
   nsLayoutStatics::Release();
@@ -772,17 +767,6 @@ void
 void
 nsGlobalWindow::CleanupCachedXBLHandlers(nsGlobalWindow* aWindow)
 {
-  if (aWindow->mCachedXBLPrototypeHandlers.IsInitialized() &&
-      aWindow->mCachedXBLPrototypeHandlers.Count() > 0) {
-    aWindow->mCachedXBLPrototypeHandlers.Clear();
-
-    nsCOMPtr<nsISupports> supports;
-    aWindow->QueryInterface(NS_GET_IID(nsCycleCollectionISupports),
-                            getter_AddRefs(supports));
-    NS_ASSERTION(supports, "Failed to QI to nsCycleCollectionISupports?!");
-
-    nsContentUtils::DropJSObjects(supports);
-  }
 }
 
 void
@@ -805,9 +789,6 @@ nsGlobalWindow::CleanUp()
 
   mOpener = nsnull;             // Forces Release
   if (mContext) {
-#ifdef DEBUG
-    nsCycleCollector_DEBUG_shouldBeFreed(mContext);
-#endif
     mContext = nsnull;            // Forces Release
   }
   mChromeEventHandler = nsnull; // Forces Release
@@ -831,10 +812,6 @@ nsGlobalWindow::CleanUp()
   mArgumentsLast = nsnull;
 
   CleanupCachedXBLHandlers(this);
-
-#ifdef DEBUG
-  nsCycleCollector_DEBUG_shouldBeFreed(static_cast<nsIScriptGlobalObject*>(this));
-#endif
 }
 
 void
@@ -877,11 +854,6 @@ nsGlobalWindow::FreeInnerObjects(PRBool 
     // Remember the document's principal.
     mDocumentPrincipal = mDoc->NodePrincipal();
   }
-
-#ifdef DEBUG
-  if (mDocument)
-    nsCycleCollector_DEBUG_shouldBeFreed(nsCOMPtr<nsISupports>(do_QueryInterface(mDocument)));
-#endif
 
   // Make sure that this is called before we null out the document.
   NotifyDOMWindowDestroyed(this);
@@ -920,10 +892,6 @@ nsGlobalWindow::FreeInnerObjects(PRBool 
 #endif
 
   CleanupCachedXBLHandlers(this);
-
-#ifdef DEBUG
-  nsCycleCollector_DEBUG_shouldBeFreed(static_cast<nsIScriptGlobalObject*>(this));
-#endif
 }
 
 //*****************************************************************************
@@ -960,125 +928,6 @@ NS_IMPL_CYCLE_COLLECTING_RELEASE_AMBIGUO
 NS_IMPL_CYCLE_COLLECTING_RELEASE_AMBIGUOUS(nsGlobalWindow,
                                            nsIScriptGlobalObject)
 
-
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsGlobalWindow)
-  if (tmp->mDoc && nsCCUncollectableMarker::InGeneration(
-                     tmp->mDoc->GetMarkedCCGeneration())) {
-    return NS_OK;
-  }
-
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mContext)
-
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mControllers)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mArguments)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mArgumentsLast)
-
-  for (PRUint32 i = 0; i < NS_STID_ARRAY_UBOUND; ++i) {      
-    NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mScriptContexts[i])
-  }
-
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(gGlobalStorageList)
-
-  for (PRUint32 i = 0; i < NS_STID_ARRAY_UBOUND; ++i) {      
-    NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mInnerWindowHolders[i])
-  }
-
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOpenerScriptPrincipal)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mListenerManager)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mSessionStorage)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mApplicationCache)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mDocumentPrincipal)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mDoc)
-
-  // Traverse any associated preserved wrappers.
-  {
-    if (tmp->mDoc) {
-      cb.NoteXPCOMChild(tmp->mDoc->GetReference(tmp));
-    }
-  }
-
-  // Traverse stuff from nsPIDOMWindow
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mChromeEventHandler)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mDocument)
-
-#ifdef OJI
-  // Traverse mDummyJavaPluginOwner
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mDummyJavaPluginOwner)
-#endif
-
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
-
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsGlobalWindow)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mContext)
-
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mControllers)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mArguments)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mArgumentsLast)
-
-  for (PRUint32 i = 0; i < NS_STID_ARRAY_UBOUND; ++i) {      
-    NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mScriptContexts[i])
-  }
-
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(gGlobalStorageList)
-
-  for (PRUint32 i = 0; i < NS_STID_ARRAY_UBOUND; ++i) {      
-    NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mInnerWindowHolders[i])
-  }
-
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOpenerScriptPrincipal)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mListenerManager)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mSessionStorage)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mApplicationCache)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mDocumentPrincipal)
-
-  // Unlink any associated preserved wrapper.
-  if (tmp->mDoc) {
-    tmp->mDoc->RemoveReference(tmp);
-    NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mDoc)
-  }
-
-  // Unlink stuff from nsPIDOMWindow
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mChromeEventHandler)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mDocument)
-
-#ifdef OJI
-  // Unlink mDummyJavaPluginOwner
-  if (tmp->mDummyJavaPluginOwner) {
-    tmp->mDummyJavaPluginOwner->Destroy();
-    NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mDummyJavaPluginOwner)
-  }
-#endif
-
-NS_IMPL_CYCLE_COLLECTION_UNLINK_END
-
-struct TraceData
-{
-  TraceData(TraceCallback& aCallback, void* aClosure) :
-    callback(aCallback), closure(aClosure) {}
-
-  TraceCallback& callback;
-  void* closure;
-};
-
-PR_STATIC_CALLBACK(PLDHashOperator)
-TraceXBLHandlers(const void* aKey, void* aData, void* aClosure)
-{
-  TraceData* data = static_cast<TraceData*>(aClosure);
-  data->callback(nsIProgrammingLanguage::JAVASCRIPT, aData, data->closure);
-  return PL_DHASH_NEXT;
-}
-
-NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(nsGlobalWindow)
-  if (tmp->mCachedXBLPrototypeHandlers.IsInitialized()) {
-    TraceData data(aCallback, aClosure);
-    tmp->mCachedXBLPrototypeHandlers.EnumerateRead(TraceXBLHandlers, &data);
-  }
-NS_IMPL_CYCLE_COLLECTION_TRACE_END
-
-NS_IMPL_CYCLE_COLLECTION_ROOT_BEGIN(nsGlobalWindow)
-  nsGlobalWindow::CleanupCachedXBLHandlers(tmp);
-NS_IMPL_CYCLE_COLLECTION_ROOT_END
-
 //*****************************************************************************
 // nsGlobalWindow::nsIScriptGlobalObject
 //*****************************************************************************
@@ -2096,10 +1945,6 @@ nsGlobalWindow::SetDocShell(nsIDocShell*
         mScriptContexts[st_ndx] = nsnull;
       }
     }
-#ifdef DEBUG
-    nsCycleCollector_DEBUG_shouldBeFreed(mContext);
-    nsCycleCollector_DEBUG_shouldBeFreed(static_cast<nsIScriptGlobalObject*>(this));
-#endif
     mContext = nsnull; // we nuked it above also
   }
 
@@ -5864,26 +5709,6 @@ nsGlobalWindow::CacheXBLPrototypeHandler
     return;
   }
 
-  if (!mCachedXBLPrototypeHandlers.Count()) {
-    // Can't use macros to get the participant because nsGlobalChromeWindow also
-    // runs through this code. Use QueryInterface to get the correct objects.
-    nsXPCOMCycleCollectionParticipant* participant;
-    CallQueryInterface(this, &participant);
-    NS_ASSERTION(participant,
-                 "Failed to QI to nsXPCOMCycleCollectionParticipant!");
-
-    nsCOMPtr<nsISupports> thisSupports;
-    QueryInterface(NS_GET_IID(nsCycleCollectionISupports),
-                   getter_AddRefs(thisSupports));
-    NS_ASSERTION(thisSupports, "Failed to QI to nsCycleCollectionISupports!");
-
-    nsresult rv = nsContentUtils::HoldJSObjects(thisSupports, participant);
-    if (NS_FAILED(rv)) {
-      NS_ERROR("nsContentUtils::HoldJSObjects failed!");
-      return;
-    }
-  }
-
   mCachedXBLPrototypeHandlers.Put(aKey, aHandler);
 }
 
diff --git a/dom/src/base/nsJSEnvironment.cpp b/dom/src/base/nsJSEnvironment.cpp
--- a/dom/src/base/nsJSEnvironment.cpp
+++ b/dom/src/base/nsJSEnvironment.cpp
@@ -79,7 +79,6 @@
 #include "jscntxt.h"
 #include "nsEventDispatcher.h"
 #include "nsIContent.h"
-#include "nsCycleCollector.h"
 #include "nsNetUtil.h"
 
 // For locale aware string methods
@@ -177,10 +176,6 @@ static PRUint32 sCCollectCount;
 static PRUint32 sCCollectCount;
 static PRBool sUserIsActive;
 static PRTime sPreviousCCTime;
-static PRUint32 sCollectedObjectsCounts;
-static PRUint32 sGCCount;
-static PRUint32 sCCSuspectChanges;
-static PRUint32 sCCSuspectedCount;
 static nsITimer *sGCTimer;
 static PRBool sReadyForGC;
 
@@ -258,7 +253,6 @@ nsUserActivityObserver::Observe(nsISuppo
     // we can reset the counter.
     mUserActivityCounter = 0;
   }
-  PRBool higherProbability = PR_FALSE;
   ++mUserActivityCounter;
   if (!strcmp(aTopic, "user-interaction-inactive")) {
 #ifdef DEBUG_smaug
@@ -271,13 +265,11 @@ nsUserActivityObserver::Observe(nsISuppo
         return NS_OK;
       }
     }
-    higherProbability = (mUserActivityCounter > NS_CC_SOFT_LIMIT_INACTIVE);
   } else if (!strcmp(aTopic, "user-interaction-active")) {
 #ifdef DEBUG_smaug
     printf("user-interaction-active\n");
 #endif
     sUserIsActive = PR_TRUE;
-    higherProbability = (mUserActivityCounter > NS_CC_SOFT_LIMIT_ACTIVE);
   } else if (!strcmp(aTopic, "xpcom-shutdown")) {
     nsCOMPtr<nsIObserverService> obs =
       do_GetService("@mozilla.org/observer-service;1");
@@ -288,7 +280,7 @@ nsUserActivityObserver::Observe(nsISuppo
     }
     return NS_OK;
   }
-  nsJSContext::MaybeCC(higherProbability);
+  nsJSContext::MaybeCC();
   return NS_OK;
 }
 
@@ -1172,9 +1164,6 @@ nsJSContext::nsJSContext(JSRuntime *aRun
 
 nsJSContext::~nsJSContext()
 {
-#ifdef DEBUG
-  nsCycleCollector_DEBUG_wasFreed(static_cast<nsIScriptContext*>(this));
-#endif
   NS_PRECONDITION(!mTerminations, "Shouldn't have termination funcs by now");
 
   Unlink();
@@ -1226,16 +1215,6 @@ nsJSContext::Unlink()
 }
 
 // QueryInterface implementation for nsJSContext
-NS_IMPL_CYCLE_COLLECTION_CLASS(nsJSContext)
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsJSContext)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mGlobalWrapperRef)
-  tmp->Unlink();
-  tmp->mIsInitialized = PR_FALSE;
-NS_IMPL_CYCLE_COLLECTION_UNLINK_END
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsJSContext)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mGlobalWrapperRef)
-  nsContentUtils::XPConnect()->NoteJSContext(tmp->mContext, cb);
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsJSContext)
   NS_INTERFACE_MAP_ENTRY(nsIScriptContext)
@@ -3331,77 +3310,15 @@ nsJSContext::CC()
 nsJSContext::CC()
 {
   ++sCCollectCount;
-#ifdef DEBUG_smaug
-  printf("Will run cycle collector (%i), %lldms since previous.\n",
-         sCCollectCount, (PR_Now() - sPreviousCCTime) / PR_USEC_PER_MSEC);
-#endif
-  sPreviousCCTime = PR_Now();
-  sDelayedCCollectCount = 0;
-  sGCCount = 0;
-  sCCSuspectChanges = 0;
-  // nsCycleCollector_collect() will run a ::JS_GC() indirectly, so
-  // we do not explicitly call ::JS_GC() here.
-  sCollectedObjectsCounts = nsCycleCollector_collect();
-  sCCSuspectedCount = nsCycleCollector_suspectedCount();
-#ifdef DEBUG_smaug
-  printf("Collected %u objects, %u suspected objects\n",
-         sCollectedObjectsCounts, sCCSuspectedCount);
-#endif
+
+  // add future call to NS_GetGC()->CollectFromRequest();
 }
 
 //static
-PRBool
-nsJSContext::MaybeCC(PRBool aHigherProbability)
+void
+nsJSContext::MaybeCC()
 {
-  ++sDelayedCCollectCount;
-
-  // Don't check suspected count if CC will be called anyway.
-  if (sCCSuspectChanges <= NS_MIN_SUSPECT_CHANGES ||
-      sGCCount <= NS_MAX_GC_COUNT) {
-#ifdef DEBUG_smaug
-    PRTime now = PR_Now();
-#endif
-    PRUint32 suspected = nsCycleCollector_suspectedCount();
-#ifdef DEBUG_smaug
-    printf("%u suspected objects (%lldms), sCCSuspectedCount %u\n",
-            suspected, (PR_Now() - now) / PR_USEC_PER_MSEC,
-            sCCSuspectedCount);
-#endif
-    // Update only when suspected count has increased.
-    if (suspected > sCCSuspectedCount) {
-      sCCSuspectChanges += (suspected - sCCSuspectedCount);
-      sCCSuspectedCount = suspected;
-    }
-  }
-#ifdef DEBUG_smaug
-  printf("sCCSuspectChanges %u, sGCCount %u\n",
-         sCCSuspectChanges, sGCCount);
-#endif
-
-  // Increase the probability also if the previous call to cycle collector
-  // collected something.
-  if (aHigherProbability ||
-      sCollectedObjectsCounts > NS_COLLECTED_OBJECTS_LIMIT) {
-    sDelayedCCollectCount *= NS_PROBABILITY_MULTIPLIER;
-  }
-
-  if (!sGCTimer &&
-      (sDelayedCCollectCount > NS_MAX_DELAYED_CCOLLECT) &&
-      ((sCCSuspectChanges > NS_MIN_SUSPECT_CHANGES &&
-        sGCCount > NS_MAX_GC_COUNT) ||
-       (sCCSuspectChanges > NS_MAX_SUSPECT_CHANGES))) {
-    if ((PR_Now() - sPreviousCCTime) >=
-        PRTime(NS_MIN_CC_INTERVAL * PR_USEC_PER_MSEC)) {
-      nsJSContext::CC();
-      return PR_TRUE;
-    }
-#ifdef DEBUG_smaug
-    else {
-      printf("Running CC was delayed because of NS_MIN_CC_INTERVAL.\n");
-    }
-#endif
-  }
-  return PR_FALSE;
+  // add future call to NS_GetGC()->MaybeGC(true);
 }
 
 //static
@@ -3409,7 +3326,7 @@ nsJSContext::CCIfUserInactive()
 nsJSContext::CCIfUserInactive()
 {
   if (sUserIsActive) {
-    MaybeCC(PR_TRUE);
+    MaybeCC();
   } else {
     CC();
   }
@@ -3612,10 +3529,6 @@ nsJSRuntime::Startup()
   sCCollectCount = 0;
   sUserIsActive = PR_FALSE;
   sPreviousCCTime = 0;
-  sCollectedObjectsCounts = 0;
-  sGCCount = 0;
-  sCCSuspectChanges = 0;
-  sCCSuspectedCount = 0;
   sGCTimer = nsnull;
   sReadyForGC = PR_FALSE;
   sLoadInProgressGCTimer = PR_FALSE;
@@ -3930,27 +3843,6 @@ nsJSArgArray::ReleaseJSObjects()
 }
 
 // QueryInterface implementation for nsJSArgArray
-NS_IMPL_CYCLE_COLLECTION_CLASS(nsJSArgArray)
-NS_IMPL_CYCLE_COLLECTION_ROOT_BEGIN(nsJSArgArray)
-  tmp->ReleaseJSObjects();
-NS_IMPL_CYCLE_COLLECTION_ROOT_END
-NS_IMPL_CYCLE_COLLECTION_UNLINK_0(nsJSArgArray)
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsJSArgArray)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
-
-NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(nsJSArgArray)
-  jsval *argv = tmp->mArgv;
-  if (argv) {
-    jsval *end;
-    for (end = argv + tmp->mArgc; argv < end; ++argv) {
-      if (JSVAL_IS_GCTHING(*argv))
-        NS_IMPL_CYCLE_COLLECTION_TRACE_CALLBACK(JAVASCRIPT,
-                                                JSVAL_TO_GCTHING(*argv))
-    }
-  }
-NS_IMPL_CYCLE_COLLECTION_TRACE_END
-
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsJSArgArray)
   NS_INTERFACE_MAP_ENTRY(nsIArray)
   NS_INTERFACE_MAP_ENTRY(nsIJSArgArray)
diff --git a/dom/src/base/nsJSEnvironment.h b/dom/src/base/nsJSEnvironment.h
--- a/dom/src/base/nsJSEnvironment.h
+++ b/dom/src/base/nsJSEnvironment.h
@@ -179,20 +179,8 @@ public:
   // that MaybeCC uses.
   static void CC();
 
-  // MaybeCC calls cycle collector if certain conditions are fulfilled.
-  // The conditions are:
-  // - The timer related to page load (sGCTimer) must not be active.
-  // - At least NS_MIN_CC_INTERVAL milliseconds must have elapsed since the
-  //   previous cycle collector call.
-  // - Certain number of MaybeCC calls have occurred.
-  //   The number of needed MaybeCC calls depends on the aHigherProbability
-  //   parameter. If the parameter is true, probability for calling cycle
-  //   collector rises increasingly. If the parameter is all the time false,
-  //   at least NS_MAX_DELAYED_CCOLLECT MaybeCC calls are needed.
-  //   If the previous call to cycle collector did collect something,
-  //   MaybeCC works effectively as if aHigherProbability was true.
-  // @return PR_TRUE if cycle collector was called.
-  static PRBool MaybeCC(PRBool aHigherProbability);
+  // MaybeCC calls cycle collector if internal thresholds have been reached
+  static void MaybeCC();
 
   // Calls CC() if user is currently inactive, otherwise MaybeCC(PR_TRUE)
   static void CCIfUserInactive();
diff --git a/dom/src/base/nsJSTimeoutHandler.cpp b/dom/src/base/nsJSTimeoutHandler.cpp
--- a/dom/src/base/nsJSTimeoutHandler.cpp
+++ b/dom/src/base/nsJSTimeoutHandler.cpp
@@ -112,21 +112,6 @@ private:
 
 // nsJSScriptTimeoutHandler
 // QueryInterface implementation for nsJSScriptTimeoutHandler
-NS_IMPL_CYCLE_COLLECTION_CLASS(nsJSScriptTimeoutHandler)
-NS_IMPL_CYCLE_COLLECTION_ROOT_BEGIN(nsJSScriptTimeoutHandler)
-  tmp->ReleaseJSObjects();
-NS_IMPL_CYCLE_COLLECTION_ROOT_END
-NS_IMPL_CYCLE_COLLECTION_UNLINK_0(nsJSScriptTimeoutHandler)
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsJSScriptTimeoutHandler)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mContext)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mArgv)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
-
-NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(nsJSScriptTimeoutHandler)
-  NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mExpr)
-  NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mFunObj)
-NS_IMPL_CYCLE_COLLECTION_TRACE_END
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsJSScriptTimeoutHandler)
   NS_INTERFACE_MAP_ENTRY(nsIScriptTimeoutHandler)
diff --git a/dom/src/base/nsWindowRoot.cpp b/dom/src/base/nsWindowRoot.cpp
--- a/dom/src/base/nsWindowRoot.cpp
+++ b/dom/src/base/nsWindowRoot.cpp
@@ -67,10 +67,10 @@ nsWindowRoot::nsWindowRoot(nsIDOMWindow*
   nsFocusController::Create(getter_AddRefs(mFocusController));
 
   nsCOMPtr<nsIDOMFocusListener> focusListener(do_QueryInterface(mFocusController));
-  mRefCnt.incr(static_cast<nsIDOMEventTarget*>(this));
+  ++mRefCnt;
   AddEventListener(NS_LITERAL_STRING("focus"), focusListener, PR_TRUE);
   AddEventListener(NS_LITERAL_STRING("blur"), focusListener, PR_TRUE);
-  mRefCnt.decr(static_cast<nsIDOMEventTarget*>(this));
+  --mRefCnt;
 }
 
 nsWindowRoot::~nsWindowRoot()
diff --git a/dom/src/events/nsJSEventListener.cpp b/dom/src/events/nsJSEventListener.cpp
--- a/dom/src/events/nsJSEventListener.cpp
+++ b/dom/src/events/nsJSEventListener.cpp
@@ -81,47 +81,11 @@ nsJSEventListener::nsJSEventListener(nsI
   // until we are done with it.
   NS_ASSERTION(aScopeObject && aContext,
                "EventListener with no context or scope?");
-  nsContentUtils::HoldScriptObject(aContext->GetScriptTypeID(), this,
-                                   &NS_CYCLE_COLLECTION_NAME(nsJSEventListener),
-                                   aScopeObject, PR_FALSE);
 }
 
 nsJSEventListener::~nsJSEventListener() 
 {
-  if (mContext)
-    nsContentUtils::DropScriptObjects(mContext->GetScriptTypeID(), this,
-                                &NS_CYCLE_COLLECTION_NAME(nsJSEventListener));
 }
-
-NS_IMPL_CYCLE_COLLECTION_CLASS(nsJSEventListener)
-NS_IMPL_CYCLE_COLLECTION_ROOT_BEGIN(nsJSEventListener)
-  if (tmp->mContext &&
-      tmp->mContext->GetScriptTypeID() == nsIProgrammingLanguage::JAVASCRIPT) {
-    NS_DROP_JS_OBJECTS(tmp, nsJSEventListener);
-    tmp->mScopeObject = nsnull;
-  }
-NS_IMPL_CYCLE_COLLECTION_ROOT_END
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsJSEventListener)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mTarget)
-  if (tmp->mContext) {
-    if (tmp->mScopeObject) {
-      nsContentUtils::DropScriptObjects(tmp->mContext->GetScriptTypeID(), tmp,
-                                  &NS_CYCLE_COLLECTION_NAME(nsJSEventListener));
-      tmp->mScopeObject = nsnull;
-    }
-    NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mContext)
-  }
-NS_IMPL_CYCLE_COLLECTION_UNLINK_END
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsJSEventListener)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mTarget)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mContext)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
-
-NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(nsJSEventListener)
-  NS_IMPL_CYCLE_COLLECTION_TRACE_MEMBER_CALLBACK(tmp->mContext->GetScriptTypeID(),
-                                                 mScopeObject)
-NS_IMPL_CYCLE_COLLECTION_TRACE_END
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsJSEventListener)
   NS_INTERFACE_MAP_ENTRY(nsIDOMEventListener)
diff --git a/dom/src/offline/nsDOMOfflineResourceList.cpp b/dom/src/offline/nsDOMOfflineResourceList.cpp
--- a/dom/src/offline/nsDOMOfflineResourceList.cpp
+++ b/dom/src/offline/nsDOMOfflineResourceList.cpp
@@ -80,66 +80,6 @@ static PRUint32 gCachedKeysCount = 0;
 //
 // nsDOMOfflineResourceList
 //
-
-NS_IMPL_CYCLE_COLLECTION_CLASS(nsDOMOfflineResourceList)
-
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsDOMOfflineResourceList)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mWindow)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mCacheSession)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mCacheUpdate)
-
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMARRAY(mCheckingListeners)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMARRAY(mErrorListeners)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMARRAY(mNoUpdateListeners)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMARRAY(mDownloadingListeners)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMARRAY(mProgressListeners)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMARRAY(mCachedListeners)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMARRAY(mUpdateReadyListeners)
-
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOnCheckingListener)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOnErrorListener)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOnNoUpdateListener)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOnDownloadingListener)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOnProgressListener)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOnCachedListener)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOnUpdateReadyListener)
-
-  for (PRUint32 i = 0; i < tmp->mPendingEvents.Length(); i++) {
-    NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mPendingEvents[i].event);
-    NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mPendingEvents[i].listener);
-    NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMARRAY(mPendingEvents[i].listeners);
-  }
-
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
-
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsDOMOfflineResourceList)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mWindow)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mCacheSession)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mCacheUpdate)
-
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMARRAY(mCheckingListeners)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMARRAY(mErrorListeners)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMARRAY(mNoUpdateListeners)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMARRAY(mDownloadingListeners)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMARRAY(mProgressListeners)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMARRAY(mCachedListeners)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMARRAY(mUpdateReadyListeners)
-
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOnCheckingListener)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOnErrorListener)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOnNoUpdateListener)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOnDownloadingListener)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOnProgressListener)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOnCachedListener)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOnUpdateReadyListener)
-
-  for (PRUint32 i = 0; i < tmp->mPendingEvents.Length(); i++) {
-    NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mPendingEvents[i].event);
-    NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mPendingEvents[i].listener);
-    NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMARRAY(mPendingEvents[i].listeners);
-  }
-
-NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsDOMOfflineResourceList)
   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMOfflineResourceList)
diff --git a/dom/src/storage/nsDOMStorage.cpp b/dom/src/storage/nsDOMStorage.cpp
--- a/dom/src/storage/nsDOMStorage.cpp
+++ b/dom/src/storage/nsDOMStorage.cpp
@@ -363,29 +363,6 @@ nsDOMStorageEntry::~nsDOMStorageEntry()
 nsDOMStorageEntry::~nsDOMStorageEntry()
 {
 }
-
-PLDHashOperator PR_CALLBACK
-SessionStorageTraverser(nsSessionStorageEntry* aEntry, void* userArg) {
-  nsCycleCollectionTraversalCallback *cb = 
-    static_cast<nsCycleCollectionTraversalCallback*>(userArg);
-
-  cb->NoteXPCOMChild((nsIDOMStorageItem *) aEntry->mItem);
-
-  return PL_DHASH_NEXT;
-}
-
-NS_IMPL_CYCLE_COLLECTION_CLASS(nsDOMStorage)
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsDOMStorage)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mURI)
-NS_IMPL_CYCLE_COLLECTION_UNLINK_END
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsDOMStorage)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mURI)
-  {
-    if (tmp->mItems.IsInitialized()) {
-      tmp->mItems.EnumerateEntries(SessionStorageTraverser, &cb);
-    }
-  }
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF_AMBIGUOUS(nsDOMStorage, nsIDOMStorage)
 NS_IMPL_CYCLE_COLLECTING_RELEASE_AMBIGUOUS(nsDOMStorage, nsIDOMStorage)
@@ -1211,18 +1188,6 @@ NS_NewDOMStorageList(nsIDOMStorageList**
 // nsDOMStorageItem
 //
 
-NS_IMPL_CYCLE_COLLECTION_CLASS(nsDOMStorageItem)
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsDOMStorageItem)
-  {
-    tmp->mStorage = nsnull;
-  }
-NS_IMPL_CYCLE_COLLECTION_UNLINK_END
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsDOMStorageItem)
-  {
-    cb.NoteXPCOMChild((nsIDOMStorage*) tmp->mStorage);
-  }
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
-
 NS_IMPL_CYCLE_COLLECTING_ADDREF_AMBIGUOUS(nsDOMStorageItem, nsIDOMStorageItem)
 NS_IMPL_CYCLE_COLLECTING_RELEASE_AMBIGUOUS(nsDOMStorageItem, nsIDOMStorageItem)
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsDOMStorageItem)
diff --git a/embedding/components/commandhandler/src/nsCommandManager.cpp b/embedding/components/commandhandler/src/nsCommandManager.cpp
--- a/embedding/components/commandhandler/src/nsCommandManager.cpp
+++ b/embedding/components/commandhandler/src/nsCommandManager.cpp
@@ -68,30 +68,6 @@ nsCommandManager::~nsCommandManager()
 {
   /* destructor code */
 }
-
-
-PR_STATIC_CALLBACK(PLDHashOperator)
-TraverseCommandObservers(const char* aKey, nsCOMArray<nsIObserver>* aObservers,
-                         void* aClosure)
-{
-  nsCycleCollectionTraversalCallback *cb = 
-    static_cast<nsCycleCollectionTraversalCallback*>(aClosure);
-
-  PRInt32 i, numItems = aObservers->Count();
-  for (i = 0; i < numItems; ++i) {
-    cb->NoteXPCOMChild(aObservers->ObjectAt(i));
-  }
-
-  return PL_DHASH_NEXT;
-}
-
-NS_IMPL_CYCLE_COLLECTION_CLASS(nsCommandManager)
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsCommandManager)
-  tmp->mObserversTable.Clear();
-NS_IMPL_CYCLE_COLLECTION_UNLINK_END
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsCommandManager)
-  tmp->mObserversTable.EnumerateRead(TraverseCommandObservers, &cb);
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF_AMBIGUOUS(nsCommandManager, nsICommandManager)
 NS_IMPL_CYCLE_COLLECTING_RELEASE_AMBIGUOUS(nsCommandManager, nsICommandManager)
diff --git a/js/src/xpconnect/idl/nsIXPConnect.idl b/js/src/xpconnect/idl/nsIXPConnect.idl
--- a/js/src/xpconnect/idl/nsIXPConnect.idl
+++ b/js/src/xpconnect/idl/nsIXPConnect.idl
@@ -405,7 +405,7 @@ interface nsIXPCFunctionThisTranslator :
     { 0xbd, 0xd6, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } }
 %}
 
-[uuid(c1d4a482-1beb-4c82-9c0b-d2ab93acc7ef)]
+[uuid(ccc89d14-104a-475e-af6f-eb83acd15bcf)]
 interface nsIXPConnect : nsISupports
 {
 %{ C++
@@ -709,28 +709,6 @@ interface nsIXPConnect : nsISupports
                                in PRUint32 aWay);
 
     /**
-     * Root JS objects held by aHolder.
-     * @param aHolder The object that hold the JS objects that should be rooted.
-     * @param aTrace The tracer for aHolder.
-     */
-    [noscript] void addJSHolder(in voidPtr aHolder,
-                                in nsScriptObjectTracerPtr aTracer);
-
-    /**
-     * Stop rooting the JS objects held by aHolder.
-     * @param aHolder The object that hold the rooted JS objects.
-     */
-    [noscript] void removeJSHolder(in voidPtr aHolder);
-
-    /**
-     * Note aJSContext as a child to the cycle collector.
-     * @param aJSContext The JSContext to note.
-     * @param aCb The cycle collection traversal callback.
-     */
-    [noscript,notxpcom] void noteJSContext(in JSContextPtr aJSContext,
-                                           in nsCCTraversalCallbackRef aCb);
-
-    /**
      * Get the JSClass and JSGetObjectOps pointers to use for
      * identifying JSObjects that hold nsIXPConnectWrappedNative
      * pointers in their private date. See IS_WRAPPER_CLASS in
diff --git a/js/src/xpconnect/src/nsXPConnect.cpp b/js/src/xpconnect/src/nsXPConnect.cpp
--- a/js/src/xpconnect/src/nsXPConnect.cpp
+++ b/js/src/xpconnect/src/nsXPConnect.cpp
@@ -81,20 +81,13 @@ nsXPConnect::nsXPConnect()
         mContextStack(nsnull),
         mDefaultSecurityManager(nsnull),
         mDefaultSecurityManagerFlags(0),
-        mShuttingDown(JS_FALSE),
-        mCycleCollectionContext(nsnull),
-        mCycleCollecting(PR_FALSE)
+        mShuttingDown(JS_FALSE)
 {
     // Ignore the result. If the runtime service is not ready to rumble
     // then we'll set this up later as needed.
     CreateRuntime();
 
     CallGetService(XPC_CONTEXT_STACK_CONTRACTID, &mContextStack);
-
-    nsCycleCollector_registerRuntime(nsIProgrammingLanguage::JAVASCRIPT, this);
-#ifdef DEBUG_CC
-    mJSRoots.ops = nsnull;
-#endif
 
 #ifdef XPC_TOOLS_SUPPORT
   {
@@ -127,10 +120,6 @@ nsXPConnect::nsXPConnect()
 
 nsXPConnect::~nsXPConnect()
 {
-    NS_ASSERTION(!mCycleCollectionContext,
-                 "Didn't call FinishCycleCollection?");
-    nsCycleCollector_forgetRuntime(nsIProgrammingLanguage::JAVASCRIPT);
-
     JSContext *cx = nsnull;
     if (mRuntime) {
         // Create our own JSContext rather than an XPCCallContext, since
@@ -415,638 +404,6 @@ nsXPConnect::GetInfoForName(const char *
 {
     return FindInfo(NameTester, name, mInterfaceInfoManager, info);
 }
-
-static JSGCCallback gOldJSGCCallback;
-// Whether cycle collection was run.
-static PRBool gDidCollection;
-// Whether starting cycle collection was successful.
-static PRBool gInCollection;
-// Whether cycle collection collected anything.
-static PRBool gCollected;
-
-JS_STATIC_DLL_CALLBACK(JSBool)
-XPCCycleCollectGCCallback(JSContext *cx, JSGCStatus status)
-{
-    // Launch the cycle collector.
-    if(status == JSGC_MARK_END)
-    {
-        // This is the hook between marking and sweeping in the JS GC. Do cycle
-        // collection.
-        if(!gDidCollection)
-        {
-            NS_ASSERTION(!gInCollection, "Recursing?");
-
-            gDidCollection = PR_TRUE;
-            gInCollection = nsCycleCollector_beginCollection();
-        }
-
-        // Mark JS objects that are held by XPCOM objects that are in cycles
-        // that will not be collected.
-        nsXPConnect::GetRuntime()->
-            TraceXPConnectRoots(cx->runtime->gc->GetTracer());
-    }
-    else if(status == JSGC_END)
-    {
-        if(gInCollection)
-        {
-            gInCollection = PR_FALSE;
-            gCollected = nsCycleCollector_finishCollection();
-        }
-        nsXPConnect::GetRuntime()->RestoreContextGlobals();
-    }
-
-    PRBool ok = gOldJSGCCallback ? gOldJSGCCallback(cx, status) : JS_TRUE;
-
-    if(status == JSGC_BEGIN)
-        nsXPConnect::GetRuntime()->UnsetContextGlobals();
-
-    return ok;
-}
-
-PRBool
-nsXPConnect::Collect()
-{
-    // We're dividing JS objects into 2 categories:
-    //
-    // 1. "real" roots, held by the JS engine itself or rooted through the root
-    //    and lock JS APIs. Roots from this category are considered black in the
-    //    cycle collector, any cycle they participate in is uncollectable.
-    //
-    // 2. roots held by C++ objects that participate in cycle collection,
-    //    held by XPConnect (see XPCJSRuntime::TraceXPConnectRoots). Roots from
-    //    this category are considered grey in the cycle collector, their final
-    //    color depends on the objects that hold them. It is thus very important
-    //    to always traverse the objects that hold these objects during cycle
-    //    collection (see XPCJSRuntime::AddXPConnectRoots).
-    //
-    // Note that if a root is in both categories it is the fact that it is in
-    // category 1 that takes precedence, so it will be considered black.
-    //
-    //
-    // We split up garbage collection into 3 phases (1, 3 and 4) and do cycle
-    // collection between the first 2 phases of garbage collection:
-    //
-    // 1. marking of the roots in category 1 by having the JS GC do its marking
-    // 2. cycle collection
-    // 3. marking of the roots in category 2 by
-    //    XPCJSRuntime::TraceXPConnectRoots 
-    // 4. sweeping of unmarked JS objects
-    //
-    // During cycle collection, marked JS objects (and the objects they hold)
-    // will be colored black. White objects holding roots from category 2 will
-    // be forgotten by XPConnect (in the unlink callback of the white objects).
-    // During phase 3 we'll only mark black objects holding JS objects (white
-    // objects were forgotten) and white JS objects will be swept during
-    // phase 4.
-    // Because splitting up the JS GC itself is hard, we're going to use a GC
-    // callback to do phase 2 and 3 after phase 1 has ended (see
-    // XPCCycleCollectGCCallback).
-    //
-    // If DEBUG_CC is not defined the cycle collector will not traverse  roots
-    // from category 1 or any JS objects held by them. Any JS objects they hold
-    // will already be marked by the JS GC and will thus be colored black
-    // themselves. Any C++ objects they hold will have a missing (untraversed)
-    // edge from the JS object to the C++ object and so it will be marked black
-    // too. This decreases the number of objects that the cycle collector has to
-    // deal with.
-    // To improve debugging, if DEBUG_CC is defined all JS objects are
-    // traversed.
-
-    XPCCallContext cycleCollectionContext(NATIVE_CALLER);
-    if(!cycleCollectionContext.IsValid())
-    {
-        return PR_FALSE;
-    }
-
-    mCycleCollecting = PR_TRUE;
-    mCycleCollectionContext = &cycleCollectionContext;
-    gDidCollection = PR_FALSE;
-    gInCollection = PR_FALSE;
-    gCollected = PR_FALSE;
-
-    JSContext *cx = mCycleCollectionContext->GetJSContext();
-    gOldJSGCCallback = JS_SetGCCallback(cx, XPCCycleCollectGCCallback);
-    JS_GC(cx);
-    JS_SetGCCallback(cx, gOldJSGCCallback);
-    gOldJSGCCallback = nsnull;
-
-    mCycleCollectionContext = nsnull;
-    mCycleCollecting = PR_FALSE;
-
-    return gCollected;
-}
-
-// JSTRACE_XML can recursively hold on to more JSTRACE_XML objects, adding it to
-// the cycle collector avoids stack overflow.
-#define ADD_TO_CC(_kind)    ((_kind) == JSTRACE_OBJECT || (_kind) == JSTRACE_XML)
-
-#ifdef DEBUG_CC
-struct NoteJSRootTracer : public JSTracer
-{
-    NoteJSRootTracer(PLDHashTable *aObjects,
-                     nsCycleCollectionTraversalCallback& cb)
-      : mObjects(aObjects),
-        mCb(cb)
-    {
-    }
-    PLDHashTable* mObjects;
-    nsCycleCollectionTraversalCallback& mCb;
-};
-
-JS_STATIC_DLL_CALLBACK(void)
-NoteJSRoot(JSTracer *trc, void *thing, uint32 kind)
-{
-    if(ADD_TO_CC(kind))
-    {
-        NoteJSRootTracer *tracer = static_cast<NoteJSRootTracer*>(trc);
-        PLDHashEntryHdr *entry = PL_DHashTableOperate(tracer->mObjects, thing,
-                                                      PL_DHASH_ADD);
-        if(entry && !reinterpret_cast<PLDHashEntryStub*>(entry)->key)
-        {
-            reinterpret_cast<PLDHashEntryStub*>(entry)->key = thing;
-            tracer->mCb.NoteRoot(nsIProgrammingLanguage::JAVASCRIPT, thing,
-                                 nsXPConnect::GetXPConnect());
-        }
-    }
-    else if(kind != JSTRACE_DOUBLE && kind != JSTRACE_STRING)
-    {
-        JS_TraceChildren(trc, thing, kind);
-    }
-}
-#endif
-
-nsresult 
-nsXPConnect::BeginCycleCollection(nsCycleCollectionTraversalCallback &cb)
-{
-#ifdef DEBUG_CC
-    NS_ASSERTION(!mJSRoots.ops, "Didn't call FinishCollection?");
-
-    if(!mCycleCollectionContext)
-    {
-        // Being called from nsCycleCollector::ExplainLiveExpectedGarbage.
-        mExplainCycleCollectionContext = new XPCCallContext(NATIVE_CALLER);
-        if(!mExplainCycleCollectionContext ||
-           !mExplainCycleCollectionContext->IsValid())
-        {
-            mExplainCycleCollectionContext = nsnull;
-            return PR_FALSE;
-        }
-
-        mCycleCollectionContext = mExplainCycleCollectionContext;
-
-        // Record all objects held by the JS runtime. This avoids doing a
-        // complete GC if we're just tracing to explain (from
-        // ExplainLiveExpectedGarbage), which makes the results of cycle
-        // collection identical for DEBUG_CC and non-DEBUG_CC builds.
-        if(!PL_DHashTableInit(&mJSRoots, PL_DHashGetStubOps(), nsnull,
-                              sizeof(PLDHashEntryStub), PL_DHASH_MIN_SIZE)) {
-            mJSRoots.ops = nsnull;
-
-            return NS_ERROR_OUT_OF_MEMORY;
-        }
-
-        nsXPConnect::GetRuntime()->UnsetContextGlobals();
-
-        PRBool alreadyCollecting = mCycleCollecting;
-        mCycleCollecting = PR_TRUE;
-        NoteJSRootTracer trc(&mJSRoots, cb);
-        JS_TRACER_INIT(&trc, mCycleCollectionContext->GetJSContext(),
-                       NoteJSRoot);
-        JS_TraceRuntime(&trc);
-        mCycleCollecting = alreadyCollecting;
-    }
-#else
-    NS_ASSERTION(mCycleCollectionContext,
-                 "Didn't call nsXPConnect::Collect()?");
-#endif
-
-    GetRuntime()->AddXPConnectRoots(mCycleCollectionContext->GetJSContext(),
-                                    cb);
-
-#ifndef XPCONNECT_STANDALONE
-    if(!mScopes.IsInitialized())
-    {
-        mScopes.Init();
-    }
-    NS_ASSERTION(mScopes.Count() == 0, "Didn't clear mScopes?");
-    XPCWrappedNativeScope::TraverseScopes(*mCycleCollectionContext);
-#endif
-
-    return NS_OK;
-}
-
-#ifndef XPCONNECT_STANDALONE
-void
-nsXPConnect::RecordTraversal(void *p, nsISupports *s)
-{
-    mScopes.Put(p, s);
-}
-#endif
-
-nsresult 
-nsXPConnect::FinishCycleCollection()
-{
-#ifdef DEBUG_CC
-    if(mExplainCycleCollectionContext)
-    {
-        mCycleCollectionContext = nsnull;
-        mExplainCycleCollectionContext = nsnull;
-
-        nsXPConnect::GetRuntime()->RestoreContextGlobals();
-    }
-#endif
-
-#ifndef XPCONNECT_STANDALONE
-    mScopes.Clear();
-#endif
-
-#ifdef DEBUG_CC
-    if(mJSRoots.ops)
-    {
-        PL_DHashTableFinish(&mJSRoots);
-        mJSRoots.ops = nsnull;
-    }
-#endif
-
-    return NS_OK;
-}
-
-nsCycleCollectionParticipant *
-nsXPConnect::ToParticipant(void *p)
-{
-    return this;
-}
-
-NS_IMETHODIMP
-nsXPConnect::RootAndUnlinkJSObjects(void *p)
-{
-    return NS_OK;
-}
-
-#ifdef DEBUG_CC
-void
-nsXPConnect::PrintAllReferencesTo(void *p)
-{
-#ifdef DEBUG
-    if(!mCycleCollectionContext) {
-        NS_NOTREACHED("no context");
-        return;
-    }
-    JS_DumpHeap(*mCycleCollectionContext, stdout, nsnull, 0, p,
-                0x7fffffff, nsnull);
-#endif
-}
-#endif
-
-NS_IMETHODIMP
-nsXPConnect::Unlink(void *p)
-{
-    return NS_OK;
-}
-
-NS_IMETHODIMP
-nsXPConnect::Unroot(void *p)
-{
-    return NS_OK;
-}
-
-struct TraversalTracer : public JSTracer
-{
-    TraversalTracer(nsCycleCollectionTraversalCallback &aCb) : cb(aCb)
-    {
-    }
-    nsCycleCollectionTraversalCallback &cb;
-};
-
-JS_STATIC_DLL_CALLBACK(void)
-NoteJSChild(JSTracer *trc, void *thing, uint32 kind)
-{
-    if(ADD_TO_CC(kind))
-    {
-        TraversalTracer *tracer = static_cast<TraversalTracer*>(trc);
-#if defined(DEBUG) && defined(DEBUG_CC)
-        // based on DumpNotify in jsapi.c
-        if (tracer->debugPrinter) {
-            char buffer[200];
-            tracer->debugPrinter(trc, buffer, sizeof(buffer));
-            tracer->cb.NoteNextEdgeName(buffer);
-        } else if (tracer->debugPrintIndex != (size_t)-1) {
-            char buffer[200];
-            JS_snprintf(buffer, sizeof(buffer), "%s[%lu]",
-                        static_cast<const char *>(tracer->debugPrintArg),
-                        tracer->debugPrintIndex);
-            tracer->cb.NoteNextEdgeName(buffer);
-        } else {
-            tracer->cb.NoteNextEdgeName(
-              static_cast<const char*>(tracer->debugPrintArg));
-        }
-#endif
-        tracer->cb.NoteScriptChild(nsIProgrammingLanguage::JAVASCRIPT, thing);
-    }
-    else if(kind != JSTRACE_DOUBLE && kind != JSTRACE_STRING)
-    {
-        JS_TraceChildren(trc, thing, kind);
-    }
-}
-
-NS_IMETHODIMP
-nsXPConnect::Traverse(void *p, nsCycleCollectionTraversalCallback &cb)
-{
-    if(!mCycleCollectionContext)
-        return NS_ERROR_FAILURE;
-
-    JSContext *cx = mCycleCollectionContext->GetJSContext();
-
-    uint32 traceKind = js_GetGCThingTraceKind(p);
-    NS_ASSERTION(traceKind != JSTRACE_NAMESPACE &&
-                 traceKind != JSTRACE_QNAME,
-                 "Somebody holds one of these objects directly?");
-
-    CCNodeType type;
-
-#ifdef DEBUG_CC
-    {
-    // Note that the conditions under which we specify GCMarked vs.
-    // GCUnmarked are different between ExplainLiveExpectedGarbage and
-    // the normal case.  In the normal case, we're saying that anything
-    // reachable from a JS runtime root is itself such a root.  This
-    // doesn't actually break anything; it really just does some of the
-    // cycle collector's work for it.  However, when debugging, we
-    // (1) actually need to know what the root is and (2) don't want to
-    // do an extra GC, so we use mJSRoots, built from JS_TraceRuntime,
-    // which produces a different result because we didn't call
-    // JS_TraceChildren to trace everything that was reachable.
-    if(mJSRoots.ops)
-    {
-        // ExplainLiveExpectedGarbage codepath
-        PLDHashEntryHdr* entry =
-            PL_DHashTableOperate(&mJSRoots, p, PL_DHASH_LOOKUP);
-        type = PL_DHASH_ENTRY_IS_BUSY(entry) ? GCMarked : GCUnmarked;
-    }
-    else
-    {
-        // Normal codepath (matches non-DEBUG_CC codepath).
-        type = JS_IsAboutToBeFinalized(cx, p) ? GCUnmarked : GCMarked;
-    }
-
-    char name[72];
-    if(traceKind == JSTRACE_OBJECT)
-    {
-        JSObject *obj = static_cast<JSObject*>(p);
-        JSClass *clazz = OBJ_GET_CLASS(cx, obj);
-        if(XPCNativeWrapper::IsNativeWrapperClass(clazz))
-        {
-            XPCWrappedNative* wn = XPCNativeWrapper::GetWrappedNative(obj);
-            if(wn)
-            {
-                XPCNativeScriptableInfo* si = wn->GetScriptableInfo();
-                if(si)
-                {
-                    JS_snprintf(name, sizeof(name), "XPCNativeWrapper (%s)",
-                                si->GetJSClass()->name);
-                }
-                else
-                {
-                    nsIClassInfo* ci = wn->GetClassInfo();
-                    char* className = nsnull;
-                    if(ci)
-                        ci->GetClassDescription(&className);
-                    if(className)
-                    {
-                        JS_snprintf(name, sizeof(name), "XPCNativeWrapper (%s)",
-                                    className);
-                        PR_Free(className);
-                    }
-                    else
-                    {
-                        XPCNativeSet* set = wn->GetSet();
-                        XPCNativeInterface** array = set->GetInterfaceArray();
-                        PRUint16 count = set->GetInterfaceCount();
-
-                        if(count > 0)
-                            JS_snprintf(name, sizeof(name),
-                                        "XPCNativeWrapper (%s)",
-                                        array[0]->GetNameString());
-                        else
-                            JS_snprintf(name, sizeof(name), "XPCNativeWrapper");
-                    }
-                }
-            }
-            else
-            {
-                JS_snprintf(name, sizeof(name), "XPCNativeWrapper");
-            }
-        }
-        else
-        {
-            XPCNativeScriptableInfo* si = nsnull;
-            if(IS_PROTO_CLASS(clazz))
-            {
-                XPCWrappedNativeProto* p =
-                    (XPCWrappedNativeProto*) xpc_GetJSPrivate(obj);
-                si = p->GetScriptableInfo();
-            }
-            if(si)
-            {
-                JS_snprintf(name, sizeof(name), "JS Object (%s - %s)",
-                            clazz->name, si->GetJSClass()->name);
-            }
-            else if(clazz == &js_ScriptClass)
-            {
-                JSScript* script = (JSScript*) xpc_GetJSPrivate(obj);
-                if(script->filename)
-                {
-                    JS_snprintf(name, sizeof(name), "JS Object (Script - %s)",
-                                script->filename);
-                }
-                else
-                {
-                    JS_snprintf(name, sizeof(name), "JS Object (Script)");
-                }
-            }
-            else if(clazz == &js_FunctionClass)
-            {
-                JSFunction* fun = (JSFunction*) xpc_GetJSPrivate(obj);
-                JSString* str = JS_GetFunctionId(fun);
-                if(str)
-                {
-                    NS_ConvertUTF16toUTF8
-                        fname(JS_GetStringChars(str));
-                    JS_snprintf(name, sizeof(name), "JS Object (Function - %s)",
-                                fname.get());
-                }
-                else
-                {
-                    JS_snprintf(name, sizeof(name), "JS Object (Function)");
-                }
-            }
-            else
-            {
-                JS_snprintf(name, sizeof(name), "JS Object (%s)", clazz->name);
-            }
-        }
-    }
-    else
-    {
-        static const char trace_types[JSTRACE_LIMIT][10] = {
-            "Object",
-            "Double",
-            "String",
-            "Namespace",
-            "Qname",
-            "Xml"
-        };
-        JS_snprintf(name, sizeof(name), "JS %s", trace_types[traceKind]);
-    }
-
-    if(traceKind == JSTRACE_OBJECT || traceKind == JSTRACE_NAMESPACE ||
-       traceKind == JSTRACE_QNAME || traceKind == JSTRACE_XML) {
-        JSObject *global = static_cast<JSObject*>(p), *parent;
-        while((parent = JS_GetParent(cx, global)))
-            global = parent;
-        char fullname[100];
-        JS_snprintf(fullname, sizeof(fullname), "%s (global=%p)", name, global);
-        cb.DescribeNode(type, 0, sizeof(JSObject), fullname);
-    } else {
-        cb.DescribeNode(type, 0, sizeof(JSObject), name);
-    }
-
-    }
-#else
-    type = JS_IsAboutToBeFinalized(cx, p) ? GCUnmarked : GCMarked;
-    cb.DescribeNode(type, 0);
-#endif
-
-    if(!ADD_TO_CC(traceKind))
-        return NS_OK;
-
-#ifndef DEBUG_CC
-    // There's no need to trace objects that have already been marked by the JS
-    // GC. Any JS objects hanging from them will already be marked. Only do this
-    // if DEBUG_CC is not defined, else we do want to know about all JS objects
-    // to get better graphs and explanations.
-    if(type == GCMarked)
-        return NS_OK;
-#endif
-
-    TraversalTracer trc(cb);
-
-    JS_TRACER_INIT(&trc, cx, NoteJSChild);
-    JS_TraceChildren(&trc, p, traceKind);
-
-    if(traceKind != JSTRACE_OBJECT)
-        return NS_OK;
-    
-    JSObject *obj = static_cast<JSObject*>(p);
-    JSClass* clazz = OBJ_GET_CLASS(cx, obj);
-
-    if(clazz == &XPC_WN_Tearoff_JSClass)
-    {
-        // A tearoff holds a strong reference to its native object
-        // (see XPCWrappedNative::FlatJSObjectFinalized). Its XPCWrappedNative
-        // will be held alive through the parent of the JSObject of the tearoff.
-        XPCWrappedNativeTearOff *to =
-            (XPCWrappedNativeTearOff*) xpc_GetJSPrivate(obj);
-        cb.NoteXPCOMChild(to->GetNative());
-    }
-    // XXX XPCNativeWrapper seems to be the only class that doesn't hold a
-    //     strong reference to its nsISupports private. This test does seem
-    //     fragile though, we should probably whitelist classes that do hold
-    //     a strong reference, but that might not be possible.
-    else if(clazz->flags & JSCLASS_HAS_PRIVATE &&
-            clazz->flags & JSCLASS_PRIVATE_IS_NSISUPPORTS &&
-            !XPCNativeWrapper::IsNativeWrapperClass(clazz))
-    {
-        cb.NoteXPCOMChild(static_cast<nsISupports*>(xpc_GetJSPrivate(obj)));
-    }
-
-#ifndef XPCONNECT_STANDALONE
-    if(clazz->flags & JSCLASS_IS_GLOBAL)
-    {
-        nsISupports *principal = nsnull;
-        mScopes.Get(obj, &principal);
-        cb.NoteXPCOMChild(principal);
-    }
-#endif
-
-    return NS_OK;
-}
-
-PRInt32
-nsXPConnect::GetRequestDepth(JSContext* cx)
-{
-    PRInt32 requestDepth = cx->outstandingRequests;
-    XPCCallContext* context = GetCycleCollectionContext();
-    if(context && cx == context->GetJSContext())
-        // Ignore the request from the XPCCallContext we created for cycle
-        // collection.
-        --requestDepth;
-    return requestDepth;
-}
-
-class JSContextParticipant : public nsCycleCollectionParticipant
-{
-public:
-    NS_IMETHOD RootAndUnlinkJSObjects(void *n)
-    {
-        return NS_OK;
-    }
-    NS_IMETHOD Unlink(void *n)
-    {
-        // We must not unlink a JSContext because Root/Unroot don't ensure that
-        // the pointer is still valid.
-        return NS_OK;
-    }
-    NS_IMETHOD Unroot(void *n)
-    {
-        return NS_OK;
-    }
-    NS_IMETHODIMP Traverse(void *n, nsCycleCollectionTraversalCallback &cb)
-    {
-        JSContext *cx = static_cast<JSContext*>(n);
-
-        // Add cx->requestDepth to the refcount, if there are outstanding
-        // requests the context needs to be kept alive and adding unknown
-        // edges will ensure that any cycles this context is in won't be
-        // collected.
-        PRInt32 refCount = nsXPConnect::GetXPConnect()->GetRequestDepth(cx) + 1;
-
-#ifdef DEBUG_CC
-        cb.DescribeNode(RefCounted, refCount, sizeof(JSContext),
-                        "JSContext");
-        cb.NoteNextEdgeName("[global object]");
-#else
-        cb.DescribeNode(RefCounted, refCount);
-#endif
-
-        void* globalObject;
-        if(cx->globalObject)
-            globalObject = cx->globalObject;
-        else
-            globalObject = nsXPConnect::GetRuntime()->GetUnsetContextGlobal(cx);
-
-        cb.NoteScriptChild(nsIProgrammingLanguage::JAVASCRIPT, globalObject);
-
-        return NS_OK;
-    }
-};
-
-static JSContextParticipant JSContext_cycleCollectorGlobal;
-
-// static
-nsCycleCollectionParticipant*
-nsXPConnect::JSContextParticipant()
-{
-    return &JSContext_cycleCollectorGlobal;
-}
-
-NS_IMETHODIMP_(void)
-nsXPConnect::NoteJSContext(JSContext *aJSContext,
-                           nsCycleCollectionTraversalCallback &aCb)
-{
-    aCb.NoteNativeChild(aJSContext, &JSContext_cycleCollectorGlobal);
-}
-
 
 /***************************************************************************/
 /***************************************************************************/
@@ -2305,18 +1662,6 @@ nsXPConnect::OnDispatchedEvent(nsIThread
 }
 
 NS_IMETHODIMP
-nsXPConnect::AddJSHolder(void* aHolder, nsScriptObjectTracer* aTracer)
-{
-    return mRuntime->AddJSHolder(aHolder, aTracer);
-}
-
-NS_IMETHODIMP
-nsXPConnect::RemoveJSHolder(void* aHolder)
-{
-    return mRuntime->RemoveJSHolder(aHolder);
-}
-
-NS_IMETHODIMP
 nsXPConnect::SetReportAllJSExceptions(PRBool newval)
 {
     // Ignore if the environment variable was set.
diff --git a/js/src/xpconnect/src/xpcjsruntime.cpp b/js/src/xpconnect/src/xpcjsruntime.cpp
--- a/js/src/xpconnect/src/xpcjsruntime.cpp
+++ b/js/src/xpconnect/src/xpcjsruntime.cpp
@@ -253,42 +253,6 @@ ContextCallback(JSContext *cx, uintN ope
            : JS_TRUE;
 }
 
-struct ObjectHolder : public JSDHashEntryHdr
-{
-    void *holder;
-    nsScriptObjectTracer* tracer;
-};
-
-nsresult
-XPCJSRuntime::AddJSHolder(void* aHolder, nsScriptObjectTracer* aTracer)
-{
-    if(!mJSHolders.ops)
-        return NS_ERROR_OUT_OF_MEMORY;
-
-    ObjectHolder *entry =
-        reinterpret_cast<ObjectHolder*>(JS_DHashTableOperate(&mJSHolders,
-                                                             aHolder,
-                                                             JS_DHASH_ADD));
-    if(!entry)
-        return NS_ERROR_OUT_OF_MEMORY;
-
-    entry->holder = aHolder;
-    entry->tracer = aTracer;
-
-    return NS_OK;
-}
-
-nsresult
-XPCJSRuntime::RemoveJSHolder(void* aHolder)
-{
-    if(!mJSHolders.ops)
-        return NS_ERROR_OUT_OF_MEMORY;
-
-    JS_DHashTableOperate(&mJSHolders, aHolder, JS_DHASH_REMOVE);
-
-    return NS_OK;
-}
-
 // static
 void XPCJSRuntime::TraceJS(JSTracer* trc, void* data)
 {
@@ -320,34 +284,7 @@ void XPCJSRuntime::TraceJS(JSTracer* trc
     for(XPCRootSetElem *e = self->mObjectHolderRoots; e ; e = e->GetNextRoot())
         static_cast<XPCJSObjectHolder*>(e)->TraceJS(trc);
         
-    if(self->GetXPConnect()->ShouldTraceRoots())
-    {
-        // Only trace these if we're not cycle-collecting, the cycle collector
-        // will do that if we are.
-        self->TraceXPConnectRoots(trc);
-    }
-}
-
-PR_STATIC_CALLBACK(void)
-TraceJSObject(PRUint32 aLangID, void *aScriptThing, void *aClosure)
-{
-    if(aLangID == nsIProgrammingLanguage::JAVASCRIPT)
-    {
-        JS_CALL_TRACER(static_cast<JSTracer*>(aClosure), aScriptThing,
-                       js_GetGCThingTraceKind(aScriptThing),
-                       "JSObjectHolder");
-    }
-}
-
-JS_STATIC_DLL_CALLBACK(JSDHashOperator)
-TraceJSHolder(JSDHashTable *table, JSDHashEntryHdr *hdr, uint32 number,
-              void *arg)
-{
-    ObjectHolder* entry = reinterpret_cast<ObjectHolder*>(hdr);
-
-    entry->tracer->Trace(entry->holder, TraceJSObject, arg);
-
-    return JS_DHASH_NEXT;
+    self->TraceXPConnectRoots(trc);
 }
 
 struct ClearedGlobalObject : public JSDHashEntryHdr
@@ -358,24 +295,6 @@ struct ClearedGlobalObject : public JSDH
 
 void XPCJSRuntime::TraceXPConnectRoots(JSTracer *trc)
 {
-    if(mClearedGlobalObjects.ops)
-    {
-        JSContext *iter = nsnull, *acx;
-        while((acx = JS_ContextIterator(GetJSRuntime(), &iter)))
-        {
-            JSDHashEntryHdr* entry =
-                JS_DHashTableOperate(&mClearedGlobalObjects, acx,
-                                     JS_DHASH_LOOKUP);
-            if(JS_DHASH_ENTRY_IS_BUSY(entry))
-            {
-                ClearedGlobalObject* clearedGlobal =
-                    reinterpret_cast<ClearedGlobalObject*>(entry);
-                JS_CALL_OBJECT_TRACER(trc, clearedGlobal->mGlobalObject,
-                                      "global object");
-            }
-        }
-    }
-
     XPCWrappedNativeScope::TraceJS(trc, this);
 
     for(XPCRootSetElem *e = mVariantRoots; e ; e = e->GetNextRoot())
@@ -383,137 +302,6 @@ void XPCJSRuntime::TraceXPConnectRoots(J
 
     for(XPCRootSetElem *e = mWrappedJSRoots; e ; e = e->GetNextRoot())
         static_cast<nsXPCWrappedJS*>(e)->TraceJS(trc);
-
-    if(mJSHolders.ops)
-        JS_DHashTableEnumerate(&mJSHolders, TraceJSHolder, trc);
-}
-
-JS_STATIC_DLL_CALLBACK(JSDHashOperator)
-NoteJSHolder(JSDHashTable *table, JSDHashEntryHdr *hdr, uint32 number,
-             void *arg)
-{
-    ObjectHolder* entry = reinterpret_cast<ObjectHolder*>(hdr);
-
-    nsCycleCollectionTraversalCallback* cb =
-        static_cast<nsCycleCollectionTraversalCallback*>(arg);
-    cb->NoteRoot(nsIProgrammingLanguage::CPLUSPLUS, entry->holder,
-                 entry->tracer);
-
-    return JS_DHASH_NEXT;
-}
-
-
-void XPCJSRuntime::AddXPConnectRoots(JSContext* cx,
-                                     nsCycleCollectionTraversalCallback &cb)
-{
-    // For all JS objects that are held by native objects but aren't held
-    // through rooting or locking, we need to add all the native objects that
-    // hold them so that the JS objects are colored correctly in the cycle
-    // collector. This includes JSContexts that don't have outstanding requests,
-    // because their global object wasn't marked by the JS GC. All other JS
-    // roots were marked by the JS GC and will be colored correctly in the cycle
-    // collector.
-
-    JSContext *iter = nsnull, *acx;
-    while((acx = JS_ContextIterator(GetJSRuntime(), &iter)))
-    {
-#ifndef DEBUG_CC
-        // Only skip JSContexts with outstanding requests if DEBUG_CC is not
-        // defined, else we do want to know about all JSContexts to get better
-        // graphs and explanations.
-        if(nsXPConnect::GetXPConnect()->GetRequestDepth(acx) != 0)
-            continue;
-#endif
-        cb.NoteRoot(nsIProgrammingLanguage::CPLUSPLUS, acx,
-                    nsXPConnect::JSContextParticipant());
-    }
-
-    XPCWrappedNativeScope::SuspectAllWrappers(this, cx, cb);
-
-    for(XPCRootSetElem *e = mVariantRoots; e ; e = e->GetNextRoot())
-        cb.NoteXPCOMRoot(static_cast<XPCTraceableVariant*>(e));
-
-    for(XPCRootSetElem *e = mWrappedJSRoots; e ; e = e->GetNextRoot())
-    {
-        nsIXPConnectWrappedJS *wrappedJS = static_cast<nsXPCWrappedJS*>(e);
-        cb.NoteXPCOMRoot(wrappedJS);
-    }
-
-    if(mJSHolders.ops)
-        JS_DHashTableEnumerate(&mJSHolders, NoteJSHolder, &cb);
-}
-
-void XPCJSRuntime::UnsetContextGlobals()
-{
-    if(!mClearedGlobalObjects.ops)
-        return;
-
-    RestoreContextGlobals();
-
-    JSContext *iter = nsnull, *acx;
-    while((acx = JS_ContextIterator(GetJSRuntime(), &iter)))
-    {
-        if(nsXPConnect::GetXPConnect()->GetRequestDepth(acx) == 0)
-        {
-            JS_ClearNewbornRoots(acx);
-            if(acx->globalObject)
-            {
-                JSDHashEntryHdr* entry =
-                    JS_DHashTableOperate(&mClearedGlobalObjects, acx,
-                                         JS_DHASH_ADD);
-                ClearedGlobalObject* clearedGlobal =
-                    reinterpret_cast<ClearedGlobalObject*>(entry);
-                if(clearedGlobal)
-                {
-                    clearedGlobal->mContext = acx;
-                    clearedGlobal->mGlobalObject = acx->globalObject;
-                    acx->globalObject = nsnull;
-                }
-            }
-        }
-    }
-}
-
-JSDHashOperator
-RemoveContextGlobal(JSDHashTable *table, JSDHashEntryHdr *hdr, uint32 number,
-                    void *arg)
-{
-  return JS_DHASH_REMOVE;
-}
-
-void XPCJSRuntime::RestoreContextGlobals()
-{
-    if(!mClearedGlobalObjects.ops || mClearedGlobalObjects.entryCount == 0)
-        return;
-
-    JSContext *iter = nsnull, *acx;
-    while((acx = JS_ContextIterator(GetJSRuntime(), &iter)))
-    {
-        JSDHashEntryHdr* entry =
-            JS_DHashTableOperate(&mClearedGlobalObjects, acx, JS_DHASH_LOOKUP);
-        if(JS_DHASH_ENTRY_IS_BUSY(entry))
-        {
-            ClearedGlobalObject* clearedGlobal =
-                reinterpret_cast<ClearedGlobalObject*>(entry);
-            acx->globalObject = clearedGlobal->mGlobalObject;
-        }
-    }
-    JS_DHashTableEnumerate(&mClearedGlobalObjects, RemoveContextGlobal, nsnull);
-}
-
-JSObject* XPCJSRuntime::GetUnsetContextGlobal(JSContext* cx)
-{
-    if(!mClearedGlobalObjects.ops)
-        return nsnull;
-
-    JSDHashEntryHdr* entry =
-        JS_DHashTableOperate(&mClearedGlobalObjects, cx, JS_DHASH_LOOKUP);
-    ClearedGlobalObject* clearedGlobal =
-        reinterpret_cast<ClearedGlobalObject*>(entry);
-
-    return JS_DHASH_ENTRY_IS_BUSY(entry) ?
-           clearedGlobal->mGlobalObject :
-           nsnull;
 }
 
 // static
@@ -1021,17 +809,6 @@ XPCJSRuntime::~XPCJSRuntime()
 
     gOldJSGCCallback = NULL;
     gOldJSContextCallback = NULL;
-
-    if(mJSHolders.ops)
-    {
-        JS_DHashTableFinish(&mJSHolders);
-        mJSHolders.ops = nsnull;
-    }
-    if(mClearedGlobalObjects.ops)
-    {
-        JS_DHashTableFinish(&mClearedGlobalObjects);
-        mClearedGlobalObjects.ops = nsnull;
-    }
 }
 
 XPCJSRuntime::XPCJSRuntime(nsXPConnect* aXPConnect,
@@ -1082,13 +859,6 @@ XPCJSRuntime::XPCJSRuntime(nsXPConnect* 
         gOldJSGCCallback = JS_SetGCCallbackRT(mJSRuntime, GCCallback);
         JS_SetExtraGCRoots(mJSRuntime, TraceJS, this);
     }
-
-    if(!JS_DHashTableInit(&mJSHolders, JS_DHashGetStubOps(), nsnull,
-                          sizeof(ObjectHolder), 512))
-        mJSHolders.ops = nsnull;
-    if(!JS_DHashTableInit(&mClearedGlobalObjects, JS_DHashGetStubOps(), nsnull,
-                          sizeof(ClearedGlobalObject), JS_DHASH_MIN_SIZE))
-        mClearedGlobalObjects.ops = nsnull;
 
     // Install a JavaScript 'debugger' keyword handler in debug builds only
 #ifdef DEBUG
diff --git a/js/src/xpconnect/src/xpcprivate.h b/js/src/xpconnect/src/xpcprivate.h
--- a/js/src/xpconnect/src/xpcprivate.h
+++ b/js/src/xpconnect/src/xpcprivate.h
@@ -54,7 +54,6 @@
 #include "nsXPCOM.h"
 #include "nsAutoPtr.h"
 #include "nsCycleCollectionParticipant.h"
-#include "nsCycleCollector.h"
 #include "nsISupports.h"
 #include "nsIServiceManager.h"
 #include "nsIClassInfoImpl.h"
@@ -444,9 +443,7 @@ const PRBool OBJ_IS_NOT_GLOBAL = PR_FALS
 
 class nsXPConnect : public nsIXPConnect,
                     public nsIThreadObserver,
-                    public nsSupportsWeakReference,
-                    public nsCycleCollectionJSRuntime,
-                    public nsCycleCollectionParticipant
+                    public nsSupportsWeakReference
 {
 public:
     // all the interface method declarations...
@@ -495,46 +492,11 @@ public:
     nsresult GetInfoForIID(const nsIID * aIID, nsIInterfaceInfo** info);
     nsresult GetInfoForName(const char * name, nsIInterfaceInfo** info);
 
-    // nsCycleCollectionParticipant
-    NS_IMETHOD RootAndUnlinkJSObjects(void *p);
-    NS_IMETHOD Unlink(void *p);
-    NS_IMETHOD Unroot(void *p);
-    NS_IMETHOD Traverse(void *p,
-                        nsCycleCollectionTraversalCallback &cb);
-    
-    // nsCycleCollectionLanguageRuntime
-    virtual nsresult BeginCycleCollection(nsCycleCollectionTraversalCallback &cb);
-    virtual nsresult FinishCycleCollection();
-    virtual nsCycleCollectionParticipant *ToParticipant(void *p);
-    virtual PRBool Collect();
-#ifdef DEBUG_CC
-    virtual void PrintAllReferencesTo(void *p);
-#endif
-
-    // We should not trace XPConnect JS roots when tracing the graph for the
-    // cycle collector. Those should be traced from the XPCOM objects that hold
-    // them when we know that they won't be collected by the cycle collector.
-    PRBool ShouldTraceRoots()
-    {
-        return !mCycleCollecting;
-    }
-
-    XPCCallContext* GetCycleCollectionContext()
-    {
-        return mCycleCollectionContext;
-    }
-
     PRInt32 GetRequestDepth(JSContext* cx);
 
-    // This returns the singleton nsCycleCollectionParticipant for JSContexts.
-    static nsCycleCollectionParticipant *JSContextParticipant();
-
-#ifndef XPCONNECT_STANDALONE
-    void RecordTraversal(void *p, nsISupports *s);
-#endif
     static PRBool ReportAllJSExceptions()
     {
-      return gReportAllJSExceptions > 0;
+        return gReportAllJSExceptions > 0;
     }
 
 #ifdef XPC_IDISPATCH_SUPPORT
@@ -561,12 +523,6 @@ private:
     nsIXPCSecurityManager*   mDefaultSecurityManager;
     PRUint16                 mDefaultSecurityManagerFlags;
     JSBool                   mShuttingDown;
-    XPCCallContext*          mCycleCollectionContext;
-#ifdef DEBUG_CC
-    nsAutoPtr<XPCCallContext> mExplainCycleCollectionContext;
-    PLDHashTable             mJSRoots;
-#endif
-    PRBool                   mCycleCollecting;
 
 #ifdef XPC_TOOLS_SUPPORT
     nsCOMPtr<nsIXPCToolsProfiler> mProfiler;
@@ -711,21 +667,12 @@ public:
 
     static void JS_DLL_CALLBACK TraceJS(JSTracer* trc, void* data);
     void TraceXPConnectRoots(JSTracer *trc);
-    void AddXPConnectRoots(JSContext* cx,
-                           nsCycleCollectionTraversalCallback& cb);
 
     static JSBool JS_DLL_CALLBACK GCCallback(JSContext *cx, JSGCStatus status);
 
     inline void AddVariantRoot(XPCTraceableVariant* variant);
     inline void AddWrappedJSRoot(nsXPCWrappedJS* wrappedJS);
     inline void AddObjectHolderRoot(XPCJSObjectHolder* holder);
-
-    nsresult AddJSHolder(void* aHolder, nsScriptObjectTracer* aTracer);
-    nsresult RemoveJSHolder(void* aHolder);
-
-    void UnsetContextGlobals();
-    void RestoreContextGlobals();
-    JSObject* GetUnsetContextGlobal(JSContext* cx);
 
     void DebugDump(PRInt16 depth);
 
@@ -790,8 +737,6 @@ private:
     XPCRootSetElem *mVariantRoots;
     XPCRootSetElem *mWrappedJSRoots;
     XPCRootSetElem *mObjectHolderRoots;
-    JSDHashTable mJSHolders;
-    JSDHashTable mClearedGlobalObjects;
 };
 
 /***************************************************************************/
@@ -1267,10 +1212,6 @@ public:
 
     static void
     TraceJS(JSTracer* trc, XPCJSRuntime* rt);
-
-    static void
-    SuspectAllWrappers(XPCJSRuntime* rt, JSContext* cx,
-                       nsCycleCollectionTraversalCallback &cb);
 
     static void
     FinishedMarkPhaseOfGC(JSContext* cx, XPCJSRuntime* rt);
@@ -2069,25 +2010,6 @@ public:
     NS_DECL_ISUPPORTS
     NS_DECL_NSIXPCONNECTJSOBJECTHOLDER
     NS_DECL_NSIXPCONNECTWRAPPEDNATIVE
-    // No need to unlink the JS objects, if the XPCWrappedNative will be cycle
-    // collected then its mFlatJSObject will be cycle collected too and
-    // finalization of the mFlatJSObject will unlink the js objects (see
-    // XPC_WN_NoHelper_Finalize and FlatJSObjectFinalized).
-    // We also rely on NS_DECL_CYCLE_COLLECTION_CLASS_NO_UNLINK having empty
-    // Root/Unroot methods, to avoid root/unrooting the JS objects from
-    // addrefing/releasing the XPCWrappedNative during unlinking, which would
-    // make the JS objects uncollectable to the JS GC.
-    class NS_CYCLE_COLLECTION_INNERCLASS
-     : public nsXPCOMCycleCollectionParticipant
-    {
-      NS_DECL_CYCLE_COLLECTION_CLASS_BODY_NO_UNLINK(XPCWrappedNative,
-                                                    XPCWrappedNative)
-      NS_IMETHOD RootAndUnlinkJSObjects(void *p);
-      NS_IMETHOD Unlink(void *p) { return NS_OK; }
-      NS_IMETHOD Unroot(void *p) { return NS_OK; }
-    };
-    NS_CYCLE_COLLECTION_PARTICIPANT_INSTANCE
-    NS_DECL_CYCLE_COLLECTION_UNMARK_PURPLE_STUB(XPCWrappedNative)
 
 #ifndef XPCONNECT_STANDALONE
     virtual nsIPrincipal* GetObjectPrincipal() const;
@@ -2322,8 +2244,6 @@ public:
     JSObject* GetWrapper()              { return mWrapper; }
     void      SetWrapper(JSObject *obj) { mWrapper = obj; }
 
-    void NoteTearoffs(nsCycleCollectionTraversalCallback& cb);
-
     // Make ctor and dtor protected (rather than private) to placate nsCOMPtr.
 protected:
     XPCWrappedNative(); // not implemented
@@ -2518,13 +2438,6 @@ public:
     NS_DECL_NSISUPPORTSWEAKREFERENCE
     NS_DECL_NSIPROPERTYBAG
 
-    class NS_CYCLE_COLLECTION_INNERCLASS
-     : public nsXPCOMCycleCollectionParticipant
-    {
-      NS_IMETHOD RootAndUnlinkJSObjects(void *p);
-      NS_DECL_CYCLE_COLLECTION_CLASS_BODY(nsXPCWrappedJS, nsIXPConnectWrappedJS)
-    };
-    NS_CYCLE_COLLECTION_PARTICIPANT_INSTANCE
     NS_DECL_CYCLE_COLLECTION_UNMARK_PURPLE_STUB(nsXPCWrappedJS)
 
     NS_IMETHOD CallMethod(PRUint16 methodIndex,
diff --git a/js/src/xpconnect/src/xpcvariant.cpp b/js/src/xpconnect/src/xpcvariant.cpp
--- a/js/src/xpconnect/src/xpcvariant.cpp
+++ b/js/src/xpconnect/src/xpcvariant.cpp
@@ -89,29 +89,6 @@ XPCTraceableVariant::PrintTraceName(JSTr
     JS_snprintf(buf, bufsize, "XPCVariant[0x%p].mJSVal", trc->debugPrintArg);
 }
 #endif
-
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(XPCVariant)
-    if(JSVAL_IS_OBJECT(tmp->mJSVal))
-        cb.NoteScriptChild(nsIProgrammingLanguage::JAVASCRIPT,
-                           JSVAL_TO_OBJECT(tmp->mJSVal));
-
-    nsVariant::Traverse(tmp->mData, cb);
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
-
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(XPCVariant)
-    // We're sharing mJSVal's buffer, clear the pointer to it
-    // so Cleanup() won't try to delete it
-    if(JSVAL_IS_STRING(tmp->mJSVal))
-        tmp->mData.u.wstr.mWStringValue = nsnull;
-    nsVariant::Cleanup(&tmp->mData);
-
-    if(JSVAL_IS_TRACEABLE(tmp->mJSVal))
-    {
-        XPCTraceableVariant *v = static_cast<XPCTraceableVariant*>(tmp);
-        v->RemoveFromRootSet(nsXPConnect::GetRuntime()->GetJSRuntime());
-    }
-    tmp->mJSVal = JSVAL_NULL;
-NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 
 // static 
 XPCVariant* XPCVariant::newVariant(XPCCallContext& ccx, jsval aJSVal)
diff --git a/js/src/xpconnect/src/xpcwrappedjs.cpp b/js/src/xpconnect/src/xpcwrappedjs.cpp
--- a/js/src/xpconnect/src/xpcwrappedjs.cpp
+++ b/js/src/xpconnect/src/xpcwrappedjs.cpp
@@ -45,83 +45,6 @@
 
 // NOTE: much of the fancy footwork is done in xpcstubs.cpp
 
-NS_IMPL_CYCLE_COLLECTION_CLASS(nsXPCWrappedJS)
-
-NS_IMETHODIMP
-NS_CYCLE_COLLECTION_CLASSNAME(nsXPCWrappedJS)::Traverse
-   (void *p, nsCycleCollectionTraversalCallback &cb)
-{
-    nsISupports *s = static_cast<nsISupports*>(p);
-    NS_ASSERTION(CheckForRightISupports(s),
-                 "not the nsISupports pointer we expect");
-    nsXPCWrappedJS *tmp = Downcast(s);
-
-    nsrefcnt refcnt = tmp->mRefCnt.get();
-#ifdef DEBUG_CC
-    char name[72];
-    if (tmp->GetClass())
-      JS_snprintf(name, sizeof(name), "nsXPCWrappedJS (%s)",
-                  tmp->GetClass()->GetInterfaceName());
-    else
-      JS_snprintf(name, sizeof(name), "nsXPCWrappedJS");
-    cb.DescribeNode(RefCounted, refcnt, sizeof(nsXPCWrappedJS), name);
-#else
-    cb.DescribeNode(RefCounted, refcnt);
-#endif
-
-    // nsXPCWrappedJS keeps its own refcount artificially at or above 1, see the
-    // comment above nsXPCWrappedJS::AddRef.
-    cb.NoteXPCOMChild(s);
-
-    if(refcnt > 1)
-        // nsXPCWrappedJS roots its mJSObj when its refcount is > 1, see
-        // the comment above nsXPCWrappedJS::AddRef.
-        cb.NoteScriptChild(nsIProgrammingLanguage::JAVASCRIPT,
-                           tmp->GetJSObject());
-
-    nsXPCWrappedJS* root = tmp->GetRootWrapper();
-    if(root == tmp)
-        // The root wrapper keeps the aggregated native object alive.
-        cb.NoteXPCOMChild(tmp->GetAggregatedNativeObject());
-    else
-        // Non-root wrappers keep their root alive.
-        cb.NoteXPCOMChild(static_cast<nsIXPConnectWrappedJS*>(root));
-
-    return NS_OK;
-}
-
-NS_IMPL_CYCLE_COLLECTION_ROOT_BEGIN(nsXPCWrappedJS)
-    if(tmp->mRoot && !tmp->mRoot->HasWeakReferences() && tmp->IsValid())
-    {
-        XPCJSRuntime* rt = nsXPConnect::GetRuntime();
-        if(rt)
-        {
-            if(tmp->mRoot == tmp)
-            {
-                // remove this root wrapper from the map
-                JSObject2WrappedJSMap* map = rt->GetWrappedJSMap();
-                if(map)
-                {
-                    XPCAutoLock lock(rt->GetMapLock());
-                    map->Remove(tmp);
-                }
-            }
-
-            if(tmp->mRefCnt > 1)
-                tmp->RemoveFromRootSet(rt->GetJSRuntime());
-        }
-
-        tmp->mJSObj = nsnull;
-    }
-NS_IMPL_CYCLE_COLLECTION_ROOT_END
-
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsXPCWrappedJS)
-    if(tmp->mRoot && !tmp->mRoot->HasWeakReferences())
-    {
-        tmp->Unlink();
-    }
-NS_IMPL_CYCLE_COLLECTION_UNLINK_END
-
 NS_IMETHODIMP
 nsXPCWrappedJS::AggregatedQueryInterface(REFNSIID aIID, void** aInstancePtr)
 {
@@ -151,19 +74,6 @@ nsXPCWrappedJS::QueryInterface(REFNSIID 
     {
         NS_PRECONDITION(0, "null pointer");
         return NS_ERROR_NULL_POINTER;
-    }
-
-    if ( aIID.Equals(NS_GET_IID(nsXPCOMCycleCollectionParticipant)) ) {
-        *aInstancePtr = & NS_CYCLE_COLLECTION_NAME(nsXPCWrappedJS);
-        return NS_OK;
-    }
-
-    if(aIID.Equals(NS_GET_IID(nsCycleCollectionISupports)))
-    {
-        NS_ADDREF(this);
-        *aInstancePtr =
-            NS_CYCLE_COLLECTION_CLASSNAME(nsXPCWrappedJS)::Upcast(this);
-        return NS_OK;
     }
 
     if(!IsValid())
diff --git a/js/src/xpconnect/src/xpcwrappednative.cpp b/js/src/xpconnect/src/xpcwrappednative.cpp
--- a/js/src/xpconnect/src/xpcwrappednative.cpp
+++ b/js/src/xpconnect/src/xpcwrappednative.cpp
@@ -47,89 +47,6 @@
 #include "XPCWrapper.h"
 
 /***************************************************************************/
-
-NS_IMPL_CYCLE_COLLECTION_CLASS(XPCWrappedNative)
-
-NS_IMETHODIMP
-NS_CYCLE_COLLECTION_CLASSNAME(XPCWrappedNative)::RootAndUnlinkJSObjects(void *p)
-{
-    XPCWrappedNative *tmp = static_cast<XPCWrappedNative*>(p);
-    tmp->ExpireWrapper();
-    return NS_OK;
-}
-
-
-NS_IMETHODIMP
-NS_CYCLE_COLLECTION_CLASSNAME(XPCWrappedNative)::Traverse(void *p,
-                                                          nsCycleCollectionTraversalCallback &cb)
-{
-    XPCWrappedNative *tmp = static_cast<XPCWrappedNative*>(p);
-    if(!tmp->IsValid())
-        return NS_OK;
-
-#ifdef DEBUG_CC
-    char name[72];
-    XPCNativeScriptableInfo* si = tmp->GetScriptableInfo();
-    if(si)
-        JS_snprintf(name, sizeof(name), "XPCWrappedNative (%s)",
-                    si->GetJSClass()->name);
-    else
-        JS_snprintf(name, sizeof(name), "XPCWrappedNative");
-
-    cb.DescribeNode(RefCounted, tmp->mRefCnt.get(), sizeof(XPCWrappedNative),
-                    name);
-#else
-    cb.DescribeNode(RefCounted, tmp->mRefCnt.get());
-#endif
-
-    if(tmp->mRefCnt.get() > 1) {
-
-        // If our refcount is > 1, our reference to the flat JS object is
-        // considered "strong", and we're going to traverse it. 
-        //
-        // If our refcount is <= 1, our reference to the flat JS object is
-        // considered "weak", and we're *not* going to traverse it.
-        //
-        // This reasoning is in line with the slightly confusing lifecycle rules
-        // for XPCWrappedNatives, described in a larger comment below and also
-        // on our wiki at http://wiki.mozilla.org/XPConnect_object_wrapping 
-
-        JSObject *obj = nsnull;
-        nsresult rv = tmp->GetJSObject(&obj);
-        if(NS_SUCCEEDED(rv))
-            cb.NoteScriptChild(nsIProgrammingLanguage::JAVASCRIPT, obj);
-    }
-
-    // XPCWrappedNative keeps its native object alive.
-    cb.NoteXPCOMChild(tmp->GetIdentityObject());
-
-    tmp->NoteTearoffs(cb);
-
-    return NS_OK;
-}
-
-void
-XPCWrappedNative::NoteTearoffs(nsCycleCollectionTraversalCallback& cb)
-{
-    // Tearoffs hold their native object alive. If their JS object hasn't been
-    // finalized yet we'll note the edge between the JS object and the native
-    // (see nsXPConnect::Traverse), but if their JS object has been finalized
-    // then the tearoff is only reachable through the XPCWrappedNative, so we
-    // record an edge here.
-    XPCWrappedNativeTearOffChunk* chunk;
-    for(chunk = &mFirstChunk; chunk; chunk = chunk->mNextChunk)
-    {
-        XPCWrappedNativeTearOff* to = chunk->mTearOffs;
-        for(int i = XPC_WRAPPED_NATIVE_TEAROFFS_PER_CHUNK-1; i >= 0; i--, to++)
-        {
-            JSObject* jso = to->GetJSObject();
-            if(!jso)
-            {
-                cb.NoteXPCOMChild(to->GetNative());
-            }
-        }
-    }
-}
 
 #ifdef XPC_CHECK_CLASSINFO_CLAIMS
 static void DEBUG_CheckClassInfoClaims(XPCWrappedNative* wrapper);
diff --git a/js/src/xpconnect/src/xpcwrappednativescope.cpp b/js/src/xpconnect/src/xpcwrappednativescope.cpp
--- a/js/src/xpconnect/src/xpcwrappednativescope.cpp
+++ b/js/src/xpconnect/src/xpcwrappednativescope.cpp
@@ -377,57 +377,6 @@ XPCWrappedNativeScope::TraceJS(JSTracer*
     for(XPCWrappedNativeScope* cur = gScopes; cur; cur = cur->mNext)
     {
         cur->mWrappedNativeMap->Enumerate(WrappedNativeJSGCThingTracer, trc);
-    }
-}
-
-struct SuspectClosure
-{
-    SuspectClosure(JSContext *aCx, nsCycleCollectionTraversalCallback& aCb)
-        : cx(aCx), cb(aCb)
-    {
-    }
-
-    JSContext* cx;
-    nsCycleCollectionTraversalCallback& cb;
-};
-
-JS_STATIC_DLL_CALLBACK(JSDHashOperator)
-WrappedNativeSuspecter(JSDHashTable *table, JSDHashEntryHdr *hdr,
-                       uint32 number, void *arg)
-{
-    SuspectClosure* closure = static_cast<SuspectClosure*>(arg);
-    XPCWrappedNative* wrapper = ((Native2WrappedNativeMap::Entry*)hdr)->value;
-    XPCWrappedNativeProto* proto = wrapper->GetProto();
-    if(proto && proto->ClassIsMainThreadOnly() && wrapper->IsValid())
-    {
-        NS_ASSERTION(NS_IsMainThread(), 
-                     "Suspecting wrapped natives from non-main thread");
-
-#ifndef DEBUG_CC
-        // Only record objects that might be part of a cycle as roots.
-        if(!JS_IsAboutToBeFinalized(closure->cx, wrapper->GetFlatJSObject()))
-            return JS_DHASH_NEXT;
-#endif
-
-        closure->cb.NoteRoot(nsIProgrammingLanguage::JAVASCRIPT,
-                             wrapper->GetFlatJSObject(),
-                             nsXPConnect::GetXPConnect());
-    }
-
-    return JS_DHASH_NEXT;
-}
-
-// static
-void
-XPCWrappedNativeScope::SuspectAllWrappers(XPCJSRuntime* rt, JSContext* cx,
-                                          nsCycleCollectionTraversalCallback& cb)
-{
-    XPCAutoLock lock(rt->GetMapLock());
-
-    SuspectClosure closure(cx, cb);
-    for(XPCWrappedNativeScope* cur = gScopes; cur; cur = cur->mNext)
-    {
-        cur->mWrappedNativeMap->Enumerate(WrappedNativeSuspecter, &closure);
     }
 }
 
@@ -959,20 +908,3 @@ XPCWrappedNativeScope::DebugDump(PRInt16
     XPC_LOG_OUTDENT();
 #endif
 }
-
-#ifndef XPCONNECT_STANDALONE
-// static
-void
-XPCWrappedNativeScope::TraverseScopes(XPCCallContext& ccx)
-{
-    // Hold the lock throughout.
-    XPCAutoLock lock(ccx.GetRuntime()->GetMapLock());
-
-    for(XPCWrappedNativeScope* cur = gScopes; cur; cur = cur->mNext)
-        if(cur->mGlobalJSObject && cur->mScriptObjectPrincipal)
-        {
-            ccx.GetXPConnect()->RecordTraversal(cur->mGlobalJSObject,
-                                                cur->mScriptObjectPrincipal);
-        }
-}
-#endif
diff --git a/layout/base/nsPresContext.cpp b/layout/base/nsPresContext.cpp
--- a/layout/base/nsPresContext.cpp
+++ b/layout/base/nsPresContext.cpp
@@ -291,61 +291,6 @@ NS_INTERFACE_MAP_END
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF(nsPresContext)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(nsPresContext)
-
-PR_STATIC_CALLBACK(PLDHashOperator)
-TraverseImageLoader(const void * aKey, nsCOMPtr<nsImageLoader>& aData,
-                    void* aClosure)
-{
-  nsCycleCollectionTraversalCallback *cb =
-    static_cast<nsCycleCollectionTraversalCallback*>(aClosure);
-
-  cb->NoteXPCOMChild(aData);
-
-  return PL_DHASH_NEXT;
-}
-
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsPresContext)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mDocument);
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_RAWPTR(mDeviceContext); // worth bothering?
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_RAWPTR(mEventManager);
-  // NS_IMPL_CYCLE_COLLECTION_TRAVERSE_RAWPTR(mLookAndFeel); // a service
-  // NS_IMPL_CYCLE_COLLECTION_TRAVERSE_RAWPTR(mLangGroup); // an atom
-
-  tmp->mImageLoaders.Enumerate(TraverseImageLoader, &cb);
-
-  // NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mTheme); // a service
-  // NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mLangService); // a service
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mPrintSettings);
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mPrefChangedTimer);
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
-
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsPresContext)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mDocument);
-  NS_RELEASE(tmp->mDeviceContext); // worth bothering?
-  if (tmp->mEventManager) {
-    // unclear if these are needed, but can't hurt
-    tmp->mEventManager->NotifyDestroyPresContext(tmp);
-    tmp->mEventManager->SetPresContext(nsnull);
-
-    NS_RELEASE(tmp->mEventManager);
-  }
-
-  // NS_RELEASE(tmp->mLookAndFeel); // a service
-  // NS_RELEASE(tmp->mLangGroup); // an atom
-
-  tmp->mImageLoaders.Enumerate(destroy_loads, nsnull);
-  tmp->mImageLoaders.Clear();
-
-  // NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mTheme); // a service
-  // NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mLangService); // a service
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mPrintSettings);
-  if (tmp->mPrefChangedTimer)
-  {
-    tmp->mPrefChangedTimer->Cancel();
-    tmp->mPrefChangedTimer = nsnull;
-  }
-NS_IMPL_CYCLE_COLLECTION_UNLINK_END
-
 
 #define MAKE_FONT_PREF_KEY(_pref, _s0, _s1) \
  _pref.Assign(_s0); \
diff --git a/layout/build/nsLayoutStatics.cpp b/layout/build/nsLayoutStatics.cpp
--- a/layout/build/nsLayoutStatics.cpp
+++ b/layout/build/nsLayoutStatics.cpp
@@ -116,8 +116,6 @@ PRBool NS_SVGEnabled();
 
 #include "nsError.h"
 #include "nsTraceRefcnt.h"
-
-#include "nsCycleCollector.h"
 
 static nsrefcnt sLayoutStaticRefcnt;
 
diff --git a/parser/htmlparser/src/nsParser.cpp b/parser/htmlparser/src/nsParser.cpp
--- a/parser/htmlparser/src/nsParser.cpp
+++ b/parser/htmlparser/src/nsParser.cpp
@@ -322,24 +322,6 @@ nsParser::Cleanup()
   // has an owning reference to |this|.
   NS_ASSERTION(!(mFlags & NS_PARSER_FLAG_PENDING_CONTINUE_EVENT), "bad");
 }
-
-NS_IMPL_CYCLE_COLLECTION_CLASS(nsParser)
-
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsParser)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mSink)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mObserver)
-NS_IMPL_CYCLE_COLLECTION_UNLINK_END
-
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsParser)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mSink)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mObserver)
-  CParserContext *pc = tmp->mParserContext;
-  while (pc) {
-    cb.NoteXPCOMChild(pc->mDTD);
-    cb.NoteXPCOMChild(pc->mTokenizer);
-    pc = pc->mPrevContext;
-  }
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF_AMBIGUOUS(nsParser, nsIParser)
 NS_IMPL_CYCLE_COLLECTING_RELEASE_AMBIGUOUS(nsParser, nsIParser)
diff --git a/rdf/base/src/nsCompositeDataSource.cpp b/rdf/base/src/nsCompositeDataSource.cpp
--- a/rdf/base/src/nsCompositeDataSource.cpp
+++ b/rdf/base/src/nsCompositeDataSource.cpp
@@ -648,21 +648,6 @@ CompositeDataSourceImpl::CompositeDataSo
 //
 // nsISupports interface
 //
-
-NS_IMPL_CYCLE_COLLECTION_CLASS(CompositeDataSourceImpl)
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(CompositeDataSourceImpl)
-    PRUint32 i, count = tmp->mDataSources.Count();
-    for (i = count; i > 0; --i) {
-        tmp->mDataSources[i - 1]->RemoveObserver(tmp);
-        tmp->mDataSources.RemoveObjectAt(i - 1);
-    }
-    NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMARRAY(mObservers);
-NS_IMPL_CYCLE_COLLECTION_UNLINK_END
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(CompositeDataSourceImpl)
-    NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMARRAY(mObservers)
-    NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMARRAY(mDataSources)
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
-
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF_AMBIGUOUS(CompositeDataSourceImpl,
                                           nsIRDFCompositeDataSource)
diff --git a/toolkit/components/places/src/nsNavHistoryResult.cpp b/toolkit/components/places/src/nsNavHistoryResult.cpp
--- a/toolkit/components/places/src/nsNavHistoryResult.cpp
+++ b/toolkit/components/places/src/nsNavHistoryResult.cpp
@@ -104,16 +104,6 @@ inline PRInt32 CompareIntegers(PRUint32 
 
 // nsNavHistoryResultNode ******************************************************
 
-
-NS_IMPL_CYCLE_COLLECTION_CLASS(nsNavHistoryResultNode)
-
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsNavHistoryResultNode)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mParent)
-NS_IMPL_CYCLE_COLLECTION_UNLINK_END 
-
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsNavHistoryResultNode)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mParent, nsINavHistoryContainerResultNode);
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsNavHistoryResultNode)
   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsINavHistoryResultNode)
@@ -3699,35 +3689,6 @@ RemoveBookmarkFolderObserversCallback(ns
   return PL_DHASH_REMOVE;
 }
 
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsNavHistoryResult)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mRootNode)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mView)
-  tmp->mBookmarkFolderObservers.Enumerate(&RemoveBookmarkFolderObserversCallback, nsnull);
-NS_IMPL_CYCLE_COLLECTION_UNLINK_END 
-
-PR_STATIC_CALLBACK(PLDHashOperator)
-TraverseBookmarkFolderObservers(nsTrimInt64HashKey::KeyType aKey,
-                                nsNavHistoryResult::FolderObserverList*& aData,
-                                void* aUserArg)
-{
-  nsCycleCollectionTraversalCallback* cb =
-    static_cast<nsCycleCollectionTraversalCallback*>(aUserArg);
-  PRUint32 i, count = aData->Length();
-  for (i = 0; i < count; ++i) {
-    NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(*cb,
-                                       "mBookmarkFolderObservers value[i]");
-    nsNavHistoryResultNode* node = aData->ElementAt(i);
-    cb->NoteXPCOMChild(node);
-  }
-  return PL_DHASH_NEXT;
-}
-
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsNavHistoryResult)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mRootNode, nsINavHistoryContainerResultNode)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mView)
-  tmp->mBookmarkFolderObservers.Enumerate(&TraverseBookmarkFolderObservers, &cb);
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
-
 NS_IMPL_CYCLE_COLLECTING_ADDREF(nsNavHistoryResult)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(nsNavHistoryResult)
 
diff --git a/xpcom/base/Makefile.in b/xpcom/base/Makefile.in
--- a/xpcom/base/Makefile.in
+++ b/xpcom/base/Makefile.in
@@ -108,14 +108,15 @@ SDK_XPIDLSRCS   = \
 		nsISupports.idl		   \
 		nsITraceRefcnt.idl         \
 		nsIWeakReference.idl	   \
-		nsrootidl.idl
+		nsrootidl.idl		   \
+		$(NULL)
 
 SDK_HEADERS     = \
 		nsError.h \
 		nsISupportsBase.h \
 		nscore.h \
-		nsCycleCollector.h \
 		nsObjCExceptions.h \
+		$(NULL)
 
 XPIDLSRCS	= \
 		nsIConsoleListener.idl \
diff --git a/xpcom/base/nsAgg.h b/xpcom/base/nsAgg.h
--- a/xpcom/base/nsAgg.h
+++ b/xpcom/base/nsAgg.h
@@ -99,28 +99,7 @@ private:                                
                                                                             \
 public:                                                                     \
 
-#define NS_DECL_AGGREGATED_CYCLE_COLLECTION_CLASS(_class)                   \
-class NS_CYCLE_COLLECTION_INNERCLASS                                        \
- : public nsXPCOMCycleCollectionParticipant                                 \
-{                                                                           \
-public:                                                                     \
-  NS_IMETHOD Unlink(void *p);                                               \
-  NS_IMETHOD Traverse(void *p,                                              \
-                      nsCycleCollectionTraversalCallback &cb);              \
-  NS_IMETHOD_(void) UnmarkPurple(nsISupports *p)                            \
-  {                                                                         \
-    Downcast(p)->UnmarkPurple();                                            \
-  }                                                                         \
-  static _class* Downcast(nsISupports* s)                                   \
-  {                                                                         \
-    return (_class*)((char*)(s) - offsetof(_class, fAggregated));           \
-  }                                                                         \
-  static nsISupports* Upcast(_class *p)                                     \
-  {                                                                         \
-    return p->InnerObject();                                                \
-  }                                                                         \
-};                                                                          \
-NS_CYCLE_COLLECTION_PARTICIPANT_INSTANCE
+#define NS_DECL_AGGREGATED_CYCLE_COLLECTION_CLASS(_class)
 
 // Put this in your class's constructor:
 #define NS_INIT_AGGREGATED(outer)                                           \
@@ -162,37 +141,7 @@ _class::Internal::Release(void)         
 }                                                                           \
 
 #define NS_IMPL_CYCLE_COLLECTING_AGGREGATED(_class)                         \
-                                                                            \
-NS_IMPL_AGGREGATED_HELPER(_class)                                           \
-                                                                            \
-NS_IMETHODIMP_(nsrefcnt)                                                    \
-_class::Internal::AddRef(void)                                              \
-{                                                                           \
-    _class* agg = NS_CYCLE_COLLECTION_CLASSNAME(_class)::Downcast(this);    \
-    NS_PRECONDITION(PRInt32(agg->mRefCnt) >= 0, "illegal refcnt");          \
-    NS_CheckThreadSafe(agg->_mOwningThread.GetThread(),                     \
-                       #_class " not thread-safe");                         \
-    nsrefcnt count = agg->mRefCnt.incr(this);                               \
-    NS_LOG_ADDREF(this, count, #_class, sizeof(*agg));                      \
-    return count;                                                           \
-}                                                                           \
-                                                                            \
-NS_IMETHODIMP_(nsrefcnt)                                                    \
-_class::Internal::Release(void)                                             \
-{                                                                           \
-    _class* agg = NS_CYCLE_COLLECTION_CLASSNAME(_class)::Downcast(this);    \
-    NS_PRECONDITION(0 != agg->mRefCnt, "dup release");                      \
-    NS_CheckThreadSafe(agg->_mOwningThread.GetThread(),                     \
-                       #_class " not thread-safe");                         \
-    nsrefcnt count = agg->mRefCnt.decr(this);                               \
-    NS_LOG_RELEASE(this, count, #_class);                                   \
-    if (count == 0) {                                                       \
-        agg->mRefCnt.stabilizeForDeletion(this);                            \
-        NS_DELETEXPCOM(agg);                                                \
-        return 0;                                                           \
-    }                                                                       \
-    return count;                                                           \
-}
+  NS_IMPL_AGGREGATED(_class)
 
 #define NS_IMPL_AGGREGATED_HELPER(_class)                                   \
 NS_IMETHODIMP                                                               \
@@ -220,52 +169,6 @@ _class::Internal::QueryInterface(const n
     return agg->AggregatedQueryInterface(aIID, aInstancePtr);               \
 }                                                                           \
 
-/**
- * To make aggregated objects participate in cycle collection we need to enable
- * the outer object (aggregator) to traverse/unlink the objects held by the
- * inner object (the aggregatee). We can't just make the inner object QI'able to
- * NS_CYCLECOLLECTIONPARTICIPANT_IID, we don't want to return the inner object's
- * nsCycleCollectionParticipant for the outer object (which will happen if the
- * outer object doesn't participate in cycle collection itself).
- * NS_AGGREGATED_CYCLECOLLECTIONPARTICIPANT_IID enables the outer object to get
- * the inner objects nsCycleCollectionParticipant.
- *
- * There are three cases:
- *   - No aggregation
- *     QI'ing to NS_CYCLECOLLECTIONPARTICIPANT_IID will return the inner
- *     object's nsCycleCollectionParticipant.
- *
- *   - Aggregation and outer object does not participate in cycle collection
- *     QI'ing to NS_CYCLECOLLECTIONPARTICIPANT_IID will not return anything.
- *
- *   - Aggregation and outer object does participate in cycle collection
- *     QI'ing to NS_CYCLECOLLECTIONPARTICIPANT_IID will return the outer
- *     object's nsCycleCollectionParticipant. The outer object's
- *     nsCycleCollectionParticipant can then QI the inner object to
- *     NS_AGGREGATED_CYCLECOLLECTIONPARTICIPANT_IID to get the inner object's
- *     nsCycleCollectionParticipant, which it can use to traverse/unlink the
- *     objects reachable from the inner object.
- */
-#define NS_AGGREGATED_CYCLECOLLECTIONPARTICIPANT_IID                        \
-{                                                                           \
-    0x32889b7e,                                                             \
-    0xe4fe,                                                                 \
-    0x43f4,                                                                 \
-    { 0x85, 0x31, 0xb5, 0x28, 0x23, 0xa2, 0xe9, 0xfc }                      \
-}
-
-/**
- * Just holds the IID so NS_GET_IID works.
- */
-class nsAggregatedCycleCollectionParticipant
-{
-public:
-    NS_DECLARE_STATIC_IID_ACCESSOR(NS_AGGREGATED_CYCLECOLLECTIONPARTICIPANT_IID)
-};
-
-NS_DEFINE_STATIC_IID_ACCESSOR(nsAggregatedCycleCollectionParticipant, 
-                              NS_AGGREGATED_CYCLECOLLECTIONPARTICIPANT_IID)
-
 // for use with QI macros in nsISupportsUtils.h:
 
 #define NS_INTERFACE_MAP_BEGIN_AGGREGATED(_class)                           \
@@ -291,25 +194,8 @@ _class::AggregatedQueryInterface(REFNSII
     foundInterface = InnerObject();                                         \
   else
 
-#define NS_IMPL_AGGREGATED_QUERY_CYCLE_COLLECTION(_class)                   \
-  if (aIID.Equals(IsPartOfAggregated() ?                                    \
-                  NS_GET_IID(nsCycleCollectionParticipant) :                \
-                  NS_GET_IID(nsAggregatedCycleCollectionParticipant)))      \
-    foundInterface = & NS_CYCLE_COLLECTION_NAME(_class);                    \
-  else
-
-#define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_AGGREGATED(_class)          \
-  NS_IMETHODIMP                                                             \
-  NS_CYCLE_COLLECTION_CLASSNAME(_class)::Traverse                           \
-                         (void *p,                                          \
-                          nsCycleCollectionTraversalCallback &cb)           \
-  {                                                                         \
-    nsISupports *s = static_cast<nsISupports*>(p);                          \
-    NS_ASSERTION(CheckForRightISupports(s),                                 \
-                 "not the nsISupports pointer we expect");                  \
-    _class *tmp = static_cast<_class*>(Downcast(s));                        \
-    if (!tmp->IsPartOfAggregated())                                         \
-        NS_IMPL_CYCLE_COLLECTION_DESCRIBE(_class)
+#define NS_IMPL_AGGREGATED_QUERY_CYCLE_COLLECTION(_class)
+#define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_AGGREGATED(_class)
 
 #define NS_GENERIC_AGGREGATED_CONSTRUCTOR(_InstanceClass)                   \
 static NS_METHOD                                                            \
diff --git a/xpcom/base/nsCycleCollector.cpp b/xpcom/base/nsCycleCollector.cpp
--- a/xpcom/base/nsCycleCollector.cpp
+++ b/xpcom/base/nsCycleCollector.cpp
@@ -38,2925 +38,21 @@
  * ***** END LICENSE BLOCK ***** */
 
 //
-// This file implements a garbage-cycle collector based on the paper
-// 
-//   Concurrent Cycle Collection in Reference Counted Systems
-//   Bacon & Rajan (2001), ECOOP 2001 / Springer LNCS vol 2072
-//
-// We are not using the concurrent or acyclic cases of that paper; so
-// the green, red and orange colors are not used.
-//
-// The collector is based on tracking pointers of four colors:
-//
-// Black nodes are definitely live. If we ever determine a node is
-// black, it's ok to forget about, drop from our records.
-//
-// White nodes are definitely garbage cycles. Once we finish with our
-// scanning, we unlink all the white nodes and expect that by
-// unlinking them they will self-destruct (since a garbage cycle is
-// only keeping itself alive with internal links, by definition).
-//
-// Grey nodes are being scanned. Nodes that turn grey will turn
-// either black if we determine that they're live, or white if we
-// determine that they're a garbage cycle. After the main collection
-// algorithm there should be no grey nodes.
-//
-// Purple nodes are *candidates* for being scanned. They are nodes we
-// haven't begun scanning yet because they're not old enough, or we're
-// still partway through the algorithm.
-//
-// XPCOM objects participating in garbage-cycle collection are obliged
-// to inform us when they ought to turn purple; that is, when their
-// refcount transitions from N+1 -> N, for nonzero N. Furthermore we
-// require that *after* an XPCOM object has informed us of turning
-// purple, they will tell us when they either transition back to being
-// black (incremented refcount) or are ultimately deleted.
+// This file used to implement a garbage-cycle collector. Now it's just for show.
 
-
-// Safety:
-//
-// An XPCOM object is either scan-safe or scan-unsafe, purple-safe or
-// purple-unsafe.
-//
-// An object is scan-safe if:
-//
-//  - It can be QI'ed to |nsXPCOMCycleCollectionParticipant|, though this
-//    operation loses ISupports identity (like nsIClassInfo).
-//  - The operation |traverse| on the resulting
-//    nsXPCOMCycleCollectionParticipant does not cause *any* refcount
-//    adjustment to occur (no AddRef / Release calls).
-//
-// An object is purple-safe if it satisfies the following properties:
-//
-//  - The object is scan-safe.  
-//  - If the object calls |nsCycleCollector::suspect(this)|, 
-//    it will eventually call |nsCycleCollector::forget(this)|, 
-//    exactly once per call to |suspect|, before being destroyed.
-//
-// When we receive a pointer |ptr| via
-// |nsCycleCollector::suspect(ptr)|, we assume it is purple-safe. We
-// can check the scan-safety, but have no way to ensure the
-// purple-safety; objects must obey, or else the entire system falls
-// apart. Don't involve an object in this scheme if you can't
-// guarantee its purple-safety.
-//
-// When we have a scannable set of purple nodes ready, we begin
-// our walks. During the walks, the nodes we |traverse| should only
-// feed us more scan-safe nodes, and should not adjust the refcounts
-// of those nodes. 
-//
-// We do not |AddRef| or |Release| any objects during scanning. We
-// rely on purple-safety of the roots that call |suspect| and
-// |forget| to hold, such that we will forget about a purple pointer
-// before it is destroyed.  The pointers that are merely scan-safe,
-// we hold only for the duration of scanning, and there should be no
-// objects released from the scan-safe set during the scan (there
-// should be no threads involved).
-//
-// We *do* call |AddRef| and |Release| on every white object, on
-// either side of the calls to |Unlink|. This keeps the set of white
-// objects alive during the unlinking.
-// 
-
-#if !defined(__MINGW32__) && !defined(WINCE)
-#ifdef WIN32
-#include <crtdbg.h>
-#include <errno.h>
-#endif
-#endif
-
-#include "nsCycleCollectionParticipant.h"
-#include "nsIProgrammingLanguage.h"
-#include "nsBaseHashtable.h"
-#include "nsHashKeys.h"
-#include "nsDeque.h"
-#include "nsCycleCollector.h"
-#include "nsThreadUtils.h"
-#include "prenv.h"
-#include "prprf.h"
-#include "plstr.h"
-#include "prtime.h"
-#include "nsPrintfCString.h"
-#include "nsTArray.h"
-#include "nsIObserverService.h"
-#include "nsIConsoleService.h"
-#include "nsServiceManagerUtils.h"
-#include "nsThreadUtils.h"
-#include "nsTPtrArray.h"
-#include "nsVoidArray.h" // for nsCStringArray
-
-#include <stdio.h>
-#include <string.h>
-#ifdef WIN32
-#include <io.h>
-#include <process.h>
-#endif
-
-#define DEFAULT_SHUTDOWN_COLLECTIONS 5
-#ifdef DEBUG_CC
-#define SHUTDOWN_COLLECTIONS(params) params.mShutdownCollections
-#else
-#define SHUTDOWN_COLLECTIONS(params) DEFAULT_SHUTDOWN_COLLECTIONS
-#endif
-
-// Various parameters of this collector can be tuned using environment
-// variables.
-
-struct nsCycleCollectorParams
-{
-    PRBool mDoNothing;
-#ifdef DEBUG_CC
-    PRBool mReportStats;
-    PRBool mHookMalloc;
-    PRBool mDrawGraphs;
-    PRBool mFaultIsFatal;
-    PRBool mLogPointers;
-
-    PRUint32 mShutdownCollections;
-#endif
-    
-    PRUint32 mScanDelay;
-    
-    nsCycleCollectorParams() :
-#ifdef DEBUG_CC
-        mDoNothing     (PR_GetEnv("XPCOM_CC_DO_NOTHING") != NULL),
-        mReportStats   (PR_GetEnv("XPCOM_CC_REPORT_STATS") != NULL),
-        mHookMalloc    (PR_GetEnv("XPCOM_CC_HOOK_MALLOC") != NULL),
-        mDrawGraphs    (PR_GetEnv("XPCOM_CC_DRAW_GRAPHS") != NULL),
-        mFaultIsFatal  (PR_GetEnv("XPCOM_CC_FAULT_IS_FATAL") != NULL),
-        mLogPointers   (PR_GetEnv("XPCOM_CC_LOG_POINTERS") != NULL),
-
-        mShutdownCollections(DEFAULT_SHUTDOWN_COLLECTIONS),
-#else
-        mDoNothing     (PR_FALSE),
-#endif
-
-        // The default number of collections to "age" candidate
-        // pointers in the purple buffer before we decide that any
-        // garbage cycle they're in has stabilized and we want to
-        // consider scanning it.
-        //
-        // Making this number smaller causes:
-        //   - More time to be spent in the collector (bad)
-        //   - Less delay between forming garbage and collecting it (good)
-
-        mScanDelay(0)
-    {
-#ifdef DEBUG_CC
-        char *s = PR_GetEnv("XPCOM_CC_SCAN_DELAY");
-        if (s)
-            PR_sscanf(s, "%d", &mScanDelay);
-        s = PR_GetEnv("XPCOM_CC_SHUTDOWN_COLLECTIONS");
-        if (s)
-            PR_sscanf(s, "%d", &mShutdownCollections);
-#endif
-    }
-};
-
-#ifdef DEBUG_CC
-// Various operations involving the collector are recorded in a
-// statistics table. These are for diagnostics.
-
-struct nsCycleCollectorStats
-{
-    PRUint32 mFailedQI;
-    PRUint32 mSuccessfulQI;
-
-    PRUint32 mVisitedNode;
-    PRUint32 mWalkedGraph;
-    PRUint32 mCollectedBytes;
-    PRUint32 mFreeCalls;
-    PRUint32 mFreedBytes;
-
-    PRUint32 mSetColorGrey;
-    PRUint32 mSetColorBlack;
-    PRUint32 mSetColorWhite;
-
-    PRUint32 mFailedUnlink;
-    PRUint32 mCollectedNode;
-    PRUint32 mBumpGeneration;
-    PRUint32 mZeroGeneration;
-
-    PRUint32 mSuspectNode;
-    PRUint32 mSpills;    
-    PRUint32 mForgetNode;
-    PRUint32 mFreedWhilePurple;
-  
-    PRUint32 mCollection;
-
-    nsCycleCollectorStats()
-    {
-        memset(this, 0, sizeof(nsCycleCollectorStats));
-    }
-  
-    void Dump()
-    {
-        fprintf(stderr, "\f\n");
-#define DUMP(entry) fprintf(stderr, "%30.30s: %-20.20d\n", #entry, entry)
-        DUMP(mFailedQI);
-        DUMP(mSuccessfulQI);
-    
-        DUMP(mVisitedNode);
-        DUMP(mWalkedGraph);
-        DUMP(mCollectedBytes);
-        DUMP(mFreeCalls);
-        DUMP(mFreedBytes);
-    
-        DUMP(mSetColorGrey);
-        DUMP(mSetColorBlack);
-        DUMP(mSetColorWhite);
-    
-        DUMP(mFailedUnlink);
-        DUMP(mCollectedNode);
-        DUMP(mBumpGeneration);
-        DUMP(mZeroGeneration);
-    
-        DUMP(mSuspectNode);
-        DUMP(mSpills);
-        DUMP(mForgetNode);
-        DUMP(mFreedWhilePurple);
-    
-        DUMP(mCollection);
-#undef DUMP
-    }
-};
-#endif
-
-#ifdef DEBUG_CC
-static PRBool nsCycleCollector_shouldSuppress(nsISupports *s);
-static void InitMemHook(void);
-#endif
-
-////////////////////////////////////////////////////////////////////////
-// Base types
-////////////////////////////////////////////////////////////////////////
-
-struct PtrInfo;
-
-class EdgePool
-{
-public:
-    // EdgePool allocates arrays of void*, primarily to hold PtrInfo*.
-    // However, at the end of a block, the last two pointers are a null
-    // and then a void** pointing to the next block.  This allows
-    // EdgePool::Iterators to be a single word but still capable of crossing
-    // block boundaries.
-
-    EdgePool()
-    {
-        mSentinelAndBlocks[0].block = nsnull;
-        mSentinelAndBlocks[1].block = nsnull;
-    }
-
-    ~EdgePool()
-    {
-        NS_ASSERTION(!mSentinelAndBlocks[0].block &&
-                     !mSentinelAndBlocks[1].block,
-                     "Didn't call Clear()?");
-    }
-
-    void Clear()
-    {
-        Block *b = Blocks();
-        while (b) {
-            Block *next = b->Next();
-            delete b;
-            b = next;
-        }
-
-        mSentinelAndBlocks[0].block = nsnull;
-        mSentinelAndBlocks[1].block = nsnull;
-    }
-
-private:
-    struct Block;
-    union PtrInfoOrBlock {
-        // Use a union to avoid reinterpret_cast and the ensuing
-        // potential aliasing bugs.
-        PtrInfo *ptrInfo;
-        Block *block;
-    };
-    struct Block {
-        enum { BlockSize = 64 * 1024 };
-
-        PtrInfoOrBlock mPointers[BlockSize];
-        Block() {
-            mPointers[BlockSize - 2].block = nsnull; // sentinel
-            mPointers[BlockSize - 1].block = nsnull; // next block pointer
-        }
-        Block*& Next()
-            { return mPointers[BlockSize - 1].block; }
-        PtrInfoOrBlock* Start()
-            { return &mPointers[0]; }
-        PtrInfoOrBlock* End()
-            { return &mPointers[BlockSize - 2]; }
-    };
-
-    // Store the null sentinel so that we can have valid iterators
-    // before adding any edges and without adding any blocks.
-    PtrInfoOrBlock mSentinelAndBlocks[2];
-
-    Block*& Blocks() { return mSentinelAndBlocks[1].block; }
-
-public:
-    class Iterator
-    {
-    public:
-        Iterator() : mPointer(nsnull) {}
-        Iterator(PtrInfoOrBlock *aPointer) : mPointer(aPointer) {}
-        Iterator(const Iterator& aOther) : mPointer(aOther.mPointer) {}
-
-        Iterator& operator++()
-        {
-            if (mPointer->ptrInfo == nsnull) {
-                // Null pointer is a sentinel for link to the next block.
-                mPointer = (mPointer + 1)->block->mPointers;
-            }
-            ++mPointer;
-            return *this;
-        }
-
-        PtrInfo* operator*() const
-        {
-            if (mPointer->ptrInfo == nsnull) {
-                // Null pointer is a sentinel for link to the next block.
-                return (mPointer + 1)->block->mPointers->ptrInfo;
-            }
-            return mPointer->ptrInfo;
-        }
-        PRBool operator==(const Iterator& aOther) const
-            { return mPointer == aOther.mPointer; }
-        PRBool operator!=(const Iterator& aOther) const
-            { return mPointer != aOther.mPointer; }
-
-    private:
-        PtrInfoOrBlock *mPointer;
-    };
-
-    class Builder;
-    friend class Builder;
-    class Builder {
-    public:
-        Builder(EdgePool &aPool)
-            : mCurrent(&aPool.mSentinelAndBlocks[0]),
-              mBlockEnd(&aPool.mSentinelAndBlocks[0]),
-              mNextBlockPtr(&aPool.Blocks())
-        {
-        }
-
-        Iterator Mark() { return Iterator(mCurrent); }
-
-        void Add(PtrInfo* aEdge) {
-            if (mCurrent == mBlockEnd) {
-                Block *b = new Block();
-                if (!b) {
-                    // This means we just won't collect (some) cycles.
-                    NS_NOTREACHED("out of memory, ignoring edges");
-                    return;
-                }
-                *mNextBlockPtr = b;
-                mCurrent = b->Start();
-                mBlockEnd = b->End();
-                mNextBlockPtr = &b->Next();
-            }
-            (mCurrent++)->ptrInfo = aEdge;
-        }
-    private:
-        // mBlockEnd points to space for null sentinel
-        PtrInfoOrBlock *mCurrent, *mBlockEnd;
-        Block **mNextBlockPtr;
-    };
-
-};
-
-#ifdef DEBUG_CC
-
-struct ReversedEdge {
-    PtrInfo *mTarget;
-    nsCString *mEdgeName;
-    ReversedEdge *mNext;
-};
-
-#endif
-
-
-enum NodeColor { black, white, grey };
-
-// This structure should be kept as small as possible; we may expect
-// a million of them to be allocated and touched repeatedly during
-// each cycle collection.
-
-struct PtrInfo
-{
-    void *mPointer;
-    nsCycleCollectionParticipant *mParticipant;
-    PRUint32 mColor : 2;
-    PRUint32 mInternalRefs : 30;
-    PRUint32 mRefCount;
-    EdgePool::Iterator mFirstChild; // first
-    EdgePool::Iterator mLastChild; // one after last
-
-#ifdef DEBUG_CC
-    size_t mBytes;
-    char *mName;
-    PRUint32 mLangID;
-
-    // For finding roots in ExplainLiveExpectedGarbage (when there are
-    // missing calls to suspect or failures to unlink).
-    PRUint32 mSCCIndex; // strongly connected component
-
-    // For finding roots in ExplainLiveExpectedGarbage (when nodes
-    // expected to be garbage are black).
-    ReversedEdge* mReversedEdges; // linked list
-    PtrInfo* mShortestPathToExpectedGarbage;
-    nsCString* mShortestPathToExpectedGarbageEdgeName;
-
-    nsCStringArray mEdgeNames;
-#endif
-
-    PtrInfo(void *aPointer, nsCycleCollectionParticipant *aParticipant
-            IF_DEBUG_CC_PARAM(PRUint32 aLangID)
-            )
-        : mPointer(aPointer),
-          mParticipant(aParticipant),
-          mColor(grey),
-          mInternalRefs(0),
-          mRefCount(0),
-          mFirstChild(),
-          mLastChild()
-#ifdef DEBUG_CC
-        , mBytes(0),
-          mName(nsnull),
-          mLangID(aLangID),
-          mSCCIndex(0),
-          mReversedEdges(nsnull),
-          mShortestPathToExpectedGarbage(nsnull),
-          mShortestPathToExpectedGarbageEdgeName(nsnull)
-#endif
-    {
-    }
-
-#ifdef DEBUG_CC
-    void Destroy() {
-        PL_strfree(mName);
-        mEdgeNames.~nsCStringArray();
-    }
-#endif
-
-    // Allow NodePool::Block's constructor to compile.
-    PtrInfo() {
-        NS_NOTREACHED("should never be called");
-    }
-};
-
-/**
- * A structure designed to be used like a linked list of PtrInfo, except
- * that allocates the PtrInfo 32K-at-a-time.
- */
-class NodePool
-{
-private:
-    enum { BlockSize = 32 * 1024 }; // could be int template parameter
-
-    struct Block {
-        // We create and destroy Block using NS_Alloc/NS_Free rather
-        // than new and delete to avoid calling its constructor and
-        // destructor.
-        Block() { NS_NOTREACHED("should never be called"); }
-        ~Block() { NS_NOTREACHED("should never be called"); }
-
-        Block* mNext;
-        PtrInfo mEntries[BlockSize];
-    };
-
-public:
-    NodePool()
-        : mBlocks(nsnull),
-          mLast(nsnull)
-    {
-    }
-
-    ~NodePool()
-    {
-        NS_ASSERTION(!mBlocks, "Didn't call Clear()?");
-    }
-
-    void Clear()
-    {
-#ifdef DEBUG_CC
-        {
-            Enumerator queue(*this);
-            while (!queue.IsDone()) {
-                queue.GetNext()->Destroy();
-            }
-        }
-#endif
-        Block *b = mBlocks;
-        while (b) {
-            Block *n = b->mNext;
-            NS_Free(b);
-            b = n;
-        }
-
-        mBlocks = nsnull;
-        mLast = nsnull;
-    }
-
-    class Builder;
-    friend class Builder;
-    class Builder {
-    public:
-        Builder(NodePool& aPool)
-            : mNextBlock(&aPool.mBlocks),
-              mNext(aPool.mLast),
-              mBlockEnd(nsnull)
-        {
-            NS_ASSERTION(aPool.mBlocks == nsnull && aPool.mLast == nsnull,
-                         "pool not empty");
-        }
-        PtrInfo *Add(void *aPointer, nsCycleCollectionParticipant *aParticipant
-                     IF_DEBUG_CC_PARAM(PRUint32 aLangID)
-                    )
-        {
-            if (mNext == mBlockEnd) {
-                Block *block;
-                if (!(*mNextBlock = block =
-                        static_cast<Block*>(NS_Alloc(sizeof(Block)))))
-                    return nsnull;
-                mNext = block->mEntries;
-                mBlockEnd = block->mEntries + BlockSize;
-                block->mNext = nsnull;
-                mNextBlock = &block->mNext;
-            }
-            return new (mNext++) PtrInfo(aPointer, aParticipant
-                                         IF_DEBUG_CC_PARAM(aLangID)
-                                        );
-        }
-    private:
-        Block **mNextBlock;
-        PtrInfo *&mNext;
-        PtrInfo *mBlockEnd;
-    };
-
-    class Enumerator;
-    friend class Enumerator;
-    class Enumerator {
-    public:
-        Enumerator(NodePool& aPool)
-            : mFirstBlock(aPool.mBlocks),
-              mCurBlock(nsnull),
-              mNext(nsnull),
-              mBlockEnd(nsnull),
-              mLast(aPool.mLast)
-        {
-        }
-
-        PRBool IsDone() const
-        {
-            return mNext == mLast;
-        }
-
-        PtrInfo* GetNext()
-        {
-            NS_ASSERTION(!IsDone(), "calling GetNext when done");
-            if (mNext == mBlockEnd) {
-                Block *nextBlock = mCurBlock ? mCurBlock->mNext : mFirstBlock;
-                mNext = nextBlock->mEntries;
-                mBlockEnd = mNext + BlockSize;
-                mCurBlock = nextBlock;
-            }
-            return mNext++;
-        }
-    private:
-        Block *mFirstBlock, *mCurBlock;
-        // mNext is the next value we want to return, unless mNext == mBlockEnd
-        // NB: mLast is a reference to allow enumerating while building!
-        PtrInfo *mNext, *mBlockEnd, *&mLast;
-    };
-
-private:
-    Block *mBlocks;
-    PtrInfo *mLast;
-};
-
-
-class GCGraphBuilder;
-
-struct GCGraph
-{
-    NodePool mNodes;
-    EdgePool mEdges;
-    PRUint32 mRootCount;
-#ifdef DEBUG_CC
-    ReversedEdge *mReversedEdges;
-#endif
-
-    GCGraph() : mRootCount(0) {
-    }
-    ~GCGraph() { 
-    }
-};
-
-// XXX Would be nice to have an nsHashSet<KeyType> API that has
-// Add/Remove/Has rather than PutEntry/RemoveEntry/GetEntry.
-typedef nsTHashtable<nsVoidPtrHashKey> PointerSet;
-typedef nsBaseHashtable<nsVoidPtrHashKey, PRUint32, PRUint32>
-    PointerSetWithGeneration;
-
-#ifdef DEBUG_CC
-static void
-WriteGraph(FILE *stream, GCGraph &graph, const void *redPtr);
-#endif
-
-struct nsPurpleBuffer
-{
-
-#define ASSOCIATIVITY 2
-#define INDEX_LOW_BIT 6
-#define N_INDEX_BITS 13
-
-#define N_ENTRIES (1 << N_INDEX_BITS)
-#define N_POINTERS (N_ENTRIES * ASSOCIATIVITY)
-#define TOTAL_BYTES (N_POINTERS * PR_BYTES_PER_WORD)
-#define INDEX_MASK PR_BITMASK(N_INDEX_BITS)
-#define POINTER_INDEX(P) ((((PRUword)P) >> INDEX_LOW_BIT) & (INDEX_MASK))
-
-#if (INDEX_LOW_BIT + N_INDEX_BITS > (8 * PR_BYTES_PER_WORD))
-#error "index bit overflow"
-#endif
-
-    // This class serves as a generational wrapper around a pldhash
-    // table: a subset of generation zero lives in mCache, the
-    // remainder spill into the mBackingStore hashtable. The idea is
-    // to get a higher hit rate and greater locality of reference for
-    // generation zero, in which the vast majority of suspect/forget
-    // calls annihilate one another.
-
-    nsCycleCollectorParams &mParams;
-#ifdef DEBUG_CC
-    nsCycleCollectorStats &mStats;
-#endif
-    void* mCache[N_POINTERS];
-    PRUint32 mCurrGen;    
-    PointerSetWithGeneration mBackingStore;
-    
-#ifdef DEBUG_CC
-    nsPurpleBuffer(nsCycleCollectorParams &params,
-                   nsCycleCollectorStats &stats) 
-        : mParams(params),
-          mStats(stats),
-          mCurrGen(0)
-    {
-        Init();
-    }
-#else
-    nsPurpleBuffer(nsCycleCollectorParams &params) 
-        : mParams(params),
-          mCurrGen(0)
-    {
-        Init();
-    }
-#endif
-
-    ~nsPurpleBuffer()
-    {
-        memset(mCache, 0, sizeof(mCache));
-        mBackingStore.Clear();
-    }
-
-    void Init()
-    {
-        memset(mCache, 0, sizeof(mCache));
-        mBackingStore.Init();
-    }
-
-    void BumpGeneration();
-    void SelectAgedPointers(GCGraphBuilder &builder);
-
-    PRBool Exists(void *p)
-    {
-        PRUint32 idx = POINTER_INDEX(p);
-        for (PRUint32 i = 0; i < ASSOCIATIVITY; ++i) {
-            if (mCache[idx+i] == p)
-                return PR_TRUE;
-        }
-        PRUint32 gen;
-        return mBackingStore.Get(p, &gen);
-    }
-
-    void Put(void *p)
-    {
-        PRUint32 idx = POINTER_INDEX(p);
-        for (PRUint32 i = 0; i < ASSOCIATIVITY; ++i) {
-            if (!mCache[idx+i]) {
-                mCache[idx+i] = p;
-                return;
-            }
-        }
-#ifdef DEBUG_CC
-        mStats.mSpills++;
-#endif
-        SpillOne(p);
-    }
-
-    void Remove(void *p)     
-    {
-        PRUint32 idx = POINTER_INDEX(p);
-        for (PRUint32 i = 0; i < ASSOCIATIVITY; ++i) {
-            if (mCache[idx+i] == p) {
-                mCache[idx+i] = (void*)0;
-                return;
-            }
-        }
-        mBackingStore.Remove(p);
-    }
-
-    void SpillOne(void* &p)
-    {
-        mBackingStore.Put(p, mCurrGen);
-        p = (void*)0;
-    }
-
-    void SpillAll()
-    {
-        for (PRUint32 i = 0; i < N_POINTERS; ++i) {
-            if (mCache[i]) {
-                SpillOne(mCache[i]);
-            }
-        }
-    }
-
-    PRUint32 Count()
-    {
-        PRUint32 count = mBackingStore.Count();
-        for (PRUint32 i = 0; i < N_POINTERS; ++i) {
-            if (mCache[i]) {
-                ++count;
-            }
-        }
-        return count;
-    }
-};
-
-static PR_CALLBACK PLDHashOperator
-zeroGenerationCallback(const void*  ptr,
-                       PRUint32&    generation,
-                       void*        userArg)
-{
-#ifdef DEBUG_CC
-    nsPurpleBuffer *purp = static_cast<nsPurpleBuffer*>(userArg);
-    purp->mStats.mZeroGeneration++;
-#endif
-    generation = 0;
-    return PL_DHASH_NEXT;
-}
-
-void nsPurpleBuffer::BumpGeneration()
-{
-    SpillAll();
-    if (mCurrGen == 0xffffffff) {
-        mBackingStore.Enumerate(zeroGenerationCallback, this);
-        mCurrGen = 0;
-    } else {
-        ++mCurrGen;
-    }
-#ifdef DEBUG_CC
-    mStats.mBumpGeneration++;
-#endif
-}
-
-static inline PRBool
-SufficientlyAged(PRUint32 generation, nsPurpleBuffer *p)
-{
-    return generation + p->mParams.mScanDelay < p->mCurrGen;
-}
-
-struct CallbackClosure
-{
-    CallbackClosure(nsPurpleBuffer *aPurpleBuffer, GCGraphBuilder &aBuilder)
-        : mPurpleBuffer(aPurpleBuffer),
-          mBuilder(aBuilder)
-    {
-    }
-    nsPurpleBuffer *mPurpleBuffer;
-    GCGraphBuilder &mBuilder;
-};
-
-static PRBool
-AddPurpleRoot(GCGraphBuilder &builder, nsISupports *root);
-
-static PR_CALLBACK PLDHashOperator
-ageSelectionCallback(const void*  ptr,
-                     PRUint32&    generation,
-                     void*        userArg)
-{
-    CallbackClosure *closure = static_cast<CallbackClosure*>(userArg);
-    if (SufficientlyAged(generation, closure->mPurpleBuffer) &&
-        AddPurpleRoot(closure->mBuilder,
-                      static_cast<nsISupports *>(const_cast<void*>(ptr))))
-        return PL_DHASH_REMOVE;
-
-    return PL_DHASH_NEXT;
-}
-
-void
-nsPurpleBuffer::SelectAgedPointers(GCGraphBuilder &aBuilder)
-{
-    // Rely on our caller having done a BumpGeneration first, which in
-    // turn calls SpillAll.
-    CallbackClosure closure(this, aBuilder);
-    mBackingStore.Enumerate(ageSelectionCallback, &closure);
-}
-
-
-
-////////////////////////////////////////////////////////////////////////
-// Implement the LanguageRuntime interface for C++/XPCOM 
-////////////////////////////////////////////////////////////////////////
-
-
-struct nsCycleCollectionXPCOMRuntime : 
-    public nsCycleCollectionLanguageRuntime 
-{
-    nsresult BeginCycleCollection(nsCycleCollectionTraversalCallback &cb) 
-    {
-        return NS_OK;
-    }
-
-    nsresult FinishCycleCollection() 
-    {
-        return NS_OK;
-    }
-
-    inline nsCycleCollectionParticipant *ToParticipant(void *p);
-
-#ifdef DEBUG_CC
-    virtual void PrintAllReferencesTo(void *p) {}
-#endif
-};
-
-struct nsCycleCollector
-{
-    PRBool mCollectionInProgress;
-    PRBool mScanInProgress;
-    PRBool mFollowupCollection;
-    PRUint32 mCollectedObjects;
-
-    nsCycleCollectionLanguageRuntime *mRuntimes[nsIProgrammingLanguage::MAX+1];
-    nsCycleCollectionXPCOMRuntime mXPCOMRuntime;
-
-    GCGraph mGraph;
-
-    nsCycleCollectorParams mParams;
-
-    nsTPtrArray<PtrInfo> *mWhiteNodes;
-    PRUint32 mWhiteNodeCount;
-
-    nsPurpleBuffer mPurpleBuf;
-
-    void RegisterRuntime(PRUint32 langID, 
-                         nsCycleCollectionLanguageRuntime *rt);
-    void ForgetRuntime(PRUint32 langID);
-
-    void SelectPurple(GCGraphBuilder &builder);
-    void MarkRoots(GCGraphBuilder &builder);
-    void ScanRoots();
-    void RootWhite();
-    PRBool CollectWhite(); // returns whether anything was collected
-
-    nsCycleCollector();
-    ~nsCycleCollector();
-
-    PRBool Suspect(nsISupports *n);
-    PRBool Forget(nsISupports *n);
-    PRUint32 Collect(PRUint32 aTryCollections = 1);
-    PRBool BeginCollection();
-    PRBool FinishCollection();
-    PRUint32 SuspectedCount();
-    void Shutdown();
-
-    void ClearGraph()
-    {
-        mGraph.mNodes.Clear();
-        mGraph.mEdges.Clear();
-        mGraph.mRootCount = 0;
-    }
-
-#ifdef DEBUG_CC
-    nsCycleCollectorStats mStats;    
-
-    FILE *mPtrLog;
-
-    void MaybeDrawGraphs();
-    void Allocated(void *n, size_t sz);
-    void Freed(void *n);
-
-    void ExplainLiveExpectedGarbage();
-    PRBool CreateReversedEdges();
-    void DestroyReversedEdges();
-    void ShouldBeFreed(nsISupports *n);
-    void WasFreed(nsISupports *n);
-    PointerSet mExpectedGarbage;
-#endif
-};
-
-
-class GraphWalker
-{
-private:
-    void DoWalk(nsDeque &aQueue);
-
-public:
-    void Walk(PtrInfo *s0);
-    void WalkFromRoots(GCGraph &aGraph);
-
-    // Provided by concrete walker subtypes.
-    virtual PRBool ShouldVisitNode(PtrInfo const *pi) = 0;
-    virtual void VisitNode(PtrInfo *pi) = 0;
-};
-
-
-////////////////////////////////////////////////////////////////////////
-// The static collector object
-////////////////////////////////////////////////////////////////////////
-
-
-static nsCycleCollector *sCollector = nsnull;
-
-
-////////////////////////////////////////////////////////////////////////
-// Utility functions
-////////////////////////////////////////////////////////////////////////
-
-class CCRunnableFaultReport : public nsRunnable {
-public:
-    CCRunnableFaultReport(const nsCString& report)
-    {
-        CopyUTF8toUTF16(report, mReport);
-    }
-    
-    NS_IMETHOD Run() {
-        nsCOMPtr<nsIObserverService> obs =
-            do_GetService(NS_OBSERVERSERVICE_CONTRACTID);
-        if (obs) {
-            obs->NotifyObservers(nsnull, "cycle-collector-fault",
-                                 mReport.get());
-        }
-
-        nsCOMPtr<nsIConsoleService> cons =
-            do_GetService(NS_CONSOLESERVICE_CONTRACTID);
-        if (cons) {
-            cons->LogStringMessage(mReport.get());
-        }
-        return NS_OK;
-    }
-
-private:
-    nsString mReport;
-};
-
-static void
-Fault(const char *msg, const void *ptr=nsnull)
-{
-#ifdef DEBUG_CC
-    // This should be nearly impossible, but just in case.
-    if (!sCollector)
-        return;
-
-    if (sCollector->mParams.mFaultIsFatal) {
-
-        if (ptr)
-            printf("Fatal fault in cycle collector: %s (ptr: %p)\n", msg, ptr);
-        else
-            printf("Fatal fault in cycle collector: %s\n", msg);
-
-     
-        if (sCollector->mGraph.mRootCount > 0) {
-            FILE *stream;
-#ifdef WIN32
-            const char fname[] = "c:\\fault-graph.dot";
-#else
-            const char fname[] = "/tmp/fault-graph.dot";
-#endif
-            printf("depositing faulting cycle-collection graph in %s\n", fname);
-            stream = fopen(fname, "w+");
-            WriteGraph(stream, sCollector->mGraph, ptr);
-            fclose(stream);
-        } 
-
-        exit(1);
-    }
-#endif
-
-    nsPrintfCString str(256, "Fault in cycle collector: %s (ptr: %p)\n",
-                        msg, ptr);
-    NS_NOTREACHED(str.get());
-
-    // When faults are not fatal, we assume we're running in a
-    // production environment and we therefore want to disable the
-    // collector on a fault. This will unfortunately cause the browser
-    // to leak pretty fast wherever creates cyclical garbage, but it's
-    // probably a better user experience than crashing. Besides, we
-    // *should* never hit a fault.
-
-    sCollector->mParams.mDoNothing = PR_TRUE;
-
-    // Report to observers off an event so we don't run JS under GC
-    // (which is where we might be right now).
-    nsCOMPtr<nsIRunnable> ev = new CCRunnableFaultReport(str);
-    NS_DispatchToCurrentThread(ev);
-}
-
-#ifdef DEBUG_CC
-static void
-Fault(const char *msg, PtrInfo *pi)
-{
-    printf("Fault in cycle collector: %s\n"
-           "  while operating on pointer %p %s\n",
-           msg, pi->mPointer, pi->mName);
-    if (pi->mInternalRefs) {
-        printf("  which has internal references from:\n");
-        NodePool::Enumerator queue(sCollector->mGraph.mNodes);
-        while (!queue.IsDone()) {
-            PtrInfo *ppi = queue.GetNext();
-            for (EdgePool::Iterator e = ppi->mFirstChild, e_end = ppi->mLastChild;
-                 e != e_end; ++e) {
-                if (*e == pi) {
-                    printf("    %p %s\n", ppi->mPointer, ppi->mName);
-                }
-            }
-        }
-    }
-
-    Fault(msg, pi->mPointer);
-}
-#else
-inline void
-Fault(const char *msg, PtrInfo *pi)
-{
-    Fault(msg, pi->mPointer);
-}
-#endif
-
-
-
-static nsISupports *
-canonicalize(nsISupports *in)
-{
-    nsCOMPtr<nsISupports> child;
-    in->QueryInterface(NS_GET_IID(nsCycleCollectionISupports),
-                       getter_AddRefs(child));
-    return child.get();
-}
-
-static inline void
-ToParticipant(nsISupports *s, nsXPCOMCycleCollectionParticipant **cp)
-{
-    // We use QI to move from an nsISupports to an
-    // nsXPCOMCycleCollectionParticipant, which is a per-class singleton helper
-    // object that implements traversal and unlinking logic for the nsISupports
-    // in question.
-    CallQueryInterface(s, cp);
-#ifdef DEBUG_CC
-    if (cp)
-        ++sCollector->mStats.mSuccessfulQI;
-    else
-        ++sCollector->mStats.mFailedQI;
-#endif
-}
-
-nsCycleCollectionParticipant *
-nsCycleCollectionXPCOMRuntime::ToParticipant(void *p)
-{
-    nsXPCOMCycleCollectionParticipant *cp;
-    ::ToParticipant(static_cast<nsISupports*>(p), &cp);
-    return cp;
-}
-
-
-void
-GraphWalker::Walk(PtrInfo *s0)
-{
-    nsDeque queue;
-    queue.Push(s0);
-    DoWalk(queue);
-}
-
-void
-GraphWalker::WalkFromRoots(GCGraph& aGraph)
-{
-    nsDeque queue;
-    NodePool::Enumerator etor(aGraph.mNodes);
-    for (PRUint32 i = 0; i < aGraph.mRootCount; ++i) {
-        queue.Push(etor.GetNext());
-    }
-    DoWalk(queue);
-}
-
-void
-GraphWalker::DoWalk(nsDeque &aQueue)
-{
-    // Use a aQueue to match the breadth-first traversal used when we
-    // built the graph, for hopefully-better locality.
-    while (aQueue.GetSize() > 0) {
-        PtrInfo *pi = static_cast<PtrInfo*>(aQueue.PopFront());
-
-        if (this->ShouldVisitNode(pi)) {
-            this->VisitNode(pi);
-            for (EdgePool::Iterator child = pi->mFirstChild,
-                                child_end = pi->mLastChild;
-                 child != child_end; ++child) {
-                aQueue.Push(*child);
-            }
-        }
-    };
-
-#ifdef DEBUG_CC
-    sCollector->mStats.mWalkedGraph++;
-#endif
-}
-
-
-////////////////////////////////////////////////////////////////////////
-// Bacon & Rajan's |MarkRoots| routine.
-////////////////////////////////////////////////////////////////////////
-
-struct PtrToNodeEntry : public PLDHashEntryHdr
-{
-    // The key is mNode->mPointer
-    PtrInfo *mNode;
-};
-
-PR_STATIC_CALLBACK(PRBool)
-PtrToNodeMatchEntry(PLDHashTable *table,
-                    const PLDHashEntryHdr *entry,
-                    const void *key)
-{
-    const PtrToNodeEntry *n = static_cast<const PtrToNodeEntry*>(entry);
-    return n->mNode->mPointer == key;
-}
-
-static PLDHashTableOps PtrNodeOps = {
-    PL_DHashAllocTable,
-    PL_DHashFreeTable,
-    PL_DHashVoidPtrKeyStub,
-    PtrToNodeMatchEntry,
-    PL_DHashMoveEntryStub,
-    PL_DHashClearEntryStub,
-    PL_DHashFinalizeStub,
-    nsnull
-};
-
-class GCGraphBuilder : public nsCycleCollectionTraversalCallback
-{
-private:
-    NodePool::Builder mNodeBuilder;
-    EdgePool::Builder mEdgeBuilder;
-    PLDHashTable mPtrToNodeMap;
-    PtrInfo *mCurrPi;
-    nsCycleCollectionLanguageRuntime **mRuntimes; // weak, from nsCycleCollector
-#ifdef DEBUG_CC
-    nsCString mNextEdgeName;
-#endif
-
-public:
-    GCGraphBuilder(GCGraph &aGraph,
-                   nsCycleCollectionLanguageRuntime **aRuntimes);
-    ~GCGraphBuilder();
-
-    PRUint32 Count() const { return mPtrToNodeMap.entryCount; }
-
-#ifdef DEBUG_CC
-    PtrInfo* AddNode(void *s, nsCycleCollectionParticipant *aParticipant,
-                     PRUint32 aLangID);
-#else
-    PtrInfo* AddNode(void *s, nsCycleCollectionParticipant *aParticipant);
-    PtrInfo* AddNode(void *s, nsCycleCollectionParticipant *aParticipant,
-                     PRUint32 aLangID)
-    {
-        return AddNode(s, aParticipant);
-    }
-#endif
-    void Traverse(PtrInfo* aPtrInfo);
-
-    // nsCycleCollectionTraversalCallback methods.
-    NS_IMETHOD_(void) NoteXPCOMRoot(nsISupports *root);
-
-private:
-#ifdef DEBUG_CC
-    NS_IMETHOD_(void) DescribeNode(CCNodeType type, nsrefcnt refCount,
-                                   size_t objSz, const char *objName);
-#else
-    NS_IMETHOD_(void) DescribeNode(CCNodeType type, nsrefcnt refCount);
-#endif
-    NS_IMETHOD_(void) NoteRoot(PRUint32 langID, void *child,
-                               nsCycleCollectionParticipant* participant);
-    NS_IMETHOD_(void) NoteXPCOMChild(nsISupports *child);
-    NS_IMETHOD_(void) NoteNativeChild(void *child,
-                                     nsCycleCollectionParticipant *participant);
-    NS_IMETHOD_(void) NoteScriptChild(PRUint32 langID, void *child);
-#ifdef DEBUG_CC
-    NS_IMETHOD_(void) NoteNextEdgeName(const char* name);
-#endif
-};
-
-GCGraphBuilder::GCGraphBuilder(GCGraph &aGraph,
-                               nsCycleCollectionLanguageRuntime **aRuntimes)
-    : mNodeBuilder(aGraph.mNodes),
-      mEdgeBuilder(aGraph.mEdges),
-      mRuntimes(aRuntimes)
-{
-    if (!PL_DHashTableInit(&mPtrToNodeMap, &PtrNodeOps, nsnull,
-                           sizeof(PtrToNodeEntry), 32768))
-        mPtrToNodeMap.ops = nsnull;
-}
-
-GCGraphBuilder::~GCGraphBuilder()
-{
-    if (mPtrToNodeMap.ops)
-        PL_DHashTableFinish(&mPtrToNodeMap);
-}
-
-PtrInfo*
-GCGraphBuilder::AddNode(void *s, nsCycleCollectionParticipant *aParticipant
-                        IF_DEBUG_CC_PARAM(PRUint32 aLangID)
-                       )
-{
-    PtrToNodeEntry *e = static_cast<PtrToNodeEntry*>(PL_DHashTableOperate(&mPtrToNodeMap, s, PL_DHASH_ADD));
-    PtrInfo *result;
-    if (!e->mNode) {
-        // New entry.
-        result = mNodeBuilder.Add(s, aParticipant
-                                  IF_DEBUG_CC_PARAM(aLangID)
-                                 );
-        if (!result) {
-            PL_DHashTableRawRemove(&mPtrToNodeMap, e);
-            return nsnull;
-        }
-        e->mNode = result;
-    } else {
-        result = e->mNode;
-        NS_ASSERTION(result->mParticipant == aParticipant,
-                     "nsCycleCollectionParticipant shouldn't change!");
-    }
-    return result;
-}
-
-void
-GCGraphBuilder::Traverse(PtrInfo* aPtrInfo)
-{
-    mCurrPi = aPtrInfo;
-
-#ifdef DEBUG_CC
-    if (!mCurrPi->mParticipant) {
-        Fault("unknown pointer during walk", aPtrInfo);
-        return;
-    }
-#endif
-
-    mCurrPi->mFirstChild = mEdgeBuilder.Mark();
-    
-    nsresult rv = aPtrInfo->mParticipant->Traverse(aPtrInfo->mPointer, *this);
-    if (NS_FAILED(rv)) {
-        Fault("script pointer traversal failed", aPtrInfo);
-    }
-
-    mCurrPi->mLastChild = mEdgeBuilder.Mark();
-}
-
-NS_IMETHODIMP_(void)
-GCGraphBuilder::NoteXPCOMRoot(nsISupports *root)
-{
-    root = canonicalize(root);
-    NS_ASSERTION(root,
-                 "Don't add objects that don't participate in collection!");
-
-#ifdef DEBUG_CC
-    if (nsCycleCollector_shouldSuppress(root))
-        return;
-#endif
-    
-    nsXPCOMCycleCollectionParticipant *cp;
-    ToParticipant(root, &cp);
-
-    NoteRoot(nsIProgrammingLanguage::CPLUSPLUS, root, cp);
-}
-
-
-NS_IMETHODIMP_(void)
-GCGraphBuilder::NoteRoot(PRUint32 langID, void *root,
-                         nsCycleCollectionParticipant* participant)
-{
-    NS_ASSERTION(root, "Don't add a null root!");
-
-    if (langID > nsIProgrammingLanguage::MAX || !mRuntimes[langID]) {
-        Fault("adding root for unregistered language", root);
-        return;
-    }
-
-    AddNode(root, participant, langID);
-}
-
-NS_IMETHODIMP_(void)
-#ifdef DEBUG_CC
-GCGraphBuilder::DescribeNode(CCNodeType type, nsrefcnt refCount,
-                             size_t objSz, const char *objName)
-#else
-GCGraphBuilder::DescribeNode(CCNodeType type, nsrefcnt refCount)
-#endif
-{
-#ifdef DEBUG_CC
-    mCurrPi->mBytes = objSz;
-    mCurrPi->mName = PL_strdup(objName);
-#endif
-
-    if (type == RefCounted) {
-        if (refCount == 0 || refCount == PR_UINT32_MAX)
-            Fault("zero or overflowing refcount", mCurrPi);
-
-        mCurrPi->mRefCount = refCount;
-    }
-    else {
-        mCurrPi->mRefCount = type == GCMarked ? PR_UINT32_MAX : 0;
-    }
-#ifdef DEBUG_CC
-    sCollector->mStats.mVisitedNode++;
-#endif
-}
-
-NS_IMETHODIMP_(void)
-GCGraphBuilder::NoteXPCOMChild(nsISupports *child) 
-{
-#ifdef DEBUG_CC
-    nsCString edgeName(mNextEdgeName);
-    mNextEdgeName.Truncate();
-#endif
-    if (!child || !(child = canonicalize(child)))
-        return; 
-
-#ifdef DEBUG_CC
-    if (nsCycleCollector_shouldSuppress(child))
-        return;
-#endif
-    
-    nsXPCOMCycleCollectionParticipant *cp;
-    ToParticipant(child, &cp);
-    if (cp) {
-        PtrInfo *childPi = AddNode(child, cp, nsIProgrammingLanguage::CPLUSPLUS);
-        if (!childPi)
-            return;
-        mEdgeBuilder.Add(childPi);
-#ifdef DEBUG_CC
-        mCurrPi->mEdgeNames.AppendCString(edgeName);
-#endif
-        ++childPi->mInternalRefs;
-    }
-}
-
-NS_IMETHODIMP_(void)
-GCGraphBuilder::NoteNativeChild(void *child,
-                                nsCycleCollectionParticipant *participant)
-{
-#ifdef DEBUG_CC
-    nsCString edgeName(mNextEdgeName);
-    mNextEdgeName.Truncate();
-#endif
-    if (!child)
-        return;
-
-    NS_ASSERTION(participant, "Need a nsCycleCollectionParticipant!");
-
-    PtrInfo *childPi = AddNode(child, participant, nsIProgrammingLanguage::CPLUSPLUS);
-    if (!childPi)
-        return;
-    mEdgeBuilder.Add(childPi);
-#ifdef DEBUG_CC
-    mCurrPi->mEdgeNames.AppendCString(edgeName);
-#endif
-    ++childPi->mInternalRefs;
-}
-
-NS_IMETHODIMP_(void)
-GCGraphBuilder::NoteScriptChild(PRUint32 langID, void *child) 
-{
-#ifdef DEBUG_CC
-    nsCString edgeName(mNextEdgeName);
-    mNextEdgeName.Truncate();
-#endif
-    if (!child)
-        return;
-
-    if (langID > nsIProgrammingLanguage::MAX) {
-        Fault("traversing pointer for unknown language", child);
-        return;
-    }
-
-    if (!mRuntimes[langID]) {
-        NS_WARNING("Not collecting cycles involving objects for scripting "
-                   "languages that don't participate in cycle collection.");
-        return;
-    }
-
-    nsCycleCollectionParticipant *cp = mRuntimes[langID]->ToParticipant(child);
-    if (!cp)
-        return;
-
-    PtrInfo *childPi = AddNode(child, cp, langID);
-    if (!childPi)
-        return;
-    mEdgeBuilder.Add(childPi);
-#ifdef DEBUG_CC
-    mCurrPi->mEdgeNames.AppendCString(edgeName);
-#endif
-    ++childPi->mInternalRefs;
-}
-
-#ifdef DEBUG_CC
-NS_IMETHODIMP_(void)
-GCGraphBuilder::NoteNextEdgeName(const char* name)
-{
-    mNextEdgeName = name;
-}
-#endif
-
-static PRBool
-AddPurpleRoot(GCGraphBuilder &builder, nsISupports *root)
-{
-    root = canonicalize(root);
-    NS_ASSERTION(root,
-                 "Don't add objects that don't participate in collection!");
-
-    nsXPCOMCycleCollectionParticipant *cp;
-    ToParticipant(root, &cp);
-
-    PtrInfo *pinfo = builder.AddNode(root, cp,
-                                     nsIProgrammingLanguage::CPLUSPLUS);
-    if (!pinfo) {
-        return PR_FALSE;
-    }
-
-    cp->UnmarkPurple(root);
-
-    return PR_TRUE;
-}
-
-void 
-nsCycleCollector::SelectPurple(GCGraphBuilder &builder)
-{
-    mPurpleBuf.BumpGeneration();
-    mPurpleBuf.SelectAgedPointers(builder);
-}
-
-void
-nsCycleCollector::MarkRoots(GCGraphBuilder &builder)
-{
-    mGraph.mRootCount = builder.Count();
-
-    // read the PtrInfo out of the graph that we are building
-    NodePool::Enumerator queue(mGraph.mNodes);
-    while (!queue.IsDone()) {
-        PtrInfo *pi = queue.GetNext();
-        builder.Traverse(pi);
-    }
-}
-
-
-////////////////////////////////////////////////////////////////////////
-// Bacon & Rajan's |ScanRoots| routine.
-////////////////////////////////////////////////////////////////////////
-
-
-struct ScanBlackWalker : public GraphWalker
-{
-    ScanBlackWalker(PRUint32 &aWhiteNodeCount) : mWhiteNodeCount(aWhiteNodeCount)
-    {
-    }
-
-    PRBool ShouldVisitNode(PtrInfo const *pi)
-    { 
-        return pi->mColor != black;
-    }
-
-    void VisitNode(PtrInfo *pi)
-    {
-        if (pi->mColor == white)
-            --mWhiteNodeCount;
-        pi->mColor = black;
-#ifdef DEBUG_CC
-        sCollector->mStats.mSetColorBlack++;
-#endif
-    }
-
-    PRUint32 &mWhiteNodeCount;
-};
-
-
-struct scanWalker : public GraphWalker
-{
-    scanWalker(PRUint32 &aWhiteNodeCount) : mWhiteNodeCount(aWhiteNodeCount)
-    {
-    }
-
-    PRBool ShouldVisitNode(PtrInfo const *pi)
-    { 
-        return pi->mColor == grey;
-    }
-
-    void VisitNode(PtrInfo *pi)
-    {
-        if (pi->mInternalRefs > pi->mRefCount && pi->mRefCount > 0)
-            Fault("traversed refs exceed refcount", pi);
-
-        if (pi->mInternalRefs == pi->mRefCount || pi->mRefCount == 0) {
-            pi->mColor = white;
-            ++mWhiteNodeCount;
-#ifdef DEBUG_CC
-            sCollector->mStats.mSetColorWhite++;
-#endif
-        } else {
-            ScanBlackWalker(mWhiteNodeCount).Walk(pi);
-            NS_ASSERTION(pi->mColor == black,
-                         "Why didn't ScanBlackWalker make pi black?");
-        }
-    }
-
-    PRUint32 &mWhiteNodeCount;
-};
-
-void
-nsCycleCollector::ScanRoots()
-{
-    mWhiteNodeCount = 0;
-
-    // On the assumption that most nodes will be black, it's
-    // probably faster to use a GraphWalker than a
-    // NodePool::Enumerator.
-    scanWalker(mWhiteNodeCount).WalkFromRoots(mGraph); 
-
-#ifdef DEBUG_CC
-    // Sanity check: scan should have colored all grey nodes black or
-    // white. So we ensure we have no grey nodes at this point.
-    NodePool::Enumerator etor(mGraph.mNodes);
-    while (!etor.IsDone())
-    {
-        PtrInfo *pinfo = etor.GetNext();
-        if (pinfo->mColor == grey) {
-            Fault("valid grey node after scanning", pinfo);
-        }
-    }
-#endif
-}
-
-
-////////////////////////////////////////////////////////////////////////
-// Bacon & Rajan's |CollectWhite| routine, somewhat modified.
-////////////////////////////////////////////////////////////////////////
-
-void
-nsCycleCollector::RootWhite()
-{
-    // Explanation of "somewhat modified": we have no way to collect the
-    // set of whites "all at once", we have to ask each of them to drop
-    // their outgoing links and assume this will cause the garbage cycle
-    // to *mostly* self-destruct (except for the reference we continue
-    // to hold). 
-    // 
-    // To do this "safely" we must make sure that the white nodes we're
-    // operating on are stable for the duration of our operation. So we
-    // make 3 sets of calls to language runtimes:
-    //
-    //   - Root(whites), which should pin the whites in memory.
-    //   - Unlink(whites), which drops outgoing links on each white.
-    //   - Unroot(whites), which returns the whites to normal GC.
-
-    nsresult rv;
-
-    NS_ASSERTION(mWhiteNodes->IsEmpty(),
-                 "FinishCollection wasn't called?");
-
-    mWhiteNodes->SetCapacity(mWhiteNodeCount);
-
-    NodePool::Enumerator etor(mGraph.mNodes);
-    while (!etor.IsDone())
-    {
-        PtrInfo *pinfo = etor.GetNext();
-        if (pinfo->mColor == white && mWhiteNodes->AppendElement(pinfo)) {
-            rv = pinfo->mParticipant->RootAndUnlinkJSObjects(pinfo->mPointer);
-            if (NS_FAILED(rv)) {
-                Fault("Failed root call while unlinking", pinfo);
-                mWhiteNodes->RemoveElementAt(mWhiteNodes->Length() - 1);
-            }
-        }
-    }
-}
-
-PRBool
-nsCycleCollector::CollectWhite()
-{
-    nsresult rv;
-
-#if defined(DEBUG_CC) && !defined(__MINGW32__) && defined(WIN32)
-    struct _CrtMemState ms1, ms2;
-    _CrtMemCheckpoint(&ms1);
-#endif
-
-    PRUint32 i, count = mWhiteNodes->Length();
-    for (i = 0; i < count; ++i) {
-        PtrInfo *pinfo = mWhiteNodes->ElementAt(i);
-        rv = pinfo->mParticipant->Unlink(pinfo->mPointer);
-        if (NS_FAILED(rv)) {
-            Fault("Failed unlink call while unlinking", pinfo);
-#ifdef DEBUG_CC
-            mStats.mFailedUnlink++;
-#endif
-        }
-        else {
-#ifdef DEBUG_CC
-            ++mStats.mCollectedNode;
-#endif
-        }
-    }
-
-    for (i = 0; i < count; ++i) {
-        PtrInfo *pinfo = mWhiteNodes->ElementAt(i);
-        rv = pinfo->mParticipant->Unroot(pinfo->mPointer);
-        if (NS_FAILED(rv))
-            Fault("Failed unroot call while unlinking", pinfo);
-    }
-
-#if defined(DEBUG_CC) && !defined(__MINGW32__) && defined(WIN32)
-    _CrtMemCheckpoint(&ms2);
-    if (ms2.lTotalCount < ms1.lTotalCount)
-        mStats.mFreedBytes += (ms1.lTotalCount - ms2.lTotalCount);
-#endif
-
-    mCollectedObjects += count;
-    return count > 0;
-}
-
-
-#ifdef DEBUG_CC
-////////////////////////////////////////////////////////////////////////
-// Memory-hooking stuff
-// When debugging wild pointers, it sometimes helps to hook malloc and
-// free. This stuff is disabled unless you set an environment variable.
-////////////////////////////////////////////////////////////////////////
-
-static PRBool hookedMalloc = PR_FALSE;
-
-#if defined(__GLIBC__) && !defined(__UCLIBC__)
-#include <malloc.h>
-
-static void* (*old_memalign_hook)(size_t, size_t, const void *);
-static void* (*old_realloc_hook)(void *, size_t, const void *);
-static void* (*old_malloc_hook)(size_t, const void *);
-static void (*old_free_hook)(void *, const void *);
-
-static void* my_memalign_hook(size_t, size_t, const void *);
-static void* my_realloc_hook(void *, size_t, const void *);
-static void* my_malloc_hook(size_t, const void *);
-static void my_free_hook(void *, const void *);
-
-static inline void 
-install_old_hooks()
-{
-    __memalign_hook = old_memalign_hook;
-    __realloc_hook = old_realloc_hook;
-    __malloc_hook = old_malloc_hook;
-    __free_hook = old_free_hook;
-}
-
-static inline void 
-save_old_hooks()
-{
-    // Glibc docs recommend re-saving old hooks on
-    // return from recursive calls. Strangely when 
-    // we do this, we find ourselves in infinite
-    // recursion.
-
-    //     old_memalign_hook = __memalign_hook;
-    //     old_realloc_hook = __realloc_hook;
-    //     old_malloc_hook = __malloc_hook;
-    //     old_free_hook = __free_hook;
-}
-
-static inline void 
-install_new_hooks()
-{
-    __memalign_hook = my_memalign_hook;
-    __realloc_hook = my_realloc_hook;
-    __malloc_hook = my_malloc_hook;
-    __free_hook = my_free_hook;
-}
-
-static void*
-my_realloc_hook(void *ptr, size_t size, const void *caller)
-{
-    void *result;    
-
-    install_old_hooks();
-    result = realloc(ptr, size);
-    save_old_hooks();
-
-    if (sCollector) {
-        sCollector->Freed(ptr);
-        sCollector->Allocated(result, size);
-    }
-
-    install_new_hooks();
-
-    return result;
-}
-
-
-static void* 
-my_memalign_hook(size_t size, size_t alignment, const void *caller)
-{
-    void *result;    
-
-    install_old_hooks();
-    result = memalign(size, alignment);
-    save_old_hooks();
-
-    if (sCollector)
-        sCollector->Allocated(result, size);
-
-    install_new_hooks();
-
-    return result;
-}
-
-
-static void 
-my_free_hook (void *ptr, const void *caller)
-{
-    install_old_hooks();
-    free(ptr);
-    save_old_hooks();
-
-    if (sCollector)
-        sCollector->Freed(ptr);
-
-    install_new_hooks();
-}      
-
-
-static void*
-my_malloc_hook (size_t size, const void *caller)
-{
-    void *result;
-
-    install_old_hooks();
-    result = malloc (size);
-    save_old_hooks();
-
-    if (sCollector)
-        sCollector->Allocated(result, size);
-
-    install_new_hooks();
-
-    return result;
-}
-
-
-static void 
-InitMemHook(void)
-{
-    if (!hookedMalloc) {
-        save_old_hooks();
-        install_new_hooks();
-        hookedMalloc = PR_TRUE;        
-    }
-}
-
-#elif defined(WIN32)
-#ifndef __MINGW32__
-
-static int 
-AllocHook(int allocType, void *userData, size_t size, int 
-          blockType, long requestNumber, const unsigned char *filename, int 
-          lineNumber)
-{
-    if (allocType == _HOOK_FREE)
-        sCollector->Freed(userData);
-    return 1;
-}
-
-
-static void InitMemHook(void)
-{
-    if (!hookedMalloc) {
-        _CrtSetAllocHook (AllocHook);
-        hookedMalloc = PR_TRUE;        
-    }
-}
-#endif // __MINGW32__
-
-#elif 0 // defined(XP_MACOSX)
-
-#include <malloc/malloc.h>
-
-static void (*old_free)(struct _malloc_zone_t *zone, void *ptr);
-
-static void
-freehook(struct _malloc_zone_t *zone, void *ptr)
-{
-    if (sCollector)
-        sCollector->Freed(ptr);
-    old_free(zone, ptr);
-}
-
-
-static void
-InitMemHook(void)
-{
-    if (!hookedMalloc) {
-        malloc_zone_t *default_zone = malloc_default_zone();
-        old_free = default_zone->free;
-        default_zone->free = freehook;
-        hookedMalloc = PR_TRUE;
-    }
-}
-
-
-#else
-
-static void
-InitMemHook(void)
-{
-}
-
-#endif // GLIBC / WIN32 / OSX
-#endif // DEBUG_CC
-
-////////////////////////////////////////////////////////////////////////
-// Collector implementation
-////////////////////////////////////////////////////////////////////////
-
-nsCycleCollector::nsCycleCollector() : 
-    mCollectionInProgress(PR_FALSE),
-    mScanInProgress(PR_FALSE),
-    mCollectedObjects(0),
-    mWhiteNodes(nsnull),
-    mWhiteNodeCount(0),
-#ifdef DEBUG_CC
-    mPurpleBuf(mParams, mStats),
-    mPtrLog(nsnull)
-#else
-    mPurpleBuf(mParams)
-#endif
-{
-#ifdef DEBUG_CC
-    mExpectedGarbage.Init();
-#endif
-
-    memset(mRuntimes, 0, sizeof(mRuntimes));
-    mRuntimes[nsIProgrammingLanguage::CPLUSPLUS] = &mXPCOMRuntime;
-}
-
-
-nsCycleCollector::~nsCycleCollector()
-{
-}
-
-
-void 
-nsCycleCollector::RegisterRuntime(PRUint32 langID, 
-                                  nsCycleCollectionLanguageRuntime *rt)
-{
-    if (mParams.mDoNothing)
-        return;
-
-    if (langID > nsIProgrammingLanguage::MAX)
-        Fault("unknown language runtime in registration");
-
-    if (mRuntimes[langID])
-        Fault("multiple registrations of language runtime", rt);
-
-    mRuntimes[langID] = rt;
-}
-
-
-void 
-nsCycleCollector::ForgetRuntime(PRUint32 langID)
-{
-    if (mParams.mDoNothing)
-        return;
-
-    if (langID > nsIProgrammingLanguage::MAX)
-        Fault("unknown language runtime in deregistration");
-
-    if (! mRuntimes[langID])
-        Fault("forgetting non-registered language runtime");
-
-    mRuntimes[langID] = nsnull;
-}
-
-
-#ifdef DEBUG_CC
-static void
-WriteGraph(FILE *stream, GCGraph &graph, const void *redPtr)
-{
-    fprintf(stream, 
-            "digraph collection {\n"
-            "rankdir=LR\n"
-            "node [fontname=fixed, fontsize=10, style=filled, shape=box]\n"
-            );
-    
-    NodePool::Enumerator etor(graph.mNodes);
-    while (!etor.IsDone()) {
-        PtrInfo *pi = etor.GetNext();
-        const void *p = pi->mPointer;
-        fprintf(stream, 
-                "n%p [label=\"%s\\n%p\\n",
-                p,
-                pi->mName,
-                p);
-        if (pi->mRefCount != 0 && pi->mRefCount != PR_UINT32_MAX) {
-            fprintf(stream, 
-                    "%u/%u refs found",
-                    pi->mInternalRefs, pi->mRefCount);
-        }
-        fprintf(stream, 
-                "\", fillcolor=%s, fontcolor=%s]\n", 
-                (redPtr && redPtr == p ? "red" : (pi->mColor == black ? "black" : "white")),
-                (pi->mColor == black ? "white" : "black"));
-        for (EdgePool::Iterator child = pi->mFirstChild,
-                 child_end = pi->mLastChild;
-             child != child_end; ++child) {
-            fprintf(stream, "n%p -> n%p\n", p, (*child)->mPointer);
-        }
-    }
-    
-    fprintf(stream, "\n}\n");    
-}
-
-
-void 
-nsCycleCollector::MaybeDrawGraphs()
-{
-    if (mParams.mDrawGraphs) {
-        // We draw graphs only if there were any white nodes.
-        PRBool anyWhites = PR_FALSE;
-        NodePool::Enumerator fwetor(mGraph.mNodes);
-        while (!fwetor.IsDone())
-        {
-            PtrInfo *pinfo = fwetor.GetNext();
-            if (pinfo->mColor == white) {
-                anyWhites = PR_TRUE;
-                break;
-            }
-        }
-
-        if (anyWhites) {
-            // We can't just use _popen here because graphviz-for-windows
-            // doesn't set up its stdin stream properly, sigh.
-            FILE *stream;
-#ifdef WIN32
-            stream = fopen("c:\\cycle-graph.dot", "w+");
-#else
-            stream = popen("dotty -", "w");
-#endif
-            WriteGraph(stream, mGraph, nsnull);
-#ifdef WIN32
-            fclose(stream);
-            // Even dotty doesn't work terribly well on windows, since
-            // they execute lefty asynchronously. So we'll just run 
-            // lefty ourselves.
-            _spawnlp(_P_WAIT, 
-                     "lefty", 
-                     "lefty",
-                     "-e",
-                     "\"load('dotty.lefty');"
-                     "dotty.simple('c:\\cycle-graph.dot');\"",
-                     NULL);
-            unlink("c:\\cycle-graph.dot");
-#else
-            pclose(stream);
-#endif
-        }
-    }
-}
-
-class Suppressor :
-    public nsCycleCollectionTraversalCallback
-{
-protected:
-    static char *sSuppressionList;
-    static PRBool sInitialized;
-    PRBool mSuppressThisNode;
-public:
-    Suppressor()
-    {
-    }
-
-    PRBool shouldSuppress(nsISupports *s)
-    {
-        if (!sInitialized) {
-            sSuppressionList = PR_GetEnv("XPCOM_CC_SUPPRESS");
-            sInitialized = PR_TRUE;
-        }
-        if (sSuppressionList == nsnull) {
-            mSuppressThisNode = PR_FALSE;
-        } else {
-            nsresult rv;
-            nsXPCOMCycleCollectionParticipant *cp;
-            rv = CallQueryInterface(s, &cp);
-            if (NS_FAILED(rv)) {
-                Fault("checking suppression on wrong type of pointer", s);
-                return PR_TRUE;
-            }
-            cp->Traverse(s, *this);
-        }
-        return mSuppressThisNode;
-    }
-
-    NS_IMETHOD_(void) DescribeNode(CCNodeType type, nsrefcnt refCount,
-                                   size_t objSz, const char *objName)
-    {
-        mSuppressThisNode = (PL_strstr(sSuppressionList, objName) != nsnull);
-    }
-
-    NS_IMETHOD_(void) NoteXPCOMRoot(nsISupports *root) {};
-    NS_IMETHOD_(void) NoteRoot(PRUint32 langID, void *root,
-                               nsCycleCollectionParticipant* participant) {};
-    NS_IMETHOD_(void) NoteXPCOMChild(nsISupports *child) {}
-    NS_IMETHOD_(void) NoteScriptChild(PRUint32 langID, void *child) {}
-    NS_IMETHOD_(void) NoteNativeChild(void *child,
-                                     nsCycleCollectionParticipant *participant) {}
-    NS_IMETHOD_(void) NoteNextEdgeName(const char* name) {}
-};
-
-char *Suppressor::sSuppressionList = nsnull;
-PRBool Suppressor::sInitialized = PR_FALSE;
-
-static PRBool
-nsCycleCollector_shouldSuppress(nsISupports *s)
-{
-    Suppressor supp;
-    return supp.shouldSuppress(s);
-}
-#endif
-
-#ifdef DEBUG
-static PRBool
-nsCycleCollector_isScanSafe(nsISupports *s)
-{
-    if (!s)
-        return PR_FALSE;
-
-    nsXPCOMCycleCollectionParticipant *cp;
-    ToParticipant(s, &cp);
-
-    return cp != nsnull;
-}
-#endif
-
-PRBool
-nsCycleCollector::Suspect(nsISupports *n)
-{
-    // 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 PR_FALSE;
-
-    NS_ASSERTION(nsCycleCollector_isScanSafe(n),
-                 "suspected a non-scansafe pointer");
-    NS_ASSERTION(NS_IsMainThread(), "trying to suspect from non-main thread");
-
-    if (mParams.mDoNothing)
-        return PR_FALSE;
-
-#ifdef DEBUG_CC
-    mStats.mSuspectNode++;
-
-    if (nsCycleCollector_shouldSuppress(n))
-        return PR_FALSE;
-
-#ifndef __MINGW32__
-    if (mParams.mHookMalloc)
-        InitMemHook();
-#endif
-
-    if (mParams.mLogPointers) {
-        if (!mPtrLog)
-            mPtrLog = fopen("pointer_log", "w");
-        fprintf(mPtrLog, "S %p\n", static_cast<void*>(n));
-    }
-#endif
-
-    mPurpleBuf.Put(n);
-
-    return PR_TRUE;
-}
-
-
-PRBool
-nsCycleCollector::Forget(nsISupports *n)
-{
-    // 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 PR_FALSE;
-
-    NS_ASSERTION(NS_IsMainThread(), "trying to forget from non-main thread");
-    
-    if (mParams.mDoNothing)
-        return PR_TRUE; // it's as good as forgotten
-
-#ifdef DEBUG_CC
-    mStats.mForgetNode++;
-
-#ifndef __MINGW32__
-    if (mParams.mHookMalloc)
-        InitMemHook();
-#endif
-
-    if (mParams.mLogPointers) {
-        if (!mPtrLog)
-            mPtrLog = fopen("pointer_log", "w");
-        fprintf(mPtrLog, "F %p\n", static_cast<void*>(n));
-    }
-#endif
-
-    mPurpleBuf.Remove(n);
-    return PR_TRUE;
-}
-
-#ifdef DEBUG_CC
-void 
-nsCycleCollector::Allocated(void *n, size_t sz)
-{
-}
-
-void 
-nsCycleCollector::Freed(void *n)
-{
-    mStats.mFreeCalls++;
-
-    if (!n) {
-        // Ignore null pointers coming through
-        return;
-    }
-
-    if (mPurpleBuf.Exists(n)) {
-        mStats.mForgetNode++;
-        mStats.mFreedWhilePurple++;
-        Fault("freed while purple", n);
-        mPurpleBuf.Remove(n);
-        
-        if (mParams.mLogPointers) {
-            if (!mPtrLog)
-                mPtrLog = fopen("pointer_log", "w");
-            fprintf(mPtrLog, "R %p\n", n);
-        }
-    }
-}
-#endif
-
-PRUint32
-nsCycleCollector::Collect(PRUint32 aTryCollections)
-{
-#if defined(DEBUG_CC) && !defined(__MINGW32__)
-    if (!mParams.mDoNothing && mParams.mHookMalloc)
-        InitMemHook();
-#endif
-
-    // This can legitimately happen in a few cases. See bug 383651.
-    if (mCollectionInProgress)
-        return 0;
-
-#ifdef COLLECT_TIME_DEBUG
-    printf("cc: Starting nsCycleCollector::Collect(%d)\n", aTryCollections);
-    PRTime start = PR_Now();
-#endif
-
-    mCollectionInProgress = PR_TRUE;
-
-    nsCOMPtr<nsIObserverService> obs =
-      do_GetService("@mozilla.org/observer-service;1");
-    if (obs) {
-        obs->NotifyObservers(nsnull, "cycle-collector-begin", nsnull);
-    }
-
-    mFollowupCollection = PR_FALSE;
-    mCollectedObjects = 0;
-    nsAutoTPtrArray<PtrInfo, 4000> whiteNodes;
-    mWhiteNodes = &whiteNodes;
-
-    PRUint32 totalCollections = 0;
-    while (aTryCollections > totalCollections) {
-        PRBool collected;
-        if (mRuntimes[nsIProgrammingLanguage::JAVASCRIPT]) {
-            collected = static_cast<nsCycleCollectionJSRuntime*>
-                (mRuntimes[nsIProgrammingLanguage::JAVASCRIPT])->Collect();
-        }
-        else {
-            collected = BeginCollection() && FinishCollection();
-        }
-
-#ifdef DEBUG_CC
-        // We wait until after FinishCollection to check the white nodes because
-        // some objects may outlive CollectWhite but then be freed by
-        // FinishCycleCollection (like XPConnect's deferred release of native
-        // objects).
-        PRUint32 i, count = mWhiteNodes->Length();
-        for (i = 0; i < count; ++i) {
-            PtrInfo *pinfo = mWhiteNodes->ElementAt(i);
-            if (pinfo->mLangID == nsIProgrammingLanguage::CPLUSPLUS &&
-                mPurpleBuf.Exists(pinfo->mPointer)) {
-                printf("nsCycleCollector: %s object @%p is still alive after\n"
-                       "  calling RootAndUnlinkJSObjects, Unlink, and Unroot on"
-                       " it!  This probably\n"
-                       "  means the Unlink implementation was insufficient.\n",
-                       pinfo->mName, pinfo->mPointer);
-            }
-        }
-#endif
-        mWhiteNodes->Clear();
-        ClearGraph();
-
-        if (!collected)
-            break;
-        
-        ++totalCollections;
-    }
-
-    mWhiteNodes = nsnull;
-
-    mCollectionInProgress = PR_FALSE;
-
-#ifdef XP_OS2
-    // Now that the cycle collector has freed some memory, we can try to
-    // force the C library to give back as much memory to the system as
-    // possible.
-    _heapmin();
-#endif
-
-#ifdef COLLECT_TIME_DEBUG
-    printf("cc: Collect() took %lldms\n",
-           (PR_Now() - start) / PR_USEC_PER_MSEC);
-#endif
-#ifdef DEBUG_CC
-    ExplainLiveExpectedGarbage();
-#endif
-    return mCollectedObjects;
-}
-
-PRBool
-nsCycleCollector::BeginCollection()
-{
-    if (mParams.mDoNothing)
-        return PR_FALSE;
-
-    GCGraphBuilder builder(mGraph, mRuntimes);
-
-#ifdef COLLECT_TIME_DEBUG
-    PRTime now = PR_Now();
-#endif
-    for (PRUint32 i = 0; i <= nsIProgrammingLanguage::MAX; ++i) {
-        if (mRuntimes[i])
-            mRuntimes[i]->BeginCycleCollection(builder);
-    }
-
-#ifdef COLLECT_TIME_DEBUG
-    printf("cc: mRuntimes[*]->BeginCycleCollection() took %lldms\n",
-           (PR_Now() - now) / PR_USEC_PER_MSEC);
-
-    now = PR_Now();
-#endif
-
-#ifdef DEBUG_CC
-    PRUint32 purpleStart = builder.Count();
-#endif
-    mScanInProgress = PR_TRUE;
-    SelectPurple(builder);
-#ifdef DEBUG_CC
-    PRUint32 purpleEnd = builder.Count();
-
-    if (purpleStart != purpleEnd) {
-#ifndef __MINGW32__
-        if (mParams.mHookMalloc)
-            InitMemHook();
-#endif
-        if (mParams.mLogPointers && !mPtrLog)
-            mPtrLog = fopen("pointer_log", "w");
-
-        PRUint32 i = 0;
-        NodePool::Enumerator queue(mGraph.mNodes);
-        while (i++ < purpleStart) {
-            queue.GetNext();
-        }
-        while (i++ < purpleEnd) {
-            mStats.mForgetNode++;
-            if (mParams.mLogPointers)
-                fprintf(mPtrLog, "F %p\n", queue.GetNext()->mPointer);
-        }
-    }
-#endif
-
-#ifdef COLLECT_TIME_DEBUG
-    printf("cc: SelectPurple() took %lldms\n",
-           (PR_Now() - now) / PR_USEC_PER_MSEC);
-#endif
-
-    if (builder.Count() > 0) {
-        // The main Bacon & Rajan collection algorithm.
-
-#ifdef COLLECT_TIME_DEBUG
-        now = PR_Now();
-#endif
-
-        MarkRoots(builder);
-
-#ifdef COLLECT_TIME_DEBUG
-        {
-            PRTime then = PR_Now();
-            printf("cc: MarkRoots() took %lldms\n",
-                   (then - now) / PR_USEC_PER_MSEC);
-            now = then;
-        }
-#endif
-
-        ScanRoots();
-
-#ifdef COLLECT_TIME_DEBUG
-        printf("cc: ScanRoots() took %lldms\n",
-               (PR_Now() - now) / PR_USEC_PER_MSEC);
-#endif
-
-#ifdef DEBUG_CC
-        MaybeDrawGraphs();
-#endif
-
-        mScanInProgress = PR_FALSE;
-
-#ifdef DEBUG_CC
-        if (mFollowupCollection && purpleStart != purpleEnd) {
-            PRUint32 i = 0;
-            NodePool::Enumerator queue(mGraph.mNodes);
-            while (i++ < purpleStart) {
-                queue.GetNext();
-            }
-            while (i++ < purpleEnd) {
-                PtrInfo *pi = queue.GetNext();
-                if (pi->mColor == white) {
-                    printf("nsCycleCollector: a later shutdown collection collected the additional\n"
-                           "  suspect %p %s\n"
-                           "  (which could be fixed by improving traversal)\n",
-                           pi->mPointer, pi->mName);
-                }
-            }
-        }
-#endif
-
-#ifdef COLLECT_TIME_DEBUG
-        now = PR_Now();
-#endif
-        RootWhite();
-
-#ifdef COLLECT_TIME_DEBUG
-        printf("cc: RootWhite() took %lldms\n",
-               (PR_Now() - now) / PR_USEC_PER_MSEC);
-#endif
-    }
-    else {
-        mScanInProgress = PR_FALSE;
-    }
-
-    return PR_TRUE;
-}
-
-PRBool
-nsCycleCollector::FinishCollection()
-{
-#ifdef COLLECT_TIME_DEBUG
-    PRTime now = PR_Now();
-#endif
-    PRBool collected = CollectWhite();
-
-#ifdef COLLECT_TIME_DEBUG
-    printf("cc: CollectWhite() took %lldms\n",
-           (PR_Now() - now) / PR_USEC_PER_MSEC);
-#endif
-
-#ifdef DEBUG_CC
-    mStats.mCollection++;
-    if (mParams.mReportStats)
-        mStats.Dump();
-#endif
-
-    for (PRUint32 i = 0; i <= nsIProgrammingLanguage::MAX; ++i) {
-        if (mRuntimes[i])
-            mRuntimes[i]->FinishCycleCollection();
-    }
-
-    mFollowupCollection = PR_TRUE;
-
-    return collected;
-}
-
-PRUint32
-nsCycleCollector::SuspectedCount()
-{
-    return mPurpleBuf.Count();
-}
-
-void
-nsCycleCollector::Shutdown()
-{
-    // Here we want to run a final collection on everything we've seen
-    // buffered, irrespective of age; then permanently disable
-    // the collector because the program is shutting down.
-
-    mParams.mScanDelay = 0;
-    Collect(SHUTDOWN_COLLECTIONS(mParams));
-
-#ifdef DEBUG_CC
-    GCGraphBuilder builder(mGraph, mRuntimes);
-    mScanInProgress = PR_TRUE;
-    SelectPurple(builder);
-    mScanInProgress = PR_FALSE;
-    if (builder.Count() != 0) {
-        printf("Might have been able to release more cycles if the cycle collector would "
-               "run once more at shutdown.\n");
-    }
-    ClearGraph();
-#endif
-    mParams.mDoNothing = PR_TRUE;
-}
-
-#ifdef DEBUG_CC
-
-PR_STATIC_CALLBACK(PLDHashOperator)
-AddExpectedGarbage(nsVoidPtrHashKey *p, void *arg)
-{
-    GCGraphBuilder *builder = static_cast<GCGraphBuilder*>(arg);
-    nsISupports *root =
-      static_cast<nsISupports*>(const_cast<void*>(p->GetKey()));
-    builder->NoteXPCOMRoot(root);
-    return PL_DHASH_NEXT;
-}
-
-struct SetSCCWalker : public GraphWalker
-{
-    SetSCCWalker(PRUint32 aIndex) : mIndex(aIndex) {}
-    PRBool ShouldVisitNode(PtrInfo const *pi) { return pi->mSCCIndex == 0; }
-    void VisitNode(PtrInfo *pi) { pi->mSCCIndex = mIndex; }
-private:
-    PRUint32 mIndex;
-};
-
-struct SetNonRootGreyWalker : public GraphWalker
-{
-    PRBool ShouldVisitNode(PtrInfo const *pi) { return pi->mColor == white; }
-    void VisitNode(PtrInfo *pi) { pi->mColor = grey; }
-};
-
-static void
-PrintPathToExpectedGarbage(PtrInfo *pi)
-{
-    printf("  An object expected to be garbage could be "
-           "reached from it by the path:\n");
-    for (PtrInfo *path = pi, *prev = nsnull; prev != path;
-         prev = path,
-         path = path->mShortestPathToExpectedGarbage) {
-        if (prev) {
-            nsCString *edgeName = prev
-                ->mShortestPathToExpectedGarbageEdgeName;
-            printf("        via %s\n",
-                   edgeName->IsEmpty() ? "<unknown edge>"
-                                       : edgeName->get());
-        }
-        printf("    %s %p\n", path->mName, path->mPointer);
-    }
-}
-
-void
-nsCycleCollector::ExplainLiveExpectedGarbage()
-{
-    if (mScanInProgress || mCollectionInProgress)
-        Fault("can't explain expected garbage during collection itself");
-
-    if (mParams.mDoNothing) {
-        printf("nsCycleCollector: not explaining expected garbage since\n"
-               "  cycle collection disabled\n");
-        return;
-    }
-
-    mCollectionInProgress = PR_TRUE;
-    mScanInProgress = PR_TRUE;
-
-    {
-        GCGraphBuilder builder(mGraph, mRuntimes);
-
-        for (PRUint32 i = 0; i <= nsIProgrammingLanguage::MAX; ++i) {
-            if (mRuntimes[i])
-                mRuntimes[i]->BeginCycleCollection(builder);
-        }
-
-        // This might fail to explain expected garbage that's also in
-        // the set of roots added by the runtimes (what used to be
-        // called suspectCurrent), but that seems pretty unlikely.
-        PRUint32 suspectCurrentCount = builder.Count();
-
-        // Instead of adding roots from the purple buffer, we add them
-        // from the list of nodes we were expected to collect.
-        mExpectedGarbage.EnumerateEntries(&AddExpectedGarbage, &builder);
-
-        MarkRoots(builder);
-        ScanRoots();
-
-        mScanInProgress = PR_FALSE;
-
-        PRBool describeExtraRefcounts = PR_FALSE;
-        PRBool findCycleRoots = PR_FALSE;
-        {
-            NodePool::Enumerator queue(mGraph.mNodes);
-            PRUint32 i = 0;
-            while (!queue.IsDone()) {
-                PtrInfo *pi = queue.GetNext();
-                if (pi->mColor == white) {
-                    findCycleRoots = PR_TRUE;
-                }
-
-                if (pi->mInternalRefs != pi->mRefCount && i >= suspectCurrentCount) {
-                    describeExtraRefcounts = PR_TRUE;
-                }
-                ++i;
-            }
-        }
-
-        if ((describeExtraRefcounts || findCycleRoots) &&
-            CreateReversedEdges()) {
-            // Note that the external references may have been external
-            // to a different node in the cycle collection that just
-            // happened, if that different node was purple and then
-            // black.
-
-            // Use mSCCIndex temporarily to track whether we've reached
-            // nodes in the breadth-first search.
-            const PRUint32 INDEX_UNREACHED = 0;
-            const PRUint32 INDEX_REACHED = 1;
-            NodePool::Enumerator etor_clear(mGraph.mNodes);
-            while (!etor_clear.IsDone()) {
-                PtrInfo *pi = etor_clear.GetNext();
-                pi->mSCCIndex = INDEX_UNREACHED;
-            }
-
-            nsDeque queue; // for breadth-first search
-            NodePool::Enumerator etor_roots(mGraph.mNodes);
-            for (PRUint32 i = 0; i < mGraph.mRootCount; ++i) {
-                PtrInfo *root_pi = etor_roots.GetNext();
-                if (i >= suspectCurrentCount) {
-                    root_pi->mSCCIndex = INDEX_REACHED;
-                    root_pi->mShortestPathToExpectedGarbage = root_pi;
-                    queue.Push(root_pi);
-                }
-            }
-
-            while (queue.GetSize() > 0) {
-                PtrInfo *pi = (PtrInfo*)queue.PopFront();
-                for (ReversedEdge *e = pi->mReversedEdges; e; e = e->mNext) {
-                    if (e->mTarget->mSCCIndex == INDEX_UNREACHED) {
-                        e->mTarget->mSCCIndex = INDEX_REACHED;
-                        PtrInfo *target = e->mTarget;
-                        if (!target->mShortestPathToExpectedGarbage) {
-                            target->mShortestPathToExpectedGarbage = pi;
-                            target->mShortestPathToExpectedGarbageEdgeName =
-                                e->mEdgeName;
-                        }
-                        queue.Push(target);
-                    }
-                }
-
-                if (pi->mRefCount == PR_UINT32_MAX ||
-                    (pi->mInternalRefs != pi->mRefCount && pi->mRefCount > 0)) {
-                    if (pi->mRefCount == PR_UINT32_MAX) {
-                        printf("nsCycleCollector: %s %p was not collected due "
-                           "to \n"
-                           "  external references\n",
-                           pi->mName, pi->mPointer);
-                    }
-                    else {
-                        printf("nsCycleCollector: %s %p was not collected due "
-                               "to %d\n"
-                               "  external references (%d total - %d known)\n",
-                               pi->mName, pi->mPointer,
-                               pi->mRefCount - pi->mInternalRefs,
-                               pi->mRefCount, pi->mInternalRefs);
-                    }
-
-                    PrintPathToExpectedGarbage(pi);
-
-                    if (pi->mRefCount == PR_UINT32_MAX) {
-                        printf("  The known references to it were from:\n");
-                    }
-                    else {
-                        printf("  The %d known references to it were from:\n",
-                               pi->mInternalRefs);
-                    }
-                    for (ReversedEdge *e = pi->mReversedEdges;
-                         e; e = e->mNext) {
-                        printf("    %s %p",
-                               e->mTarget->mName, e->mTarget->mPointer);
-                        if (!e->mEdgeName->IsEmpty()) {
-                            printf(" via %s", e->mEdgeName->get());
-                        }
-                        printf("\n");
-                    }
-                    mRuntimes[pi->mLangID]->PrintAllReferencesTo(pi->mPointer);
-                }
-            }
-
-            if (findCycleRoots) {
-                // NOTE: This code changes the white nodes that are not
-                // roots to gray.
-
-                // Put the nodes in post-order traversal order from a
-                // depth-first search.
-                nsDeque DFSPostOrder;
-
-                {
-                    // Use mSCCIndex temporarily to track the DFS numbering:
-                    const PRUint32 INDEX_UNREACHED = 0;
-                    const PRUint32 INDEX_TRAVERSING = 1;
-                    const PRUint32 INDEX_NUMBERED = 2;
-
-                    NodePool::Enumerator etor_clear(mGraph.mNodes);
-                    while (!etor_clear.IsDone()) {
-                        PtrInfo *pi = etor_clear.GetNext();
-                        pi->mSCCIndex = INDEX_UNREACHED;
-                    }
-
-                    nsDeque stack;
-
-                    NodePool::Enumerator etor_roots(mGraph.mNodes);
-                    for (PRUint32 i = 0; i < mGraph.mRootCount; ++i) {
-                        PtrInfo *root_pi = etor_roots.GetNext();
-                        stack.Push(root_pi);
-                    }
-
-                    while (stack.GetSize() > 0) {
-                        PtrInfo *pi = (PtrInfo*)stack.Peek();
-                        if (pi->mSCCIndex == INDEX_UNREACHED) {
-                            pi->mSCCIndex = INDEX_TRAVERSING;
-                            for (EdgePool::Iterator child = pi->mFirstChild,
-                                                child_end = pi->mLastChild;
-                                 child != child_end; ++child) {
-                                stack.Push(*child);
-                            }
-                        } else {
-                            stack.Pop();
-                            // Somebody else might have numbered it already
-                            // (since this is depth-first, not breadth-first).
-                            // This happens if a node is pushed on the stack
-                            // a second time while it is on the stack in
-                            // UNREACHED state.
-                            if (pi->mSCCIndex == INDEX_TRAVERSING) {
-                                pi->mSCCIndex = INDEX_NUMBERED;
-                                DFSPostOrder.Push(pi);
-                            }
-                        }
-                    }
-                }
-
-                // Put the nodes into strongly-connected components.
-                {
-                    NodePool::Enumerator etor_clear(mGraph.mNodes);
-                    while (!etor_clear.IsDone()) {
-                        PtrInfo *pi = etor_clear.GetNext();
-                        pi->mSCCIndex = 0;
-                    }
-
-                    PRUint32 currentSCC = 1;
-
-                    while (DFSPostOrder.GetSize() > 0) {
-                        SetSCCWalker(currentSCC).Walk((PtrInfo*)DFSPostOrder.PopFront());
-                        ++currentSCC;
-                    }
-                }
-
-                // Mark any white nodes reachable from other components as
-                // grey.
-                {
-                    NodePool::Enumerator queue(mGraph.mNodes);
-                    while (!queue.IsDone()) {
-                        PtrInfo *pi = queue.GetNext();
-                        if (pi->mColor != white)
-                            continue;
-                        for (EdgePool::Iterator child = pi->mFirstChild,
-                                            child_end = pi->mLastChild;
-                             child != child_end; ++child) {
-                            if ((*child)->mSCCIndex != pi->mSCCIndex) {
-                                SetNonRootGreyWalker().Walk(*child);
-                            }
-                        }
-                    }
-                }
-
-                {
-                    NodePool::Enumerator queue(mGraph.mNodes);
-                    while (!queue.IsDone()) {
-                        PtrInfo *pi = queue.GetNext();
-                        if (pi->mColor == white) {
-                            printf("nsCycleCollector: %s %p in component %d\n"
-                                   "  was not collected due to missing call to "
-                                   "suspect, failure to unlink,\n"
-                                   "  or deficiency in traverse that causes "
-                                   "cycles referenced only from other\n"
-                                   "  cycles to require multiple rounds of cycle "
-                                   "collection\n",
-                                   pi->mName, pi->mPointer, pi->mSCCIndex);
-                            if (pi->mShortestPathToExpectedGarbage)
-                                PrintPathToExpectedGarbage(pi);
-                        }
-                    }
-                }
-            }
-
-            DestroyReversedEdges();
-        }
-    }
-
-    ClearGraph();
-
-    mCollectionInProgress = PR_FALSE;
-
-    for (PRUint32 i = 0; i <= nsIProgrammingLanguage::MAX; ++i) {
-        if (mRuntimes[i])
-            mRuntimes[i]->FinishCycleCollection();
-    }    
-}
-
-PRBool
-nsCycleCollector::CreateReversedEdges()
-{
-    // Count the edges in the graph.
-    PRUint32 edgeCount = 0;
-    NodePool::Enumerator countQueue(mGraph.mNodes);
-    while (!countQueue.IsDone()) {
-        PtrInfo *pi = countQueue.GetNext();
-        for (EdgePool::Iterator e = pi->mFirstChild, e_end = pi->mLastChild;
-             e != e_end; ++e, ++edgeCount) {
-        }
-    }
-
-    // Allocate a pool to hold all of the edges.
-    mGraph.mReversedEdges = new ReversedEdge[edgeCount];
-    if (mGraph.mReversedEdges == nsnull) {
-        NS_NOTREACHED("allocation failure creating reversed edges");
-        return PR_FALSE;
-    }
-
-    // Fill in the reversed edges by scanning all forward edges.
-    ReversedEdge *current = mGraph.mReversedEdges;
-    NodePool::Enumerator buildQueue(mGraph.mNodes);
-    while (!buildQueue.IsDone()) {
-        PtrInfo *pi = buildQueue.GetNext();
-        PRInt32 i = 0;
-        for (EdgePool::Iterator e = pi->mFirstChild, e_end = pi->mLastChild;
-             e != e_end; ++e) {
-            current->mTarget = pi;
-            current->mEdgeName = pi->mEdgeNames.CStringAt(i);
-            current->mNext = (*e)->mReversedEdges;
-            (*e)->mReversedEdges = current;
-            ++current;
-            ++i;
-        }
-    }
-    NS_ASSERTION(current - mGraph.mReversedEdges == ptrdiff_t(edgeCount),
-                 "misallocation");
-    return PR_TRUE;
-}
-
-void
-nsCycleCollector::DestroyReversedEdges()
-{
-    NodePool::Enumerator queue(mGraph.mNodes);
-    while (!queue.IsDone()) {
-        PtrInfo *pi = queue.GetNext();
-        pi->mReversedEdges = nsnull;
-    }
-
-    delete mGraph.mReversedEdges;
-    mGraph.mReversedEdges = nsnull;
-}
-
-void
-nsCycleCollector::ShouldBeFreed(nsISupports *n)
-{
-    mExpectedGarbage.PutEntry(n);
-}
-
-void
-nsCycleCollector::WasFreed(nsISupports *n)
-{
-    mExpectedGarbage.RemoveEntry(n);
-}
-#endif
-
-////////////////////////////////////////////////////////////////////////
-// Module public API (exported in nsCycleCollector.h)
-// Just functions that redirect into the singleton, once it's built.
-////////////////////////////////////////////////////////////////////////
-
-void 
-nsCycleCollector_registerRuntime(PRUint32 langID, 
-                                 nsCycleCollectionLanguageRuntime *rt)
-{
-    if (sCollector)
-        sCollector->RegisterRuntime(langID, rt);
-}
-
-
-void 
-nsCycleCollector_forgetRuntime(PRUint32 langID)
-{
-    if (sCollector)
-        sCollector->ForgetRuntime(langID);
-}
-
+#include "nsXPCOM.h"
+#include "nsDebug.h"
 
 PRBool
 NS_CycleCollectorSuspect(nsISupports *n)
 {
-    if (sCollector)
-        return sCollector->Suspect(n);
+    NS_NOTREACHED("Dead code.");
     return PR_FALSE;
 }
-
 
 PRBool
 NS_CycleCollectorForget(nsISupports *n)
 {
-    return sCollector ? sCollector->Forget(n) : PR_TRUE;
+    NS_NOTREACHED("Dead code.");
+    return PR_FALSE;
 }
-
-
-PRUint32
-nsCycleCollector_collect()
-{
-    return sCollector ? sCollector->Collect() : 0;
-}
-
-PRUint32
-nsCycleCollector_suspectedCount()
-{
-    return sCollector ? sCollector->SuspectedCount() : 0;
-}
-
-PRBool 
-nsCycleCollector_beginCollection()
-{
-    return sCollector ? sCollector->BeginCollection() : PR_FALSE;
-}
-
-PRBool 
-nsCycleCollector_finishCollection()
-{
-    return sCollector ? sCollector->FinishCollection() : PR_FALSE;
-}
-
-nsresult 
-nsCycleCollector_startup()
-{
-    NS_ASSERTION(!sCollector, "Forgot to call nsCycleCollector_shutdown?");
-
-    sCollector = new nsCycleCollector();
-    return sCollector ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
-}
-
-void 
-nsCycleCollector_shutdown()
-{
-    if (sCollector) {
-        sCollector->Shutdown();
-        delete sCollector;
-        sCollector = nsnull;
-    }
-}
-
-#ifdef DEBUG
-void
-nsCycleCollector_DEBUG_shouldBeFreed(nsISupports *n)
-{
-#ifdef DEBUG_CC
-    if (sCollector)
-        sCollector->ShouldBeFreed(n);
-#endif
-}
-
-void
-nsCycleCollector_DEBUG_wasFreed(nsISupports *n)
-{
-#ifdef DEBUG_CC
-    if (sCollector)
-        sCollector->WasFreed(n);
-#endif
-}
-#endif
diff --git a/xpcom/base/nsCycleCollector.h b/xpcom/base/nsCycleCollector.h
deleted file mode 100644
--- a/xpcom/base/nsCycleCollector.h
+++ /dev/null
@@ -1,97 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * The Mozilla Foundation.
- * Portions created by the Initial Developer are Copyright (C) 2006
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#ifndef nsCycleCollector_h__
-#define nsCycleCollector_h__
-
-// NOTE: If you use header files to define DEBUG_CC, you must do so here
-// *and* in nsCycleCollectionParticipant.h
-//#define DEBUG_CC
-
-class nsISupports;
-class nsCycleCollectionParticipant;
-class nsCycleCollectionTraversalCallback;
-
-// An nsCycleCollectionLanguageRuntime is a per-language object that
-// implements language-specific aspects of the cycle collection task.
-
-struct nsCycleCollectionLanguageRuntime
-{
-    virtual nsresult BeginCycleCollection(nsCycleCollectionTraversalCallback &cb) = 0;
-    virtual nsresult FinishCycleCollection() = 0;
-    virtual nsCycleCollectionParticipant *ToParticipant(void *p) = 0;
-#ifdef DEBUG_CC
-    virtual void PrintAllReferencesTo(void *p) = 0;
-#endif
-};
-
-nsresult nsCycleCollector_startup();
-// Returns the number of collected nodes.
-NS_COM PRUint32 nsCycleCollector_collect();
-NS_COM PRUint32 nsCycleCollector_suspectedCount();
-void nsCycleCollector_shutdown();
-
-// The JS runtime is special, it needs to call cycle collection during its GC.
-// If the JS runtime is registered nsCycleCollector_collect will call
-// nsCycleCollectionJSRuntime::Collect which will call
-// nsCycleCollector_doCollect, else nsCycleCollector_collect will call
-// nsCycleCollector_doCollect directly.
-struct nsCycleCollectionJSRuntime : public nsCycleCollectionLanguageRuntime
-{
-    /**
-     * Runs cycle collection and returns whether cycle collection collected
-     * anything.
-     */
-    virtual PRBool Collect() = 0;
-};
-// Returns PR_TRUE if cycle collection was started.
-NS_COM PRBool nsCycleCollector_beginCollection();
-// Returns PR_TRUE if some nodes were collected. Should only be called after
-// nsCycleCollector_beginCollection() returned PR_TRUE.
-NS_COM PRBool nsCycleCollector_finishCollection();
-
-#ifdef DEBUG
-NS_COM void nsCycleCollector_DEBUG_shouldBeFreed(nsISupports *n);
-NS_COM void nsCycleCollector_DEBUG_wasFreed(nsISupports *n);
-#endif
-
-// Helpers for interacting with language-identified scripts
-
-NS_COM void nsCycleCollector_registerRuntime(PRUint32 langID, nsCycleCollectionLanguageRuntime *rt);
-NS_COM void nsCycleCollector_forgetRuntime(PRUint32 langID);
-
-#endif // nsCycleCollector_h__
diff --git a/xpcom/build/dlldeps.cpp b/xpcom/build/dlldeps.cpp
--- a/xpcom/build/dlldeps.cpp
+++ b/xpcom/build/dlldeps.cpp
@@ -95,7 +95,6 @@
 #include "nsStringBuffer.h"
 #include "nsCategoryCache.h"
 #include "nsCycleCollectionParticipant.h"
-#include "nsCycleCollector.h"
 #include "nsThreadUtils.h"
 #include "nsTObserverArray.h"
 
@@ -278,9 +277,6 @@ void XXXNeverCalled()
       b.ToString(0, y);
     }
 
-    nsXPCOMCycleCollectionParticipant();
-    nsCycleCollector_collect();
-
 #if !defined(WINCE) && !defined(XP_OS2)
     NS_NewWindowsRegKey(nsnull);
 #endif
@@ -294,4 +290,6 @@ void XXXNeverCalled()
     NS_ProcessPendingEvents(nsnull, 0);
     NS_HasPendingEvents(nsnull);
     NS_ProcessNextEvent(nsnull, PR_FALSE);
+    NS_CycleCollectorSuspect(nsnull);
+    NS_CycleCollectorForget(nsnull);
 }
diff --git a/xpcom/build/nsXPComInit.cpp b/xpcom/build/nsXPComInit.cpp
--- a/xpcom/build/nsXPComInit.cpp
+++ b/xpcom/build/nsXPComInit.cpp
@@ -601,9 +601,6 @@ NS_InitXPCOM3(nsIServiceManager* *result
     if (NS_FAILED(rv)) return rv;
 #endif
 
-    rv = nsCycleCollector_startup();
-    if (NS_FAILED(rv)) return rv;
-
     // 2. Register the global services with the component manager so that
     //    clients can create new objects.
 
@@ -780,8 +777,6 @@ NS_ShutdownXPCOM(nsIServiceManager* serv
     // Release the directory service
     NS_IF_RELEASE(nsDirectoryService::gService);
 
-    nsCycleCollector_shutdown();
-
     if (moduleLoaders) {
         PRBool more;
         nsCOMPtr<nsISupports> el;
diff --git a/xpcom/ds/nsArray.cpp b/xpcom/ds/nsArray.cpp
--- a/xpcom/ds/nsArray.cpp
+++ b/xpcom/ds/nsArray.cpp
@@ -63,14 +63,6 @@ nsArray::~nsArray()
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF(nsArray)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(nsArray)
-
-NS_IMPL_CYCLE_COLLECTION_CLASS(nsArray)
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsArray)
-    tmp->Clear();
-NS_IMPL_CYCLE_COLLECTION_UNLINK_END
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsArray)
-    NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMARRAY(mArray)
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_IMETHODIMP
 nsArray::GetLength(PRUint32* aLength)
diff --git a/xpcom/ds/nsVariant.cpp b/xpcom/ds/nsVariant.cpp
--- a/xpcom/ds/nsVariant.cpp
+++ b/xpcom/ds/nsVariant.cpp
@@ -45,7 +45,6 @@
 #include "prdtoa.h"
 #include <math.h>
 #include "nsCRT.h"
-#include "nsCycleCollectionParticipant.h"
 
 /***************************************************************************/
 // Helpers for static convert functions...
@@ -1658,33 +1657,6 @@ nsVariant::Cleanup(nsDiscriminatedUnion*
     return NS_OK;
 }
 
-/* static */ void
-nsVariant::Traverse(const nsDiscriminatedUnion& data,
-                    nsCycleCollectionTraversalCallback &cb)
-{
-    switch(data.mType)
-    {
-        case nsIDataType::VTYPE_INTERFACE:
-        case nsIDataType::VTYPE_INTERFACE_IS:
-            cb.NoteXPCOMChild(data.u.iface.mInterfaceValue);
-            break;
-        case nsIDataType::VTYPE_ARRAY:
-            switch(data.u.array.mArrayType) {
-                case nsIDataType::VTYPE_INTERFACE:
-                case nsIDataType::VTYPE_INTERFACE_IS:
-                {
-                    nsISupports** p = (nsISupports**) data.u.array.mArrayValue;
-                    for(PRUint32 i = data.u.array.mArrayCount; i > 0; p++, i--)
-                        cb.NoteXPCOMChild(*p);
-                }
-                default:
-                    break;
-            }
-        default:
-            break;
-    }
-}
-
 /***************************************************************************/
 /***************************************************************************/
 // members...
diff --git a/xpcom/ds/nsVariant.h b/xpcom/ds/nsVariant.h
--- a/xpcom/ds/nsVariant.h
+++ b/xpcom/ds/nsVariant.h
@@ -42,8 +42,6 @@
 #include "nsIVariant.h"
 #include "nsStringFwd.h"
 #include "xpt_struct.h"
-
-class nsCycleCollectionTraversalCallback;
 
 /** 
  * Map the nsAUTF8String, nsUTF8String classes to the nsACString and
@@ -181,9 +179,6 @@ public:
     static nsresult SetToEmpty(nsDiscriminatedUnion* data);
     static nsresult SetToEmptyArray(nsDiscriminatedUnion* data);
 
-    static void Traverse(const nsDiscriminatedUnion& data,
-                         nsCycleCollectionTraversalCallback &cb);
-
 private:
     ~nsVariant();
 
diff --git a/xpcom/glue/nsCycleCollectionParticipant.cpp b/xpcom/glue/nsCycleCollectionParticipant.cpp
deleted file mode 100644
--- a/xpcom/glue/nsCycleCollectionParticipant.cpp
+++ /dev/null
@@ -1,103 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * The Mozilla Foundation.
- * Portions created by the Initial Developer are Copyright (C) 2006
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#include "nsCycleCollectionParticipant.h"
-#include "nsCOMPtr.h"
-
-PR_STATIC_CALLBACK(void)
-NoteChild(PRUint32 aLangID, void *aScriptThing, void *aClosure)
-{
-  nsCycleCollectionTraversalCallback *cb =
-    static_cast<nsCycleCollectionTraversalCallback*>(aClosure);
-  cb->NoteScriptChild(aLangID, aScriptThing);
-}
-
-void
-nsScriptObjectTracer::TraverseScriptObjects(void *p,
-                                        nsCycleCollectionTraversalCallback &cb)
-{
-  Trace(p, NoteChild, &cb);
-}
-
-nsresult
-nsXPCOMCycleCollectionParticipant::RootAndUnlinkJSObjects(void *p)
-{
-    nsISupports *s = static_cast<nsISupports*>(p);
-    NS_ADDREF(s);
-    return NS_OK;
-}
-
-nsresult
-nsXPCOMCycleCollectionParticipant::Unlink(void *p)
-{
-  return NS_OK;
-}
-
-nsresult
-nsXPCOMCycleCollectionParticipant::Unroot(void *p)
-{
-    nsISupports *s = static_cast<nsISupports*>(p);
-    NS_RELEASE(s);
-    return NS_OK;
-}
-
-nsresult
-nsXPCOMCycleCollectionParticipant::Traverse
-    (void *p, nsCycleCollectionTraversalCallback &cb)
-{
-  return NS_OK;
-}
-
-void
-nsXPCOMCycleCollectionParticipant::UnmarkPurple(nsISupports *n)
-{
-}
-
-NS_IMETHODIMP_(void)
-nsXPCOMCycleCollectionParticipant::Trace(void *p, TraceCallback cb,
-                                         void *closure)
-{
-}
-
-PRBool
-nsXPCOMCycleCollectionParticipant::CheckForRightISupports(nsISupports *s)
-{
-    nsCOMPtr<nsISupports> foo;
-    s->QueryInterface(NS_GET_IID(nsCycleCollectionISupports),
-                      getter_AddRefs(foo));
-    return s == foo;
-}
diff --git a/xpcom/glue/nsCycleCollectionParticipant.h b/xpcom/glue/nsCycleCollectionParticipant.h
--- a/xpcom/glue/nsCycleCollectionParticipant.h
+++ b/xpcom/glue/nsCycleCollectionParticipant.h
@@ -40,18 +40,6 @@
 
 #include "nsISupports.h"
 
-// NOTE: If you use header files to define DEBUG_CC, you must do so here
-// *and* in nsCycleCollector.h
-//#define DEBUG_CC
-
-#ifdef DEBUG_CC
-#define IF_DEBUG_CC_PARAM(_p) , _p
-#define IF_DEBUG_CC_ONLY_PARAM(_p) _p
-#else
-#define IF_DEBUG_CC_PARAM(_p)
-#define IF_DEBUG_CC_ONLY_PARAM(_p)
-#endif
-
 #define NS_CYCLECOLLECTIONPARTICIPANT_IID                                      \
 {                                                                              \
     0x9674489b,                                                                \
@@ -87,147 +75,76 @@ NS_DEFINE_STATIC_IID_ACCESSOR(nsCycleCol
 NS_DEFINE_STATIC_IID_ACCESSOR(nsCycleCollectionISupports, 
                               NS_CYCLECOLLECTIONISUPPORTS_IID)
 
-class nsCycleCollectionParticipant;
+class nsCycleCollectionTraversalCallback;
 
-enum CCNodeType { RefCounted, GCMarked, GCUnmarked };
-
-class NS_NO_VTABLE nsCycleCollectionTraversalCallback
-{
-public:
-    // If type is RefCounted you must call DescribeNode() with an accurate
-    // refcount, otherwise cycle collection will fail, and probably crash.
-    // If type is not refcounted then the refcount will be ignored.
-#ifdef DEBUG_CC
-    NS_IMETHOD_(void) DescribeNode(CCNodeType type,
-                                   nsrefcnt refcount,
-                                   size_t objsz,
-                                   const char *objname) = 0;
-#else
-    NS_IMETHOD_(void) DescribeNode(CCNodeType type,
-                                   nsrefcnt refcount) = 0;
-#endif
-    NS_IMETHOD_(void) NoteXPCOMRoot(nsISupports *root) = 0;
-    NS_IMETHOD_(void) NoteRoot(PRUint32 langID, void *root,
-                               nsCycleCollectionParticipant* helper) = 0;
-    NS_IMETHOD_(void) NoteScriptChild(PRUint32 langID, void *child) = 0;
-    NS_IMETHOD_(void) NoteXPCOMChild(nsISupports *child) = 0;
-    NS_IMETHOD_(void) NoteNativeChild(void *child,
-                                      nsCycleCollectionParticipant *helper) = 0;
-#ifdef DEBUG_CC
-    // Give a name to the edge associated with the next call to
-    // NoteScriptChild, NoteXPCOMChild, or NoteNativeChild.
-    NS_IMETHOD_(void) NoteNextEdgeName(const char* name) = 0;
-#endif
-};
-
-class NS_NO_VTABLE nsCycleCollectionParticipant
+class nsCycleCollectionParticipant
 {
 public:
     NS_DECLARE_STATIC_IID_ACCESSOR(NS_CYCLECOLLECTIONPARTICIPANT_IID)
 
-    NS_IMETHOD Traverse(void *p, nsCycleCollectionTraversalCallback &cb) = 0;
+    NS_IMETHOD Traverse(void *p, nsCycleCollectionTraversalCallback &cb)
+    {
+        NS_NOTREACHED("No CC");
+        return NS_ERROR_UNEXPECTED;
+    }
 
-    NS_IMETHOD RootAndUnlinkJSObjects(void *p) = 0;
-    NS_IMETHOD Unlink(void *p) = 0;
-    NS_IMETHOD Unroot(void *p) = 0;
+    NS_IMETHOD Root(void *p)
+    {
+        NS_NOTREACHED("No CC");
+        return NS_ERROR_UNEXPECTED;
+    }
+
+    NS_IMETHOD RootAndUnlinkJSObjects(void *p)
+    {
+        NS_NOTREACHED("No CC");
+        return NS_ERROR_UNEXPECTED;
+    }
+
+    NS_IMETHOD Unlink(void *p)
+    {
+        NS_NOTREACHED("No CC");
+        return NS_ERROR_UNEXPECTED;
+    }
+
+    NS_IMETHOD Unroot(void *p)
+    {
+        NS_NOTREACHED("No CC");
+        return NS_ERROR_UNEXPECTED;
+    }
 };
 
 NS_DEFINE_STATIC_IID_ACCESSOR(nsCycleCollectionParticipant, 
                               NS_CYCLECOLLECTIONPARTICIPANT_IID)
 
-#undef IMETHOD_VISIBILITY
-#define IMETHOD_VISIBILITY NS_COM_GLUE
-
-typedef void
-(* PR_CALLBACK TraceCallback)(PRUint32 langID, void *p, void *closure);
-
-class NS_NO_VTABLE nsScriptObjectTracer : public nsCycleCollectionParticipant
-{
-public:
-    NS_IMETHOD_(void) Trace(void *p, TraceCallback cb, void *closure) = 0;
-    void NS_COM_GLUE TraverseScriptObjects(void *p,
-                                        nsCycleCollectionTraversalCallback &cb);
-};
-
-class NS_COM_GLUE nsXPCOMCycleCollectionParticipant
-    : public nsScriptObjectTracer
-{
-public:
-    NS_IMETHOD Traverse(void *p, nsCycleCollectionTraversalCallback &cb);
-
-    NS_IMETHOD RootAndUnlinkJSObjects(void *p);
-    NS_IMETHOD Unlink(void *p);
-    NS_IMETHOD Unroot(void *p);
-
-    NS_IMETHOD_(void) Trace(void *p, TraceCallback cb, void *closure);
-
-    NS_IMETHOD_(void) UnmarkPurple(nsISupports *p);
-
-    PRBool CheckForRightISupports(nsISupports *s);
-};
-
-#undef IMETHOD_VISIBILITY
-#define IMETHOD_VISIBILITY NS_VISIBILITY_HIDDEN
+typedef nsCycleCollectionParticipant nsXPCOMCycleCollectionParticipant;
 
 ///////////////////////////////////////////////////////////////////////////////
 // Helpers for implementing a QI to nsXPCOMCycleCollectionParticipant
 ///////////////////////////////////////////////////////////////////////////////
 
-#define NS_CYCLE_COLLECTION_INNERCLASS                                         \
-        cycleCollection
+#define NS_IMPL_QUERY_CYCLE_COLLECTION(_class)
 
-#define NS_CYCLE_COLLECTION_CLASSNAME(_class)                                  \
-        _class::NS_CYCLE_COLLECTION_INNERCLASS
+#define NS_INTERFACE_MAP_ENTRY_CYCLE_COLLECTION(_class)
 
-#define NS_CYCLE_COLLECTION_INNERNAME                                          \
-        _cycleCollectorGlobal
+#define NS_INTERFACE_MAP_ENTRY_CYCLE_COLLECTION_ISUPPORTS(_class)
 
-#define NS_CYCLE_COLLECTION_NAME(_class)                                       \
-        _class::NS_CYCLE_COLLECTION_INNERNAME
-
-#define NS_IMPL_QUERY_CYCLE_COLLECTION(_class)                                 \
-  if ( aIID.Equals(NS_GET_IID(nsXPCOMCycleCollectionParticipant)) ) {          \
-    *aInstancePtr = & NS_CYCLE_COLLECTION_NAME(_class);                        \
-    return NS_OK;                                                              \
-  } else
-
-#define NS_IMPL_QUERY_CYCLE_COLLECTION_ISUPPORTS(_class)                       \
-  if ( aIID.Equals(NS_GET_IID(nsCycleCollectionISupports)) )                   \
-    foundInterface = NS_CYCLE_COLLECTION_CLASSNAME(_class)::Upcast(this);      \
-  else
-
-#define NS_INTERFACE_MAP_ENTRY_CYCLE_COLLECTION(_class)                        \
-  NS_IMPL_QUERY_CYCLE_COLLECTION(_class)
-
-#define NS_INTERFACE_MAP_ENTRY_CYCLE_COLLECTION_ISUPPORTS(_class)              \
-  NS_IMPL_QUERY_CYCLE_COLLECTION_ISUPPORTS(_class)
-
-#define NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(_class)                      \
-  NS_INTERFACE_MAP_ENTRY_CYCLE_COLLECTION(_class)                              \
-  NS_INTERFACE_MAP_ENTRY_CYCLE_COLLECTION_ISUPPORTS(_class)
+#define NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(_class)
 
 #define NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(_class)                        \
-  NS_INTERFACE_MAP_BEGIN(_class)                                               \
-    NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(_class)
+  NS_INTERFACE_MAP_BEGIN(_class)
 
 #define NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(_class)              \
-  NS_INTERFACE_MAP_BEGIN(_class)                                               \
-    NS_INTERFACE_MAP_ENTRY_CYCLE_COLLECTION(_class)
+  NS_INTERFACE_MAP_BEGIN(_class)
 
 #define NS_INTERFACE_TABLE_TO_MAP_SEGUE_CYCLE_COLLECTION(_class)  \
   if (rv == NS_OK) return rv; \
-  nsISupports* foundInterface; \
-  NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(_class)
+  nsISupports* foundInterface;
 
 #define NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(_class)            \
   NS_IMETHODIMP _class::QueryInterface(REFNSIID aIID, void** aInstancePtr)    \
   {                                                                           \
     NS_PRECONDITION(aInstancePtr, "null out param");                          \
                                                                               \
-    if ( aIID.Equals(NS_GET_IID(nsXPCOMCycleCollectionParticipant)) ) {       \
-      *aInstancePtr = &NS_CYCLE_COLLECTION_NAME(_class);                      \
-      return NS_OK;                                                           \
-    }                                                                         \
     nsresult rv;
 
 #define NS_CYCLE_COLLECTION_UPCAST(obj, clazz)                                 \
@@ -262,319 +179,58 @@ public:
 // Helpers for implementing nsCycleCollectionParticipant::Unlink
 ///////////////////////////////////////////////////////////////////////////////
 
-#define NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(_class)                          \
-  NS_IMETHODIMP                                                                \
-  NS_CYCLE_COLLECTION_CLASSNAME(_class)::Unlink(void *p)                       \
-  {                                                                            \
-    nsISupports *s = static_cast<nsISupports*>(p);                             \
-    NS_ASSERTION(CheckForRightISupports(s),                                    \
-                 "not the nsISupports pointer we expect");                     \
-    _class *tmp = Downcast(s);
-
-#define NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(_class, _base_class)   \
-  NS_IMETHODIMP                                                                \
-  NS_CYCLE_COLLECTION_CLASSNAME(_class)::Unlink(void *p)                       \
-  {                                                                            \
-    nsISupports *s = static_cast<nsISupports*>(p);                             \
-    NS_ASSERTION(CheckForRightISupports(s),                                    \
-                 "not the nsISupports pointer we expect");                     \
-    _class *tmp = static_cast<_class*>(Downcast(s));                           \
-    NS_CYCLE_COLLECTION_CLASSNAME(_base_class)::Unlink(s);
-
-#define NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_NATIVE(_class)                   \
-  NS_IMETHODIMP                                                                \
-  NS_CYCLE_COLLECTION_CLASSNAME(_class)::Unlink(void *p)                       \
-  {                                                                            \
-    _class *tmp = static_cast<_class*>(p);
-
-#define NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(_field)                       \
-    tmp->_field = NULL;    
-
-#define NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMARRAY(_field)                     \
-    tmp->_field.Clear();
-
-#define NS_IMPL_CYCLE_COLLECTION_UNLINK_NSTARRAY(_field)                       \
-    tmp->_field.Clear();
-
-#define NS_IMPL_CYCLE_COLLECTION_UNLINK_END                                    \
-    return NS_OK;                                                              \
-  }
-
-#define NS_IMPL_CYCLE_COLLECTION_UNLINK_0(_class)                              \
-  NS_IMETHODIMP                                                                \
-  NS_CYCLE_COLLECTION_CLASSNAME(_class)::Unlink(void *p)                       \
-  {                                                                            \
-    NS_ASSERTION(CheckForRightISupports(static_cast<nsISupports*>(p)),         \
-                 "not the nsISupports pointer we expect");                     \
-    return NS_OK;                                                              \
-  }
-
-#define NS_IMPL_CYCLE_COLLECTION_UNLINK_NATIVE_0(_class)                       \
-  NS_IMETHODIMP                                                                \
-  NS_CYCLE_COLLECTION_CLASSNAME(_class)::Unlink(void *p)                       \
-  {                                                                            \
-    return NS_OK;                                                              \
-  }
+#define NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(_class)
+#define NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(_class, _base_class)
+#define NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_NATIVE(_class)
+#define NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(_field)
+#define NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMARRAY(_field)
+#define NS_IMPL_CYCLE_COLLECTION_UNLINK_NSTARRAY(_field)
+#define NS_IMPL_CYCLE_COLLECTION_UNLINK_END
+#define NS_IMPL_CYCLE_COLLECTION_UNLINK_0(_class)
+#define NS_IMPL_CYCLE_COLLECTION_UNLINK_NATIVE_0(_class)
 
 
 ///////////////////////////////////////////////////////////////////////////////
 // Helpers for implementing nsCycleCollectionParticipant::Traverse
 ///////////////////////////////////////////////////////////////////////////////
 
-#ifdef DEBUG_CC
-#define NS_IMPL_CYCLE_COLLECTION_DESCRIBE(_class)                              \
-    cb.DescribeNode(RefCounted, tmp->mRefCnt.get(), sizeof(_class), #_class);
-#else
-#define NS_IMPL_CYCLE_COLLECTION_DESCRIBE(_class)                              \
-    cb.DescribeNode(RefCounted, tmp->mRefCnt.get());
-#endif
-
-#define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(_class)                        \
-  NS_IMETHODIMP                                                                \
-  NS_CYCLE_COLLECTION_CLASSNAME(_class)::Traverse                              \
-                         (void *p,                                             \
-                          nsCycleCollectionTraversalCallback &cb)              \
-  {                                                                            \
-    nsISupports *s = static_cast<nsISupports*>(p);                             \
-    NS_ASSERTION(CheckForRightISupports(s),                                    \
-                 "not the nsISupports pointer we expect");                     \
-    _class *tmp = Downcast(s);                                                 \
-    NS_IMPL_CYCLE_COLLECTION_DESCRIBE(_class)
-
-#define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(_class, _base_class) \
-  NS_IMETHODIMP                                                                \
-  NS_CYCLE_COLLECTION_CLASSNAME(_class)::Traverse                              \
-                         (void *p,                                             \
-                          nsCycleCollectionTraversalCallback &cb)              \
-  {                                                                            \
-    nsISupports *s = static_cast<nsISupports*>(p);                             \
-    NS_ASSERTION(CheckForRightISupports(s),                                    \
-                 "not the nsISupports pointer we expect");                     \
-    _class *tmp = static_cast<_class*>(Downcast(s));                           \
-    NS_CYCLE_COLLECTION_CLASSNAME(_base_class)::Traverse(s, cb);
-
-#define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_BEGIN(_class)                 \
-  NS_IMETHODIMP                                                                \
-  NS_CYCLE_COLLECTION_CLASSNAME(_class)::Traverse                              \
-                         (void *p,                                             \
-                          nsCycleCollectionTraversalCallback &cb)              \
-  {                                                                            \
-    _class *tmp = static_cast<_class*>(p);                                     \
-    NS_IMPL_CYCLE_COLLECTION_DESCRIBE(_class)
-
-#ifdef DEBUG_CC
-  #define NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(_cb, _name)                       \
-    PR_BEGIN_MACRO (_cb).NoteNextEdgeName(_name); PR_END_MACRO
-#else
-  #define NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(_cb, _name)                       \
-    PR_BEGIN_MACRO PR_END_MACRO
-#endif
-
-#define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_RAWPTR(_field)                       \
-  PR_BEGIN_MACRO                                                               \
-    NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, #_field);                           \
-    cb.NoteXPCOMChild(tmp->_field);                                            \
-  PR_END_MACRO;
-
-#define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(_field)                     \
-  PR_BEGIN_MACRO                                                               \
-    NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, #_field);                           \
-    cb.NoteXPCOMChild(tmp->_field.get());                                      \
-  PR_END_MACRO;
-
-#define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(_field, _base)    \
-  PR_BEGIN_MACRO                                                               \
-    NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, #_field);                           \
-    cb.NoteXPCOMChild(NS_ISUPPORTS_CAST(_base*, tmp->_field));                 \
-  PR_END_MACRO;
-
-#define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMARRAY(_field)                   \
-    {                                                                          \
-      PRInt32 i;                                                               \
-      for (i = 0; i < tmp->_field.Count(); ++i) {                              \
-        NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, #_field "[i]");                 \
-        cb.NoteXPCOMChild(tmp->_field[i]);                                     \
-      }                                                                        \
-    }
-
-#define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_PTR(_ptr, _ptr_class, _name)  \
-  PR_BEGIN_MACRO                                                               \
-    NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, _name);                             \
-    cb.NoteNativeChild(_ptr, &NS_CYCLE_COLLECTION_NAME(_ptr_class));           \
-  PR_END_MACRO;
-
-#define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_MEMBER(_field, _field_class)  \
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_PTR(tmp->_field, _field_class,      \
-                                               #_field)
-
-#define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSTARRAY(_array, _element_class,     \
-                                                   _name)                      \
-    {                                                                          \
-      PRUint32 i, length = (_array).Length();                                  \
-      for (i = 0; i < length; ++i)                                             \
-        NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_PTR((_array)[i],              \
-                                                     _element_class,           \
-                                                     _name "[i]");             \
-    }
-
-#define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSTARRAY_MEMBER(_field,              \
-                                                          _element_class)      \
-    NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSTARRAY(tmp->_field, _element_class,    \
-                                               #_field)
-
-#define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS                       \
-    TraverseScriptObjects(tmp, cb);
-
-#define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END                                  \
-    return NS_OK;                                                              \
-  }
+#define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(_class)
+#define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(_class, _base_class)
+#define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_BEGIN(_class)
+#define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_RAWPTR(_field)
+#define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(_field)
+#define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(_field, _base)
+#define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMARRAY(_field)
+#define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_PTR(_ptr, _ptr_class)
+#define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE_MEMBER(_field, _field_class)
+#define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSTARRAY(_array, _element_class)
+#define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSTARRAY_MEMBER(_field, _element_class)
+#define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 ///////////////////////////////////////////////////////////////////////////////
 // Helpers for implementing nsScriptObjectTracer::Trace
 ///////////////////////////////////////////////////////////////////////////////
 
-#define NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(_class)                           \
-  void                                                                         \
-  NS_CYCLE_COLLECTION_CLASSNAME(_class)::Trace(void *p,                        \
-                                               TraceCallback aCallback,        \
-                                               void *aClosure)                 \
-  {                                                                            \
-    nsISupports *s = static_cast<nsISupports*>(p);                             \
-    NS_ASSERTION(CheckForRightISupports(s),                                    \
-                 "not the nsISupports pointer we expect");                     \
-    _class *tmp = Downcast(s);
+#define NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(_class)
+#define NS_IMPL_CYCLE_COLLECTION_TRACE_NATIVE_BEGIN(_class)
 
-#define NS_IMPL_CYCLE_COLLECTION_TRACE_NATIVE_BEGIN(_class)                    \
-  void                                                                         \
-  NS_CYCLE_COLLECTION_CLASSNAME(_class)::Trace(void *p,                        \
-                                               TraceCallback aCallback,        \
-                                               void *aClosure)                 \
-  {                                                                            \
-    _class *tmp = static_cast<_class*>(p);
-
-#define NS_IMPL_CYCLE_COLLECTION_TRACE_CALLBACK(_langID, _object)              \
-  if (_object)                                                                 \
-    aCallback(_langID, _object, aClosure);
-
-#define NS_IMPL_CYCLE_COLLECTION_TRACE_MEMBER_CALLBACK(_langID, _field)        \
-  NS_IMPL_CYCLE_COLLECTION_TRACE_CALLBACK(_langID, tmp->_field)
-
-#define NS_IMPL_CYCLE_COLLECTION_TRACE_JS_CALLBACK(_object)                    \
-  NS_IMPL_CYCLE_COLLECTION_TRACE_CALLBACK(nsIProgrammingLanguage::JAVASCRIPT,  \
-                                          _object)
-
-#define NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(_field)              \
-  NS_IMPL_CYCLE_COLLECTION_TRACE_JS_CALLBACK(tmp->_field)
-
-#define NS_IMPL_CYCLE_COLLECTION_TRACE_END                                     \
-  }
+#define NS_IMPL_CYCLE_COLLECTION_TRACE_CALLBACK(_langID, _object)
+#define NS_IMPL_CYCLE_COLLECTION_TRACE_MEMBER_CALLBACK(_langID, _field)
+#define NS_IMPL_CYCLE_COLLECTION_TRACE_JS_CALLBACK(_object)
+#define NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(_field)
+#define NS_IMPL_CYCLE_COLLECTION_TRACE_END
 
 ///////////////////////////////////////////////////////////////////////////////
 // Helpers for implementing a concrete nsCycleCollectionParticipant 
 ///////////////////////////////////////////////////////////////////////////////
 
-#define NS_CYCLE_COLLECTION_PARTICIPANT_INSTANCE                               \
-  static NS_CYCLE_COLLECTION_INNERCLASS NS_CYCLE_COLLECTION_INNERNAME;
-
-#define NS_DECL_CYCLE_COLLECTION_CLASS_BODY_NO_UNLINK(_class, _base)           \
-public:                                                                        \
-  NS_IMETHOD Traverse(void *p,                                                 \
-                      nsCycleCollectionTraversalCallback &cb);                 \
-  NS_IMETHOD_(void) UnmarkPurple(nsISupports *s)                               \
-  {                                                                            \
-    Downcast(s)->UnmarkPurple();                                               \
-  }                                                                            \
-  static _class* Downcast(nsISupports* s)                                      \
-  {                                                                            \
-    return static_cast<_class*>(static_cast<_base*>(s));                       \
-  }                                                                            \
-  static nsISupports* Upcast(_class *p)                                        \
-  {                                                                            \
-    return NS_ISUPPORTS_CAST(_base*, p);                                       \
-  }
-
-#define NS_DECL_CYCLE_COLLECTION_CLASS_BODY(_class, _base)                     \
-  NS_DECL_CYCLE_COLLECTION_CLASS_BODY_NO_UNLINK(_class, _base)                 \
-  NS_IMETHOD Unlink(void *p);
-
-#define NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(_class, _base)                \
-class NS_CYCLE_COLLECTION_INNERCLASS                                           \
- : public nsXPCOMCycleCollectionParticipant                                    \
-{                                                                              \
-  NS_DECL_CYCLE_COLLECTION_CLASS_BODY(_class, _base)                           \
-};                                                                             \
-NS_CYCLE_COLLECTION_PARTICIPANT_INSTANCE
-
-#define NS_DECL_CYCLE_COLLECTION_CLASS(_class)                                 \
-  NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(_class, _class)
-
-// Cycle collector helper for classes that don't want to unlink anything.
-// Note: if this is used a lot it might make sense to have a base class that
-//       doesn't do anything in RootAndUnlinkJSObjects/Unlink/Unroot.
-#define NS_DECL_CYCLE_COLLECTION_CLASS_NO_UNLINK(_class)                       \
-class NS_CYCLE_COLLECTION_INNERCLASS                                           \
- : public nsXPCOMCycleCollectionParticipant                                    \
-{                                                                              \
-  NS_DECL_CYCLE_COLLECTION_CLASS_BODY_NO_UNLINK(_class, _class)                \
-  NS_IMETHOD RootAndUnlinkJSObjects(void *p)                                   \
-  {                                                                            \
-    return NS_OK;                                                              \
-  }                                                                            \
-  NS_IMETHOD Unlink(void *p)                                                   \
-  {                                                                            \
-    return NS_OK;                                                              \
-  }                                                                            \
-  NS_IMETHOD Unroot(void *p)                                                   \
-  {                                                                            \
-    return NS_OK;                                                              \
-  }                                                                            \
-};                                                                             \
-NS_CYCLE_COLLECTION_PARTICIPANT_INSTANCE
-
-#define NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(_class, _base)  \
-class NS_CYCLE_COLLECTION_INNERCLASS                                           \
- : public nsXPCOMCycleCollectionParticipant                                    \
-{                                                                              \
-  NS_IMETHOD RootAndUnlinkJSObjects(void *p);                                  \
-  NS_DECL_CYCLE_COLLECTION_CLASS_BODY(_class, _base)                           \
-  NS_IMETHOD_(void) Trace(void *p, TraceCallback cb, void *closure);           \
-};                                                                             \
-NS_CYCLE_COLLECTION_PARTICIPANT_INSTANCE
-
-#define NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(_class)  \
-  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(_class, _class)
-
-#define NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(_class, _base_class)          \
-class NS_CYCLE_COLLECTION_INNERCLASS                                           \
- : public NS_CYCLE_COLLECTION_CLASSNAME(_base_class)                           \
-{                                                                              \
-public:                                                                        \
-  NS_IMETHOD Unlink(void *p);                                                  \
-  NS_IMETHOD Traverse(void *p,                                                 \
-                      nsCycleCollectionTraversalCallback &cb);                 \
-  static _class* Downcast(nsISupports* s)                                      \
-  {                                                                            \
-    return static_cast<_class*>(static_cast<_base_class*>(                     \
-      NS_CYCLE_COLLECTION_CLASSNAME(_base_class)::Downcast(s)));               \
-  }                                                                            \
-};                                                                             \
-NS_CYCLE_COLLECTION_PARTICIPANT_INSTANCE
-
-#define NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_NO_UNLINK(_class,             \
-                                                           _base_class)        \
-class NS_CYCLE_COLLECTION_INNERCLASS                                           \
- : public NS_CYCLE_COLLECTION_CLASSNAME(_base_class)                           \
-{                                                                              \
-public:                                                                        \
-  NS_IMETHOD Traverse(void *p,                                                 \
-                      nsCycleCollectionTraversalCallback &cb);                 \
-  static _class* Downcast(nsISupports* s)                                      \
-  {                                                                            \
-    return static_cast<_class*>(static_cast<_base_class*>(                     \
-      NS_CYCLE_COLLECTION_CLASSNAME(_base_class)::Downcast(s)));               \
-  }                                                                            \
-};                                                                             \
-NS_CYCLE_COLLECTION_PARTICIPANT_INSTANCE
+#define NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(_class, _base)
+#define NS_DECL_CYCLE_COLLECTION_CLASS(_class)
+#define NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(_class)
+#define NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(_class, _iface)
+#define NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(_class)
+#define NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(_class, _base_class)
+#define NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_NO_UNLINK(_class, _base_class)
 
 /**
  * This implements a stub UnmarkPurple function for classes that want to be
@@ -582,56 +238,15 @@ NS_CYCLE_COLLECTION_PARTICIPANT_INSTANCE
  * the purple buffer. If you're just using NS_DECL_CYCLE_COLLECTING_ISUPPORTS
  * then you don't need this.
  */
-#define NS_DECL_CYCLE_COLLECTION_UNMARK_PURPLE_STUB(_class)                    \
-  NS_IMETHODIMP_(void) UnmarkPurple()                                          \
-  {                                                                            \
-  }                                                                            \
+#define NS_DECL_CYCLE_COLLECTION_UNMARK_PURPLE_STUB(_class)
 
-#define NS_IMPL_CYCLE_COLLECTION_CLASS(_class)                                 \
-  NS_CYCLE_COLLECTION_CLASSNAME(_class) NS_CYCLE_COLLECTION_NAME(_class);
-
-#define NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS_BODY                             \
-  public:                                                                      \
-    NS_IMETHOD RootAndUnlinkJSObjects(void *n);                                \
-    NS_IMETHOD Unlink(void *n);                                                \
-    NS_IMETHOD Unroot(void *n);                                                \
-    NS_IMETHOD Traverse(void *n,                                               \
-                      nsCycleCollectionTraversalCallback &cb);
-
-#define NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(_class)                          \
-  class NS_CYCLE_COLLECTION_INNERCLASS                                         \
-   : public nsCycleCollectionParticipant                                       \
-  {                                                                            \
-     NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS_BODY                                \
-  };                                                                           \
-  NS_CYCLE_COLLECTION_PARTICIPANT_INSTANCE
-
-#define NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(_class)            \
-  class NS_CYCLE_COLLECTION_INNERCLASS                                         \
-   : public nsScriptObjectTracer                                               \
-  {                                                                            \
-    NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS_BODY                                 \
-    NS_IMETHOD_(void) Trace(void *p, TraceCallback cb, void *closure);         \
-  };                                                                           \
-  NS_CYCLE_COLLECTION_PARTICIPANT_INSTANCE
-
-#define NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(_class, _root_function)           \
-  NS_IMETHODIMP                                                                \
-  NS_CYCLE_COLLECTION_CLASSNAME(_class)::RootAndUnlinkJSObjects(void *p)       \
-  {                                                                            \
-    _class *tmp = static_cast<_class*>(p);                                     \
-    tmp->_root_function();                                                     \
-    return NS_OK;                                                              \
-  }
-
-#define NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(_class, _unroot_function)       \
-  NS_IMETHODIMP                                                                \
-  NS_CYCLE_COLLECTION_CLASSNAME(_class)::Unroot(void *p)                       \
-  {                                                                            \
-    _class *tmp = static_cast<_class*>(p);                                     \
-    tmp->_unroot_function();                                                   \
-    return NS_OK;                                                              \
-  }
+#define NS_IMPL_CYCLE_COLLECTION_CLASS(_class)
+#define NS_CYCLE_COLLECTION_NATIVE_INNERNAME
+#define NS_CYCLE_COLLECTION_NATIVE_NAME(_class)
+#define NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(_class)
+#define NS_IMPL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(_class)
+#define NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(_class, _root_function)
+#define NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(_class, _unroot_function)
 
 #define NS_IMPL_CYCLE_COLLECTION_0(_class)                                     \
  NS_IMPL_CYCLE_COLLECTION_CLASS(_class)                                        \
diff --git a/xpcom/glue/nsISupportsImpl.h b/xpcom/glue/nsISupportsImpl.h
--- a/xpcom/glue/nsISupportsImpl.h
+++ b/xpcom/glue/nsISupportsImpl.h
@@ -55,7 +55,6 @@
 
 #include "nsDebug.h"
 #include "nsTraceRefcnt.h"
-#include "nsCycleCollector.h"
 
 ////////////////////////////////////////////////////////////////////////////////
 // Macros to help detect thread-safety:
@@ -92,102 +91,6 @@ private:
 
 // Support for ISupports classes which interact with cycle collector.
 
-class nsCycleCollectingAutoRefCnt {
-
-public:
-  nsCycleCollectingAutoRefCnt()
-    : mValue(0)
-  {}
-
-  nsCycleCollectingAutoRefCnt(nsrefcnt aValue)
-    : mValue(aValue)
-  {
-    NS_CLEAR_PURPLE_BIT(mValue);
-  }
-
-  nsrefcnt incr(nsISupports *owner)
-  {
-    if (NS_UNLIKELY(mValue == NS_PURPLE_BIT)) {
-      // The sentinel value "purple bit alone, refcount 0" means
-      // that we're stabilized, during finalization. In this
-      // state we lie about our actual refcount if anyone asks
-      // and say it's 2, which is basically true: the caller who
-      // is incrementing has a reference, as does the decr() frame
-      // that stabilized-and-is-deleting us.
-      return 2;
-    }
-
-    nsrefcnt tmp = get();
-    PRBool purple = static_cast<PRBool>(NS_PURPLE_BIT_SET(mValue));
-
-    if (NS_UNLIKELY(purple)) {
-      NS_ASSERTION(tmp != 0, "purple ISupports pointer with zero refcnt");
-      if (!NS_CycleCollectorForget(owner))
-        tmp |= NS_PURPLE_BIT;
-    }
-
-    mValue = tmp + 1;
-    return mValue;
-  }
-
-  void stabilizeForDeletion(nsISupports *owner)
-  {
-    mValue = NS_PURPLE_BIT;
-  }
-
-  nsrefcnt decr(nsISupports *owner)
-  {
-    if (NS_UNLIKELY(mValue == NS_PURPLE_BIT))
-      return 1;
-
-    nsrefcnt tmp = get();
-    NS_ASSERTION(tmp >= 1, "decr() called with zero refcnt");
-
-    PRBool purple = static_cast<PRBool>(NS_PURPLE_BIT_SET(mValue));
-    PRBool shouldBePurple = tmp > 1;
-
-    if (NS_UNLIKELY(shouldBePurple && !purple)) {
-      if (!NS_CycleCollectorSuspect(owner))
-        shouldBePurple = PR_FALSE;
-    } else if (NS_UNLIKELY(tmp == 1 && purple)) {
-      if (!NS_CycleCollectorForget(owner)) {
-        NS_NOTREACHED("forget should not fail when reference count hits 0");
-      }
-    }
-
-    --tmp;
-
-    if (shouldBePurple)
-      mValue = tmp | NS_PURPLE_BIT;
-    else
-      mValue = tmp;
-
-    return tmp;
-  }
-
-  void unmarkPurple()
-  {
-    if (NS_LIKELY(mValue != NS_PURPLE_BIT))
-      NS_CLEAR_PURPLE_BIT(mValue);
-  }
-
-  nsrefcnt get() const
-  {
-    if (NS_UNLIKELY(mValue == NS_PURPLE_BIT))
-      return 1;
-
-    return NS_VALUE_WITHOUT_PURPLE_BIT(mValue);
-  }
-
-  operator nsrefcnt() const
-  {
-    return get();
-  }
-
- private:
-  nsrefcnt mValue;
-};
-
 class nsAutoRefCnt {
 
  public:
@@ -208,6 +111,8 @@ class nsAutoRefCnt {
     nsrefcnt mValue;
 };
 
+typedef nsAutoRefCnt nsCycleCollectingAutoRefCnt;
+
 ///////////////////////////////////////////////////////////////////////////////
 
 /**
@@ -226,21 +131,7 @@ protected:                              
   NS_DECL_OWNINGTHREAD                                                        \
 public:
 
-#define NS_DECL_CYCLE_COLLECTING_ISUPPORTS                                    \
-public:                                                                       \
-  NS_IMETHOD QueryInterface(REFNSIID aIID,                                    \
-                            void** aInstancePtr);                             \
-  NS_IMETHOD_(nsrefcnt) AddRef(void);                                         \
-  NS_IMETHOD_(nsrefcnt) Release(void);                                        \
-  void UnmarkPurple()                                                         \
-  {                                                                           \
-    mRefCnt.unmarkPurple();                                                   \
-  }                                                                           \
-protected:                                                                    \
-  nsCycleCollectingAutoRefCnt mRefCnt;                                        \
-  NS_DECL_OWNINGTHREAD                                                        \
-public:
-
+#define NS_DECL_CYCLE_COLLECTING_ISUPPORTS NS_DECL_ISUPPORTS
 
 ///////////////////////////////////////////////////////////////////////////////
 
@@ -344,35 +235,12 @@ NS_IMETHODIMP_(nsrefcnt) _class::Release
 }
 
 
-#define NS_IMPL_CYCLE_COLLECTING_ADDREF_AMBIGUOUS(_class, _basetype)          \
-NS_IMETHODIMP_(nsrefcnt) _class::AddRef(void)                                 \
-{                                                                             \
-  NS_PRECONDITION(PRInt32(mRefCnt) >= 0, "illegal refcnt");                   \
-  NS_ASSERT_OWNINGTHREAD(_class);                                             \
-  nsrefcnt count =                                                            \
-    mRefCnt.incr(NS_CYCLE_COLLECTION_CLASSNAME(_class)::Upcast(this));        \
-  NS_LOG_ADDREF(this, count, #_class, sizeof(*this));                         \
-  return count;                                                               \
-}
+#define NS_IMPL_CYCLE_COLLECTING_ADDREF_AMBIGUOUS(_class, _basetype)  NS_IMPL_ADDREF(_class)
 
-#define NS_IMPL_CYCLE_COLLECTING_ADDREF(_class)      \
-  NS_IMPL_CYCLE_COLLECTING_ADDREF_AMBIGUOUS(_class, _class)
+#define NS_IMPL_CYCLE_COLLECTING_ADDREF(_class) NS_IMPL_ADDREF(_class)
 
-#define NS_IMPL_CYCLE_COLLECTING_RELEASE_FULL(_class, _basetype, _destroy)    \
-NS_IMETHODIMP_(nsrefcnt) _class::Release(void)                                \
-{                                                                             \
-  NS_PRECONDITION(0 != mRefCnt, "dup release");                               \
-  NS_ASSERT_OWNINGTHREAD(_class);                                             \
-  nsISupports *base = NS_CYCLE_COLLECTION_CLASSNAME(_class)::Upcast(this);    \
-  nsrefcnt count = mRefCnt.decr(base);                                        \
-  NS_LOG_RELEASE(this, count, #_class);                                       \
-  if (count == 0) {                                                           \
-    mRefCnt.stabilizeForDeletion(base);                                       \
-    _destroy;                                                                 \
-    return 0;                                                                 \
-  }                                                                           \
-  return count;                                                               \
-}
+#define NS_IMPL_CYCLE_COLLECTING_RELEASE_FULL(_class, _basetype, _destroy) \
+  NS_IMPL_RELEASE_WITH_DESTROY(_class, _destroy)
 
 #define NS_IMPL_CYCLE_COLLECTING_RELEASE_WITH_DESTROY(_class, _destroy)       \
   NS_IMPL_CYCLE_COLLECTING_RELEASE_FULL(_class, _class, _destroy)
diff --git a/xpcom/glue/objs.mk b/xpcom/glue/objs.mk
--- a/xpcom/glue/objs.mk
+++ b/xpcom/glue/objs.mk
@@ -63,7 +63,6 @@ XPCOM_GLUE_SRC_LCPPSRCS =        \
   nsTArray.cpp                   \
   nsThreadUtils.cpp              \
   nsTObserverArray.cpp           \
-  nsCycleCollectionParticipant.cpp \
   nsDeque.cpp \
   $(NULL)
 
diff --git a/xpfe/components/intl/nsCharsetMenu.cpp b/xpfe/components/intl/nsCharsetMenu.cpp
--- a/xpfe/components/intl/nsCharsetMenu.cpp
+++ b/xpfe/components/intl/nsCharsetMenu.cpp
@@ -466,12 +466,6 @@ NS_IMETHODIMP nsCharsetMenuObserver::Obs
 
 //----------------------------------------------------------------------------
 // Class nsCharsetMenu [implementation]
-
-NS_IMPL_CYCLE_COLLECTION_CLASS(nsCharsetMenu)
-NS_IMPL_CYCLE_COLLECTION_UNLINK_0(nsCharsetMenu)
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsCharsetMenu)
-  cb.NoteXPCOMChild(nsCharsetMenu::mInner);
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF_AMBIGUOUS(nsCharsetMenu, nsIRDFDataSource)
 NS_IMPL_CYCLE_COLLECTING_RELEASE_AMBIGUOUS(nsCharsetMenu, nsIRDFDataSource)