Bug 692226 - Record weak map entries in the cycle collector log. r=smaug
authorAndrew McCreight <amccreight@mozilla.com>
Fri, 26 Jul 2013 08:12:51 -0700
changeset 140164 155ab662755e07b1a582381ff0ff286d13df3de1
parent 140163 98c66f6c0414887fb3865527fb5f50326d740a58
child 140165 7c565590d6713593dffea789d5fc6df954b794dc
push id1945
push userryanvm@gmail.com
push dateSat, 27 Jul 2013 02:27:26 +0000
treeherderfx-team@4874fa438b1c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs692226
milestone25.0a1
Bug 692226 - Record weak map entries in the cycle collector log. r=smaug
xpcom/base/nsCycleCollector.cpp
xpcom/base/nsICycleCollectorListener.idl
--- a/xpcom/base/nsCycleCollector.cpp
+++ b/xpcom/base/nsCycleCollector.cpp
@@ -1514,16 +1514,26 @@ public:
             CCGraphDescriber* d = mDescribers.AppendElement();
             d->mType = CCGraphDescriber::eEdge;
             d->mAddress = mCurrentAddress;
             d->mToAddress.AppendInt(aToAddress, 16);
             d->mName.Append(aEdgeName);
         }
         return NS_OK;
     }
+    NS_IMETHOD NoteWeakMapEntry(uint64_t aMap, uint64_t aKey,
+                                uint64_t aKeyDelegate, uint64_t aValue)
+    {
+        if (!mDisableLog) {
+            fprintf(mStream, "WeakMapEntry map=%p key=%p keyDelegate=%p value=%p\n",
+                    (void*)aMap, (void*)aKey, (void*)aKeyDelegate, (void*)aValue);
+        }
+        // We don't support after-processing for weak map entries.
+        return NS_OK;
+    }
     NS_IMETHOD BeginResults()
     {
         if (!mDisableLog) {
             fputs("==========\n", mStream);
         }
         return NS_OK;
     }
     NS_IMETHOD DescribeRoot(uint64_t aAddress, uint32_t aKnownEdges)
@@ -2065,16 +2075,21 @@ GCGraphBuilder::NoteWeakMapping(void *ma
 {
     // Don't try to optimize away the entry here, as we've already attempted to
     // do that in TraceWeakMapping in nsXPConnect.
     WeakMapping *mapping = mWeakMaps.AppendElement();
     mapping->mMap = map ? AddWeakMapNode(map) : nullptr;
     mapping->mKey = key ? AddWeakMapNode(key) : nullptr;
     mapping->mKeyDelegate = kdelegate ? AddWeakMapNode(kdelegate) : mapping->mKey;
     mapping->mVal = val ? AddWeakMapNode(val) : nullptr;
+
+    if (mListener) {
+        mListener->NoteWeakMapEntry((uint64_t)map, (uint64_t)key,
+                                    (uint64_t)kdelegate, (uint64_t)val);
+    }
 }
 
 static bool
 AddPurpleRoot(GCGraphBuilder &builder, void *root, nsCycleCollectionParticipant *cp)
 {
     CanonicalizeParticipant(&root, &cp);
 
     if (builder.WantAllTraces() || !cp->CanSkipInCC(root)) {
--- a/xpcom/base/nsICycleCollectorListener.idl
+++ b/xpcom/base/nsICycleCollectorListener.idl
@@ -29,17 +29,17 @@ interface nsICycleCollectorHandler : nsI
  * beginResults(); then a mixture of describeRoot() for ref counted
  * nodes the CC has identified as roots and describeGarbage() for
  * nodes the CC has identified as garbage.  Ref counted nodes that are
  * not identified as either roots or garbage are neither, and have a
  * known edges count equal to their ref count.  Finally, there will be
  * a call to end().  If begin() returns an error none of the other
  * functions will be called.
  */
-[scriptable, builtinclass, uuid(4282249c-7f80-4093-b620-96c573ad683e)]
+[scriptable, builtinclass, uuid(32a3ab19-82a3-4096-a12a-de37274f51c3)]
 interface nsICycleCollectorListener : nsISupports
 {
     nsICycleCollectorListener allTraces();
     // false if allTraces() has not been called.
     readonly attribute boolean wantAllTraces;
 
     // The default implementation of this interface will print out
     // a log to a file unless disableLog is set to true.
@@ -53,16 +53,20 @@ interface nsICycleCollectorListener : ns
     void noteRefCountedObject (in unsigned long long aAddress,
 			       in unsigned long aRefCount,
 			       in string aObjectDescription);
     void noteGCedObject (in unsigned long long aAddress,
 			 in boolean aMarked,
 			 in string aObjectDescription);
     void noteEdge(in unsigned long long aToAddress,
                   in string aEdgeName);
+    void noteWeakMapEntry(in unsigned long long aMap,
+                          in unsigned long long aKey,
+                          in unsigned long long aKeyDelegate,
+                          in unsigned long long aValue);
     void beginResults();
     void describeRoot(in unsigned long long aAddress,
 		      in unsigned long aKnownEdges);
     void describeGarbage(in unsigned long long aAddress);
     void end();
 
     // Returns false if there isn't anything more to process.
     boolean processNext(in nsICycleCollectorHandler aHandler);