Bug 831193 (part 2) - Don't use NS_MEMORY_REPORTER_IMPLEMENT for the effective-tld-service reporter. r=michal.novotny.
authorNicholas Nethercote <nnethercote@mozilla.com>
Tue, 15 Jan 2013 21:26:44 -0800
changeset 144665 9af570dfad86b8735f08456d4ce0dd047113082d
parent 144640 6afb1f4536886b1eeb3574e3f340c4ba3755bae0
child 144666 76345eaa94fcf61a5e8dfcba7462887e974dd22a
push id25171
push useremorley@mozilla.com
push dateWed, 28 Aug 2013 15:20:13 +0000
treeherdermozilla-central@f280351a238f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmichal.novotny
bugs831193
milestone26.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 831193 (part 2) - Don't use NS_MEMORY_REPORTER_IMPLEMENT for the effective-tld-service reporter. r=michal.novotny.
netwerk/dns/nsEffectiveTLDService.cpp
netwerk/dns/nsEffectiveTLDService.h
--- a/netwerk/dns/nsEffectiveTLDService.cpp
+++ b/netwerk/dns/nsEffectiveTLDService.cpp
@@ -1,9 +1,10 @@
-//* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 // This service reads a file of rules describing TLD-like domain names.  For a
 // complete description of the expected file format and parsing rules, see
 // http://wiki.mozilla.org/Gecko:Effective_TLD_Service
 
@@ -55,31 +56,31 @@ nsDomainEntry::FuncForStaticAsserts(void
 #undef ETLD_ENTRY_OFFSET
 #undef ETLD_STR_NUM
 #undef ETLD_STR_NUM1
 
 // ----------------------------------------------------------------------
 
 static nsEffectiveTLDService *gService = nullptr;
 
-NS_MEMORY_REPORTER_MALLOC_SIZEOF_FUN(EffectiveTLDServiceMallocSizeOf)
-
-static int64_t
-GetEffectiveTLDSize()
+class EffectiveTLDServiceReporter MOZ_FINAL : public MemoryReporterBase
 {
-  return gService->SizeOfIncludingThis(EffectiveTLDServiceMallocSizeOf);
-}
+public:
+  EffectiveTLDServiceReporter()
+    : MemoryReporterBase("explicit/xpcom/effective-TLD-service",
+                         KIND_HEAP, UNITS_BYTES,
+                         "Memory used by the effective TLD service.")
+  {}
 
-NS_MEMORY_REPORTER_IMPLEMENT(
-  EffectiveTLDService,
-  "explicit/xpcom/effective-TLD-service",
-  KIND_HEAP,
-  nsIMemoryReporter::UNITS_BYTES,
-  GetEffectiveTLDSize,
-  "Memory used by the effective TLD service.")
+private:
+  int64_t Amount() MOZ_OVERRIDE
+  {
+    return gService ? gService->SizeOfIncludingThis(MallocSizeOf) : 0;
+  }
+};
 
 nsresult
 nsEffectiveTLDService::Init()
 {
   const ETLDEntry *entries = nsDomainEntry::entries;
 
   // We'll probably have to rehash at least once, since nsTHashtable doesn't
   // use a perfect hash, but at least we'll save a few rehashes along the way.
@@ -103,26 +104,25 @@ nsEffectiveTLDService::Init()
 #endif
     nsDomainEntry *entry = mHash.PutEntry(domain);
     NS_ENSURE_TRUE(entry, NS_ERROR_OUT_OF_MEMORY);
     entry->SetData(&entries[i]);
   }
 
   MOZ_ASSERT(!gService);
   gService = this;
-  mReporter = new NS_MEMORY_REPORTER_NAME(EffectiveTLDService);
-  (void)::NS_RegisterMemoryReporter(mReporter);
+  mReporter = new EffectiveTLDServiceReporter();
+  NS_RegisterMemoryReporter(mReporter);
 
   return NS_OK;
 }
 
 nsEffectiveTLDService::~nsEffectiveTLDService()
 {
-  (void)::NS_UnregisterMemoryReporter(mReporter);
-  mReporter = nullptr;
+  NS_UnregisterMemoryReporter(mReporter);
   gService = nullptr;
 }
 
 size_t
 nsEffectiveTLDService::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf)
 {
   size_t n = aMallocSizeOf(this);
   n += mHash.SizeOfExcludingThis(nullptr, aMallocSizeOf);
--- a/netwerk/dns/nsEffectiveTLDService.h
+++ b/netwerk/dns/nsEffectiveTLDService.h
@@ -1,23 +1,23 @@
 //* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsIEffectiveTLDService.h"
 
+#include "nsIMemoryReporter.h"
 #include "nsTHashtable.h"
 #include "nsString.h"
 #include "nsCOMPtr.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/MemoryReporting.h"
 
 class nsIIDNService;
-class nsIMemoryReporter;
 
 #define ETLD_ENTRY_N_INDEX_BITS 30
 
 // struct for static data generated from effective_tld_names.dat
 struct ETLDEntry {
   uint32_t strtab_index : ETLD_ENTRY_N_INDEX_BITS;
   uint32_t exception : 1;
   uint32_t wild : 1;
@@ -113,12 +113,12 @@ public:
 
   size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf);
 
 private:
   nsresult GetBaseDomainInternal(nsCString &aHostname, int32_t aAdditionalParts, nsACString &aBaseDomain);
   nsresult NormalizeHostname(nsCString &aHostname);
   ~nsEffectiveTLDService();
 
-  nsIMemoryReporter*          mReporter;
+  nsCOMPtr<nsIMemoryReporter> mReporter;
   nsTHashtable<nsDomainEntry> mHash;
   nsCOMPtr<nsIIDNService>     mIDNService;
 };