Bug 677466 - Add memory reporter for the atoms table. r=luke.
authorNicholas Nethercote <nnethercote@mozilla.com>
Tue, 09 Aug 2011 22:33:27 -0700
changeset 74164 b391327ee19af7438cc6b4d70f3ad1c9a9d8e634
parent 74163 6835028a54e874f815c1a14615a9c115c3064019
child 74165 89bbee4ec270fadde04578b2b8765a588535e0fc
push id20955
push usereakhgari@mozilla.com
push dateWed, 10 Aug 2011 14:22:13 +0000
treeherdermozilla-central@93328efd3d77 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke
bugs677466
milestone8.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 677466 - Add memory reporter for the atoms table. r=luke.
js/src/jshashtable.h
js/src/xpconnect/src/xpcjsruntime.cpp
js/src/xpconnect/src/xpcpublic.h
--- a/js/src/jshashtable.h
+++ b/js/src/jshashtable.h
@@ -623,24 +623,28 @@ class HashTable : private AllocPolicy
     Range all() const {
         return Range(table, table + tableCapacity);
     }
 
     bool empty() const {
         return !entryCount;
     }
 
-    uint32 count() const{
+    uint32 count() const {
         return entryCount;
     }
 
     uint32 generation() const {
         return gen;
     }
 
+    size_t tableSize() const {
+        return tableCapacity * sizeof(Entry);
+    }
+
     Ptr lookup(const Lookup &l) const {
         ReentrancyGuard g(*this);
         HashNumber keyHash = prepareHash(l);
         return Ptr(lookup(l, keyHash, 0));
     }
 
     AddPtr lookupForAdd(const Lookup &l) const {
         ReentrancyGuard g(*this);
@@ -1059,16 +1063,17 @@ class HashMap
      *   for (HM::Range r = h.all(); !r.empty(); r.popFront())
      *     char c = r.front().value;
      *
      * Also see the definition of Range in HashTable above (with T = Entry).
      */
     typedef typename Impl::Range Range;
     Range all() const                                 { return impl.all(); }
     size_t count() const                              { return impl.count(); }
+    size_t tableSize() const                          { return impl.tableSize(); }
 
     /*
      * Typedef for the enumeration class. An Enum may be used to examine and
      * remove table entries:
      *
      *   typedef HashMap<int,char> HM;
      *   HM s;
      *   for (HM::Enum e(s); !e.empty(); e.popFront())
@@ -1257,16 +1262,17 @@ class HashSet
      *   for (HS::Range r = h.all(); !r.empty(); r.popFront())
      *     int i = r.front();
      *
      * Also see the definition of Range in HashTable above.
      */
     typedef typename Impl::Range Range;
     Range all() const                                 { return impl.all(); }
     size_t count() const                              { return impl.count(); }
+    size_t tableSize() const                          { return impl.tableSize(); }
 
     /*
      * Typedef for the enumeration class. An Enum may be used to examine and
      * remove table entries:
      *
      *   typedef HashSet<int> HS;
      *   HS s;
      *   for (HS::Enum e(s); !e.empty(); e.popFront())
--- a/js/src/xpconnect/src/xpcjsruntime.cpp
+++ b/js/src/xpconnect/src/xpcjsruntime.cpp
@@ -1619,16 +1619,18 @@ CollectCompartmentStatsForRuntime(JSRunt
             PRInt64(JS_GetGCParameter(rt, JSGC_TOTAL_CHUNKS)) *
             js::GC_CHUNK_SIZE;
 
         js::IterateCompartmentsArenasCells(cx, data, CompartmentCallback,
                                            ArenaCallback, CellCallback);
 
         for(js::ThreadDataIter i(rt); !i.empty(); i.popFront())
             data->stackSize += i.threadData()->stackSpace.committedSize();
+
+        data->atomsTableSize += rt->atomState.atoms.tableSize();
     }
 
     JS_DestroyContextNoGC(cx);
 
     // This is initialized to all bytes stored in used chunks, and then we
     // subtract used space from it each time around the loop.
     data->gcHeapChunkDirtyUnused = data->gcHeapChunkTotal -
                                    data->gcHeapChunkCleanUnused;
@@ -1812,16 +1814,26 @@ ReportJSRuntimeStats(const IterateData &
     for(PRUint32 index = 0;
         index < data.compartmentStatsVector.Length();
         index++)
     {
         ReportCompartmentStats(data.compartmentStatsVector[index], pathPrefix,
                                callback, closure);
     }
 
+    ReportMemoryBytes(pathPrefix + NS_LITERAL_CSTRING("runtime/runtime-object"),
+                      nsIMemoryReporter::KIND_NONHEAP, sizeof(JSRuntime),
+    "Memory used by the JSRuntime object.",
+                      callback, closure);
+
+    ReportMemoryBytes(pathPrefix + NS_LITERAL_CSTRING("runtime/atoms-table"),
+                      nsIMemoryReporter::KIND_NONHEAP, data.atomsTableSize,
+    "Memory used by the atoms table.",
+                      callback, closure);
+
     ReportMemoryBytes(pathPrefix + NS_LITERAL_CSTRING("stack"),
                       nsIMemoryReporter::KIND_NONHEAP, data.stackSize,
     "Memory used for the JavaScript stack.  This is the committed portion "
     "of the stack; any uncommitted portion is not measured because it "
     "hardly costs anything.",
                       callback, closure);
 
     ReportMemoryBytes(pathPrefix +
--- a/js/src/xpconnect/src/xpcpublic.h
+++ b/js/src/xpconnect/src/xpcpublic.h
@@ -220,26 +220,28 @@ struct CompartmentStats
     PRInt64 tjitDataAllocatorsMain;
     PRInt64 tjitDataAllocatorsReserve;
 #endif
 };
 
 struct IterateData
 {
     IterateData()
-      : stackSize(0),
+      : atomsTableSize(0),
+        stackSize(0),
         gcHeapChunkTotal(0),
         gcHeapChunkCleanUnused(0),
         gcHeapChunkDirtyUnused(0),
         gcHeapArenaUnused(0),
         gcHeapChunkAdmin(0),
         gcHeapUnusedPercentage(0),
         compartmentStatsVector(),
         currCompartmentStats(NULL) { }
 
+    PRInt64 atomsTableSize;
     PRInt64 stackSize;
     PRInt64 gcHeapChunkTotal;
     PRInt64 gcHeapChunkCleanUnused;
     PRInt64 gcHeapChunkDirtyUnused;
     PRInt64 gcHeapArenaUnused;
     PRInt64 gcHeapChunkAdmin;
     PRInt64 gcHeapUnusedPercentage;