Backed out changeset 1c79adcd8483 (bug 1546498) for build bustage. CLOSED TREE
authorDorel Luca <dluca@mozilla.com>
Tue, 30 Apr 2019 22:59:23 +0300
changeset 530828 eb170900104e63918906d2275959ffdd6f7775b3
parent 530827 8cd6ecc6fc399dd83234f45dab2e9c9159a693c0
child 530829 bd1d3ebde97bf8e180f25adf954907708830955a
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1546498
milestone68.0a1
backs out1c79adcd8483d038b94b6690c65a6f868132733d
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
Backed out changeset 1c79adcd8483 (bug 1546498) for build bustage. CLOSED TREE
modules/libjar/nsZipArchive.cpp
xpcom/glue/FileUtils.cpp
xpcom/glue/MemUtils.cpp
xpcom/glue/MemUtils.h
--- a/modules/libjar/nsZipArchive.cpp
+++ b/modules/libjar/nsZipArchive.cpp
@@ -646,17 +646,18 @@ nsresult nsZipArchive::BuildFileList(PRF
   // Only perform readahead in the parent process. Children processes
   // don't need readahead when the file has already been readahead by
   // the parent process, and readahead only really happens for omni.ja,
   // which is used in the parent process.
   if (XRE_IsParentProcess() && mFd->mLen > ZIPCENTRAL_SIZE &&
       xtolong(startp + centralOffset) == CENTRALSIG) {
     // Success means optimized jar layout from bug 559961 is in effect
     uint32_t readaheadLength = xtolong(startp);
-    mozilla::PrefetchMemory(const_cast<uint8_t *>(startp), readaheadLength);
+    mozilla::MaybePrefetchMemory(const_cast<uint8_t *>(startp),
+                                 readaheadLength);
   } else {
     for (buf = endp - ZIPEND_SIZE; buf > startp; buf--) {
       if (xtolong(buf) == ENDSIG) {
         centralOffset = xtolong(((ZipEnd *)buf)->offset_central_dir);
         break;
       }
     }
   }
--- a/xpcom/glue/FileUtils.cpp
+++ b/xpcom/glue/FileUtils.cpp
@@ -353,20 +353,16 @@ void mozilla::ReadAhead(mozilla::filedes
 #endif
 }
 
 void mozilla::ReadAheadLib(mozilla::pathstr_t aFilePath) {
   if (!aFilePath) {
     return;
   }
 #if defined(XP_WIN)
-  if (!CanPrefetchMemory()) {
-    ReadAheadFile(aFilePath);
-    return;
-  }
   nsAutoHandle fd(CreateFileW(aFilePath, GENERIC_READ, FILE_SHARE_READ, nullptr,
                               OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN,
                               nullptr));
   if (!fd) {
     return;
   }
   LARGE_INTEGER fileSize = {};
   BOOL success = GetFileSizeEx(fd, &fileSize);
@@ -381,18 +377,21 @@ void mozilla::ReadAheadLib(mozilla::path
   if (!mapping) {
     return;
   }
 
   PVOID data =
       MapViewOfFile(mapping, FILE_MAP_READ, 0, 0, (size_t)fileSize.QuadPart);
   auto guard = MakeScopeExit([=]() { UnmapViewOfFile(data); });
 
-  if (data) {
-    PrefetchMemory((uint8_t*)data, (size_t)fileSize.QuadPart);
+  if (data && !MaybePrefetchMemory((uint8_t*)data, (size_t)fileSize.QuadPart)) {
+    volatile uint8_t read = 0;
+    for (size_t i = 0; i < (size_t)fileSize.QuadPart; i += 4096) {
+      read += ((uint8_t*)data)[i];
+    }
   }
 
 #elif defined(LINUX) && !defined(ANDROID)
   int fd = open(aFilePath, O_RDONLY);
   if (fd < 0) {
     return;
   }
 
--- a/xpcom/glue/MemUtils.cpp
+++ b/xpcom/glue/MemUtils.cpp
@@ -3,65 +3,48 @@
 /* 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 "mozilla/MemUtils.h"
 
 #if defined(XP_WIN)
 #  include <windows.h>
-#  include "mozilla/Maybe.h"
 #else
 #  include <sys/mman.h>
 #endif
 
-#if defined(XP_WIN)
-typedef BOOL (*PrefetchVirtualMemoryFn)(HANDLE, ULONG_PTR, PVOID, ULONG);
-
-mozilla::Maybe<PrefetchVirtualMemoryFn> sPrefetchVirtualMemory;
-
-void MaybeInitPrefetchVirtualMemory() {
-  if (sPrefetchVirtualMemory.isNothing()) {
-    sPrefetchVirtualMemory.emplace(
-        reinterpret_cast<PrefetchVirtualMemoryFn>(GetProcAddress(
-            GetModuleHandleW(L"kernel32.dll"), "PrefetchVirtualMemory")));
-  }
-}
-#endif
-
-bool mozilla::CanPrefetchMemory() {
-#if defined(XP_SOLARIS) || defined(XP_UNIX)
-  return true;
-#elif defined(XP_WIN)
-  MaybeInitPrefetchVirtualMemory();
-  return *sPrefetchVirtualMemory;
-#else
-  return false;
-#endif
-}
-
-void mozilla::PrefetchMemory(uint8_t* aStart, size_t aNumBytes) {
+bool mozilla::MaybePrefetchMemory(uint8_t* aStart, size_t aNumBytes) {
   if (aNumBytes == 0) {
-    return;
+    return true;
   }
 
 #if defined(XP_SOLARIS)
   posix_madvise(aStart, aNumBytes, POSIX_MADV_WILLNEED);
+  return true;
 #elif defined(XP_UNIX)
   madvise(aStart, aNumBytes, MADV_WILLNEED);
+  return true;
 #elif defined(XP_WIN)
-  MaybeInitPrefetchVirtualMemory();
-  if (*sPrefetchVirtualMemory) {
+  static auto prefetchVirtualMemory =
+      reinterpret_cast<BOOL(WINAPI*)(HANDLE, ULONG_PTR, PVOID, ULONG)>(
+          GetProcAddress(GetModuleHandleW(L"kernel32.dll"),
+                         "PrefetchVirtualMemory"));
+
+  if (prefetchVirtualMemory) {
     // Normally, we'd use WIN32_MEMORY_RANGE_ENTRY, but that requires
     // a different _WIN32_WINNT value before including windows.h, but
     // that causes complications with unified sources. It's a simple
     // enough struct anyways.
     struct {
       PVOID VirtualAddress;
       SIZE_T NumberOfBytes;
     } entry;
     entry.VirtualAddress = aStart;
     entry.NumberOfBytes = aNumBytes;
-    (*sPrefetchVirtualMemory)(GetCurrentProcess(), 1, &entry, 0);
-    return;
+    prefetchVirtualMemory(GetCurrentProcess(), 1, &entry, 0);
+    return true;
   }
+  return false;
+#else
+  return false;
 #endif
 }
--- a/xpcom/glue/MemUtils.h
+++ b/xpcom/glue/MemUtils.h
@@ -7,14 +7,13 @@
 #ifndef mozilla_MemUtils_h
 #define mozilla_MemUtils_h
 
 #include <stddef.h>
 #include <stdint.h>
 
 namespace mozilla {
 
-bool CanPrefetchMemory();
-void PrefetchMemory(uint8_t* aStart, size_t aNumBytes);
+bool MaybePrefetchMemory(uint8_t* aStart, size_t aNumBytes);
 
 }  // namespace mozilla
 
 #endif