Bug 1301449 - Fix assertions in MapAlignedPages to make it more intuitive. r=terrence CLOSED TREE
authorEmanuel Hoogeveen <emanuel.hoogeveen@gmail.com>
Thu, 08 Sep 2016 15:46:54 -0700
changeset 354644 cfa4bfef55aa1f78bd6c51faa46cbc23d6643715
parent 354643 93cf1a5af6a0384c4dc08869af8c5e14312aed7a
child 354645 15ff27b2a1453e7445f19204f8c18d36e278425d
push id6570
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:26:13 +0000
treeherdermozilla-beta@f455459b2ae5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersterrence
bugs1301449
milestone51.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 1301449 - Fix assertions in MapAlignedPages to make it more intuitive. r=terrence CLOSED TREE
js/src/gc/Memory.cpp
--- a/js/src/gc/Memory.cpp
+++ b/js/src/gc/Memory.cpp
@@ -116,19 +116,21 @@ MapMemory(size_t length, int flags, int 
 {
     return VirtualAlloc(nullptr, length, flags, prot);
 }
 
 void*
 MapAlignedPages(size_t size, size_t alignment)
 {
     MOZ_ASSERT(size >= alignment);
+    MOZ_ASSERT(size >= allocGranularity);
     MOZ_ASSERT(size % alignment == 0);
     MOZ_ASSERT(size % pageSize == 0);
-    MOZ_ASSERT(alignment % allocGranularity == 0);
+    MOZ_ASSERT_IF(alignment < allocGranularity, allocGranularity % alignment == 0);
+    MOZ_ASSERT_IF(alignment > allocGranularity, alignment % allocGranularity == 0);
 
     void* p = MapMemory(size, MEM_COMMIT | MEM_RESERVE);
 
     /* Special case: If we want allocation alignment, no further work is needed. */
     if (alignment == allocGranularity)
         return p;
 
     if (OffsetFromAligned(p, alignment) == 0)
@@ -282,16 +284,17 @@ GetPageFaultCount()
 
 void*
 AllocateMappedContent(int fd, size_t offset, size_t length, size_t alignment)
 {
     MOZ_ASSERT(length && alignment);
 
     // The allocation granularity and the requested offset
     // must both be divisible by the requested alignment.
+    // Alignments larger than the allocation granularity are not supported.
     if (allocGranularity % alignment != 0 || offset % alignment != 0)
         return nullptr;
 
     HANDLE hFile = reinterpret_cast<HANDLE>(intptr_t(fd));
 
     // This call will fail if the file does not exist, which is what we want.
     HANDLE hMap = CreateFileMapping(hFile, nullptr, PAGE_READONLY, 0, 0, nullptr);
     if (!hMap)
@@ -340,19 +343,21 @@ DeallocateMappedContent(void* p, size_t 
 }
 
 #  else // Various APIs are unavailable.
 
 void*
 MapAlignedPages(size_t size, size_t alignment)
 {
     MOZ_ASSERT(size >= alignment);
+    MOZ_ASSERT(size >= allocGranularity);
     MOZ_ASSERT(size % alignment == 0);
     MOZ_ASSERT(size % pageSize == 0);
-    MOZ_ASSERT(alignment % allocGranularity == 0);
+    MOZ_ASSERT_IF(alignment < allocGranularity, allocGranularity % alignment == 0);
+    MOZ_ASSERT_IF(alignment > allocGranularity, alignment % allocGranularity == 0);
 
     void* p = _aligned_malloc(size, alignment);
 
     MOZ_ASSERT(OffsetFromAligned(p, alignment) == 0);
     return p;
 }
 
 static void*
@@ -415,19 +420,21 @@ InitMemorySubsystem()
     if (pageSize == 0)
         pageSize = allocGranularity = size_t(sysconf(_SC_PAGESIZE));
 }
 
 void*
 MapAlignedPages(size_t size, size_t alignment)
 {
     MOZ_ASSERT(size >= alignment);
+    MOZ_ASSERT(size >= allocGranularity);
     MOZ_ASSERT(size % alignment == 0);
     MOZ_ASSERT(size % pageSize == 0);
-    MOZ_ASSERT(alignment % allocGranularity == 0);
+    MOZ_ASSERT_IF(alignment < allocGranularity, allocGranularity % alignment == 0);
+    MOZ_ASSERT_IF(alignment > allocGranularity, alignment % allocGranularity == 0);
 
     int prot = PROT_READ | PROT_WRITE;
     int flags = MAP_PRIVATE | MAP_ANON | MAP_ALIGN | MAP_NOSYNC;
 
     void* p = mmap((caddr_t)alignment, size, prot, flags, -1, 0);
     if (p == MAP_FAILED)
         return nullptr;
     return p;
@@ -586,19 +593,21 @@ MapMemory(size_t length, int prot = PROT
     return region;
 #endif
 }
 
 void*
 MapAlignedPages(size_t size, size_t alignment)
 {
     MOZ_ASSERT(size >= alignment);
+    MOZ_ASSERT(size >= allocGranularity);
     MOZ_ASSERT(size % alignment == 0);
     MOZ_ASSERT(size % pageSize == 0);
-    MOZ_ASSERT(alignment % allocGranularity == 0);
+    MOZ_ASSERT_IF(alignment < allocGranularity, allocGranularity % alignment == 0);
+    MOZ_ASSERT_IF(alignment > allocGranularity, alignment % allocGranularity == 0);
 
     void* p = MapMemory(size);
 
     /* Special case: If we want page alignment, no further work is needed. */
     if (alignment == allocGranularity)
         return p;
 
     if (OffsetFromAligned(p, alignment) == 0)
@@ -779,16 +788,17 @@ GetPageFaultCount()
 
 void*
 AllocateMappedContent(int fd, size_t offset, size_t length, size_t alignment)
 {
     MOZ_ASSERT(length && alignment);
 
     // The allocation granularity and the requested offset
     // must both be divisible by the requested alignment.
+    // Alignments larger than the allocation granularity are not supported.
     if (allocGranularity % alignment != 0 || offset % alignment != 0)
         return nullptr;
 
     // Sanity check the offset and size, as mmap does not do this for us.
     struct stat st;
     if (fstat(fd, &st) || offset >= uint64_t(st.st_size) || length > uint64_t(st.st_size) - offset)
         return nullptr;