Bug 765326 - atom-table numbers should include the static atom table; r=njn
authorNathan Froyd <froydnj@mozilla.com>
Fri, 15 Jun 2012 15:51:42 -0400
changeset 102865 408e24552eeb219889b0241dc240729c3d6f1086
parent 102864 542074e589ebbddd4a030809f8f27639ec4b2921
child 102866 f57e5a2598786a08a2684ccd442b2bb0d15f6323
push id191
push userlsblakk@mozilla.com
push dateFri, 05 Oct 2012 17:12:53 +0000
treeherdermozilla-release@ddb22ac6c03b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnjn
bugs765326
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 765326 - atom-table numbers should include the static atom table; r=njn
xpcom/base/nsMemoryReporterManager.cpp
xpcom/ds/nsAtomTable.cpp
xpcom/ds/nsAtomTable.h
xpcom/glue/nsBaseHashtable.h
--- a/xpcom/base/nsMemoryReporterManager.cpp
+++ b/xpcom/base/nsMemoryReporterManager.cpp
@@ -512,30 +512,30 @@ NS_FALLIBLE_MEMORY_REPORTER_IMPLEMENT(Ex
     "This is the same measurement as the root of the 'explicit' tree.  "
     "However, it is measured at a different time and so gives slightly "
     "different results.")
 #endif  // HAVE_HEAP_ALLOCATED_REPORTERS
 
 NS_MEMORY_REPORTER_MALLOC_SIZEOF_FUN(AtomTableMallocSizeOf, "atom-table")
 
 static PRInt64 GetAtomTableSize() {
-  return NS_SizeOfAtomTableIncludingThis(AtomTableMallocSizeOf);
+  return NS_SizeOfAtomTablesIncludingThis(AtomTableMallocSizeOf);
 }
 
 // Why is this here?  At first glance, you'd think it could be defined and
 // registered with nsMemoryReporterManager entirely within nsAtomTable.cpp.
 // However, the obvious time to register it is when the table is initialized,
 // and that happens before XPCOM components are initialized, which means the
 // NS_RegisterMemoryReporter call fails.  So instead we do it here.
 NS_MEMORY_REPORTER_IMPLEMENT(AtomTable,
-    "explicit/atom-table",
+    "explicit/atom-tables",
     KIND_HEAP,
     UNITS_BYTES,
     GetAtomTableSize,
-    "Memory used by the atoms table.")
+    "Memory used by the dynamic and static atoms tables.")
 
 /**
  ** nsMemoryReporterManager implementation
  **/
 
 NS_IMPL_THREADSAFE_ISUPPORTS1(nsMemoryReporterManager, nsIMemoryReporterManager)
 
 NS_IMETHODIMP
--- a/xpcom/ds/nsAtomTable.cpp
+++ b/xpcom/ds/nsAtomTable.cpp
@@ -447,21 +447,36 @@ static size_t
 SizeOfAtomTableEntryExcludingThis(PLDHashEntryHdr *aHdr,
                                   nsMallocSizeOfFun aMallocSizeOf,
                                   void *aArg)
 {
   AtomTableEntry* entry = static_cast<AtomTableEntry*>(aHdr);
   return entry->mAtom->SizeOfIncludingThis(aMallocSizeOf);
 }
 
-size_t NS_SizeOfAtomTableIncludingThis(nsMallocSizeOfFun aMallocSizeOf) {
+static size_t
+SizeOfStaticAtomTableEntryExcludingThis(const nsAString& aKey,
+                                        nsIAtom* const& aData,
+                                        nsMallocSizeOfFun aMallocSizeOf,
+                                        void* aArg)
+{
+  return aKey.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
+}
+
+size_t
+NS_SizeOfAtomTablesIncludingThis(nsMallocSizeOfFun aMallocSizeOf) {
+  size_t n = 0;
   if (gAtomTable.ops) {
-      return PL_DHashTableSizeOfExcludingThis(&gAtomTable,
-                                              SizeOfAtomTableEntryExcludingThis,
-                                              aMallocSizeOf);
+      n += PL_DHashTableSizeOfExcludingThis(&gAtomTable,
+                                            SizeOfAtomTableEntryExcludingThis,
+                                            aMallocSizeOf);
+  }
+  if (gStaticAtomTable) {
+    n += gStaticAtomTable->SizeOfIncludingThis(SizeOfStaticAtomTableEntryExcludingThis,
+                                               aMallocSizeOf);
   }
   return 0;
 }
 
 #define ATOM_HASHTABLE_INITIAL_SIZE  4096
 
 static inline bool
 EnsureTableExists()
--- a/xpcom/ds/nsAtomTable.h
+++ b/xpcom/ds/nsAtomTable.h
@@ -6,11 +6,11 @@
 #ifndef nsAtomTable_h__
 #define nsAtomTable_h__
 
 #include <stdlib.h>
 #include "nscore.h"
 
 void NS_PurgeAtomTable();
 
-size_t NS_SizeOfAtomTableIncludingThis(nsMallocSizeOfFun aMallocSizeOf);
+size_t NS_SizeOfAtomTablesIncludingThis(nsMallocSizeOfFun aMallocSizeOf);
 
 #endif // nsAtomTable_h__
--- a/xpcom/glue/nsBaseHashtable.h
+++ b/xpcom/glue/nsBaseHashtable.h
@@ -239,16 +239,35 @@ public:
    */
   typedef size_t
     (* SizeOfEntryExcludingThisFun)(KeyType           aKey,
                                     const DataType    &aData,
                                     nsMallocSizeOfFun mallocSizeOf,
                                     void*             userArg);
 
   /**
+   * Measure the size of the table's entry storage and the table itself.
+   * If |sizeOfEntryExcludingThis| is non-nsnull, measure the size of things
+   * pointed to by entries.
+   *
+   * @param    sizeOfEntryExcludingThis
+   *           the <code>SizeOfEntryExcludingThisFun</code> function to call
+   * @param    mallocSizeOf the function used to meeasure heap-allocated blocks
+   * @param    userArg a point to pass to the
+   *           <code>SizeOfEntryExcludingThisFun</code> function
+   * @return   the summed size of the entries, the table, and the table's storage
+   */
+  size_t SizeOfIncludingThis(SizeOfEntryExcludingThisFun sizeOfEntryExcludingThis,
+                             nsMallocSizeOfFun mallocSizeOf, void *userArg = nsnull)
+  {
+    return mallocSizeOf(this) + this->SizeOfExcludingThis(sizeOfEntryExcludingThis,
+                                                          mallocSizeOf, userArg);
+  }
+
+  /**
    * Measure the size of the table's entry storage, and if
    * |sizeOfEntryExcludingThis| is non-nsnull, measure the size of things pointed
    * to by entries.
    * 
    * @param     sizeOfEntryExcludingThis the
    *            <code>SizeOfEntryExcludingThisFun</code> function to call
    * @param     mallocSizeOf the function used to measure heap-allocated blocks
    * @param     userArg a pointer to pass to the