<!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>[173645] 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/173645">173645</a></dd>
<dt>Author</dt> <dd>ggaren@apple.com</dd>
<dt>Date</dt> <dd>2014-09-15 19:24:35 -0700 (Mon, 15 Sep 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>bmalloc: allocate small and medium objects using the same bump pointer class
https://bugs.webkit.org/show_bug.cgi?id=136843

Reviewed by Gavin Barraclough.

4% speedup on MallocBench.

Now that medium-sized objects have dedicated per-size allocators, they
don't need to use an arbitrary bump pointer allocator. This means that
every allocator knows how many objects it will allocate from the start,
and we don't need a post-processing step to adjust refcounts based on
real allocation count.

* bmalloc.xcodeproj/project.pbxproj: Renamed SmallAllocator to BumpAllocator
since it's used for small and medium objects now.

* bmalloc/Allocator.cpp:
(bmalloc::Allocator::Allocator): Updated to use new interface.
(bmalloc::Allocator::scavenge): To &quot;retire&quot; an allocator, we just need
to make sure that we finish allocating all the objects in it.

(bmalloc::Allocator::allocateMedium):
(bmalloc::Allocator::allocateSlowCase):
(bmalloc::Allocator::retire): Deleted.
(bmalloc::Allocator::processSmallAllocatorLog): Deleted.
(bmalloc::Allocator::processMediumAllocatorLog): Deleted.
* bmalloc/Allocator.h:
(bmalloc::Allocator::allocateFastCase): Removed abstractions and data
used to post-process an allocator based on how many objects it allocated.

* bmalloc/BumpAllocator.h: Copied from Source/bmalloc/bmalloc/SmallAllocator.h.
(bmalloc::BumpAllocator::BumpAllocator):
(bmalloc::BumpAllocator::init):
(bmalloc::BumpAllocator::line):
(bmalloc::BumpAllocator::validate):
(bmalloc::BumpAllocator::allocate):
(bmalloc::BumpAllocator::refill):
(bmalloc::BumpAllocator::clear): Updated these functions to be agnostic
about the kinds of lines they allocate into. In some cases, the line
type must be provided as a template parameter by the caller.

(bmalloc::SmallAllocator::SmallAllocator): Deleted.
(bmalloc::SmallAllocator::line): Deleted.
(bmalloc::SmallAllocator::allocate): Deleted.
(bmalloc::SmallAllocator::objectCount): Deleted.
(bmalloc::SmallAllocator::derefCount): Deleted.
(bmalloc::SmallAllocator::refill): Deleted.
(bmalloc::SmallAllocator::clear): Deleted.

* bmalloc/ObjectType.h:
(bmalloc::isMedium):

* bmalloc/SmallAllocator.h:
(bmalloc::SmallAllocator::isNull): Deleted.
(bmalloc::SmallAllocator::canAllocate): Deleted.
(bmalloc::SmallAllocator::SmallAllocator): Deleted.
(bmalloc::SmallAllocator::line): Deleted.
(bmalloc::SmallAllocator::allocate): Deleted.
(bmalloc::SmallAllocator::objectCount): Deleted.
(bmalloc::SmallAllocator::derefCount): Deleted.
(bmalloc::SmallAllocator::refill): Deleted.
(bmalloc::SmallAllocator::clear): Deleted.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourcebmallocChangeLog">trunk/Source/bmalloc/ChangeLog</a></li>
<li><a href="#trunkSourcebmallocbmallocAllocatorcpp">trunk/Source/bmalloc/bmalloc/Allocator.cpp</a></li>
<li><a href="#trunkSourcebmallocbmallocAllocatorh">trunk/Source/bmalloc/bmalloc/Allocator.h</a></li>
<li><a href="#trunkSourcebmallocbmallocObjectTypeh">trunk/Source/bmalloc/bmalloc/ObjectType.h</a></li>
<li><a href="#trunkSourcebmallocbmallocSizesh">trunk/Source/bmalloc/bmalloc/Sizes.h</a></li>
<li><a href="#trunkSourcebmallocbmallocSmallAllocatorh">trunk/Source/bmalloc/bmalloc/SmallAllocator.h</a></li>
<li><a href="#trunkSourcebmallocbmallocxcodeprojprojectpbxproj">trunk/Source/bmalloc/bmalloc.xcodeproj/project.pbxproj</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourcebmallocbmallocBumpAllocatorh">trunk/Source/bmalloc/bmalloc/BumpAllocator.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourcebmallocChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/bmalloc/ChangeLog (173644 => 173645)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/bmalloc/ChangeLog        2014-09-16 01:22:08 UTC (rev 173644)
+++ trunk/Source/bmalloc/ChangeLog        2014-09-16 02:24:35 UTC (rev 173645)
</span><span class="lines">@@ -1,3 +1,68 @@
</span><ins>+2014-09-15  Geoffrey Garen  &lt;ggaren@apple.com&gt;
+
+        bmalloc: allocate small and medium objects using the same bump pointer class
+        https://bugs.webkit.org/show_bug.cgi?id=136843
+
+        Reviewed by Gavin Barraclough.
+
+        4% speedup on MallocBench.
+
+        Now that medium-sized objects have dedicated per-size allocators, they
+        don't need to use an arbitrary bump pointer allocator. This means that
+        every allocator knows how many objects it will allocate from the start,
+        and we don't need a post-processing step to adjust refcounts based on
+        real allocation count.
+
+        * bmalloc.xcodeproj/project.pbxproj: Renamed SmallAllocator to BumpAllocator
+        since it's used for small and medium objects now.
+
+        * bmalloc/Allocator.cpp:
+        (bmalloc::Allocator::Allocator): Updated to use new interface.
+        (bmalloc::Allocator::scavenge): To &quot;retire&quot; an allocator, we just need
+        to make sure that we finish allocating all the objects in it.
+
+        (bmalloc::Allocator::allocateMedium):
+        (bmalloc::Allocator::allocateSlowCase):
+        (bmalloc::Allocator::retire): Deleted.
+        (bmalloc::Allocator::processSmallAllocatorLog): Deleted.
+        (bmalloc::Allocator::processMediumAllocatorLog): Deleted.
+        * bmalloc/Allocator.h:
+        (bmalloc::Allocator::allocateFastCase): Removed abstractions and data
+        used to post-process an allocator based on how many objects it allocated.
+
+        * bmalloc/BumpAllocator.h: Copied from Source/bmalloc/bmalloc/SmallAllocator.h.
+        (bmalloc::BumpAllocator::BumpAllocator):
+        (bmalloc::BumpAllocator::init):
+        (bmalloc::BumpAllocator::line):
+        (bmalloc::BumpAllocator::validate):
+        (bmalloc::BumpAllocator::allocate):
+        (bmalloc::BumpAllocator::refill):
+        (bmalloc::BumpAllocator::clear): Updated these functions to be agnostic
+        about the kinds of lines they allocate into. In some cases, the line
+        type must be provided as a template parameter by the caller.
+
+        (bmalloc::SmallAllocator::SmallAllocator): Deleted.
+        (bmalloc::SmallAllocator::line): Deleted.
+        (bmalloc::SmallAllocator::allocate): Deleted.
+        (bmalloc::SmallAllocator::objectCount): Deleted.
+        (bmalloc::SmallAllocator::derefCount): Deleted.
+        (bmalloc::SmallAllocator::refill): Deleted.
+        (bmalloc::SmallAllocator::clear): Deleted.
+
+        * bmalloc/ObjectType.h:
+        (bmalloc::isMedium):
+
+        * bmalloc/SmallAllocator.h:
+        (bmalloc::SmallAllocator::isNull): Deleted.
+        (bmalloc::SmallAllocator::canAllocate): Deleted.
+        (bmalloc::SmallAllocator::SmallAllocator): Deleted.
+        (bmalloc::SmallAllocator::line): Deleted.
+        (bmalloc::SmallAllocator::allocate): Deleted.
+        (bmalloc::SmallAllocator::objectCount): Deleted.
+        (bmalloc::SmallAllocator::derefCount): Deleted.
+        (bmalloc::SmallAllocator::refill): Deleted.
+        (bmalloc::SmallAllocator::clear): Deleted.
+
</ins><span class="cx"> 2014-09-12  Geoffrey Garen  &lt;ggaren@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Fixed a goof in bmalloc Vector sizing
</span></span></pre></div>
<a id="trunkSourcebmallocbmallocAllocatorcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/bmalloc/bmalloc/Allocator.cpp (173644 => 173645)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/bmalloc/bmalloc/Allocator.cpp        2014-09-16 01:22:08 UTC (rev 173644)
+++ trunk/Source/bmalloc/bmalloc/Allocator.cpp        2014-09-16 02:24:35 UTC (rev 173645)
</span><span class="lines">@@ -37,16 +37,12 @@
</span><span class="cx"> 
</span><span class="cx"> Allocator::Allocator(Deallocator&amp; deallocator)
</span><span class="cx">     : m_deallocator(deallocator)
</span><del>-    , m_smallAllocators()
-    , m_mediumAllocators()
-    , m_smallAllocatorLog()
-    , m_mediumAllocatorLog()
</del><span class="cx"> {
</span><del>-    unsigned short size = alignment;
-    for (auto&amp; allocator : m_smallAllocators) {
-        allocator = SmallAllocator(size);
-        size += alignment;
-    }
</del><ins>+    for (unsigned short i = alignment; i &lt;= smallMax; i += alignment)
+        m_smallAllocators[smallSizeClassFor(i)].init&lt;SmallLine&gt;(i);
+
+    for (unsigned short i = smallMax + alignment; i &lt;= mediumMax; i += alignment)
+        m_mediumAllocators[mediumSizeClassFor(i)].init&lt;MediumLine&gt;(i);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> Allocator::~Allocator()
</span><span class="lines">@@ -57,64 +53,18 @@
</span><span class="cx"> void Allocator::scavenge()
</span><span class="cx"> {
</span><span class="cx">     for (auto&amp; allocator : m_smallAllocators) {
</span><del>-        retire(allocator);
</del><ins>+        while (allocator.canAllocate())
+            m_deallocator.deallocate(allocator.allocate());
</ins><span class="cx">         allocator.clear();
</span><span class="cx">     }
</span><del>-    processSmallAllocatorLog();
</del><span class="cx"> 
</span><span class="cx">     for (auto&amp; allocator : m_mediumAllocators) {
</span><del>-        retire(allocator);
</del><ins>+        while (allocator.canAllocate())
+            m_deallocator.deallocate(allocator.allocate());
</ins><span class="cx">         allocator.clear();
</span><span class="cx">     }
</span><del>-    processMediumAllocatorLog();
</del><span class="cx"> }
</span><span class="cx"> 
</span><del>-void Allocator::retire(SmallAllocator&amp; allocator)
-{
-    if (m_smallAllocatorLog.size() == m_smallAllocatorLog.capacity())
-        processSmallAllocatorLog();
-    
-    if (allocator.isNull())
-        return;
-
-    m_smallAllocatorLog.push(std::make_pair(allocator.line(), allocator.derefCount()));
-}
-
-void Allocator::processSmallAllocatorLog()
-{
-    std::lock_guard&lt;StaticMutex&gt; lock(PerProcess&lt;Heap&gt;::mutex());
-
-    for (auto&amp; logEntry : m_smallAllocatorLog) {
-        if (!logEntry.first-&gt;deref(lock, logEntry.second))
-            continue;
-        m_deallocator.deallocateSmallLine(lock, logEntry.first);
-    }
-    m_smallAllocatorLog.clear();
-}
-
-void Allocator::retire(MediumAllocator&amp; allocator)
-{
-    if (m_mediumAllocatorLog.size() == m_mediumAllocatorLog.capacity())
-        processMediumAllocatorLog();
-
-    if (allocator.isNull())
-        return;
-
-    m_mediumAllocatorLog.push(std::make_pair(allocator.line(), allocator.derefCount()));
-}
-
-void Allocator::processMediumAllocatorLog()
-{
-    std::lock_guard&lt;StaticMutex&gt; lock(PerProcess&lt;Heap&gt;::mutex());
-
-    for (auto&amp; logEntry : m_mediumAllocatorLog) {
-        if (!logEntry.first-&gt;deref(lock, logEntry.second))
-            continue;
-        m_deallocator.deallocateMediumLine(lock, logEntry.first);
-    }
-    m_mediumAllocatorLog.clear();
-}
-
</del><span class="cx"> void* Allocator::allocateLarge(size_t size)
</span><span class="cx"> {
</span><span class="cx">     size = roundUpToMultipleOf&lt;largeAlignment&gt;(size);
</span><span class="lines">@@ -131,16 +81,11 @@
</span><span class="cx"> 
</span><span class="cx"> void* Allocator::allocateMedium(size_t size)
</span><span class="cx"> {
</span><del>-    MediumAllocator&amp; allocator = m_mediumAllocators[mediumSizeClassFor(size)];
-    size = roundUpToMultipleOf&lt;alignment&gt;(size);
</del><ins>+    BumpAllocator&amp; allocator = m_mediumAllocators[mediumSizeClassFor(size)];
</ins><span class="cx"> 
</span><del>-    void* object;
-    if (allocator.allocate(size, object))
-        return object;
-
-    retire(allocator);
-    allocator.refill(m_deallocator.allocateMediumLine());
-    return allocator.allocate(size);
</del><ins>+    if (!allocator.canAllocate())
+        allocator.refill(m_deallocator.allocateMediumLine());
+    return allocator.allocate();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void* Allocator::allocateSlowCase(size_t size)
</span><span class="lines">@@ -151,8 +96,7 @@
</span><span class="cx"> )
</span><span class="cx">     if (size &lt;= smallMax) {
</span><span class="cx">         size_t smallSizeClass = smallSizeClassFor(size);
</span><del>-        SmallAllocator&amp; allocator = m_smallAllocators[smallSizeClass];
-        retire(allocator);
</del><ins>+        BumpAllocator&amp; allocator = m_smallAllocators[smallSizeClass];
</ins><span class="cx">         allocator.refill(m_deallocator.allocateSmallLine(smallSizeClass));
</span><span class="cx">         return allocator.allocate();
</span><span class="cx">     }
</span></span></pre></div>
<a id="trunkSourcebmallocbmallocAllocatorh"></a>
<div class="modfile"><h4>Modified: trunk/Source/bmalloc/bmalloc/Allocator.h (173644 => 173645)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/bmalloc/bmalloc/Allocator.h        2014-09-16 01:22:08 UTC (rev 173644)
+++ trunk/Source/bmalloc/bmalloc/Allocator.h        2014-09-16 02:24:35 UTC (rev 173645)
</span><span class="lines">@@ -26,10 +26,11 @@
</span><span class="cx"> #ifndef Allocator_h
</span><span class="cx"> #define Allocator_h
</span><span class="cx"> 
</span><ins>+#include &quot;BumpAllocator.h&quot;
</ins><span class="cx"> #include &quot;FixedVector.h&quot;
</span><span class="cx"> #include &quot;MediumAllocator.h&quot;
</span><span class="cx"> #include &quot;Sizes.h&quot;
</span><del>-#include &quot;SmallAllocator.h&quot;
</del><ins>+#include &quot;SmallLine.h&quot;
</ins><span class="cx"> #include &lt;array&gt;
</span><span class="cx"> 
</span><span class="cx"> namespace bmalloc {
</span><span class="lines">@@ -50,25 +51,16 @@
</span><span class="cx">     void scavenge();
</span><span class="cx"> 
</span><span class="cx"> private:
</span><del>-    void* allocateFastCase(SmallAllocator&amp;);
</del><ins>+    void* allocateFastCase(BumpAllocator&amp;);
</ins><span class="cx"> 
</span><span class="cx">     void* allocateMedium(size_t);
</span><span class="cx">     void* allocateLarge(size_t);
</span><span class="cx">     void* allocateXLarge(size_t);
</span><span class="cx">     
</span><del>-    void retire(SmallAllocator&amp;);
-    void retire(MediumAllocator&amp;);
-
-    void processSmallAllocatorLog();
-    void processMediumAllocatorLog();
-
</del><span class="cx">     Deallocator&amp; m_deallocator;
</span><span class="cx"> 
</span><del>-    std::array&lt;SmallAllocator, smallMax / alignment&gt; m_smallAllocators;
-    std::array&lt;MediumAllocator, mediumMax / alignment&gt; m_mediumAllocators;
-
-    FixedVector&lt;std::pair&lt;SmallLine*, unsigned char&gt;, smallAllocatorLogCapacity&gt; m_smallAllocatorLog;
-    FixedVector&lt;std::pair&lt;MediumLine*, unsigned char&gt;, mediumAllocatorLogCapacity&gt; m_mediumAllocatorLog;
</del><ins>+    std::array&lt;BumpAllocator, smallMax / alignment&gt; m_smallAllocators;
+    std::array&lt;BumpAllocator, mediumMax / alignment&gt; m_mediumAllocators;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> inline bool Allocator::allocateFastCase(size_t size, void*&amp; object)
</span><span class="lines">@@ -76,7 +68,7 @@
</span><span class="cx">     if (size &gt; smallMax)
</span><span class="cx">         return false;
</span><span class="cx"> 
</span><del>-    SmallAllocator&amp; allocator = m_smallAllocators[smallSizeClassFor(size)];
</del><ins>+    BumpAllocator&amp; allocator = m_smallAllocators[smallSizeClassFor(size)];
</ins><span class="cx">     if (!allocator.canAllocate())
</span><span class="cx">         return false;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourcebmallocbmallocBumpAllocatorhfromrev173530trunkSourcebmallocbmallocSmallAllocatorh"></a>
<div class="copfile"><h4>Copied: trunk/Source/bmalloc/bmalloc/BumpAllocator.h (from rev 173530, trunk/Source/bmalloc/bmalloc/SmallAllocator.h) (0 => 173645)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/bmalloc/bmalloc/BumpAllocator.h                                (rev 0)
+++ trunk/Source/bmalloc/bmalloc/BumpAllocator.h        2014-09-16 02:24:35 UTC (rev 173645)
</span><span class="lines">@@ -0,0 +1,124 @@
</span><ins>+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#ifndef BumpAllocator_h
+#define BumpAllocator_h
+
+#include &quot;BAssert.h&quot;
+#include &quot;ObjectType.h&quot;
+
+namespace bmalloc {
+
+// Helper object for allocating small and medium objects.
+
+class BumpAllocator {
+public:
+    BumpAllocator();
+    template&lt;typename Line&gt; void init(size_t);
+    
+    bool isNull() { return !m_ptr; }
+    template&lt;typename Line&gt; Line* line();
+
+    bool canAllocate() { return !!m_remaining; }
+    void* allocate();
+
+    template&lt;typename Line&gt; void refill(Line*);
+    void clear();
+
+private:
+    void validate(void*);
+
+    char* m_ptr;
+    unsigned short m_size;
+    unsigned char m_remaining;
+    unsigned char m_maxObjectCount;
+};
+
+inline BumpAllocator::BumpAllocator()
+    : m_ptr()
+    , m_size()
+    , m_remaining()
+    , m_maxObjectCount()
+{
+}
+
+template&lt;typename Line&gt;
+inline void BumpAllocator::init(size_t size)
+{
+    BASSERT(size &gt;= Line::minimumObjectSize);
+
+    m_ptr = nullptr;
+    m_size = size;
+    m_remaining = 0;
+    m_maxObjectCount = Line::lineSize / size;
+}
+
+template&lt;typename Line&gt;
+inline Line* BumpAllocator::line()
+{
+    return Line::get(canAllocate() ? m_ptr : m_ptr - 1);
+}
+
+inline void BumpAllocator::validate(void* ptr)
+{
+    UNUSED(ptr);
+    if (m_size &lt;= smallMax) {
+        BASSERT(isSmall(ptr));
+        return;
+    }
+    
+    BASSERT(m_size &lt;= mediumMax);
+    BASSERT(isMedium(ptr));
+}
+
+inline void* BumpAllocator::allocate()
+{
+    BASSERT(m_remaining);
+
+    --m_remaining;
+    char* result = m_ptr;
+    m_ptr += m_size;
+    validate(result);
+    return result;
+}
+
+template&lt;typename Line&gt;
+inline void BumpAllocator::refill(Line* line)
+{
+    BASSERT(!canAllocate());
+    line-&gt;concurrentRef(m_maxObjectCount);
+    m_ptr = line-&gt;begin();
+    m_remaining = m_maxObjectCount;
+}
+
+inline void BumpAllocator::clear()
+{
+    m_ptr = nullptr;
+    m_remaining = 0;
+}
+
+} // namespace bmalloc
+
+#endif // BumpAllocator_h
</ins></span></pre></div>
<a id="trunkSourcebmallocbmallocObjectTypeh"></a>
<div class="modfile"><h4>Modified: trunk/Source/bmalloc/bmalloc/ObjectType.h (173644 => 173645)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/bmalloc/bmalloc/ObjectType.h        2014-09-16 01:22:08 UTC (rev 173644)
+++ trunk/Source/bmalloc/bmalloc/ObjectType.h        2014-09-16 02:24:35 UTC (rev 173645)
</span><span class="lines">@@ -46,6 +46,11 @@
</span><span class="cx">     return test(smallOrMedium, smallOrMediumSmallTypeMask);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+inline bool isMedium(void* smallOrMedium)
+{
+    return !isSmall(smallOrMedium);
+}
+
</ins><span class="cx"> } // namespace bmalloc
</span><span class="cx"> 
</span><span class="cx"> #endif // ObjectType_h
</span></span></pre></div>
<a id="trunkSourcebmallocbmallocSizesh"></a>
<div class="modfile"><h4>Modified: trunk/Source/bmalloc/bmalloc/Sizes.h (173644 => 173645)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/bmalloc/bmalloc/Sizes.h        2014-09-16 01:22:08 UTC (rev 173644)
+++ trunk/Source/bmalloc/bmalloc/Sizes.h        2014-09-16 02:24:35 UTC (rev 173645)
</span><span class="lines">@@ -86,9 +86,6 @@
</span><span class="cx"> 
</span><span class="cx">     static const size_t smallLineCacheCapacity = 16;
</span><span class="cx">     static const size_t mediumLineCacheCapacity = 8;
</span><del>-
-    static const size_t smallAllocatorLogCapacity = 16;
-    static const size_t mediumAllocatorLogCapacity = 8;
</del><span class="cx">     
</span><span class="cx">     static const std::chrono::milliseconds scavengeSleepDuration = std::chrono::milliseconds(512);
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourcebmallocbmallocSmallAllocatorh"></a>
<div class="modfile"><h4>Modified: trunk/Source/bmalloc/bmalloc/SmallAllocator.h (173644 => 173645)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/bmalloc/bmalloc/SmallAllocator.h        2014-09-16 01:22:08 UTC (rev 173644)
+++ trunk/Source/bmalloc/bmalloc/SmallAllocator.h        2014-09-16 02:24:35 UTC (rev 173645)
</span><span class="lines">@@ -1,120 +0,0 @@
</span><del>-/*
- * Copyright (C) 2014 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
- */
-
-#ifndef SmallAllocator_h
-#define SmallAllocator_h
-
-#include &quot;BAssert.h&quot;
-#include &quot;SmallChunk.h&quot;
-#include &quot;SmallLine.h&quot;
-
-namespace bmalloc {
-
-// Helper object for allocating small objects.
-
-class SmallAllocator {
-public:
-    SmallAllocator();
-    SmallAllocator(size_t);
-    
-    bool isNull() { return !m_ptr; }
-    SmallLine* line();
-
-    bool canAllocate() { return !!m_remaining; }
-    void* allocate();
-
-    unsigned short objectCount();
-    unsigned char derefCount();
-
-    void refill(SmallLine*);
-    void clear();
-
-private:
-    char* m_ptr;
-    unsigned short m_size;
-    unsigned char m_remaining;
-    unsigned char m_maxObjectCount;
-};
-
-inline SmallAllocator::SmallAllocator()
-    : m_ptr()
-    , m_size()
-    , m_remaining()
-    , m_maxObjectCount()
-{
-}
-
-inline SmallAllocator::SmallAllocator(size_t size)
-    : m_ptr()
-    , m_size(size)
-    , m_remaining()
-    , m_maxObjectCount(smallLineSize / size)
-{
-}
-
-inline SmallLine* SmallAllocator::line()
-{
-    return SmallLine::get(canAllocate() ? m_ptr : m_ptr - 1);
-}
-
-inline void* SmallAllocator::allocate()
-{
-    BASSERT(m_remaining);
-    BASSERT(m_size &gt;= SmallLine::minimumObjectSize);
-
-    --m_remaining;
-    char* result = m_ptr;
-    m_ptr += m_size;
-    BASSERT(isSmall(result));
-    return result;
-}
-
-inline unsigned short SmallAllocator::objectCount()
-{
-    return m_maxObjectCount - m_remaining;
-}
-
-inline unsigned char SmallAllocator::derefCount()
-{
-    return SmallLine::maxRefCount - objectCount();
-}
-
-inline void SmallAllocator::refill(SmallLine* line)
-{
-    BASSERT(!canAllocate());
-    line-&gt;concurrentRef(SmallLine::maxRefCount);
-    m_ptr = line-&gt;begin();
-    m_remaining = m_maxObjectCount;
-}
-
-inline void SmallAllocator::clear()
-{
-    m_ptr = nullptr;
-    m_remaining = 0;
-}
-
-} // namespace bmalloc
-
-#endif // SmallAllocator_h
</del></span></pre></div>
<a id="trunkSourcebmallocbmallocxcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/bmalloc/bmalloc.xcodeproj/project.pbxproj (173644 => 173645)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/bmalloc/bmalloc.xcodeproj/project.pbxproj        2014-09-16 01:22:08 UTC (rev 173644)
+++ trunk/Source/bmalloc/bmalloc.xcodeproj/project.pbxproj        2014-09-16 02:24:35 UTC (rev 173645)
</span><span class="lines">@@ -27,7 +27,7 @@
</span><span class="cx">                 14DD789918F48D4A00950702 /* Cache.h in Headers */ = {isa = PBXBuildFile; fileRef = 144469E517A46BFE00F9EA1D /* Cache.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 14DD789A18F48D4A00950702 /* Deallocator.h in Headers */ = {isa = PBXBuildFile; fileRef = 145F685A179DC90200D65598 /* Deallocator.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 14DD789B18F48D4A00950702 /* MediumAllocator.h in Headers */ = {isa = PBXBuildFile; fileRef = 1413E47018A0661700546D68 /* MediumAllocator.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><del>-                14DD789C18F48D4A00950702 /* SmallAllocator.h in Headers */ = {isa = PBXBuildFile; fileRef = 1413E462189DE1CD00546D68 /* SmallAllocator.h */; settings = {ATTRIBUTES = (Private, ); }; };
</del><ins>+                14DD789C18F48D4A00950702 /* BumpAllocator.h in Headers */ = {isa = PBXBuildFile; fileRef = 1413E462189DE1CD00546D68 /* BumpAllocator.h */; settings = {ATTRIBUTES = (Private, ); }; };
</ins><span class="cx">                 14DD78B418F48D6B00950702 /* Chunk.h in Headers */ = {isa = PBXBuildFile; fileRef = 147AAA9418CE5CA6002201E4 /* Chunk.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 14DD78B518F48D6B00950702 /* Line.h in Headers */ = {isa = PBXBuildFile; fileRef = 14DA32071885F9E6007269E0 /* Line.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 14DD78B618F48D6B00950702 /* MediumChunk.h in Headers */ = {isa = PBXBuildFile; fileRef = 147AAA8E18CD89E3002201E4 /* MediumChunk.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="lines">@@ -75,7 +75,7 @@
</span><span class="cx">                 14105E7B18DBD7AF003A106E /* BoundaryTagInlines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BoundaryTagInlines.h; path = bmalloc/BoundaryTagInlines.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 14105E8318E14374003A106E /* ObjectType.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ObjectType.cpp; path = bmalloc/ObjectType.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 1413E460189DCE1E00546D68 /* Inline.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Inline.h; path = bmalloc/Inline.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><del>-                1413E462189DE1CD00546D68 /* SmallAllocator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = SmallAllocator.h; path = bmalloc/SmallAllocator.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</del><ins>+                1413E462189DE1CD00546D68 /* BumpAllocator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = BumpAllocator.h; path = bmalloc/BumpAllocator.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</ins><span class="cx">                 1413E468189EEDE400546D68 /* BAssert.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BAssert.h; path = bmalloc/BAssert.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 1413E47018A0661700546D68 /* MediumAllocator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MediumAllocator.h; path = bmalloc/MediumAllocator.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 1417F64518B54A700076FA3F /* BeginTag.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BeginTag.h; path = bmalloc/BeginTag.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="lines">@@ -236,7 +236,7 @@
</span><span class="cx">                                 145F6859179DC90200D65598 /* Deallocator.cpp */,
</span><span class="cx">                                 145F685A179DC90200D65598 /* Deallocator.h */,
</span><span class="cx">                                 1413E47018A0661700546D68 /* MediumAllocator.h */,
</span><del>-                                1413E462189DE1CD00546D68 /* SmallAllocator.h */,
</del><ins>+                                1413E462189DE1CD00546D68 /* BumpAllocator.h */,
</ins><span class="cx">                         );
</span><span class="cx">                         name = cache;
</span><span class="cx">                         sourceTree = &quot;&lt;group&gt;&quot;;
</span><span class="lines">@@ -307,7 +307,7 @@
</span><span class="cx">                                 1400274C18F89C3D00115C97 /* SegregatedFreeList.h in Headers */,
</span><span class="cx">                                 14DD788D18F48CC600950702 /* BeginTag.h in Headers */,
</span><span class="cx">                                 14DD78CD18F48D7500950702 /* Range.h in Headers */,
</span><del>-                                14DD789C18F48D4A00950702 /* SmallAllocator.h in Headers */,
</del><ins>+                                14DD789C18F48D4A00950702 /* BumpAllocator.h in Headers */,
</ins><span class="cx">                                 14DD789918F48D4A00950702 /* Cache.h in Headers */,
</span><span class="cx">                                 14DD789B18F48D4A00950702 /* MediumAllocator.h in Headers */,
</span><span class="cx">                                 14DD78BE18F48D6B00950702 /* SmallTraits.h in Headers */,
</span></span></pre>
</div>
</div>

</body>
</html>