Bug 752952 - account for nsIDocument's property tables in about:memory; r=njn,f=smaug
authorNathan Froyd <froydnj@mozilla.com>
Fri, 15 Jun 2012 00:10:08 -0400
changeset 96806 9c09642d4cd05903baa6285b788faa8300cf8723
parent 96805 d4fc8a49540cf0c43d067fc827578b24a867e822
child 96807 29c7d4df9bd4f4efa8c26efe602806b8155a0574
push id10718
push usernfroyd@mozilla.com
push dateFri, 15 Jun 2012 13:05:05 +0000
treeherdermozilla-inbound@9c09642d4cd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnjn
bugs752952
milestone16.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 752952 - account for nsIDocument's property tables in about:memory; r=njn,f=smaug
content/base/src/nsDocument.cpp
content/base/src/nsPropertyTable.cpp
content/base/src/nsPropertyTable.h
dom/base/nsWindowMemoryReporter.cpp
dom/base/nsWindowMemoryReporter.h
--- a/content/base/src/nsDocument.cpp
+++ b/content/base/src/nsDocument.cpp
@@ -9603,16 +9603,24 @@ nsIDocument::DocSizeOfExcludingThis(nsWi
     mPresShell->SizeOfIncludingThis(aWindowSizes->mMallocSizeOf,
                                     &aWindowSizes->mArenaStats,
                                     &aWindowSizes->mLayoutPresShell,
                                     &aWindowSizes->mLayoutStyleSets,
                                     &aWindowSizes->mLayoutTextRuns,
                                     &aWindowSizes->mLayoutPresContext);
   }
 
+  aWindowSizes->mPropertyTables +=
+    mPropertyTable.SizeOfExcludingThis(aWindowSizes->mMallocSizeOf);
+  for (PRUint32 i = 0, count = mExtraPropertyTables.Length();
+       i < count; ++i) {
+    aWindowSizes->mPropertyTables +=
+      mExtraPropertyTables[i]->SizeOfExcludingThis(aWindowSizes->mMallocSizeOf);
+  }
+
   // Measurement of the following members may be added later if DMD finds it
   // is worthwhile:
   // - many!
 }
 
 void
 nsIDocument::DocSizeOfIncludingThis(nsWindowSizes* aWindowSizes) const
 {
--- a/content/base/src/nsPropertyTable.cpp
+++ b/content/base/src/nsPropertyTable.cpp
@@ -47,16 +47,18 @@ public:
   // Destroy all remaining properties (without removing them)
   NS_HIDDEN_(void) Destroy();
 
   NS_HIDDEN_(bool) Equals(nsIAtom *aPropertyName)
   {
     return mName == aPropertyName;
   }
 
+  size_t SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf);
+
   nsCOMPtr<nsIAtom>  mName;           // property name
   PLDHashTable       mObjectValueMap; // map of object/value pairs
   NSPropertyDtorFunc mDtorFunc;       // property specific value dtor function
   void*              mDtorData;       // pointer to pass to dtor
   bool               mTransfer;       // whether to transfer in
                                       // TransferOrDeleteAllPropertiesFor
   
   PropertyList*      mNext;
@@ -332,16 +334,36 @@ nsPropertyTable::PropertyList::DeletePro
   PL_DHashTableRawRemove(&mObjectValueMap, entry);
 
   if (mDtorFunc)
     mDtorFunc(const_cast<void*>(aObject.get()), mName, value, mDtorData);
 
   return true;
 }
 
+size_t
+nsPropertyTable::PropertyList::SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf)
+{
+  size_t n = aMallocSizeOf(this);
+  n += PL_DHashTableSizeOfExcludingThis(&mObjectValueMap, NULL, aMallocSizeOf);
+  return n;
+}
+
+size_t
+nsPropertyTable::SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf) const
+{
+  size_t n = 0;
+
+  for (PropertyList *prop = mPropertyList; prop; prop = prop->mNext) {
+    n += prop->SizeOfIncludingThis(aMallocSizeOf);
+  }
+
+  return n;
+}
+
 /* static */
 void
 nsPropertyTable::SupportsDtorFunc(void *aObject, nsIAtom *aPropertyName,
                                   void *aPropertyValue, void *aData)
 {
   nsISupports *propertyValue = static_cast<nsISupports*>(aPropertyValue);
   NS_IF_RELEASE(propertyValue);
 }
--- a/content/base/src/nsPropertyTable.h
+++ b/content/base/src/nsPropertyTable.h
@@ -172,16 +172,18 @@ class nsPropertyTable
    * XPCOM objects. The function will call NS_IF_RELASE on the value
    * to destroy it.
    */
   static void SupportsDtorFunc(void *aObject, nsIAtom *aPropertyName,
                                void *aPropertyValue, void *aData);
 
   class PropertyList;
 
+  size_t SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf) const;
+
  private:
   NS_HIDDEN_(void) DestroyPropertyList();
   NS_HIDDEN_(PropertyList*) GetPropertyListFor(nsIAtom *aPropertyName) const;
   NS_HIDDEN_(void*) GetPropertyInternal(nsPropertyOwner aObject,
                                         nsIAtom    *aPropertyName,
                                         bool        aRemove,
                                         nsresult   *aStatus);
   NS_HIDDEN_(nsresult) SetPropertyInternal(nsPropertyOwner     aObject,
--- a/dom/base/nsWindowMemoryReporter.cpp
+++ b/dom/base/nsWindowMemoryReporter.cpp
@@ -172,16 +172,21 @@ CollectWindowReports(nsGlobalWindow *aWi
   REPORT("/dom/cdata-nodes", windowSizes.mDOMCDATANodes,
          "Memory used by the CDATA nodes in a window's DOM.");
   aWindowTotalSizes->mDOMCDATANodes += windowSizes.mDOMCDATANodes;
 
   REPORT("/dom/comment-nodes", windowSizes.mDOMCommentNodes,
          "Memory used by the comment nodes in a window's DOM.");
   aWindowTotalSizes->mDOMCommentNodes += windowSizes.mDOMCommentNodes;
 
+  REPORT("/property-tables",
+         windowSizes.mPropertyTables,
+         "Memory used for the property tables within a window.");
+  aWindowTotalSizes->mPropertyTables += windowSizes.mPropertyTables;
+
   REPORT("/style-sheets", windowSizes.mStyleSheets,
          "Memory used by style sheets within a window.");
   aWindowTotalSizes->mStyleSheets += windowSizes.mStyleSheets;
 
   REPORT("/layout/pres-shell", windowSizes.mLayoutPresShell,
          "Memory used by layout's PresShell, along with any structures "
          "allocated in its arena and not measured elsewhere, "
          "within a window.");
@@ -323,16 +328,21 @@ nsWindowMemoryReporter::CollectReports(n
   REPORT("window-objects/dom/cdata-nodes", windowTotalSizes.mDOMCDATANodes,
          "Memory used for DOM CDATA nodes within windows. "
          "This is the sum of all windows' 'dom/cdata-nodes' numbers.");
 
   REPORT("window-objects/dom/comment-nodes", windowTotalSizes.mDOMCommentNodes,
          "Memory used for DOM comment nodes within windows. "
          "This is the sum of all windows' 'dom/comment-nodes' numbers.");
 
+  REPORT("window-objects/property-tables",
+         windowTotalSizes.mPropertyTables,
+         "Memory used for property tables within windows. "
+         "This is the sum of all windows' 'property-tables' numbers.");
+
   REPORT("window-objects/style-sheets", windowTotalSizes.mStyleSheets, 
          "Memory used for style sheets within windows. "
          "This is the sum of all windows' 'style-sheets' numbers.");
     
   REPORT("window-objects/layout/pres-shell", windowTotalSizes.mLayoutPresShell, 
          "Memory used by layout PresShell and other related "
          "areas within windows. This is the sum of all windows' "
          "'layout/arenas' numbers.");
--- a/dom/base/nsWindowMemoryReporter.h
+++ b/dom/base/nsWindowMemoryReporter.h
@@ -34,16 +34,17 @@ public:
   size_t mDOMCDATANodes;
   size_t mDOMCommentNodes;
   size_t mDOMOther;
   size_t mStyleSheets;
   size_t mLayoutPresShell;
   size_t mLayoutStyleSets;
   size_t mLayoutTextRuns;
   size_t mLayoutPresContext;
+  size_t mPropertyTables;
 };
 
 /**
  * nsWindowMemoryReporter is responsible for the 'explicit/window-objects'
  * memory reporter.
  *
  * We classify DOM window objects into one of three categories:
  *