<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[198702] trunk/Source/bmalloc</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/198702">198702</a></dd>
<dt>Author</dt> <dd>ggaren@apple.com</dd>
<dt>Date</dt> <dd>2016-03-25 16:46:01 -0700 (Fri, 25 Mar 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>bmalloc: support physical page sizes that don't match the virtual page size
https://bugs.webkit.org/show_bug.cgi?id=155898

Reviewed by Gavin Barraclough.

This is a memory savings on iOS devices where the virtual page size
is 16kB but the physical page size is 4kB.

* bmalloc/Chunk.h:
(bmalloc::Chunk::Chunk): smallPageSize is now unrelated to the OS's
page size -- it just reflects the optimal unit of memory to recycle
between small objects.

We only need to round up to largeAlignment because small objects allocate
as subsets of large objects now.

(bmalloc::Chunk::page):
(bmalloc::Object::pageBegin):
(bmalloc::Object::line): Adopt smallPageSize.

* bmalloc/Heap.cpp:
(bmalloc::Heap::initializeLineMetadata):
(bmalloc::Heap::allocateSmallPage):
(bmalloc::Heap::allocateLarge): Adopt smallPageSize.

(bmalloc::Heap::splitAndAllocate):
(bmalloc::Heap::tryAllocateXLarge):
(bmalloc::Heap::shrinkXLarge): Adopt vmPageSizePhysical(). We want the
physical page size because that's the unit at which the hardware MMU
will recycle memory.

* bmalloc/Sizes.h: Adopt smallPageSize.

* bmalloc/VMAllocate.h:
(bmalloc::vmPageSizePhysical):
(bmalloc::vmPageSize): Distinguish between page size, which is the virtual
memory page size advertised by the OS, and physical page size, which the
true hardware page size.

(bmalloc::vmSize):
(bmalloc::vmValidate):
(bmalloc::vmValidatePhysical):
(bmalloc::tryVMAllocate):
(bmalloc::vmDeallocatePhysicalPages):
(bmalloc::vmAllocatePhysicalPages):
(bmalloc::vmDeallocatePhysicalPagesSloppy):
(bmalloc::vmAllocatePhysicalPagesSloppy): Adopt vmPageSize() and
vmPageSizePhyiscal().

* bmalloc/Vector.h:
(bmalloc::Vector::initialCapacity):
(bmalloc::Vector&lt;T&gt;::shrink):
(bmalloc::Vector&lt;T&gt;::shrinkCapacity):
(bmalloc::Vector&lt;T&gt;::growCapacity): Adopt vmPageSize(). We'd prefer to
use vmPageSizePhysical() but mmap() doesn't support it.

* bmalloc/XLargeMap.cpp: #include.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourcebmallocChangeLog">trunk/Source/bmalloc/ChangeLog</a></li>
<li><a href="#trunkSourcebmallocbmallocChunkh">trunk/Source/bmalloc/bmalloc/Chunk.h</a></li>
<li><a href="#trunkSourcebmallocbmallocHeapcpp">trunk/Source/bmalloc/bmalloc/Heap.cpp</a></li>
<li><a href="#trunkSourcebmallocbmallocSizesh">trunk/Source/bmalloc/bmalloc/Sizes.h</a></li>
<li><a href="#trunkSourcebmallocbmallocVMAllocateh">trunk/Source/bmalloc/bmalloc/VMAllocate.h</a></li>
<li><a href="#trunkSourcebmallocbmallocVectorh">trunk/Source/bmalloc/bmalloc/Vector.h</a></li>
<li><a href="#trunkSourcebmallocbmallocXLargeMapcpp">trunk/Source/bmalloc/bmalloc/XLargeMap.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourcebmallocChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/bmalloc/ChangeLog (198701 => 198702)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/bmalloc/ChangeLog        2016-03-25 23:45:13 UTC (rev 198701)
+++ trunk/Source/bmalloc/ChangeLog        2016-03-25 23:46:01 UTC (rev 198702)
</span><span class="lines">@@ -1,5 +1,65 @@
</span><span class="cx"> 2016-03-25  Geoffrey Garen  &lt;ggaren@apple.com&gt;
</span><span class="cx"> 
</span><ins>+        bmalloc: support physical page sizes that don't match the virtual page size
+        https://bugs.webkit.org/show_bug.cgi?id=155898
+
+        Reviewed by Gavin Barraclough.
+
+        This is a memory savings on iOS devices where the virtual page size
+        is 16kB but the physical page size is 4kB.
+
+        * bmalloc/Chunk.h:
+        (bmalloc::Chunk::Chunk): smallPageSize is now unrelated to the OS's
+        page size -- it just reflects the optimal unit of memory to recycle
+        between small objects.
+
+        We only need to round up to largeAlignment because small objects allocate
+        as subsets of large objects now.
+
+        (bmalloc::Chunk::page):
+        (bmalloc::Object::pageBegin):
+        (bmalloc::Object::line): Adopt smallPageSize.
+
+        * bmalloc/Heap.cpp:
+        (bmalloc::Heap::initializeLineMetadata):
+        (bmalloc::Heap::allocateSmallPage):
+        (bmalloc::Heap::allocateLarge): Adopt smallPageSize.
+
+        (bmalloc::Heap::splitAndAllocate):
+        (bmalloc::Heap::tryAllocateXLarge):
+        (bmalloc::Heap::shrinkXLarge): Adopt vmPageSizePhysical(). We want the
+        physical page size because that's the unit at which the hardware MMU
+        will recycle memory.
+
+        * bmalloc/Sizes.h: Adopt smallPageSize.
+
+        * bmalloc/VMAllocate.h:
+        (bmalloc::vmPageSizePhysical):
+        (bmalloc::vmPageSize): Distinguish between page size, which is the virtual
+        memory page size advertised by the OS, and physical page size, which the
+        true hardware page size.
+
+        (bmalloc::vmSize):
+        (bmalloc::vmValidate):
+        (bmalloc::vmValidatePhysical):
+        (bmalloc::tryVMAllocate):
+        (bmalloc::vmDeallocatePhysicalPages):
+        (bmalloc::vmAllocatePhysicalPages):
+        (bmalloc::vmDeallocatePhysicalPagesSloppy):
+        (bmalloc::vmAllocatePhysicalPagesSloppy): Adopt vmPageSize() and
+        vmPageSizePhyiscal().
+
+        * bmalloc/Vector.h:
+        (bmalloc::Vector::initialCapacity):
+        (bmalloc::Vector&lt;T&gt;::shrink):
+        (bmalloc::Vector&lt;T&gt;::shrinkCapacity):
+        (bmalloc::Vector&lt;T&gt;::growCapacity): Adopt vmPageSize(). We'd prefer to
+        use vmPageSizePhysical() but mmap() doesn't support it.
+
+        * bmalloc/XLargeMap.cpp: #include.
+
+2016-03-25  Geoffrey Garen  &lt;ggaren@apple.com&gt;
+
</ins><span class="cx">         Unreviewed, rolling in r198679.
</span><span class="cx"> 
</span><span class="cx">         r198679 was just a rename. The regression was caused by r198675 and then
</span></span></pre></div>
<a id="trunkSourcebmallocbmallocChunkh"></a>
<div class="modfile"><h4>Modified: trunk/Source/bmalloc/bmalloc/Chunk.h (198701 => 198702)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/bmalloc/bmalloc/Chunk.h        2016-03-25 23:45:13 UTC (rev 198701)
+++ trunk/Source/bmalloc/bmalloc/Chunk.h        2016-03-25 23:46:01 UTC (rev 198702)
</span><span class="lines">@@ -81,14 +81,14 @@
</span><span class="cx">     // We use the X's for boundary tags and the O's for edge sentinels.
</span><span class="cx"> 
</span><span class="cx">     std::array&lt;SmallLine, chunkSize / smallLineSize&gt; m_lines;
</span><del>-    std::array&lt;SmallPage, chunkSize / vmPageSize&gt; m_pages;
</del><ins>+    std::array&lt;SmallPage, chunkSize / smallPageSize&gt; m_pages;
</ins><span class="cx">     std::array&lt;BoundaryTag, boundaryTagCount&gt; m_boundaryTags;
</span><del>-    char m_memory[] __attribute__((aligned(2 * smallMax + 0)));
</del><ins>+    char m_memory[] __attribute__((aligned(largeAlignment + 0)));
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> static_assert(sizeof(Chunk) + largeMax &lt;= chunkSize, &quot;largeMax is too big&quot;);
</span><span class="cx"> static_assert(
</span><del>-    sizeof(Chunk) % vmPageSize + 2 * smallMax &lt;= vmPageSize,
</del><ins>+    sizeof(Chunk) % smallPageSize + 2 * smallMax &lt;= smallPageSize,
</ins><span class="cx">     &quot;the first page of object memory in a small chunk must be able to allocate smallMax&quot;);
</span><span class="cx"> 
</span><span class="cx"> inline Chunk::Chunk(std::lock_guard&lt;StaticMutex&gt;&amp; lock)
</span><span class="lines">@@ -165,7 +165,7 @@
</span><span class="cx"> 
</span><span class="cx"> inline SmallPage* Chunk::page(size_t offset)
</span><span class="cx"> {
</span><del>-    size_t pageNumber = offset / vmPageSize;
</del><ins>+    size_t pageNumber = offset / smallPageSize;
</ins><span class="cx">     return &amp;m_pages[pageNumber];
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -221,7 +221,7 @@
</span><span class="cx"> 
</span><span class="cx"> inline void* Object::pageBegin()
</span><span class="cx"> {
</span><del>-    return m_chunk-&gt;object(roundDownToMultipleOf(vmPageSize, m_offset));
</del><ins>+    return m_chunk-&gt;object(roundDownToMultipleOf(smallPageSize, m_offset));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> inline SmallLine* Object::line()
</span></span></pre></div>
<a id="trunkSourcebmallocbmallocHeapcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/bmalloc/bmalloc/Heap.cpp (198701 => 198702)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/bmalloc/bmalloc/Heap.cpp        2016-03-25 23:45:13 UTC (rev 198701)
+++ trunk/Source/bmalloc/bmalloc/Heap.cpp        2016-03-25 23:46:01 UTC (rev 198702)
</span><span class="lines">@@ -52,7 +52,7 @@
</span><span class="cx"> 
</span><span class="cx">         size_t object = 0;
</span><span class="cx">         size_t line = 0;
</span><del>-        while (object &lt; vmPageSize) {
</del><ins>+        while (object &lt; smallPageSize) {
</ins><span class="cx">             line = object / smallLineSize;
</span><span class="cx">             size_t leftover = object % smallLineSize;
</span><span class="cx"> 
</span><span class="lines">@@ -66,7 +66,7 @@
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         // Don't allow the last object in a page to escape the page.
</span><del>-        if (object &gt; vmPageSize) {
</del><ins>+        if (object &gt; smallPageSize) {
</ins><span class="cx">             BASSERT(metadata[line].objectCount);
</span><span class="cx">             --metadata[line].objectCount;
</span><span class="cx">         }
</span><span class="lines">@@ -200,8 +200,8 @@
</span><span class="cx">         return page;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    size_t unalignedSize = largeMin + vmPageSize - largeAlignment + vmPageSize;
-    LargeObject largeObject = allocateLarge(lock, vmPageSize, vmPageSize, unalignedSize);
</del><ins>+    size_t unalignedSize = largeMin + smallPageSize - largeAlignment + smallPageSize;
+    LargeObject largeObject = allocateLarge(lock, smallPageSize, smallPageSize, unalignedSize);
</ins><span class="cx"> 
</span><span class="cx">     // Transform our large object into a small object page. We deref here
</span><span class="cx">     // because our small objects will keep their own refcounts on the line.
</span><span class="lines">@@ -307,7 +307,7 @@
</span><span class="cx">     BASSERT(size &gt;= largeMin);
</span><span class="cx">     BASSERT(size == roundUpToMultipleOf&lt;largeAlignment&gt;(size));
</span><span class="cx">     
</span><del>-    if (size &lt;= vmPageSize)
</del><ins>+    if (size &lt;= smallPageSize)
</ins><span class="cx">         scavengeSmallPages(lock);
</span><span class="cx"> 
</span><span class="cx">     LargeObject largeObject = m_largeObjects.take(size);
</span><span class="lines">@@ -338,7 +338,7 @@
</span><span class="cx">     BASSERT(alignment &gt;= largeAlignment);
</span><span class="cx">     BASSERT(isPowerOfTwo(alignment));
</span><span class="cx"> 
</span><del>-    if (size &lt;= vmPageSize)
</del><ins>+    if (size &lt;= smallPageSize)
</ins><span class="cx">         scavengeSmallPages(lock);
</span><span class="cx"> 
</span><span class="cx">     LargeObject largeObject = m_largeObjects.take(alignment, size, unalignedSize);
</span><span class="lines">@@ -412,7 +412,7 @@
</span><span class="cx">     // in the allocated list. This is an important optimization because it
</span><span class="cx">     // keeps the free list short, speeding up allocation and merging.
</span><span class="cx"> 
</span><del>-    std::pair&lt;XLargeRange, XLargeRange&gt; allocated = range.split(roundUpToMultipleOf&lt;vmPageSize&gt;(size));
</del><ins>+    std::pair&lt;XLargeRange, XLargeRange&gt; allocated = range.split(roundUpToMultipleOf(vmPageSizePhysical(), size));
</ins><span class="cx">     if (allocated.first.vmState().hasVirtual()) {
</span><span class="cx">         vmAllocatePhysicalPagesSloppy(allocated.first.begin(), allocated.first.size());
</span><span class="cx">         allocated.first.setVMState(VMState::Physical);
</span><span class="lines">@@ -429,7 +429,7 @@
</span><span class="cx"> 
</span><span class="cx">     m_isAllocatingPages = true;
</span><span class="cx"> 
</span><del>-    size = std::max(vmPageSize, size);
</del><ins>+    size = std::max(vmPageSizePhysical(), size);
</ins><span class="cx">     alignment = roundUpToMultipleOf&lt;xLargeAlignment&gt;(alignment);
</span><span class="cx"> 
</span><span class="cx">     XLargeRange range = m_xLargeMap.takeFree(alignment, size);
</span><span class="lines">@@ -456,7 +456,7 @@
</span><span class="cx"> {
</span><span class="cx">     BASSERT(object.size() &gt; newSize);
</span><span class="cx"> 
</span><del>-    if (object.size() - newSize &lt; vmPageSize)
</del><ins>+    if (object.size() - newSize &lt; vmPageSizePhysical())
</ins><span class="cx">         return;
</span><span class="cx">     
</span><span class="cx">     XLargeRange range = m_xLargeMap.takeAllocated(object.begin());
</span></span></pre></div>
<a id="trunkSourcebmallocbmallocSizesh"></a>
<div class="modfile"><h4>Modified: trunk/Source/bmalloc/bmalloc/Sizes.h (198701 => 198702)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/bmalloc/bmalloc/Sizes.h        2016-03-25 23:45:13 UTC (rev 198701)
+++ trunk/Source/bmalloc/bmalloc/Sizes.h        2016-03-25 23:46:01 UTC (rev 198702)
</span><span class="lines">@@ -46,14 +46,10 @@
</span><span class="cx">     static const size_t alignment = 8;
</span><span class="cx">     static const size_t alignmentMask = alignment - 1ul;
</span><span class="cx"> 
</span><del>-#if BPLATFORM(IOS)
-    static const size_t vmPageSize = 16 * kB;
-#else
-    static const size_t vmPageSize = 4 * kB;
-#endif
-    
</del><ins>+    static const size_t smallPageSize = 4 * kB;
+
</ins><span class="cx">     static const size_t smallLineSize = 256;
</span><del>-    static const size_t smallLineCount = vmPageSize / smallLineSize;
</del><ins>+    static const size_t smallLineCount = smallPageSize / smallLineSize;
</ins><span class="cx"> 
</span><span class="cx">     static const size_t smallMax = 1 * kB;
</span><span class="cx">     static const size_t maskSizeClassMax = 512;
</span></span></pre></div>
<a id="trunkSourcebmallocbmallocVMAllocateh"></a>
<div class="modfile"><h4>Modified: trunk/Source/bmalloc/bmalloc/VMAllocate.h (198701 => 198702)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/bmalloc/bmalloc/VMAllocate.h        2016-03-25 23:45:13 UTC (rev 198701)
+++ trunk/Source/bmalloc/bmalloc/VMAllocate.h        2016-03-25 23:46:01 UTC (rev 198702)
</span><span class="lines">@@ -26,15 +26,16 @@
</span><span class="cx"> #ifndef VMAllocate_h
</span><span class="cx"> #define VMAllocate_h
</span><span class="cx"> 
</span><ins>+#include &quot;Algorithm.h&quot;
</ins><span class="cx"> #include &quot;BAssert.h&quot;
</span><span class="cx"> #include &quot;Range.h&quot;
</span><del>-#include &quot;Sizes.h&quot;
</del><span class="cx"> #include &quot;Syscall.h&quot;
</span><span class="cx"> #include &lt;algorithm&gt;
</span><span class="cx"> #include &lt;sys/mman.h&gt;
</span><span class="cx"> #include &lt;unistd.h&gt;
</span><span class="cx"> 
</span><span class="cx"> #if BOS(DARWIN)
</span><ins>+#include &lt;mach/vm_page_size.h&gt;
</ins><span class="cx"> #include &lt;mach/vm_statistics.h&gt;
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="lines">@@ -46,31 +47,59 @@
</span><span class="cx"> #define BMALLOC_VM_TAG -1
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+inline size_t vmPageSizePhysical()
+{
+#if BPLATFORM(DARWIN)
+    return vm_kernel_page_size;
+#else
+    return sysconf(_SC_PAGESIZE);
+#endif
+}
+
+inline size_t vmPageSize()
+{
+#if BPLATFORM(DARWIN)
+    return vm_page_size;
+#else
+    return sysconf(_SC_PAGESIZE);
+#endif
+}
+
</ins><span class="cx"> inline size_t vmSize(size_t size)
</span><span class="cx"> {
</span><del>-    return roundUpToMultipleOf&lt;vmPageSize&gt;(size);
</del><ins>+    return roundUpToMultipleOf(vmPageSize(), size);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> inline void vmValidate(size_t vmSize)
</span><span class="cx"> {
</span><del>-    // We use getpagesize() here instead of vmPageSize because vmPageSize is
-    // allowed to be larger than the OS's true page size.
-
</del><span class="cx">     UNUSED(vmSize);
</span><span class="cx">     BASSERT(vmSize);
</span><del>-    BASSERT(vmSize == roundUpToMultipleOf(static_cast&lt;size_t&gt;(getpagesize()), vmSize));
</del><ins>+    BASSERT(vmSize == roundUpToMultipleOf(vmPageSize(), vmSize));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> inline void vmValidate(void* p, size_t vmSize)
</span><span class="cx"> {
</span><del>-    // We use getpagesize() here instead of vmPageSize because vmPageSize is
-    // allowed to be larger than the OS's true page size.
</del><ins>+    vmValidate(vmSize);
+    
+    UNUSED(p);
+    BASSERT(p);
+    BASSERT(p == mask(p, ~(vmPageSize() - 1)));
+}
</ins><span class="cx"> 
</span><ins>+inline void vmValidatePhysical(size_t vmSize)
+{
+    UNUSED(vmSize);
+    BASSERT(vmSize);
+    BASSERT(vmSize == roundUpToMultipleOf(vmPageSizePhysical(), vmSize));
+}
+
+inline void vmValidatePhysical(void* p, size_t vmSize)
+{
</ins><span class="cx">     vmValidate(vmSize);
</span><span class="cx">     
</span><span class="cx">     UNUSED(p);
</span><span class="cx">     BASSERT(p);
</span><del>-    BASSERT(p == mask(p, ~(getpagesize() - 1)));
</del><ins>+    BASSERT(p == mask(p, ~(vmPageSizePhysical() - 1)));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> inline void* tryVMAllocate(size_t vmSize)
</span><span class="lines">@@ -135,7 +164,7 @@
</span><span class="cx"> 
</span><span class="cx"> inline void vmDeallocatePhysicalPages(void* p, size_t vmSize)
</span><span class="cx"> {
</span><del>-    vmValidate(p, vmSize);
</del><ins>+    vmValidatePhysical(p, vmSize);
</ins><span class="cx"> #if BOS(DARWIN)
</span><span class="cx">     SYSCALL(madvise(p, vmSize, MADV_FREE_REUSABLE));
</span><span class="cx"> #else
</span><span class="lines">@@ -145,7 +174,7 @@
</span><span class="cx"> 
</span><span class="cx"> inline void vmAllocatePhysicalPages(void* p, size_t vmSize)
</span><span class="cx"> {
</span><del>-    vmValidate(p, vmSize);
</del><ins>+    vmValidatePhysical(p, vmSize);
</ins><span class="cx"> #if BOS(DARWIN)
</span><span class="cx">     SYSCALL(madvise(p, vmSize, MADV_FREE_REUSE));
</span><span class="cx"> #else
</span><span class="lines">@@ -156,8 +185,8 @@
</span><span class="cx"> // Trims requests that are un-page-aligned.
</span><span class="cx"> inline void vmDeallocatePhysicalPagesSloppy(void* p, size_t size)
</span><span class="cx"> {
</span><del>-    char* begin = roundUpToMultipleOf&lt;vmPageSize&gt;(static_cast&lt;char*&gt;(p));
-    char* end = roundDownToMultipleOf&lt;vmPageSize&gt;(static_cast&lt;char*&gt;(p) + size);
</del><ins>+    char* begin = roundUpToMultipleOf(vmPageSizePhysical(), static_cast&lt;char*&gt;(p));
+    char* end = roundDownToMultipleOf(vmPageSizePhysical(), static_cast&lt;char*&gt;(p) + size);
</ins><span class="cx"> 
</span><span class="cx">     if (begin &gt;= end)
</span><span class="cx">         return;
</span><span class="lines">@@ -168,8 +197,8 @@
</span><span class="cx"> // Expands requests that are un-page-aligned.
</span><span class="cx"> inline void vmAllocatePhysicalPagesSloppy(void* p, size_t size)
</span><span class="cx"> {
</span><del>-    char* begin = roundDownToMultipleOf&lt;vmPageSize&gt;(static_cast&lt;char*&gt;(p));
-    char* end = roundUpToMultipleOf&lt;vmPageSize&gt;(static_cast&lt;char*&gt;(p) + size);
</del><ins>+    char* begin = roundDownToMultipleOf(vmPageSizePhysical(), static_cast&lt;char*&gt;(p));
+    char* end = roundUpToMultipleOf(vmPageSizePhysical(), static_cast&lt;char*&gt;(p) + size);
</ins><span class="cx"> 
</span><span class="cx">     if (begin &gt;= end)
</span><span class="cx">         return;
</span></span></pre></div>
<a id="trunkSourcebmallocbmallocVectorh"></a>
<div class="modfile"><h4>Modified: trunk/Source/bmalloc/bmalloc/Vector.h (198701 => 198702)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/bmalloc/bmalloc/Vector.h        2016-03-25 23:45:13 UTC (rev 198701)
+++ trunk/Source/bmalloc/bmalloc/Vector.h        2016-03-25 23:46:01 UTC (rev 198702)
</span><span class="lines">@@ -73,7 +73,7 @@
</span><span class="cx"> private:
</span><span class="cx">     static const size_t growFactor = 2;
</span><span class="cx">     static const size_t shrinkFactor = 4;
</span><del>-    static const size_t initialCapacity = vmPageSize / sizeof(T);
</del><ins>+    static size_t initialCapacity() { return vmPageSize() / sizeof(T); }
</ins><span class="cx"> 
</span><span class="cx">     void growCapacity();
</span><span class="cx">     void shrinkCapacity();
</span><span class="lines">@@ -150,7 +150,7 @@
</span><span class="cx"> {
</span><span class="cx">     BASSERT(size &lt;= m_size);
</span><span class="cx">     m_size = size;
</span><del>-    if (m_capacity &gt; initialCapacity &amp;&amp; m_size &lt; m_capacity / shrinkFactor)
</del><ins>+    if (m_size &lt; m_capacity / shrinkFactor &amp;&amp; m_capacity &gt; initialCapacity())
</ins><span class="cx">         shrinkCapacity();
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -171,14 +171,14 @@
</span><span class="cx"> template&lt;typename T&gt;
</span><span class="cx"> NO_INLINE void Vector&lt;T&gt;::shrinkCapacity()
</span><span class="cx"> {
</span><del>-    size_t newCapacity = max(initialCapacity, m_capacity / shrinkFactor);
</del><ins>+    size_t newCapacity = max(initialCapacity(), m_capacity / shrinkFactor);
</ins><span class="cx">     reallocateBuffer(newCapacity);
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> template&lt;typename T&gt;
</span><span class="cx"> NO_INLINE void Vector&lt;T&gt;::growCapacity()
</span><span class="cx"> {
</span><del>-    size_t newCapacity = max(initialCapacity, m_size * growFactor);
</del><ins>+    size_t newCapacity = max(initialCapacity(), m_size * growFactor);
</ins><span class="cx">     reallocateBuffer(newCapacity);
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourcebmallocbmallocXLargeMapcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/bmalloc/bmalloc/XLargeMap.cpp (198701 => 198702)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/bmalloc/bmalloc/XLargeMap.cpp        2016-03-25 23:45:13 UTC (rev 198701)
+++ trunk/Source/bmalloc/bmalloc/XLargeMap.cpp        2016-03-25 23:46:01 UTC (rev 198702)
</span><span class="lines">@@ -24,6 +24,7 @@
</span><span class="cx">  */
</span><span class="cx"> 
</span><span class="cx"> #include &quot;XLargeMap.h&quot;
</span><ins>+#include &quot;Sizes.h&quot;
</ins><span class="cx"> 
</span><span class="cx"> namespace bmalloc {
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>