Bug 1521713 - Relax overzealous assertions on memory alignment in commit and decommit functions. r=sfink a=lizzard
authorEmanuel Hoogeveen <emanuel.hoogeveen@protonmail.com>
Fri, 01 Feb 2019 00:00:18 +0200
changeset 515699 b2a7987967e45c1ee946ee1c7605e8e8020691a6
parent 515698 f53c459f828ac3254e948afa32b6b2bd58605f1c
child 515700 1cbb34b8d9121febe694732fec7b62ac10840b2f
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssfink, lizzard
bugs1521713
milestone66.0
Bug 1521713 - Relax overzealous assertions on memory alignment in commit and decommit functions. r=sfink a=lizzard
js/src/gc/Memory.cpp
--- a/js/src/gc/Memory.cpp
+++ b/js/src/gc/Memory.cpp
@@ -721,40 +721,62 @@ void UnmapPages(void* region, size_t len
 
   // ASan does not automatically unpoison memory, so we have to do this here.
   MOZ_MAKE_MEM_UNDEFINED(region, length);
 
   UnmapInternal(region, length);
 }
 
 bool MarkPagesUnused(void* region, size_t length) {
-  MOZ_RELEASE_ASSERT(region && OffsetFromAligned(region, pageSize) == 0);
-  MOZ_RELEASE_ASSERT(length > 0 && length % pageSize == 0);
+  MOZ_RELEASE_ASSERT(region);
+  MOZ_RELEASE_ASSERT(length > 0);
+
+  // pageSize == ArenaSize doesn't necessarily hold, but this function is
+  // used by the GC to decommit unused Arenas, so we don't want to assert
+  // if pageSize > ArenaSize.
+  MOZ_ASSERT(OffsetFromAligned(region, ArenaSize) == 0);
+  MOZ_ASSERT(length % ArenaSize == 0);
 
   MOZ_MAKE_MEM_NOACCESS(region, length);
 
   if (!DecommitEnabled()) {
     return true;
   }
+  // We can't decommit part of a page.
+  MOZ_RELEASE_ASSERT(OffsetFromAligned(region, pageSize) == 0);
+  MOZ_RELEASE_ASSERT(length % pageSize == 0);
 
 #if defined(XP_WIN)
   return VirtualAlloc(region, length, MEM_RESET,
                       DWORD(PageAccess::ReadWrite)) == region;
 #elif defined(XP_DARWIN)
   return madvise(region, length, MADV_FREE) == 0;
 #else
   return madvise(region, length, MADV_DONTNEED) == 0;
 #endif
 }
 
 void MarkPagesInUse(void* region, size_t length) {
-  MOZ_RELEASE_ASSERT(region && OffsetFromAligned(region, pageSize) == 0);
-  MOZ_RELEASE_ASSERT(length > 0 && length % pageSize == 0);
+  MOZ_RELEASE_ASSERT(region);
+  MOZ_RELEASE_ASSERT(length > 0);
+
+  // pageSize == ArenaSize doesn't necessarily hold, but this function is
+  // used by the GC to recommit Arenas that were previously decommitted,
+  // so we don't want to assert if pageSize > ArenaSize.
+  MOZ_ASSERT(OffsetFromAligned(region, ArenaSize) == 0);
+  MOZ_ASSERT(length % ArenaSize == 0);
 
   MOZ_MAKE_MEM_UNDEFINED(region, length);
+
+  if (!DecommitEnabled()) {
+    return;
+  }
+  // We can't commit part of a page.
+  MOZ_RELEASE_ASSERT(OffsetFromAligned(region, pageSize) == 0);
+  MOZ_RELEASE_ASSERT(length % pageSize == 0);
 }
 
 size_t GetPageFaultCount() {
   if (mozilla::recordreplay::IsRecordingOrReplaying()) {
     return 0;
   }
 #ifdef XP_WIN
   PROCESS_MEMORY_COUNTERS pmc;