Changeset 167546 in webkit


Ignore:
Timestamp:
Apr 19, 2014, 1:41:16 PM (11 years ago)
Author:
ggaren@apple.com
Message:

2014-04-19 Geoffrey Garen <ggaren@apple.com>

Rolled out r167502 because it caused a crash on the facebook benchmark.

Unreviewed.

bmalloc: Added an XSmall line size
https://bugs.webkit.org/show_bug.cgi?id=131851

Reviewed by Sam Weinig.

Location:
trunk/Source/bmalloc
Files:
5 deleted
21 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/bmalloc/ChangeLog

    r167540 r167546  
     12014-04-19  Geoffrey Garen  <ggaren@apple.com>
     2
     3        Rolled out r167502 because it caused a crash on the facebook benchmark.
     4
     5        Unreviewed.
     6
     7            bmalloc: Added an XSmall line size
     8            https://bugs.webkit.org/show_bug.cgi?id=131851
     9
     10            Reviewed by Sam Weinig.
     11
    1122014-04-19  Geoffrey Garen  <ggaren@apple.com>
    213
  • trunk/Source/bmalloc/bmalloc.xcodeproj/project.pbxproj

    r167540 r167546  
    1212                1400274B18F89C3D00115C97 /* BoundaryTagInlines.h in Headers */ = {isa = PBXBuildFile; fileRef = 14105E7B18DBD7AF003A106E /* BoundaryTagInlines.h */; settings = {ATTRIBUTES = (Private, ); }; };
    1313                1400274C18F89C3D00115C97 /* SegregatedFreeList.h in Headers */ = {isa = PBXBuildFile; fileRef = 146BEE1E18C841C50002D5A2 /* SegregatedFreeList.h */; settings = {ATTRIBUTES = (Private, ); }; };
    14                 142FCC78190080B8009032D4 /* XSmallChunk.h in Headers */ = {isa = PBXBuildFile; fileRef = 142FCC74190080B8009032D4 /* XSmallChunk.h */; };
    15                 142FCC79190080B8009032D4 /* XSmallLine.h in Headers */ = {isa = PBXBuildFile; fileRef = 142FCC75190080B8009032D4 /* XSmallLine.h */; };
    16                 142FCC7A190080B8009032D4 /* XSmallPage.h in Headers */ = {isa = PBXBuildFile; fileRef = 142FCC76190080B8009032D4 /* XSmallPage.h */; };
    17                 142FCC7B190080B8009032D4 /* XSmallTraits.h in Headers */ = {isa = PBXBuildFile; fileRef = 142FCC77190080B8009032D4 /* XSmallTraits.h */; };
    18                 142FCC7D1900815E009032D4 /* XSmallAllocator.h in Headers */ = {isa = PBXBuildFile; fileRef = 142FCC7C1900815E009032D4 /* XSmallAllocator.h */; };
    1914                143CB81C19022BC900B16A45 /* StaticMutex.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 143CB81A19022BC900B16A45 /* StaticMutex.cpp */; };
    2015                143CB81D19022BC900B16A45 /* StaticMutex.h in Headers */ = {isa = PBXBuildFile; fileRef = 143CB81B19022BC900B16A45 /* StaticMutex.h */; };
     
    8984                1417F65218BA88A00076FA3F /* AsyncTask.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AsyncTask.h; path = bmalloc/AsyncTask.h; sourceTree = "<group>"; };
    9085                1421A87718EE462A00B4DD68 /* Algorithm.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = Algorithm.h; path = bmalloc/Algorithm.h; sourceTree = "<group>"; };
    91                 142FCC74190080B8009032D4 /* XSmallChunk.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = XSmallChunk.h; path = bmalloc/XSmallChunk.h; sourceTree = "<group>"; };
    92                 142FCC75190080B8009032D4 /* XSmallLine.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = XSmallLine.h; path = bmalloc/XSmallLine.h; sourceTree = "<group>"; };
    93                 142FCC76190080B8009032D4 /* XSmallPage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = XSmallPage.h; path = bmalloc/XSmallPage.h; sourceTree = "<group>"; };
    94                 142FCC77190080B8009032D4 /* XSmallTraits.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = XSmallTraits.h; path = bmalloc/XSmallTraits.h; sourceTree = "<group>"; };
    95                 142FCC7C1900815E009032D4 /* XSmallAllocator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = XSmallAllocator.h; path = bmalloc/XSmallAllocator.h; sourceTree = "<group>"; };
    9686                143CB81A19022BC900B16A45 /* StaticMutex.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = StaticMutex.cpp; path = bmalloc/StaticMutex.cpp; sourceTree = "<group>"; };
    9787                143CB81B19022BC900B16A45 /* StaticMutex.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = StaticMutex.h; path = bmalloc/StaticMutex.h; sourceTree = "<group>"; };
     
    208198                                143E29ED18CAE90500FE8A0F /* SmallPage.h */,
    209199                                147AAA9718CE5FB6002201E4 /* SmallTraits.h */,
    210                                 142FCC74190080B8009032D4 /* XSmallChunk.h */,
    211                                 142FCC75190080B8009032D4 /* XSmallLine.h */,
    212                                 142FCC76190080B8009032D4 /* XSmallPage.h */,
    213                                 142FCC77190080B8009032D4 /* XSmallTraits.h */,
    214200                        );
    215201                        name = "heap: small | medium";
     
    254240                                1413E47018A0661700546D68 /* MediumAllocator.h */,
    255241                                1413E462189DE1CD00546D68 /* SmallAllocator.h */,
    256                                 142FCC7C1900815E009032D4 /* XSmallAllocator.h */,
    257242                        );
    258243                        name = cache;
     
    309294                        buildActionMask = 2147483647;
    310295                        files = (
    311                                 142FCC7B190080B8009032D4 /* XSmallTraits.h in Headers */,
    312296                                14DD78B518F48D6B00950702 /* Line.h in Headers */,
    313297                                14DD78CF18F48D7500950702 /* Vector.h in Headers */,
     
    318302                                14DD78B418F48D6B00950702 /* Chunk.h in Headers */,
    319303                                14DD78CA18F48D7500950702 /* Mutex.h in Headers */,
    320                                 142FCC7D1900815E009032D4 /* XSmallAllocator.h in Headers */,
    321304                                143CB81D19022BC900B16A45 /* StaticMutex.h in Headers */,
    322305                                14DD78D118F48EC600950702 /* XLargeChunk.h in Headers */,
     
    340323                                14DD78C918F48D7500950702 /* Inline.h in Headers */,
    341324                                1400274A18F89C2300115C97 /* VMHeap.h in Headers */,
    342                                 142FCC7A190080B8009032D4 /* XSmallPage.h in Headers */,
    343325                                1400274918F89C1300115C97 /* Heap.h in Headers */,
    344326                                14DD78B818F48D6B00950702 /* MediumPage.h in Headers */,
     
    346328                                14DD78BD18F48D6B00950702 /* SmallPage.h in Headers */,
    347329                                1400274B18F89C3D00115C97 /* BoundaryTagInlines.h in Headers */,
    348                                 142FCC79190080B8009032D4 /* XSmallLine.h in Headers */,
    349                                 142FCC78190080B8009032D4 /* XSmallChunk.h in Headers */,
    350330                                14DD788E18F48CCD00950702 /* BoundaryTag.h in Headers */,
    351331                                14DD78C818F48D7500950702 /* FixedVector.h in Headers */,
  • trunk/Source/bmalloc/bmalloc/Allocator.cpp

    r167540 r167546  
    4444{
    4545    unsigned short size = alignment;
    46     for ( ; size <= xSmallMax; size += alignment)
    47         xSmallAllocatorFor(size) = XSmallAllocator(size);
    48 
    49     for ( ; size <= smallMax; size += alignment)
    50         smallAllocatorFor(size) = SmallAllocator(size);
     46    for (auto& allocator : m_smallAllocators) {
     47        allocator = SmallAllocator(size);
     48        size += alignment;
     49    }
    5150}
    5251
     
    5857void Allocator::scavenge()
    5958{
    60     for (auto& allocator : m_xSmallAllocators)
    61         log(allocator);
    62     processXSmallAllocatorLog();
    63 
    6459    for (auto& allocator : m_smallAllocators)
    6560        log(allocator);
     
    7065}
    7166
    72 void Allocator::log(XSmallAllocator& allocator)
     67void Allocator::log(SmallAllocator& allocator)
    7368{
     69    if (m_smallAllocatorLog.size() == m_smallAllocatorLog.capacity())
     70        processSmallAllocatorLog();
     71   
    7472    if (allocator.isNull())
    7573        return;
    7674
    77     if (m_xSmallAllocatorLog.size() == m_xSmallAllocatorLog.capacity())
    78         processXSmallAllocatorLog();
    79    
    80     m_xSmallAllocatorLog.push(std::make_pair(allocator.line(), allocator.derefCount()));
    81 }
    82 
    83 void Allocator::processXSmallAllocatorLog()
    84 {
    85     std::lock_guard<StaticMutex> lock(PerProcess<Heap>::mutex());
    86 
    87     for (auto& logEntry : m_xSmallAllocatorLog) {
    88         if (!logEntry.first->deref(lock, logEntry.second))
    89             continue;
    90         m_deallocator.deallocateXSmallLine(lock, logEntry.first);
    91     }
    92     m_xSmallAllocatorLog.clear();
    93 }
    94 
    95 void Allocator::log(SmallAllocator& allocator)
    96 {
    97     if (allocator.isNull())
    98         return;
    99 
    100     if (m_smallAllocatorLog.size() == m_smallAllocatorLog.capacity())
    101         processSmallAllocatorLog();
    102    
    10375    m_smallAllocatorLog.push(std::make_pair(allocator.line(), allocator.derefCount()));
    10476}
     
    11890void Allocator::log(MediumAllocator& allocator)
    11991{
     92    if (m_mediumAllocatorLog.size() == m_mediumAllocatorLog.capacity())
     93        processMediumAllocatorLog();
     94
    12095    if (allocator.isNull())
    12196        return;
    122 
    123     if (m_mediumAllocatorLog.size() == m_mediumAllocatorLog.capacity())
    124         processMediumAllocatorLog();
    12597
    12698    m_mediumAllocatorLog.push(std::make_pair(allocator.line(), allocator.derefCount()));
     
    173145    BASSERT(!allocateFastCase(size, dummy));
    174146)
    175     if (size <= xSmallMax) {
    176         XSmallAllocator& allocator = xSmallAllocatorFor(size);
    177         log(allocator);
    178         allocator.refill(m_deallocator.allocateXSmallLine());
    179         return allocator.allocate();
    180     }
    181 
    182147    if (size <= smallMax) {
    183148        SmallAllocator& allocator = smallAllocatorFor(size);
  • trunk/Source/bmalloc/bmalloc/Allocator.h

    r167502 r167546  
    3131#include "Sizes.h"
    3232#include "SmallAllocator.h"
    33 #include "XSmallAllocator.h"
    3433#include <array>
    3534
     
    5251
    5352private:
    54     XSmallAllocator& xSmallAllocatorFor(size_t);
    5553    SmallAllocator& smallAllocatorFor(size_t);
    56    
    5754    void* allocateFastCase(SmallAllocator&);
    5855
     
    6158    void* allocateXLarge(size_t);
    6259   
    63     void log(XSmallAllocator&);
    6460    void log(SmallAllocator&);
    6561    void log(MediumAllocator&);
    6662
    67     void processXSmallAllocatorLog();
    6863    void processSmallAllocatorLog();
    6964    void processMediumAllocatorLog();
     
    7166    Deallocator& m_deallocator;
    7267
    73     std::array<XSmallAllocator, xSmallMax / alignment> m_xSmallAllocators;
    7468    std::array<SmallAllocator, smallMax / alignment> m_smallAllocators;
    7569    MediumAllocator m_mediumAllocator;
    7670
    77     FixedVector<std::pair<XSmallLine*, unsigned char>, xSmallAllocatorLogCapacity> m_xSmallAllocatorLog;
    7871    FixedVector<std::pair<SmallLine*, unsigned char>, smallAllocatorLogCapacity> m_smallAllocatorLog;
    7972    FixedVector<std::pair<MediumLine*, unsigned char>, mediumAllocatorLogCapacity> m_mediumAllocatorLog;
    8073};
    81 
    82 inline XSmallAllocator& Allocator::xSmallAllocatorFor(size_t size)
    83 {
    84     size_t index = mask((size - 1ul) / alignment, m_xSmallAllocators.size() - 1);
    85     return m_xSmallAllocators[index];
    86 }
    8774
    8875inline SmallAllocator& Allocator::smallAllocatorFor(size_t size)
     
    9481inline bool Allocator::allocateFastCase(size_t size, void*& object)
    9582{
    96     if (size <= xSmallMax) {
    97         XSmallAllocator& allocator = xSmallAllocatorFor(size);
    98         if (!allocator.canAllocate())
    99             return false;
    100        
    101         object = allocator.allocate();
    102         return true;
    103     }
    104    
    105     if (size <= smallMax) {
    106         SmallAllocator& allocator = smallAllocatorFor(size);
    107         if (!allocator.canAllocate())
    108             return false;
     83    if (size > smallMax)
     84        return false;
    10985
    110         object = allocator.allocate();
    111         return true;
    112     }
    113    
    114     return false;
     86    SmallAllocator& allocator = smallAllocatorFor(size);
     87    if (!allocator.canAllocate())
     88        return false;
     89
     90    object = allocator.allocate();
     91    return true;
    11592}
    11693
  • trunk/Source/bmalloc/bmalloc/Chunk.h

    r167502 r167546  
    7878inline auto Chunk<Traits>::get(void* object) -> Chunk*
    7979{
    80     BASSERT(!isLarge(object));
     80    BASSERT(isSmallOrMedium(object));
    8181    return static_cast<Chunk*>(mask(object, chunkMask));
    8282}
  • trunk/Source/bmalloc/bmalloc/Deallocator.cpp

    r167540 r167546  
    3232#include "PerProcess.h"
    3333#include "SmallChunk.h"
    34 #include "XSmallChunk.h"
    3534#include <algorithm>
    3635#include <sys/mman.h>
     
    5958    Heap* heap = PerProcess<Heap>::getFastCase();
    6059   
    61     while (m_xSmallLineCache.size())
    62         heap->deallocateXSmallLine(lock, m_xSmallLineCache.pop());
    6360    while (m_smallLineCache.size())
    6461        heap->deallocateSmallLine(lock, m_smallLineCache.pop());
     
    8481   
    8582    for (auto object : m_objectLog) {
    86         if (isXSmall(object)) {
    87             XSmallLine* line = XSmallLine::get(object);
    88             if (!line->deref(lock))
    89                 continue;
    90             deallocateXSmallLine(lock, line);
    91         } else if (isSmall(object)) {
     83        if (isSmall(object)) {
    9284            SmallLine* line = SmallLine::get(object);
    9385            if (!line->deref(lock))
     
    9587            deallocateSmallLine(lock, line);
    9688        } else {
    97             BASSERT(isMedium(object));
     89            BASSERT(isSmallOrMedium(object));
    9890            MediumLine* line = MediumLine::get(object);
    9991            if (!line->deref(lock))
     
    113105        return;
    114106
    115     if (!isLarge(object)) {
     107    if (isSmallOrMedium(object)) {
    116108        processObjectLog();
    117109        m_objectLog.push(object);
     
    134126}
    135127
    136 void Deallocator::deallocateXSmallLine(std::lock_guard<StaticMutex>& lock, XSmallLine* line)
    137 {
    138     if (m_xSmallLineCache.size() == m_xSmallLineCache.capacity())
    139         return PerProcess<Heap>::getFastCase()->deallocateXSmallLine(lock, line);
    140 
    141     m_xSmallLineCache.push(line);
    142 }
    143 
    144128SmallLine* Deallocator::allocateSmallLine()
    145129{
     
    153137
    154138    return m_smallLineCache.pop();
    155 }
    156 
    157 XSmallLine* Deallocator::allocateXSmallLine()
    158 {
    159     if (!m_xSmallLineCache.size()) {
    160         std::lock_guard<StaticMutex> lock(PerProcess<Heap>::mutex());
    161         Heap* heap = PerProcess<Heap>::getFastCase();
    162 
    163         while (m_xSmallLineCache.size() != m_xSmallLineCache.capacity())
    164             m_xSmallLineCache.push(heap->allocateXSmallLine(lock));
    165     }
    166 
    167     return m_xSmallLineCache.pop();
    168139}
    169140
  • trunk/Source/bmalloc/bmalloc/Deallocator.h

    r167540 r167546  
    3131#include "Sizes.h"
    3232#include "SmallLine.h"
    33 #include "XSmallLine.h"
    3433
    3534namespace bmalloc {
     
    4544    bool deallocateFastCase(void*);
    4645    void deallocateSlowCase(void*);
    47 
    48     void deallocateXSmallLine(std::lock_guard<StaticMutex>&, XSmallLine*);
    49     XSmallLine* allocateXSmallLine();
    5046
    5147    void deallocateSmallLine(std::lock_guard<StaticMutex>&, SmallLine*);
     
    6359
    6460    FixedVector<void*, deallocatorLogCapacity> m_objectLog;
    65     FixedVector<XSmallLine*, xSmallLineCacheCapacity> m_xSmallLineCache;
    6661    FixedVector<SmallLine*, smallLineCacheCapacity> m_smallLineCache;
    6762    FixedVector<MediumLine*, mediumLineCacheCapacity> m_mediumLineCache;
     
    7065inline bool Deallocator::deallocateFastCase(void* object)
    7166{
    72     if (isLarge(object))
     67    if (!isSmallOrMedium(object))
    7368        return false;
    7469
  • trunk/Source/bmalloc/bmalloc/Heap.cpp

    r167540 r167546  
    3333#include "SmallChunk.h"
    3434#include "XLargeChunk.h"
    35 #include "XSmallChunk.h"
    3635#include <thread>
    3736
     
    6261void Heap::scavenge(std::unique_lock<StaticMutex>& lock, std::chrono::milliseconds sleepDuration)
    6362{
    64     scavengeXSmallPages(lock, sleepDuration);
    6563    scavengeSmallPages(lock, sleepDuration);
    6664    scavengeMediumPages(lock, sleepDuration);
     
    8381            return;
    8482        m_vmHeap.deallocateSmallPage(lock, m_smallPages.pop());
    85     }
    86 }
    87 
    88 void Heap::scavengeXSmallPages(std::unique_lock<StaticMutex>& lock, std::chrono::milliseconds sleepDuration)
    89 {
    90     while (1) {
    91         if (m_isAllocatingPages) {
    92             m_isAllocatingPages = false;
    93 
    94             sleep(lock, sleepDuration);
    95             continue;
    96         }
    97 
    98         if (!m_xSmallPages.size())
    99             return;
    100         m_vmHeap.deallocateXSmallPage(lock, m_xSmallPages.pop());
    10183    }
    10284}
     
    133115        m_vmHeap.deallocateLargeRange(lock, range);
    134116    }
    135 }
    136 
    137 XSmallLine* Heap::allocateXSmallLineSlowCase(std::lock_guard<StaticMutex>& lock)
    138 {
    139     m_isAllocatingPages = true;
    140 
    141     XSmallPage* page = [this]() {
    142         if (m_xSmallPages.size())
    143             return m_xSmallPages.pop();
    144        
    145         XSmallPage* page = m_vmHeap.allocateXSmallPage();
    146         vmAllocatePhysicalPages(page->begin()->begin(), vmPageSize);
    147         return page;
    148     }();
    149 
    150     XSmallLine* line = page->begin();
    151     for (auto it = line + 1; it != page->end(); ++it)
    152         m_xSmallLines.push(it);
    153 
    154     page->ref(lock);
    155     return line;
    156117}
    157118
  • trunk/Source/bmalloc/bmalloc/Heap.h

    r167540 r167546  
    2929#include "FixedVector.h"
    3030#include "VMHeap.h"
     31#include "MediumLine.h"
    3132#include "Mutex.h"
     33#include "SmallPage.h"
    3234#include "MediumChunk.h"
     35#include "MediumPage.h"
    3336#include "SegregatedFreeList.h"
    3437#include "SmallChunk.h"
     38#include "SmallLine.h"
    3539#include "Vector.h"
    36 #include "XSmallChunk.h"
    3740#include <array>
    3841#include <mutex>
     
    4649public:
    4750    Heap(std::lock_guard<StaticMutex>&);
    48    
    49     XSmallLine* allocateXSmallLine(std::lock_guard<StaticMutex>&);
    50     void deallocateXSmallLine(std::lock_guard<StaticMutex>&, XSmallLine*);
    5151
    5252    SmallLine* allocateSmallLine(std::lock_guard<StaticMutex>&);
     
    6767    ~Heap() = delete;
    6868
    69     XSmallLine* allocateXSmallLineSlowCase(std::lock_guard<StaticMutex>&);
    7069    SmallLine* allocateSmallLineSlowCase(std::lock_guard<StaticMutex>&);
    7170    MediumLine* allocateMediumLineSlowCase(std::lock_guard<StaticMutex>&);
     
    8079   
    8180    void concurrentScavenge();
    82     void scavengeXSmallPages(std::unique_lock<StaticMutex>&, std::chrono::milliseconds);
    8381    void scavengeSmallPages(std::unique_lock<StaticMutex>&, std::chrono::milliseconds);
    8482    void scavengeMediumPages(std::unique_lock<StaticMutex>&, std::chrono::milliseconds);
    8583    void scavengeLargeRanges(std::unique_lock<StaticMutex>&, std::chrono::milliseconds);
    8684
    87     Vector<XSmallLine*> m_xSmallLines;
    8885    Vector<SmallLine*> m_smallLines;
    8986    Vector<MediumLine*> m_mediumLines;
    9087
    91     Vector<XSmallPage*> m_xSmallPages;
    9288    Vector<SmallPage*> m_smallPages;
    9389    Vector<MediumPage*> m_mediumPages;
     
    10096    AsyncTask<Heap, decltype(&Heap::concurrentScavenge)> m_scavenger;
    10197};
    102 
    103 inline void Heap::deallocateXSmallLine(std::lock_guard<StaticMutex>& lock, XSmallLine* line)
    104 {
    105     XSmallPage* page = XSmallPage::get(line);
    106     if (page->deref(lock)) {
    107         m_xSmallPages.push(page);
    108         m_scavenger.run();
    109         return;
    110     }
    111     m_xSmallLines.push(line);
    112 }
    113 
    114 inline XSmallLine* Heap::allocateXSmallLine(std::lock_guard<StaticMutex>& lock)
    115 {
    116     while (m_xSmallLines.size()) {
    117         XSmallLine* line = m_xSmallLines.pop();
    118         XSmallPage* page = XSmallPage::get(line);
    119         if (!page->refCount(lock)) // The line was promoted to the small pages list.
    120             continue;
    121         page->ref(lock);
    122         return line;
    123     }
    124 
    125     return allocateXSmallLineSlowCase(lock);
    126 }
    12798
    12899inline void Heap::deallocateSmallLine(std::lock_guard<StaticMutex>& lock, SmallLine* line)
  • trunk/Source/bmalloc/bmalloc/LargeChunk.h

    r167502 r167546  
    7777inline LargeChunk* LargeChunk::get(void* object)
    7878{
    79     BASSERT(isLarge(object));
     79    BASSERT(!isSmallOrMedium(object));
    8080    return static_cast<LargeChunk*>(mask(object, largeChunkMask));
    8181}
     
    9090inline EndTag* LargeChunk::endTag(void* object, size_t size)
    9191{
    92     BASSERT(isLarge(object));
     92    BASSERT(!isSmallOrMedium(object));
    9393
    9494    LargeChunk* chunk = get(object);
  • trunk/Source/bmalloc/bmalloc/Line.h

    r167540 r167546  
    5959inline auto Line<Traits>::get(void* object) -> Line*
    6060{
    61     BASSERT(!isLarge(object));
     61    BASSERT(isSmallOrMedium(object));
    6262    Chunk* chunk = Chunk::get(object);
    6363    size_t lineNumber = (reinterpret_cast<char*>(object) - reinterpret_cast<char*>(chunk)) / lineSize;
  • trunk/Source/bmalloc/bmalloc/MediumAllocator.h

    r167502 r167546  
    7474    m_remaining -= size;
    7575    void* object = m_end - m_remaining - size;
    76     BASSERT(objectType(object) == Medium);
     76    BASSERT(isSmallOrMedium(object) && !isSmall(object));
    7777
    7878    ++m_objectCount;
     
    100100    m_remaining = mediumLineSize;
    101101    m_objectCount = 0;
    102     BASSERT(objectType(m_end - 1) == Medium);
    103102}
    104103
  • trunk/Source/bmalloc/bmalloc/ObjectType.cpp

    r167502 r167546  
    3131ObjectType objectType(void* object)
    3232{
    33     switch (mask(reinterpret_cast<uintptr_t>(object), typeMask)) {
    34     case xSmallType: {
    35         return XSmall;
    36     }
    37     case smallType: {
    38         return Small;
    39     }
    40     case mediumType: {
     33    if (isSmallOrMedium(object)) {
     34        if (isSmall(object))
     35            return Small;
    4136        return Medium;
    4237    }
    43     case largeType: {
    44         BeginTag* beginTag = LargeChunk::beginTag(object);
    45         if (!beginTag->isXLarge())
    46             return Large;
    47         return XLarge;
    48     }
    49     default: {
    50         RELEASE_BASSERT(false);
    51         return XLarge;
    52     }
    53     }
     38   
     39    BeginTag* beginTag = LargeChunk::beginTag(object);
     40    if (!beginTag->isXLarge())
     41        return Large;
     42    return XLarge;
    5443}
    5544
  • trunk/Source/bmalloc/bmalloc/ObjectType.h

    r167502 r167546  
    3232namespace bmalloc {
    3333
    34 enum ObjectType { XSmall, Small, Medium, Large, XLarge };
     34enum ObjectType { Small, Medium, Large, XLarge };
    3535
    3636ObjectType objectType(void*);
    3737
    38 inline bool isXSmall(void* object)
     38inline bool isSmallOrMedium(void* object)
    3939{
    40     return mask(reinterpret_cast<uintptr_t>(object), typeMask) == xSmallType;
     40    return test(object, smallOrMediumTypeMask);
    4141}
    4242
    43 inline bool isSmall(void* object)
     43inline bool isSmall(void* smallOrMedium)
    4444{
    45     return mask(reinterpret_cast<uintptr_t>(object), typeMask) == smallType;
    46 }
    47 
    48 inline bool isMedium(void* object)
    49 {
    50     return mask(reinterpret_cast<uintptr_t>(object), typeMask) == mediumType;
    51 }
    52 
    53 inline bool isLarge(void* object)
    54 {
    55     return mask(reinterpret_cast<uintptr_t>(object), typeMask) == largeType;
     45    BASSERT(isSmallOrMedium(smallOrMedium));
     46    return test(smallOrMedium, smallOrMediumSmallTypeMask);
    5647}
    5748
  • trunk/Source/bmalloc/bmalloc/SegregatedFreeList.h

    r167502 r167546  
    5959    Range takeGreedy(List&, size_t);
    6060
    61     std::array<List, 18> m_lists;
     61    std::array<List, 19> m_lists;
    6262};
    6363
  • trunk/Source/bmalloc/bmalloc/Sizes.h

    r167502 r167546  
    4848    static const size_t superChunkSize = 32 * MB;
    4949
    50     static const size_t xSmallMax = 64;
    51     static const size_t xSmallLineSize = 256;
    52     static const size_t xSmallLineMask = ~(xSmallLineSize - 1ul);
    53 
    54     static const size_t xSmallChunkSize = superChunkSize / 4;
    55     static const size_t xSmallChunkOffset = superChunkSize * 1 / 4;
    56     static const size_t xSmallChunkMask = ~(xSmallChunkSize - 1ul);
    57 
    58     static const size_t smallMax = 128;
    59     static const size_t smallLineSize = 256;
     50    static const size_t smallMax = 256;
     51    static const size_t smallLineSize = 512;
    6052    static const size_t smallLineMask = ~(smallLineSize - 1ul);
    6153
    6254    static const size_t smallChunkSize = superChunkSize / 4;
    63     static const size_t smallChunkOffset = superChunkSize * 2 / 4;
     55    static const size_t smallChunkOffset = superChunkSize * 3 / 4;
    6456    static const size_t smallChunkMask = ~(smallChunkSize - 1ul);
    6557
    66     static const size_t mediumMax = 256;
    67     static const size_t mediumLineSize = 512;
     58    static const size_t mediumMax = 1024;
     59    static const size_t mediumLineSize = 2048;
    6860    static const size_t mediumLineMask = ~(mediumLineSize - 1ul);
    6961
    7062    static const size_t mediumChunkSize = superChunkSize / 4;
    71     static const size_t mediumChunkOffset = superChunkSize * 3 / 4;
     63    static const size_t mediumChunkOffset = superChunkSize * 2 / 4;
    7264    static const size_t mediumChunkMask = ~(mediumChunkSize - 1ul);
    7365
    74     static const size_t largeChunkSize = superChunkSize / 4;
    75     static const size_t largeChunkOffset = superChunkSize * 0 / 4;
     66    static const size_t largeChunkSize = superChunkSize / 2;
     67    static const size_t largeChunkOffset = 0;
    7668    static const size_t largeChunkMask = ~(largeChunkSize - 1ul);
    7769
    7870    static const size_t largeAlignment = 64;
    7971    static const size_t largeMax = largeChunkSize * 99 / 100; // Plenty of room for metadata.
    80     static const size_t largeMin = mediumMax;
     72    static const size_t largeMin = 1024;
    8173
    8274    static const size_t segregatedFreeListSearchDepth = 16;
    8375
    8476    static const uintptr_t typeMask = (superChunkSize - 1) & ~((superChunkSize / 4) - 1); // 4 taggable chunks
    85     static const uintptr_t xSmallType = (superChunkSize + xSmallChunkOffset) & typeMask;
    8677    static const uintptr_t smallType = (superChunkSize + smallChunkOffset) & typeMask;
    8778    static const uintptr_t mediumType = (superChunkSize + mediumChunkOffset) & typeMask;
    88     static const uintptr_t largeType = (superChunkSize + largeChunkOffset) & typeMask;
    89    
     79    static const uintptr_t largeTypeMask = ~(mediumType & smallType);
     80    static const uintptr_t smallOrMediumTypeMask = mediumType & smallType;
     81    static const uintptr_t smallOrMediumSmallTypeMask = smallType ^ mediumType; // Only valid if object is known to be small or medium.
     82
    9083    static const size_t deallocatorLogCapacity = 256;
    9184
    92     static const size_t xSmallLineCacheCapacity = 32;
    9385    static const size_t smallLineCacheCapacity = 16;
    9486    static const size_t mediumLineCacheCapacity = 8;
    9587
    96     static const size_t xSmallAllocatorLogCapacity = 32;
    9788    static const size_t smallAllocatorLogCapacity = 16;
    9889    static const size_t mediumAllocatorLogCapacity = 8;
  • trunk/Source/bmalloc/bmalloc/SmallAllocator.h

    r167502 r167546  
    2929#include "BAssert.h"
    3030#include "SmallChunk.h"
     31#include "SmallLine.h"
    3132
    3233namespace bmalloc {
     
    8586    char* result = m_ptr;
    8687    m_ptr += m_size;
    87     BASSERT(objectType(result) == Small);
     88    BASSERT(isSmall(result));
    8889    return result;
    8990}
  • trunk/Source/bmalloc/bmalloc/SmallTraits.h

    r167502 r167546  
    4141
    4242    static const size_t lineSize = smallLineSize;
    43     static const size_t minimumObjectSize = xSmallMax + alignment;
     43    static const size_t minimumObjectSize = alignment;
    4444    static const size_t chunkSize = smallChunkSize;
    4545    static const size_t chunkOffset = smallChunkOffset;
  • trunk/Source/bmalloc/bmalloc/VMHeap.cpp

    r167502 r167546  
    3737}
    3838
    39 void VMHeap::allocateXSmallChunk()
    40 {
    41     XSmallChunk* chunk = XSmallChunk::create();
    42     for (auto* it = chunk->begin(); it != chunk->end(); ++it)
    43         m_xSmallPages.push(it);
    44 }
    45 
    4639void VMHeap::allocateSmallChunk()
    4740{
  • trunk/Source/bmalloc/bmalloc/VMHeap.h

    r167540 r167546  
    3535#include "SmallChunk.h"
    3636#include "Vector.h"
    37 #include "XSmallChunk.h"
    3837
    3938namespace bmalloc {
     
    4746    VMHeap();
    4847
    49     XSmallPage* allocateXSmallPage();
    5048    SmallPage* allocateSmallPage();
    5149    MediumPage* allocateMediumPage();
    5250    Range allocateLargeRange(size_t);
    5351
    54     void deallocateXSmallPage(std::unique_lock<StaticMutex>&, XSmallPage*);
    5552    void deallocateSmallPage(std::unique_lock<StaticMutex>&, SmallPage*);
    5653    void deallocateMediumPage(std::unique_lock<StaticMutex>&, MediumPage*);
     
    5855
    5956private:
    60     void allocateXSmallChunk();
    6157    void allocateSmallChunk();
    6258    void allocateMediumChunk();
    6359    Range allocateLargeChunk();
    6460   
    65     Vector<XSmallPage*> m_xSmallPages;
    6661    Vector<SmallPage*> m_smallPages;
    6762    Vector<MediumPage*> m_mediumPages;
    6863    SegregatedFreeList m_largeRanges;
    6964};
    70 
    71 inline XSmallPage* VMHeap::allocateXSmallPage()
    72 {
    73     if (!m_xSmallPages.size())
    74         allocateXSmallChunk();
    75 
    76     return m_xSmallPages.pop();
    77 }
    7865
    7966inline SmallPage* VMHeap::allocateSmallPage()
     
    9986        range = allocateLargeChunk();
    10087    return range;
    101 }
    102 
    103 inline void VMHeap::deallocateXSmallPage(std::unique_lock<StaticMutex>& lock, XSmallPage* page)
    104 {
    105     lock.unlock();
    106     vmDeallocatePhysicalPages(page->begin()->begin(), vmPageSize);
    107     lock.lock();
    108    
    109     m_xSmallPages.push(page);
    11088}
    11189
  • trunk/Source/bmalloc/bmalloc/bmalloc.h

    r167540 r167546  
    5151
    5252    size_t oldSize = 0;
    53     switch (objectType(object)) {
    54     case XSmall: {
    55         // We don't have an exact size, but we can calculate a maximum.
    56         void* end = roundUpToMultipleOf<xSmallLineSize>(static_cast<char*>(object) + 1);
    57         oldSize = static_cast<char*>(end) - static_cast<char*>(object);
    58         break;
    59     }
     53    switch(objectType(object)) {
    6054    case Small: {
    6155        // We don't have an exact size, but we can calculate a maximum.
Note: See TracChangeset for help on using the changeset viewer.