<!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>[199435] releases/WebKitGTK/webkit-2.12/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/199435">199435</a></dd>
<dt>Author</dt> <dd>carlosgc@webkit.org</dd>
<dt>Date</dt> <dd>2016-04-13 01:54:22 -0700 (Wed, 13 Apr 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>Merge <a href="http://trac.webkit.org/projects/webkit/changeset/198571">r198571</a> - bmalloc: use a log scale for large-ish size classes
https://bugs.webkit.org/show_bug.cgi?id=155770

Reviewed by Michael Saboff.

At larger sizes, precise allocation sizes don't save much memory -- and
they can cost memory when objects of distinct size classes can't
allocate together.

This is a small savings up to our current allocation limits, and it may
enable changing those limits in the long term.

* bmalloc/Algorithm.h:
(bmalloc::log2): We use this to compute large-ish size classes.

* bmalloc/Allocator.cpp:
(bmalloc::Allocator::Allocator): Iterate by size class instead of by
object size so we can change object size limits without breaking stuff.

(bmalloc::Allocator::scavenge): Ditto.

(bmalloc::Allocator::allocateLogSizeClass): New helper function for
allocating based on log size classes.

(bmalloc::Allocator::allocateSlowCase): Account for extra size class
possibilities.

* bmalloc/Allocator.h:
(bmalloc::Allocator::allocateFastCase): We only handle up to 512b on
the fastest fast path now.

* bmalloc/BumpAllocator.h:
(bmalloc::BumpAllocator::validate): Deleted. I noticed that this function
had been refactored not to do anything anymore.

* bmalloc/Heap.cpp:
(bmalloc::Heap::initializeLineMetadata): Iterate by size class. (See
Allocator::Allocator.)

* bmalloc/Heap.h: Use the sizeClassCount constant instead of hard coding
things.

* bmalloc/Sizes.h:
(bmalloc::Sizes::maskSizeClass):
(bmalloc::Sizes::maskObjectSize):
(bmalloc::Sizes::logSizeClass):
(bmalloc::Sizes::logObjectSize):
(bmalloc::Sizes::sizeClass):
(bmalloc::Sizes::objectSize): Separate size class calculation between
simple size classes that can be computed with a mask and are 8-byte-precise
and complex size classes that require more math and are less precise.

* bmalloc/SmallLine.h:
(bmalloc::SmallLine::ref):
* bmalloc/SmallPage.h:
(bmalloc::SmallPage::SmallPage):
(bmalloc::SmallPage::ref):
(bmalloc::SmallPage::deref): Cleaned up some ASSERTs that triggered
while working on this patch.

* bmalloc/Zone.cpp:
(bmalloc::statistics):
(bmalloc::zoneSize):
(bmalloc::Zone::Zone):
(bmalloc::size): Deleted. Renamed these symbols to work around an lldb
bug that makes it impossible to print out variables named 'size' -- which
can be a problem when working on malloc.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#releasesWebKitGTKwebkit212SourcebmallocChangeLog">releases/WebKitGTK/webkit-2.12/Source/bmalloc/ChangeLog</a></li>
<li><a href="#releasesWebKitGTKwebkit212SourcebmallocbmallocAlgorithmh">releases/WebKitGTK/webkit-2.12/Source/bmalloc/bmalloc/Algorithm.h</a></li>
<li><a href="#releasesWebKitGTKwebkit212SourcebmallocbmallocAllocatorcpp">releases/WebKitGTK/webkit-2.12/Source/bmalloc/bmalloc/Allocator.cpp</a></li>
<li><a href="#releasesWebKitGTKwebkit212SourcebmallocbmallocAllocatorh">releases/WebKitGTK/webkit-2.12/Source/bmalloc/bmalloc/Allocator.h</a></li>
<li><a href="#releasesWebKitGTKwebkit212SourcebmallocbmallocBumpAllocatorh">releases/WebKitGTK/webkit-2.12/Source/bmalloc/bmalloc/BumpAllocator.h</a></li>
<li><a href="#releasesWebKitGTKwebkit212SourcebmallocbmallocHeapcpp">releases/WebKitGTK/webkit-2.12/Source/bmalloc/bmalloc/Heap.cpp</a></li>
<li><a href="#releasesWebKitGTKwebkit212SourcebmallocbmallocHeaph">releases/WebKitGTK/webkit-2.12/Source/bmalloc/bmalloc/Heap.h</a></li>
<li><a href="#releasesWebKitGTKwebkit212SourcebmallocbmallocSizesh">releases/WebKitGTK/webkit-2.12/Source/bmalloc/bmalloc/Sizes.h</a></li>
<li><a href="#releasesWebKitGTKwebkit212SourcebmallocbmallocSmallLineh">releases/WebKitGTK/webkit-2.12/Source/bmalloc/bmalloc/SmallLine.h</a></li>
<li><a href="#releasesWebKitGTKwebkit212SourcebmallocbmallocSmallPageh">releases/WebKitGTK/webkit-2.12/Source/bmalloc/bmalloc/SmallPage.h</a></li>
<li><a href="#releasesWebKitGTKwebkit212SourcebmallocbmallocZonecpp">releases/WebKitGTK/webkit-2.12/Source/bmalloc/bmalloc/Zone.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="releasesWebKitGTKwebkit212SourcebmallocChangeLog"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.12/Source/bmalloc/ChangeLog (199434 => 199435)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.12/Source/bmalloc/ChangeLog        2016-04-13 08:52:20 UTC (rev 199434)
+++ releases/WebKitGTK/webkit-2.12/Source/bmalloc/ChangeLog        2016-04-13 08:54:22 UTC (rev 199435)
</span><span class="lines">@@ -1,5 +1,75 @@
</span><span class="cx"> 2016-03-22  Geoffrey Garen  &lt;ggaren@apple.com&gt;
</span><span class="cx"> 
</span><ins>+        bmalloc: use a log scale for large-ish size classes
+        https://bugs.webkit.org/show_bug.cgi?id=155770
+
+        Reviewed by Michael Saboff.
+
+        At larger sizes, precise allocation sizes don't save much memory -- and
+        they can cost memory when objects of distinct size classes can't
+        allocate together.
+
+        This is a small savings up to our current allocation limits, and it may
+        enable changing those limits in the long term.
+
+        * bmalloc/Algorithm.h:
+        (bmalloc::log2): We use this to compute large-ish size classes.
+
+        * bmalloc/Allocator.cpp:
+        (bmalloc::Allocator::Allocator): Iterate by size class instead of by
+        object size so we can change object size limits without breaking stuff.
+
+        (bmalloc::Allocator::scavenge): Ditto.
+
+        (bmalloc::Allocator::allocateLogSizeClass): New helper function for
+        allocating based on log size classes.
+
+        (bmalloc::Allocator::allocateSlowCase): Account for extra size class
+        possibilities.
+
+        * bmalloc/Allocator.h:
+        (bmalloc::Allocator::allocateFastCase): We only handle up to 512b on
+        the fastest fast path now.
+
+        * bmalloc/BumpAllocator.h:
+        (bmalloc::BumpAllocator::validate): Deleted. I noticed that this function
+        had been refactored not to do anything anymore.
+
+        * bmalloc/Heap.cpp:
+        (bmalloc::Heap::initializeLineMetadata): Iterate by size class. (See
+        Allocator::Allocator.)
+
+        * bmalloc/Heap.h: Use the sizeClassCount constant instead of hard coding
+        things.
+
+        * bmalloc/Sizes.h:
+        (bmalloc::Sizes::maskSizeClass):
+        (bmalloc::Sizes::maskObjectSize):
+        (bmalloc::Sizes::logSizeClass):
+        (bmalloc::Sizes::logObjectSize):
+        (bmalloc::Sizes::sizeClass):
+        (bmalloc::Sizes::objectSize): Separate size class calculation between
+        simple size classes that can be computed with a mask and are 8-byte-precise
+        and complex size classes that require more math and are less precise.
+
+        * bmalloc/SmallLine.h:
+        (bmalloc::SmallLine::ref):
+        * bmalloc/SmallPage.h:
+        (bmalloc::SmallPage::SmallPage):
+        (bmalloc::SmallPage::ref):
+        (bmalloc::SmallPage::deref): Cleaned up some ASSERTs that triggered
+        while working on this patch.
+
+        * bmalloc/Zone.cpp:
+        (bmalloc::statistics):
+        (bmalloc::zoneSize):
+        (bmalloc::Zone::Zone):
+        (bmalloc::size): Deleted. Renamed these symbols to work around an lldb
+        bug that makes it impossible to print out variables named 'size' -- which
+        can be a problem when working on malloc.
+
+2016-03-22  Geoffrey Garen  &lt;ggaren@apple.com&gt;
+
</ins><span class="cx">         bmalloc: shrink largeMax
</span><span class="cx">         https://bugs.webkit.org/show_bug.cgi?id=155759
</span><span class="cx"> 
</span></span></pre></div>
<a id="releasesWebKitGTKwebkit212SourcebmallocbmallocAlgorithmh"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.12/Source/bmalloc/bmalloc/Algorithm.h (199434 => 199435)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.12/Source/bmalloc/bmalloc/Algorithm.h        2016-04-13 08:52:20 UTC (rev 199434)
+++ releases/WebKitGTK/webkit-2.12/Source/bmalloc/bmalloc/Algorithm.h        2016-04-13 08:54:22 UTC (rev 199435)
</span><span class="lines">@@ -108,6 +108,11 @@
</span><span class="cx">     return sizeof(T) * 8;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+inline constexpr unsigned long log2(unsigned long value)
+{
+    return bitCount&lt;unsigned long&gt;() - 1 - __builtin_clzl(value);
+}
+
</ins><span class="cx"> } // namespace bmalloc
</span><span class="cx"> 
</span><span class="cx"> #endif // Algorithm_h
</span></span></pre></div>
<a id="releasesWebKitGTKwebkit212SourcebmallocbmallocAllocatorcpp"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.12/Source/bmalloc/bmalloc/Allocator.cpp (199434 => 199435)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.12/Source/bmalloc/bmalloc/Allocator.cpp        2016-04-13 08:52:20 UTC (rev 199434)
+++ releases/WebKitGTK/webkit-2.12/Source/bmalloc/bmalloc/Allocator.cpp        2016-04-13 08:54:22 UTC (rev 199435)
</span><span class="lines">@@ -42,8 +42,8 @@
</span><span class="cx">     : m_isBmallocEnabled(heap-&gt;environment().isBmallocEnabled())
</span><span class="cx">     , m_deallocator(deallocator)
</span><span class="cx"> {
</span><del>-    for (unsigned short size = alignment; size &lt;= smallMax; size += alignment)
-        m_bumpAllocators[sizeClass(size)].init(size);
</del><ins>+    for (size_t sizeClass = 0; sizeClass &lt; sizeClassCount; ++sizeClass)
+        m_bumpAllocators[sizeClass].init(objectSize(sizeClass));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> Allocator::~Allocator()
</span><span class="lines">@@ -164,9 +164,9 @@
</span><span class="cx"> 
</span><span class="cx"> void Allocator::scavenge()
</span><span class="cx"> {
</span><del>-    for (unsigned short i = alignment; i &lt;= smallMax; i += alignment) {
-        BumpAllocator&amp; allocator = m_bumpAllocators[sizeClass(i)];
-        BumpRangeCache&amp; bumpRangeCache = m_bumpRangeCaches[sizeClass(i)];
</del><ins>+    for (size_t sizeClass = 0; sizeClass &lt; sizeClassCount; ++sizeClass) {
+        BumpAllocator&amp; allocator = m_bumpAllocators[sizeClass];
+        BumpRangeCache&amp; bumpRangeCache = m_bumpRangeCaches[sizeClass];
</ins><span class="cx"> 
</span><span class="cx">         while (allocator.canAllocate())
</span><span class="cx">             m_deallocator.deallocate(allocator.allocate());
</span><span class="lines">@@ -210,18 +210,30 @@
</span><span class="cx">     return PerProcess&lt;Heap&gt;::getFastCase()-&gt;allocateXLarge(lock, size);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+NO_INLINE void* Allocator::allocateLogSizeClass(size_t size)
+{
+    size_t sizeClass = bmalloc::sizeClass(size);
+    BumpAllocator&amp; allocator = m_bumpAllocators[sizeClass];
+    if (!allocator.canAllocate())
+        refillAllocator(allocator, sizeClass);
+    return allocator.allocate();
+}
+
</ins><span class="cx"> void* Allocator::allocateSlowCase(size_t size)
</span><span class="cx"> {
</span><span class="cx">     if (!m_isBmallocEnabled)
</span><span class="cx">         return malloc(size);
</span><span class="cx"> 
</span><del>-    if (size &lt;= smallMax) {
-        size_t sizeClass = bmalloc::sizeClass(size);
</del><ins>+    if (size &lt;= maskSizeClassMax) {
+        size_t sizeClass = bmalloc::maskSizeClass(size);
</ins><span class="cx">         BumpAllocator&amp; allocator = m_bumpAllocators[sizeClass];
</span><span class="cx">         refillAllocator(allocator, sizeClass);
</span><span class="cx">         return allocator.allocate();
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    if (size &lt;= smallMax)
+        return allocateLogSizeClass(size);
+
</ins><span class="cx">     if (size &lt;= largeMax)
</span><span class="cx">         return allocateLarge(size);
</span><span class="cx"> 
</span></span></pre></div>
<a id="releasesWebKitGTKwebkit212SourcebmallocbmallocAllocatorh"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.12/Source/bmalloc/bmalloc/Allocator.h (199434 => 199435)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.12/Source/bmalloc/bmalloc/Allocator.h        2016-04-13 08:52:20 UTC (rev 199434)
+++ releases/WebKitGTK/webkit-2.12/Source/bmalloc/bmalloc/Allocator.h        2016-04-13 08:54:22 UTC (rev 199435)
</span><span class="lines">@@ -52,14 +52,15 @@
</span><span class="cx">     bool allocateFastCase(size_t, void*&amp;);
</span><span class="cx">     void* allocateSlowCase(size_t);
</span><span class="cx">     
</span><ins>+    void* allocateLogSizeClass(size_t);
</ins><span class="cx">     void* allocateLarge(size_t);
</span><span class="cx">     void* allocateXLarge(size_t);
</span><span class="cx">     
</span><span class="cx">     void refillAllocator(BumpAllocator&amp;, size_t sizeClass);
</span><span class="cx">     void refillAllocatorSlowCase(BumpAllocator&amp;, size_t sizeClass);
</span><span class="cx">     
</span><del>-    std::array&lt;BumpAllocator, smallMax / alignment&gt; m_bumpAllocators;
-    std::array&lt;BumpRangeCache, smallMax / alignment&gt; m_bumpRangeCaches;
</del><ins>+    std::array&lt;BumpAllocator, sizeClassCount&gt; m_bumpAllocators;
+    std::array&lt;BumpRangeCache, sizeClassCount&gt; m_bumpRangeCaches;
</ins><span class="cx"> 
</span><span class="cx">     bool m_isBmallocEnabled;
</span><span class="cx">     Deallocator&amp; m_deallocator;
</span><span class="lines">@@ -67,10 +68,10 @@
</span><span class="cx"> 
</span><span class="cx"> inline bool Allocator::allocateFastCase(size_t size, void*&amp; object)
</span><span class="cx"> {
</span><del>-    if (size &gt; smallMax)
</del><ins>+    if (size &gt; maskSizeClassMax)
</ins><span class="cx">         return false;
</span><span class="cx"> 
</span><del>-    BumpAllocator&amp; allocator = m_bumpAllocators[sizeClass(size)];
</del><ins>+    BumpAllocator&amp; allocator = m_bumpAllocators[maskSizeClass(size)];
</ins><span class="cx">     if (!allocator.canAllocate())
</span><span class="cx">         return false;
</span><span class="cx"> 
</span></span></pre></div>
<a id="releasesWebKitGTKwebkit212SourcebmallocbmallocBumpAllocatorh"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.12/Source/bmalloc/bmalloc/BumpAllocator.h (199434 => 199435)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.12/Source/bmalloc/bmalloc/BumpAllocator.h        2016-04-13 08:52:20 UTC (rev 199434)
+++ releases/WebKitGTK/webkit-2.12/Source/bmalloc/bmalloc/BumpAllocator.h        2016-04-13 08:54:22 UTC (rev 199435)
</span><span class="lines">@@ -50,8 +50,6 @@
</span><span class="cx">     void refill(const BumpRange&amp;);
</span><span class="cx"> 
</span><span class="cx"> private:
</span><del>-    void validate(void*);
-
</del><span class="cx">     char* m_ptr;
</span><span class="cx">     unsigned short m_size;
</span><span class="cx">     unsigned short m_remaining;
</span><span class="lines">@@ -71,18 +69,6 @@
</span><span class="cx">     m_remaining = 0;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-inline void BumpAllocator::validate(void* ptr)
-{
-    UNUSED(ptr);
-    if (m_size &lt;= smallMax) {
-        BASSERT(isSmall(ptr));
-        return;
-    }
-    
-    BASSERT(m_size &lt;= smallMax);
-    BASSERT(isSmall(ptr));
-}
-
</del><span class="cx"> inline void* BumpAllocator::allocate()
</span><span class="cx"> {
</span><span class="cx">     BASSERT(m_remaining);
</span><span class="lines">@@ -90,7 +76,7 @@
</span><span class="cx">     --m_remaining;
</span><span class="cx">     char* result = m_ptr;
</span><span class="cx">     m_ptr += m_size;
</span><del>-    validate(result);
</del><ins>+    BASSERT(isSmall(result));
</ins><span class="cx">     return result;
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="releasesWebKitGTKwebkit212SourcebmallocbmallocHeapcpp"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.12/Source/bmalloc/bmalloc/Heap.cpp (199434 => 199435)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.12/Source/bmalloc/bmalloc/Heap.cpp        2016-04-13 08:52:20 UTC (rev 199434)
+++ releases/WebKitGTK/webkit-2.12/Source/bmalloc/bmalloc/Heap.cpp        2016-04-13 08:54:22 UTC (rev 199435)
</span><span class="lines">@@ -47,8 +47,8 @@
</span><span class="cx"> {
</span><span class="cx">     // We assume that m_smallLineMetadata is zero-filled.
</span><span class="cx"> 
</span><del>-    for (size_t size = alignment; size &lt;= smallMax; size += alignment) {
-        size_t sizeClass = bmalloc::sizeClass(size);
</del><ins>+    for (size_t sizeClass = 0; sizeClass &lt; sizeClassCount; ++sizeClass) {
+        size_t size = objectSize(sizeClass);
</ins><span class="cx">         auto&amp; metadata = m_smallLineMetadata[sizeClass];
</span><span class="cx"> 
</span><span class="cx">         size_t object = 0;
</span></span></pre></div>
<a id="releasesWebKitGTKwebkit212SourcebmallocbmallocHeaph"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.12/Source/bmalloc/bmalloc/Heap.h (199434 => 199435)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.12/Source/bmalloc/bmalloc/Heap.h        2016-04-13 08:52:20 UTC (rev 199434)
+++ releases/WebKitGTK/webkit-2.12/Source/bmalloc/bmalloc/Heap.h        2016-04-13 08:54:22 UTC (rev 199435)
</span><span class="lines">@@ -92,9 +92,9 @@
</span><span class="cx">     void scavengeLargeObjects(std::unique_lock&lt;StaticMutex&gt;&amp;, std::chrono::milliseconds);
</span><span class="cx">     void scavengeXLargeObjects(std::unique_lock&lt;StaticMutex&gt;&amp;, std::chrono::milliseconds);
</span><span class="cx"> 
</span><del>-    std::array&lt;std::array&lt;LineMetadata, smallLineCount&gt;, smallMax / alignment&gt; m_smallLineMetadata;
</del><ins>+    std::array&lt;std::array&lt;LineMetadata, smallLineCount&gt;, sizeClassCount&gt; m_smallLineMetadata;
</ins><span class="cx"> 
</span><del>-    std::array&lt;List&lt;SmallPage&gt;, smallMax / alignment&gt; m_smallPagesWithFreeLines;
</del><ins>+    std::array&lt;List&lt;SmallPage&gt;, sizeClassCount&gt; m_smallPagesWithFreeLines;
</ins><span class="cx"> 
</span><span class="cx">     List&lt;SmallPage&gt; m_smallPages;
</span><span class="cx"> 
</span></span></pre></div>
<a id="releasesWebKitGTKwebkit212SourcebmallocbmallocSizesh"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.12/Source/bmalloc/bmalloc/Sizes.h (199434 => 199435)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.12/Source/bmalloc/bmalloc/Sizes.h        2016-04-13 08:52:20 UTC (rev 199434)
+++ releases/WebKitGTK/webkit-2.12/Source/bmalloc/bmalloc/Sizes.h        2016-04-13 08:54:22 UTC (rev 199435)
</span><span class="lines">@@ -60,10 +60,12 @@
</span><span class="cx">     static const size_t smallChunkOffset = superChunkSize / 2;
</span><span class="cx">     static const size_t smallChunkMask = ~(smallChunkSize - 1ul);
</span><span class="cx"> 
</span><del>-    static const size_t smallMax = 1024;
</del><span class="cx">     static const size_t smallLineSize = 256;
</span><span class="cx">     static const size_t smallLineCount = vmPageSize / smallLineSize;
</span><span class="cx"> 
</span><ins>+    static const size_t smallMax = 1 * kB;
+    static const size_t maskSizeClassMax = 512;
+
</ins><span class="cx">     static const size_t largeChunkSize = superChunkSize / 2;
</span><span class="cx">     static const size_t largeChunkOffset = 0;
</span><span class="cx">     static const size_t largeChunkMask = ~(largeChunkSize - 1ul);
</span><span class="lines">@@ -90,17 +92,54 @@
</span><span class="cx">     
</span><span class="cx">     static const std::chrono::milliseconds scavengeSleepDuration = std::chrono::milliseconds(512);
</span><span class="cx"> 
</span><ins>+    static const size_t maskSizeClassCount = maskSizeClassMax / alignment;
+
+    inline constexpr size_t maskSizeClass(size_t size)
+    {
+        // We mask to accommodate zero.
+        return mask((size - 1) / alignment, maskSizeClassCount - 1);
+    }
+
+    inline size_t maskObjectSize(size_t maskSizeClass)
+    {
+        return (maskSizeClass + 1) * alignment;
+    }
+
+    static const size_t logWasteFactor = 8;
+    static const size_t logAlignmentMin = maskSizeClassMax / logWasteFactor;
+
+    static const size_t logSizeClassCount = (log2(smallMax) - log2(maskSizeClassMax)) * logWasteFactor;
+
+    inline size_t logSizeClass(size_t size)
+    {
+        size_t base = log2(size - 1) - log2(maskSizeClassMax);
+        size_t offset = (size - 1 - (maskSizeClassMax &lt;&lt; base));
+        return base * logWasteFactor + offset / (logAlignmentMin &lt;&lt; base);
+    }
+
+    inline size_t logObjectSize(size_t logSizeClass)
+    {
+        size_t base = logSizeClass / logWasteFactor;
+        size_t offset = logSizeClass % logWasteFactor;
+        return (maskSizeClassMax &lt;&lt; base) + (offset + 1) * (logAlignmentMin &lt;&lt; base);
+    }
+
+    static const size_t sizeClassCount = maskSizeClassCount + logSizeClassCount;
+
</ins><span class="cx">     inline size_t sizeClass(size_t size)
</span><span class="cx">     {
</span><del>-        static const size_t sizeClassMask = (smallMax / alignment) - 1;
-        return mask((size - 1) / alignment, sizeClassMask);
</del><ins>+        if (size &lt;= maskSizeClassMax)
+            return maskSizeClass(size);
+        return maskSizeClassCount + logSizeClass(size);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     inline size_t objectSize(size_t sizeClass)
</span><span class="cx">     {
</span><del>-        return (sizeClass + 1) * alignment;
</del><ins>+        if (sizeClass &lt; maskSizeClassCount)
+            return maskObjectSize(sizeClass);
+        return logObjectSize(sizeClass - maskSizeClassCount);
</ins><span class="cx">     }
</span><del>-};
</del><ins>+}
</ins><span class="cx"> 
</span><span class="cx"> using namespace Sizes;
</span><span class="cx"> 
</span></span></pre></div>
<a id="releasesWebKitGTKwebkit212SourcebmallocbmallocSmallLineh"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.12/Source/bmalloc/bmalloc/SmallLine.h (199434 => 199435)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.12/Source/bmalloc/bmalloc/SmallLine.h        2016-04-13 08:52:20 UTC (rev 199434)
+++ releases/WebKitGTK/webkit-2.12/Source/bmalloc/bmalloc/SmallLine.h        2016-04-13 08:54:22 UTC (rev 199435)
</span><span class="lines">@@ -35,9 +35,6 @@
</span><span class="cx"> 
</span><span class="cx"> class SmallLine {
</span><span class="cx"> public:
</span><del>-    static const unsigned char maxRefCount = std::numeric_limits&lt;unsigned char&gt;::max();
-    static_assert(smallLineSize / alignment &lt; maxRefCount, &quot;maximum object count must fit in Line&quot;);
-
</del><span class="cx">     static SmallLine* get(void*);
</span><span class="cx"> 
</span><span class="cx">     void ref(std::lock_guard&lt;StaticMutex&gt;&amp;, unsigned char);
</span><span class="lines">@@ -49,6 +46,11 @@
</span><span class="cx"> 
</span><span class="cx"> private:
</span><span class="cx">     unsigned char m_refCount;
</span><ins>+
+static_assert(
+    smallLineSize / alignment &lt;= std::numeric_limits&lt;decltype(m_refCount)&gt;::max(),
+    &quot;maximum object count must fit in SmallLine::m_refCount&quot;);
+
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> inline void SmallLine::ref(std::lock_guard&lt;StaticMutex&gt;&amp;, unsigned char refCount)
</span></span></pre></div>
<a id="releasesWebKitGTKwebkit212SourcebmallocbmallocSmallPageh"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.12/Source/bmalloc/bmalloc/SmallPage.h (199434 => 199435)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.12/Source/bmalloc/bmalloc/SmallPage.h        2016-04-13 08:52:20 UTC (rev 199434)
+++ releases/WebKitGTK/webkit-2.12/Source/bmalloc/bmalloc/SmallPage.h        2016-04-13 08:54:22 UTC (rev 199435)
</span><span class="lines">@@ -36,9 +36,6 @@
</span><span class="cx"> 
</span><span class="cx"> class SmallPage : public ListNode&lt;SmallPage&gt; {
</span><span class="cx"> public:
</span><del>-    static const unsigned char maxRefCount = std::numeric_limits&lt;unsigned char&gt;::max();
-    static_assert(smallLineCount &lt; maxRefCount, &quot;maximum line count must fit in SmallPage&quot;);
-    
</del><span class="cx">     static SmallPage* get(SmallLine*);
</span><span class="cx"> 
</span><span class="cx">     SmallPage()
</span><span class="lines">@@ -63,12 +60,16 @@
</span><span class="cx">     unsigned char m_hasFreeLines: 1;
</span><span class="cx">     unsigned char m_refCount: 7;
</span><span class="cx">     unsigned char m_sizeClass;
</span><ins>+
+static_assert(
+    sizeClassCount &lt;= std::numeric_limits&lt;decltype(m_sizeClass)&gt;::max(),
+    &quot;Largest size class must fit in SmallPage metadata&quot;);
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> inline void SmallPage::ref(std::lock_guard&lt;StaticMutex&gt;&amp;)
</span><span class="cx"> {
</span><del>-    BASSERT(m_refCount &lt; maxRefCount);
</del><span class="cx">     ++m_refCount;
</span><ins>+    BASSERT(m_refCount);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> inline bool SmallPage::deref(std::lock_guard&lt;StaticMutex&gt;&amp;)
</span></span></pre></div>
<a id="releasesWebKitGTKwebkit212SourcebmallocbmallocZonecpp"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.12/Source/bmalloc/bmalloc/Zone.cpp (199434 => 199435)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.12/Source/bmalloc/bmalloc/Zone.cpp        2016-04-13 08:52:20 UTC (rev 199434)
+++ releases/WebKitGTK/webkit-2.12/Source/bmalloc/bmalloc/Zone.cpp        2016-04-13 08:54:22 UTC (rev 199435)
</span><span class="lines">@@ -78,7 +78,7 @@
</span><span class="cx">     memset(statistics, 0, sizeof(malloc_statistics_t));
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static size_t size(malloc_zone_t*, const void*)
</del><ins>+static size_t zoneSize(malloc_zone_t*, const void*)
</ins><span class="cx"> {
</span><span class="cx">     // Our zone is not public API, so no pointer can belong to us.
</span><span class="cx">     return 0;
</span><span class="lines">@@ -104,7 +104,7 @@
</span><span class="cx"> // The memory analysis API requires the contents of this struct to be a static
</span><span class="cx"> // constant in the program binary. The leaks process will load this struct
</span><span class="cx"> // out of the program binary (and not out of the running process).
</span><del>-static malloc_introspection_t introspect = {
</del><ins>+static malloc_introspection_t zoneIntrospect = {
</ins><span class="cx">     .enumerator = bmalloc::enumerator,
</span><span class="cx">     .good_size = bmalloc::good_size,
</span><span class="cx">     .check = bmalloc::check,
</span><span class="lines">@@ -117,9 +117,9 @@
</span><span class="cx"> 
</span><span class="cx"> Zone::Zone()
</span><span class="cx"> {
</span><del>-    malloc_zone_t::size = &amp;bmalloc::size;
</del><ins>+    malloc_zone_t::size = &amp;bmalloc::zoneSize;
</ins><span class="cx">     malloc_zone_t::zone_name = &quot;WebKit Malloc&quot;;
</span><del>-    malloc_zone_t::introspect = &amp;bmalloc::introspect;
</del><ins>+    malloc_zone_t::introspect = &amp;bmalloc::zoneIntrospect;
</ins><span class="cx">     malloc_zone_t::version = 4;
</span><span class="cx">     malloc_zone_register(this);
</span><span class="cx"> }
</span></span></pre>
</div>
</div>

</body>
</html>