Bug 802007 - Remove unneeded Mac-only memory reporters. r=jlebar.
authorNicholas Nethercote <nnethercote@mozilla.com>
Mon, 15 Oct 2012 21:45:54 -0700
changeset 110608 3dc836fcff4316cdb9bc697feb1a384c12e060f1
parent 110607 2dc84b223c276efec569468ac59e87fc20f9c109
child 110609 2604cbda92ac9f47b893439f32b20f612c3b8af3
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersjlebar
bugs802007
milestone19.0a1
Bug 802007 - Remove unneeded Mac-only memory reporters. r=jlebar.
xpcom/base/nsMemoryReporterManager.cpp
--- a/xpcom/base/nsMemoryReporterManager.cpp
+++ b/xpcom/base/nsMemoryReporterManager.cpp
@@ -414,18 +414,16 @@ NS_FALLIBLE_MEMORY_REPORTER_IMPLEMENT(Pa
 /**
  ** memory reporter implementation for jemalloc and OSX malloc,
  ** to obtain info on total memory in use (that we know about,
  ** at least -- on OSX, there are sometimes other zones in use).
  **/
 
 #if HAVE_JEMALLOC_STATS
 
-#define HAVE_HEAP_ALLOCATED_REPORTERS 1
-
 static int64_t GetHeapUnused()
 {
     jemalloc_stats_t stats;
     jemalloc_stats(&stats);
     return (int64_t) (stats.mapped - stats.allocated);
 }
 
 static int64_t GetHeapAllocated()
@@ -500,72 +498,16 @@ NS_MEMORY_REPORTER_IMPLEMENT(HeapDirty,
     KIND_OTHER,
     UNITS_BYTES,
     GetHeapDirty,
     "Memory which the allocator could return to the operating system, but "
     "hasn't.  The allocator keeps this memory around as an optimization, so it "
     "doesn't have to ask the OS the next time it needs to fulfill a request. "
     "This value is typically not larger than a few megabytes.")
 
-#elif defined(XP_MACOSX) && !defined(MOZ_MEMORY)
-#include <malloc/malloc.h>
-
-#define HAVE_HEAP_ALLOCATED_REPORTERS 1
-
-static int64_t GetHeapUnused()
-{
-    struct mstats stats = mstats();
-    return stats.bytes_total - stats.bytes_used;
-}
-
-static int64_t GetHeapAllocated()
-{
-    struct mstats stats = mstats();
-    return stats.bytes_used;
-}
-
-// malloc_zone_statistics() crashes when run under DMDV because Valgrind
-// doesn't intercept it.  This measurement isn't important for DMDV, so don't
-// even try to get it.
-#ifndef MOZ_DMDV
-#define HAVE_HEAP_ZONE0_REPORTERS 1
-static int64_t GetHeapZone0Committed()
-{
-    malloc_statistics_t stats;
-    malloc_zone_statistics(malloc_default_zone(), &stats);
-    return stats.size_in_use;
-}
-
-static int64_t GetHeapZone0Used()
-{
-    malloc_statistics_t stats;
-    malloc_zone_statistics(malloc_default_zone(), &stats);
-    return stats.size_allocated;
-}
-
-NS_MEMORY_REPORTER_IMPLEMENT(HeapZone0Committed,
-    "heap-zone0-committed",
-    KIND_OTHER,
-    UNITS_BYTES,
-    GetHeapZone0Committed,
-    "Memory mapped by the heap allocator that is committed in the default "
-    "zone.")
-
-NS_MEMORY_REPORTER_IMPLEMENT(HeapZone0Used,
-    "heap-zone0-used",
-    KIND_OTHER,
-    UNITS_BYTES,
-    GetHeapZone0Used,
-    "Memory mapped by the heap allocator in the default zone that is "
-    "allocated to the application.")
-#endif  // MOZ_DMDV
-
-#endif
-
-#ifdef HAVE_HEAP_ALLOCATED_REPORTERS
 NS_MEMORY_REPORTER_IMPLEMENT(HeapUnused,
     "heap-unused",
     KIND_OTHER,
     UNITS_BYTES,
     GetHeapUnused,
     "Memory mapped by the heap allocator that is not part of an active "
     "allocation. Much of this memory may be uncommitted -- that is, it does not "
     "take up space in physical memory or in the swap file.")
@@ -576,18 +518,17 @@ NS_MEMORY_REPORTER_IMPLEMENT(HeapAllocat
     UNITS_BYTES,
     GetHeapAllocated,
     "Memory mapped by the heap allocator that is currently allocated to the "
     "application.  This may exceed the amount of memory requested by the "
     "application because the allocator regularly rounds up request sizes. (The "
     "exact amount requested is not recorded.)")
 
 // The computation of "explicit" fails if "heap-allocated" isn't available,
-// which is why this is depends on HAVE_HEAP_ALLOCATED_AND_EXPLICIT_REPORTERS.
-#define HAVE_EXPLICIT_REPORTER 1
+// which is why this is depends on HAVE_JEMALLOC_STATS.
 static nsresult GetExplicit(int64_t *n)
 {
     nsCOMPtr<nsIMemoryReporterManager> mgr = do_GetService("@mozilla.org/memory-reporter-manager;1");
     if (mgr == nullptr)
         return NS_ERROR_FAILURE;
 
     return mgr->GetExplicit(n);
 }
@@ -595,17 +536,17 @@ static nsresult GetExplicit(int64_t *n)
 NS_FALLIBLE_MEMORY_REPORTER_IMPLEMENT(Explicit,
     "explicit",
     KIND_OTHER,
     UNITS_BYTES,
     GetExplicit,
     "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
+#endif  // HAVE_JEMALLOC_STATS
 
 NS_MEMORY_REPORTER_MALLOC_SIZEOF_FUN(AtomTableMallocSizeOf, "atom-table")
 
 static int64_t GetAtomTableSize() {
   return NS_SizeOfAtomTablesIncludingThis(AtomTableMallocSizeOf);
 }
 
 // Why is this here?  At first glance, you'd think it could be defined and
@@ -631,22 +572,23 @@ nsMemoryReporterManager::Init()
 {
 #if HAVE_JEMALLOC_STATS && defined(XP_LINUX)
     if (!jemalloc_stats)
         return NS_ERROR_FAILURE;
 #endif
 
 #define REGISTER(_x)  RegisterReporter(new NS_MEMORY_REPORTER_NAME(_x))
 
-#ifdef HAVE_HEAP_ALLOCATED_REPORTERS
+#ifdef HAVE_JEMALLOC_STATS
     REGISTER(HeapAllocated);
     REGISTER(HeapUnused);
-#endif
-
-#ifdef HAVE_EXPLICIT_REPORTER
+    REGISTER(HeapCommitted);
+    REGISTER(HeapCommittedUnused);
+    REGISTER(HeapCommittedUnusedRatio);
+    REGISTER(HeapDirty);
     REGISTER(Explicit);
 #endif
 
 #ifdef HAVE_VSIZE_AND_RESIDENT_REPORTERS
     REGISTER(Vsize);
     REGISTER(Resident);
 #endif
 
@@ -654,25 +596,16 @@ nsMemoryReporterManager::Init()
     REGISTER(PageFaultsSoft);
     REGISTER(PageFaultsHard);
 #endif
 
 #ifdef HAVE_PRIVATE_REPORTER
     REGISTER(Private);
 #endif
 
-#if defined(HAVE_JEMALLOC_STATS)
-    REGISTER(HeapCommitted);
-    REGISTER(HeapCommittedUnused);
-    REGISTER(HeapCommittedUnusedRatio);
-    REGISTER(HeapDirty);
-#elif defined(HAVE_HEAP_ZONE0_REPORTERS)
-    REGISTER(HeapZone0Committed);
-    REGISTER(HeapZone0Used);
-#endif
 
     REGISTER(AtomTable);
 
 #if defined(XP_LINUX)
     MemoryInfoDumper::Initialize();
 #endif
 
     return NS_OK;
@@ -815,17 +748,17 @@ NS_IMPL_ISUPPORTS1(
 )
 #endif
 
 NS_IMETHODIMP
 nsMemoryReporterManager::GetExplicit(int64_t *aExplicit)
 {
     NS_ENSURE_ARG_POINTER(aExplicit);
     *aExplicit = 0;
-#ifndef HAVE_EXPLICIT_REPORTER
+#ifndef HAVE_JEMALLOC_STATS
     return NS_ERROR_NOT_AVAILABLE;
 #else
     nsresult rv;
     bool more;
 
     // Get "heap-allocated" and all the KIND_NONHEAP measurements from normal
     // (i.e. non-multi) "explicit" reporters.
     int64_t heapAllocated = int64_t(-1);
@@ -908,17 +841,17 @@ nsMemoryReporterManager::GetExplicit(int
                                    "usage don't match (%lld vs %lld)",
                                    explicitNonHeapMultiSize,
                                    explicitNonHeapMultiSize2).get());
     }
 #endif  // DEBUG
 
     *aExplicit = heapAllocated + explicitNonHeapNormalSize + explicitNonHeapMultiSize;
     return NS_OK;
-#endif // HAVE_HEAP_ALLOCATED_AND_EXPLICIT_REPORTERS
+#endif // HAVE_JEMALLOC_STATS
 }
 
 NS_IMETHODIMP
 nsMemoryReporterManager::GetHasMozMallocUsableSize(bool *aHas)
 {
     void *p = malloc(16);
     if (!p) {
         return NS_ERROR_OUT_OF_MEMORY;