Bug 1415454 - Inline MallocBinEasy and MallocBinHard. r=njn
authorMike Hommey <mh+mozilla@glandium.org>
Fri, 03 Nov 2017 15:48:40 +0900
changeset 390907 f64defe0d11edb2a76bb6cca295a7fd864542501
parent 390906 78acf48d63c3dacd8885ba93cdf5f1b2efccafe5
child 390908 b8acdda178182e9dec084f84af572294d6d58ac6
push id32851
push userdluca@mozilla.com
push dateThu, 09 Nov 2017 13:54:04 +0000
treeherdermozilla-central@05ae89bebb64 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnjn
bugs1415454
milestone58.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 1415454 - Inline MallocBinEasy and MallocBinHard. r=njn They are both only used once, are trivial wrappers, and even repeat the same assertions.
memory/build/mozjemalloc.cpp
--- a/memory/build/mozjemalloc.cpp
+++ b/memory/build/mozjemalloc.cpp
@@ -1019,20 +1019,16 @@ private:
                    size_t aNewSize);
 
   void TrimRunTail(arena_chunk_t* aChunk,
                    arena_run_t* aRun,
                    size_t aOldSize,
                    size_t aNewSize,
                    bool dirty);
 
-  inline void* MallocBinEasy(arena_bin_t* aBin, arena_run_t* aRun);
-
-  void* MallocBinHard(arena_bin_t* aBin);
-
   arena_run_t* GetNonFullBinRun(arena_bin_t* aBin);
 
   inline void* MallocSmall(size_t aSize, bool aZero);
 
   void* MallocLarge(size_t aSize, bool aZero);
 
 public:
   inline void* Malloc(size_t aSize, bool aZero);
@@ -2931,46 +2927,16 @@ arena_t::GetNonFullBinRun(arena_bin_t* a
 #if defined(MOZ_DIAGNOSTIC_ASSERT_ENABLED)
   run->mMagic = ARENA_RUN_MAGIC;
 #endif
 
   aBin->mNumRuns++;
   return run;
 }
 
-// bin->mCurrentRun must have space available before this function is called.
-void*
-arena_t::MallocBinEasy(arena_bin_t* aBin, arena_run_t* aRun)
-{
-  void* ret;
-
-  MOZ_DIAGNOSTIC_ASSERT(aRun->mMagic == ARENA_RUN_MAGIC);
-  MOZ_DIAGNOSTIC_ASSERT(aRun->mNumFree > 0);
-
-  ret = arena_run_reg_alloc(aRun, aBin);
-  MOZ_DIAGNOSTIC_ASSERT(ret);
-  aRun->mNumFree--;
-
-  return ret;
-}
-
-// Re-fill aBin->mCurrentRun, then call arena_t::MallocBinEasy().
-void*
-arena_t::MallocBinHard(arena_bin_t* aBin)
-{
-  aBin->mCurrentRun = GetNonFullBinRun(aBin);
-  if (!aBin->mCurrentRun) {
-    return nullptr;
-  }
-  MOZ_DIAGNOSTIC_ASSERT(aBin->mCurrentRun->mMagic == ARENA_RUN_MAGIC);
-  MOZ_DIAGNOSTIC_ASSERT(aBin->mCurrentRun->mNumFree > 0);
-
-  return MallocBinEasy(aBin, aBin->mCurrentRun);
-}
-
 void
 arena_bin_t::Init(SizeClass aSizeClass)
 {
   size_t try_run_size;
   unsigned try_nregs, try_mask_nelms, try_reg0_offset;
   // Size of the run header, excluding mRegionsMask.
   static const size_t kFixedHeaderSize = offsetof(arena_run_t, mRegionsMask);
 
@@ -3069,22 +3035,28 @@ arena_t::MallocSmall(size_t aSize, bool 
       break;
     default:
       MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE("Unexpected size class type");
   }
   MOZ_DIAGNOSTIC_ASSERT(aSize == bin->mSizeClass);
 
   {
     MutexAutoLock lock(mLock);
-    if ((run = bin->mCurrentRun) && run->mNumFree > 0) {
-      ret = MallocBinEasy(bin, run);
-    } else {
-      ret = MallocBinHard(bin);
+    run = bin->mCurrentRun;
+    if (MOZ_UNLIKELY(!run || run->mNumFree == 0)) {
+      run = bin->mCurrentRun = GetNonFullBinRun(bin);
     }
-
+    if (MOZ_UNLIKELY(!run)) {
+      return nullptr;
+    }
+    MOZ_DIAGNOSTIC_ASSERT(run->mMagic == ARENA_RUN_MAGIC);
+    MOZ_DIAGNOSTIC_ASSERT(run->mNumFree > 0);
+    ret = arena_run_reg_alloc(run, bin);
+    MOZ_DIAGNOSTIC_ASSERT(ret);
+    run->mNumFree--;
     if (!ret) {
       return nullptr;
     }
 
     mStats.allocated_small += aSize;
   }
 
   if (aZero == false) {