Bug 1573229 - part 2 - Make memory allocation functions in HyphenReporter infallible. r=njn
authorJonathan Kew <jkew@mozilla.com>
Wed, 14 Aug 2019 09:52:22 +0000
changeset 488206 f1d84baef0c346d83245fc92884d4132c921c99e
parent 488205 3fd3531df50ecc4d4e4a0d1603d40eb1d6031a3e
child 488207 ad04c84153da637000c7a472ccbc248116b5c330
push id36437
push userncsoregi@mozilla.com
push dateThu, 15 Aug 2019 19:33:18 +0000
treeherdermozilla-central@44aac6fc3352 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnjn
bugs1573229
milestone70.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 1573229 - part 2 - Make memory allocation functions in HyphenReporter infallible. r=njn Differential Revision: https://phabricator.services.mozilla.com/D41614
intl/hyphenation/glue/nsHyphenationManager.cpp
--- a/intl/hyphenation/glue/nsHyphenationManager.cpp
+++ b/intl/hyphenation/glue/nsHyphenationManager.cpp
@@ -32,24 +32,16 @@ static const char kMemoryPressureNotific
 class HyphenReporter final : public nsIMemoryReporter,
                              public CountingAllocatorBase<HyphenReporter> {
  private:
   ~HyphenReporter() = default;
 
  public:
   NS_DECL_ISUPPORTS
 
-  static void* Malloc(long aSize) { return CountingMalloc(aSize); }
-
-  static void Free(void* aPtr) { return CountingFree(aPtr); }
-
-  static void* Realloc(void* aPtr, long aNewSize) {
-    return CountingRealloc(aPtr, aNewSize);
-  }
-
   NS_IMETHOD CollectReports(nsIHandleReportCallback* aHandleReport,
                             nsISupports* aData, bool aAnonymize) override {
     size_t total = MemoryAllocated();
     if (nsHyphenationManager::Instance()) {
       total += nsHyphenationManager::Instance()->SizeOfIncludingThis(
           moz_malloc_size_of);
     }
     MOZ_COLLECT_REPORT("explicit/hyphenation", KIND_HEAP, UNITS_BYTES, total,
@@ -61,30 +53,33 @@ class HyphenReporter final : public nsIM
 NS_IMPL_ISUPPORTS(HyphenReporter, nsIMemoryReporter)
 
 template <>
 CountingAllocatorBase<HyphenReporter>::AmountType
     CountingAllocatorBase<HyphenReporter>::sAmount(0);
 
 /**
  * Allocation wrappers to track the amount of memory allocated by libhyphen.
+ * Note that libhyphen assumes its malloc/realloc functions are infallible!
  */
 extern "C" {
 void* hnj_malloc(size_t aSize);
 void* hnj_realloc(void* aPtr, size_t aSize);
 void hnj_free(void* aPtr);
 };
 
-void* hnj_malloc(size_t aSize) { return HyphenReporter::Malloc(aSize); }
+void* hnj_malloc(size_t aSize) {
+  return HyphenReporter::InfallibleCountingMalloc(aSize);
+}
 
 void* hnj_realloc(void* aPtr, size_t aSize) {
-  return HyphenReporter::Realloc(aPtr, aSize);
+  return HyphenReporter::InfallibleCountingRealloc(aPtr, aSize);
 }
 
-void hnj_free(void* aPtr) { HyphenReporter::Free(aPtr); }
+void hnj_free(void* aPtr) { HyphenReporter::CountingFree(aPtr); }
 
 nsHyphenationManager* nsHyphenationManager::sInstance = nullptr;
 
 NS_IMPL_ISUPPORTS(nsHyphenationManager::MemoryPressureObserver, nsIObserver)
 
 NS_IMETHODIMP
 nsHyphenationManager::MemoryPressureObserver::Observe(nsISupports* aSubject,
                                                       const char* aTopic,