Bug 1594598 - Tweak the control flow in MaybePageAlloc()'s loop. r=glandium
authorNicholas Nethercote <nnethercote@mozilla.com>
Wed, 06 Nov 2019 23:52:31 +0000
changeset 501022 f17d8e2af670fb037e668575e1813702c3e25eee
parent 501021 99e7c9afdf92bda5f2f1f519a828b39c7c3007ee
child 501023 ba5dde550477b6902efd0185b33bf9dd22bba06d
push id99937
push usernnethercote@mozilla.com
push dateThu, 07 Nov 2019 00:37:00 +0000
treeherderautoland@ec3308aa7246 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglandium
bugs1594598
milestone72.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 1594598 - Tweak the control flow in MaybePageAlloc()'s loop. r=glandium This reduces the indentation level by one for most of the loop body. Differential Revision: https://phabricator.services.mozilla.com/D43837
memory/replace/phc/PHC.cpp
--- a/memory/replace/phc/PHC.cpp
+++ b/memory/replace/phc/PHC.cpp
@@ -865,40 +865,42 @@ static void* MaybePageAlloc(const Maybe<
   Time now = GAtomic::Now();
   Delay newAllocDelay = Rnd64ToDelay<kAvgAllocDelay>(gMut->Random64(lock));
 
   // We start at a random page alloc and wrap around, to ensure pages get even
   // amounts of use.
   void* ptr = nullptr;
   for (uintptr_t n = 0, i = size_t(gMut->Random64(lock)) % kMaxPageAllocs;
        n < kMaxPageAllocs; n++, i = (i + 1) % kMaxPageAllocs) {
-    if (gMut->IsPageAllocatable(lock, i, now)) {
-      void* pagePtr = gConst->PagePtr(i);
-      bool ok =
+    if (!gMut->IsPageAllocatable(lock, i, now)) {
+      continue;
+    }
+
+    void* pagePtr = gConst->PagePtr(i);
+    bool ok =
 #ifdef XP_WIN
-          !!VirtualAlloc(pagePtr, kPageSize, MEM_COMMIT, PAGE_READWRITE);
+        !!VirtualAlloc(pagePtr, kPageSize, MEM_COMMIT, PAGE_READWRITE);
 #else
-          mprotect(pagePtr, kPageSize, PROT_READ | PROT_WRITE) == 0;
+        mprotect(pagePtr, kPageSize, PROT_READ | PROT_WRITE) == 0;
 #endif
-      size_t usableSize = sMallocTable.malloc_good_size(aReqSize);
-      if (ok) {
-        gMut->SetPageInUse(lock, i, aArenaId, usableSize, allocStack);
-        ptr = pagePtr;
-        if (aZero) {
-          memset(ptr, 0, usableSize);
-        } else {
+    size_t usableSize = sMallocTable.malloc_good_size(aReqSize);
+    if (ok) {
+      gMut->SetPageInUse(lock, i, aArenaId, usableSize, allocStack);
+      ptr = pagePtr;
+      if (aZero) {
+        memset(ptr, 0, usableSize);
+      } else {
 #ifdef DEBUG
-          memset(ptr, kAllocJunk, usableSize);
+        memset(ptr, kAllocJunk, usableSize);
 #endif
-        }
       }
-      LOG("PageAlloc(%zu) -> %p[%zu] (%zu) (z%zu), sAllocDelay <- %zu\n",
-          aReqSize, ptr, i, usableSize, size_t(aZero), size_t(newAllocDelay));
-      break;
     }
+    LOG("PageAlloc(%zu) -> %p[%zu] (%zu) (z%zu), sAllocDelay <- %zu\n",
+        aReqSize, ptr, i, usableSize, size_t(aZero), size_t(newAllocDelay));
+    break;
   }
 
   if (!ptr) {
     // No pages are available, or VirtualAlloc/mprotect failed.
     LOG("No PageAlloc(%zu), sAllocDelay <- %zu\n", aReqSize,
         size_t(newAllocDelay));
   }