Changeset 167546 in webkit
- Timestamp:
- Apr 19, 2014, 1:41:16 PM (11 years ago)
- Location:
- trunk/Source/bmalloc
- Files:
-
- 5 deleted
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/bmalloc/ChangeLog
r167540 r167546 1 2014-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 1 12 2014-04-19 Geoffrey Garen <ggaren@apple.com> 2 13 -
trunk/Source/bmalloc/bmalloc.xcodeproj/project.pbxproj
r167540 r167546 12 12 1400274B18F89C3D00115C97 /* BoundaryTagInlines.h in Headers */ = {isa = PBXBuildFile; fileRef = 14105E7B18DBD7AF003A106E /* BoundaryTagInlines.h */; settings = {ATTRIBUTES = (Private, ); }; }; 13 13 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 */; };19 14 143CB81C19022BC900B16A45 /* StaticMutex.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 143CB81A19022BC900B16A45 /* StaticMutex.cpp */; }; 20 15 143CB81D19022BC900B16A45 /* StaticMutex.h in Headers */ = {isa = PBXBuildFile; fileRef = 143CB81B19022BC900B16A45 /* StaticMutex.h */; }; … … 89 84 1417F65218BA88A00076FA3F /* AsyncTask.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AsyncTask.h; path = bmalloc/AsyncTask.h; sourceTree = "<group>"; }; 90 85 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>"; };96 86 143CB81A19022BC900B16A45 /* StaticMutex.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = StaticMutex.cpp; path = bmalloc/StaticMutex.cpp; sourceTree = "<group>"; }; 97 87 143CB81B19022BC900B16A45 /* StaticMutex.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = StaticMutex.h; path = bmalloc/StaticMutex.h; sourceTree = "<group>"; }; … … 208 198 143E29ED18CAE90500FE8A0F /* SmallPage.h */, 209 199 147AAA9718CE5FB6002201E4 /* SmallTraits.h */, 210 142FCC74190080B8009032D4 /* XSmallChunk.h */,211 142FCC75190080B8009032D4 /* XSmallLine.h */,212 142FCC76190080B8009032D4 /* XSmallPage.h */,213 142FCC77190080B8009032D4 /* XSmallTraits.h */,214 200 ); 215 201 name = "heap: small | medium"; … … 254 240 1413E47018A0661700546D68 /* MediumAllocator.h */, 255 241 1413E462189DE1CD00546D68 /* SmallAllocator.h */, 256 142FCC7C1900815E009032D4 /* XSmallAllocator.h */,257 242 ); 258 243 name = cache; … … 309 294 buildActionMask = 2147483647; 310 295 files = ( 311 142FCC7B190080B8009032D4 /* XSmallTraits.h in Headers */,312 296 14DD78B518F48D6B00950702 /* Line.h in Headers */, 313 297 14DD78CF18F48D7500950702 /* Vector.h in Headers */, … … 318 302 14DD78B418F48D6B00950702 /* Chunk.h in Headers */, 319 303 14DD78CA18F48D7500950702 /* Mutex.h in Headers */, 320 142FCC7D1900815E009032D4 /* XSmallAllocator.h in Headers */,321 304 143CB81D19022BC900B16A45 /* StaticMutex.h in Headers */, 322 305 14DD78D118F48EC600950702 /* XLargeChunk.h in Headers */, … … 340 323 14DD78C918F48D7500950702 /* Inline.h in Headers */, 341 324 1400274A18F89C2300115C97 /* VMHeap.h in Headers */, 342 142FCC7A190080B8009032D4 /* XSmallPage.h in Headers */,343 325 1400274918F89C1300115C97 /* Heap.h in Headers */, 344 326 14DD78B818F48D6B00950702 /* MediumPage.h in Headers */, … … 346 328 14DD78BD18F48D6B00950702 /* SmallPage.h in Headers */, 347 329 1400274B18F89C3D00115C97 /* BoundaryTagInlines.h in Headers */, 348 142FCC79190080B8009032D4 /* XSmallLine.h in Headers */,349 142FCC78190080B8009032D4 /* XSmallChunk.h in Headers */,350 330 14DD788E18F48CCD00950702 /* BoundaryTag.h in Headers */, 351 331 14DD78C818F48D7500950702 /* FixedVector.h in Headers */, -
trunk/Source/bmalloc/bmalloc/Allocator.cpp
r167540 r167546 44 44 { 45 45 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 } 51 50 } 52 51 … … 58 57 void Allocator::scavenge() 59 58 { 60 for (auto& allocator : m_xSmallAllocators)61 log(allocator);62 processXSmallAllocatorLog();63 64 59 for (auto& allocator : m_smallAllocators) 65 60 log(allocator); … … 70 65 } 71 66 72 void Allocator::log( XSmallAllocator& allocator)67 void Allocator::log(SmallAllocator& allocator) 73 68 { 69 if (m_smallAllocatorLog.size() == m_smallAllocatorLog.capacity()) 70 processSmallAllocatorLog(); 71 74 72 if (allocator.isNull()) 75 73 return; 76 74 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 103 75 m_smallAllocatorLog.push(std::make_pair(allocator.line(), allocator.derefCount())); 104 76 } … … 118 90 void Allocator::log(MediumAllocator& allocator) 119 91 { 92 if (m_mediumAllocatorLog.size() == m_mediumAllocatorLog.capacity()) 93 processMediumAllocatorLog(); 94 120 95 if (allocator.isNull()) 121 96 return; 122 123 if (m_mediumAllocatorLog.size() == m_mediumAllocatorLog.capacity())124 processMediumAllocatorLog();125 97 126 98 m_mediumAllocatorLog.push(std::make_pair(allocator.line(), allocator.derefCount())); … … 173 145 BASSERT(!allocateFastCase(size, dummy)); 174 146 ) 175 if (size <= xSmallMax) {176 XSmallAllocator& allocator = xSmallAllocatorFor(size);177 log(allocator);178 allocator.refill(m_deallocator.allocateXSmallLine());179 return allocator.allocate();180 }181 182 147 if (size <= smallMax) { 183 148 SmallAllocator& allocator = smallAllocatorFor(size); -
trunk/Source/bmalloc/bmalloc/Allocator.h
r167502 r167546 31 31 #include "Sizes.h" 32 32 #include "SmallAllocator.h" 33 #include "XSmallAllocator.h"34 33 #include <array> 35 34 … … 52 51 53 52 private: 54 XSmallAllocator& xSmallAllocatorFor(size_t);55 53 SmallAllocator& smallAllocatorFor(size_t); 56 57 54 void* allocateFastCase(SmallAllocator&); 58 55 … … 61 58 void* allocateXLarge(size_t); 62 59 63 void log(XSmallAllocator&);64 60 void log(SmallAllocator&); 65 61 void log(MediumAllocator&); 66 62 67 void processXSmallAllocatorLog();68 63 void processSmallAllocatorLog(); 69 64 void processMediumAllocatorLog(); … … 71 66 Deallocator& m_deallocator; 72 67 73 std::array<XSmallAllocator, xSmallMax / alignment> m_xSmallAllocators;74 68 std::array<SmallAllocator, smallMax / alignment> m_smallAllocators; 75 69 MediumAllocator m_mediumAllocator; 76 70 77 FixedVector<std::pair<XSmallLine*, unsigned char>, xSmallAllocatorLogCapacity> m_xSmallAllocatorLog;78 71 FixedVector<std::pair<SmallLine*, unsigned char>, smallAllocatorLogCapacity> m_smallAllocatorLog; 79 72 FixedVector<std::pair<MediumLine*, unsigned char>, mediumAllocatorLogCapacity> m_mediumAllocatorLog; 80 73 }; 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 }87 74 88 75 inline SmallAllocator& Allocator::smallAllocatorFor(size_t size) … … 94 81 inline bool Allocator::allocateFastCase(size_t size, void*& object) 95 82 { 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; 109 85 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; 115 92 } 116 93 -
trunk/Source/bmalloc/bmalloc/Chunk.h
r167502 r167546 78 78 inline auto Chunk<Traits>::get(void* object) -> Chunk* 79 79 { 80 BASSERT( !isLarge(object));80 BASSERT(isSmallOrMedium(object)); 81 81 return static_cast<Chunk*>(mask(object, chunkMask)); 82 82 } -
trunk/Source/bmalloc/bmalloc/Deallocator.cpp
r167540 r167546 32 32 #include "PerProcess.h" 33 33 #include "SmallChunk.h" 34 #include "XSmallChunk.h"35 34 #include <algorithm> 36 35 #include <sys/mman.h> … … 59 58 Heap* heap = PerProcess<Heap>::getFastCase(); 60 59 61 while (m_xSmallLineCache.size())62 heap->deallocateXSmallLine(lock, m_xSmallLineCache.pop());63 60 while (m_smallLineCache.size()) 64 61 heap->deallocateSmallLine(lock, m_smallLineCache.pop()); … … 84 81 85 82 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)) { 92 84 SmallLine* line = SmallLine::get(object); 93 85 if (!line->deref(lock)) … … 95 87 deallocateSmallLine(lock, line); 96 88 } else { 97 BASSERT(is Medium(object));89 BASSERT(isSmallOrMedium(object)); 98 90 MediumLine* line = MediumLine::get(object); 99 91 if (!line->deref(lock)) … … 113 105 return; 114 106 115 if ( !isLarge(object)) {107 if (isSmallOrMedium(object)) { 116 108 processObjectLog(); 117 109 m_objectLog.push(object); … … 134 126 } 135 127 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 144 128 SmallLine* Deallocator::allocateSmallLine() 145 129 { … … 153 137 154 138 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();168 139 } 169 140 -
trunk/Source/bmalloc/bmalloc/Deallocator.h
r167540 r167546 31 31 #include "Sizes.h" 32 32 #include "SmallLine.h" 33 #include "XSmallLine.h"34 33 35 34 namespace bmalloc { … … 45 44 bool deallocateFastCase(void*); 46 45 void deallocateSlowCase(void*); 47 48 void deallocateXSmallLine(std::lock_guard<StaticMutex>&, XSmallLine*);49 XSmallLine* allocateXSmallLine();50 46 51 47 void deallocateSmallLine(std::lock_guard<StaticMutex>&, SmallLine*); … … 63 59 64 60 FixedVector<void*, deallocatorLogCapacity> m_objectLog; 65 FixedVector<XSmallLine*, xSmallLineCacheCapacity> m_xSmallLineCache;66 61 FixedVector<SmallLine*, smallLineCacheCapacity> m_smallLineCache; 67 62 FixedVector<MediumLine*, mediumLineCacheCapacity> m_mediumLineCache; … … 70 65 inline bool Deallocator::deallocateFastCase(void* object) 71 66 { 72 if ( isLarge(object))67 if (!isSmallOrMedium(object)) 73 68 return false; 74 69 -
trunk/Source/bmalloc/bmalloc/Heap.cpp
r167540 r167546 33 33 #include "SmallChunk.h" 34 34 #include "XLargeChunk.h" 35 #include "XSmallChunk.h"36 35 #include <thread> 37 36 … … 62 61 void Heap::scavenge(std::unique_lock<StaticMutex>& lock, std::chrono::milliseconds sleepDuration) 63 62 { 64 scavengeXSmallPages(lock, sleepDuration);65 63 scavengeSmallPages(lock, sleepDuration); 66 64 scavengeMediumPages(lock, sleepDuration); … … 83 81 return; 84 82 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());101 83 } 102 84 } … … 133 115 m_vmHeap.deallocateLargeRange(lock, range); 134 116 } 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;156 117 } 157 118 -
trunk/Source/bmalloc/bmalloc/Heap.h
r167540 r167546 29 29 #include "FixedVector.h" 30 30 #include "VMHeap.h" 31 #include "MediumLine.h" 31 32 #include "Mutex.h" 33 #include "SmallPage.h" 32 34 #include "MediumChunk.h" 35 #include "MediumPage.h" 33 36 #include "SegregatedFreeList.h" 34 37 #include "SmallChunk.h" 38 #include "SmallLine.h" 35 39 #include "Vector.h" 36 #include "XSmallChunk.h"37 40 #include <array> 38 41 #include <mutex> … … 46 49 public: 47 50 Heap(std::lock_guard<StaticMutex>&); 48 49 XSmallLine* allocateXSmallLine(std::lock_guard<StaticMutex>&);50 void deallocateXSmallLine(std::lock_guard<StaticMutex>&, XSmallLine*);51 51 52 52 SmallLine* allocateSmallLine(std::lock_guard<StaticMutex>&); … … 67 67 ~Heap() = delete; 68 68 69 XSmallLine* allocateXSmallLineSlowCase(std::lock_guard<StaticMutex>&);70 69 SmallLine* allocateSmallLineSlowCase(std::lock_guard<StaticMutex>&); 71 70 MediumLine* allocateMediumLineSlowCase(std::lock_guard<StaticMutex>&); … … 80 79 81 80 void concurrentScavenge(); 82 void scavengeXSmallPages(std::unique_lock<StaticMutex>&, std::chrono::milliseconds);83 81 void scavengeSmallPages(std::unique_lock<StaticMutex>&, std::chrono::milliseconds); 84 82 void scavengeMediumPages(std::unique_lock<StaticMutex>&, std::chrono::milliseconds); 85 83 void scavengeLargeRanges(std::unique_lock<StaticMutex>&, std::chrono::milliseconds); 86 84 87 Vector<XSmallLine*> m_xSmallLines;88 85 Vector<SmallLine*> m_smallLines; 89 86 Vector<MediumLine*> m_mediumLines; 90 87 91 Vector<XSmallPage*> m_xSmallPages;92 88 Vector<SmallPage*> m_smallPages; 93 89 Vector<MediumPage*> m_mediumPages; … … 100 96 AsyncTask<Heap, decltype(&Heap::concurrentScavenge)> m_scavenger; 101 97 }; 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 }127 98 128 99 inline void Heap::deallocateSmallLine(std::lock_guard<StaticMutex>& lock, SmallLine* line) -
trunk/Source/bmalloc/bmalloc/LargeChunk.h
r167502 r167546 77 77 inline LargeChunk* LargeChunk::get(void* object) 78 78 { 79 BASSERT( isLarge(object));79 BASSERT(!isSmallOrMedium(object)); 80 80 return static_cast<LargeChunk*>(mask(object, largeChunkMask)); 81 81 } … … 90 90 inline EndTag* LargeChunk::endTag(void* object, size_t size) 91 91 { 92 BASSERT( isLarge(object));92 BASSERT(!isSmallOrMedium(object)); 93 93 94 94 LargeChunk* chunk = get(object); -
trunk/Source/bmalloc/bmalloc/Line.h
r167540 r167546 59 59 inline auto Line<Traits>::get(void* object) -> Line* 60 60 { 61 BASSERT( !isLarge(object));61 BASSERT(isSmallOrMedium(object)); 62 62 Chunk* chunk = Chunk::get(object); 63 63 size_t lineNumber = (reinterpret_cast<char*>(object) - reinterpret_cast<char*>(chunk)) / lineSize; -
trunk/Source/bmalloc/bmalloc/MediumAllocator.h
r167502 r167546 74 74 m_remaining -= size; 75 75 void* object = m_end - m_remaining - size; 76 BASSERT( objectType(object) == Medium);76 BASSERT(isSmallOrMedium(object) && !isSmall(object)); 77 77 78 78 ++m_objectCount; … … 100 100 m_remaining = mediumLineSize; 101 101 m_objectCount = 0; 102 BASSERT(objectType(m_end - 1) == Medium);103 102 } 104 103 -
trunk/Source/bmalloc/bmalloc/ObjectType.cpp
r167502 r167546 31 31 ObjectType objectType(void* object) 32 32 { 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; 41 36 return Medium; 42 37 } 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; 54 43 } 55 44 -
trunk/Source/bmalloc/bmalloc/ObjectType.h
r167502 r167546 32 32 namespace bmalloc { 33 33 34 enum ObjectType { XSmall,Small, Medium, Large, XLarge };34 enum ObjectType { Small, Medium, Large, XLarge }; 35 35 36 36 ObjectType objectType(void*); 37 37 38 inline bool is XSmall(void* object)38 inline bool isSmallOrMedium(void* object) 39 39 { 40 return mask(reinterpret_cast<uintptr_t>(object), typeMask) == xSmallType;40 return test(object, smallOrMediumTypeMask); 41 41 } 42 42 43 inline bool isSmall(void* object)43 inline bool isSmall(void* smallOrMedium) 44 44 { 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); 56 47 } 57 48 -
trunk/Source/bmalloc/bmalloc/SegregatedFreeList.h
r167502 r167546 59 59 Range takeGreedy(List&, size_t); 60 60 61 std::array<List, 1 8> m_lists;61 std::array<List, 19> m_lists; 62 62 }; 63 63 -
trunk/Source/bmalloc/bmalloc/Sizes.h
r167502 r167546 48 48 static const size_t superChunkSize = 32 * MB; 49 49 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; 60 52 static const size_t smallLineMask = ~(smallLineSize - 1ul); 61 53 62 54 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; 64 56 static const size_t smallChunkMask = ~(smallChunkSize - 1ul); 65 57 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; 68 60 static const size_t mediumLineMask = ~(mediumLineSize - 1ul); 69 61 70 62 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; 72 64 static const size_t mediumChunkMask = ~(mediumChunkSize - 1ul); 73 65 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; 76 68 static const size_t largeChunkMask = ~(largeChunkSize - 1ul); 77 69 78 70 static const size_t largeAlignment = 64; 79 71 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; 81 73 82 74 static const size_t segregatedFreeListSearchDepth = 16; 83 75 84 76 static const uintptr_t typeMask = (superChunkSize - 1) & ~((superChunkSize / 4) - 1); // 4 taggable chunks 85 static const uintptr_t xSmallType = (superChunkSize + xSmallChunkOffset) & typeMask;86 77 static const uintptr_t smallType = (superChunkSize + smallChunkOffset) & typeMask; 87 78 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 90 83 static const size_t deallocatorLogCapacity = 256; 91 84 92 static const size_t xSmallLineCacheCapacity = 32;93 85 static const size_t smallLineCacheCapacity = 16; 94 86 static const size_t mediumLineCacheCapacity = 8; 95 87 96 static const size_t xSmallAllocatorLogCapacity = 32;97 88 static const size_t smallAllocatorLogCapacity = 16; 98 89 static const size_t mediumAllocatorLogCapacity = 8; -
trunk/Source/bmalloc/bmalloc/SmallAllocator.h
r167502 r167546 29 29 #include "BAssert.h" 30 30 #include "SmallChunk.h" 31 #include "SmallLine.h" 31 32 32 33 namespace bmalloc { … … 85 86 char* result = m_ptr; 86 87 m_ptr += m_size; 87 BASSERT( objectType(result) == Small);88 BASSERT(isSmall(result)); 88 89 return result; 89 90 } -
trunk/Source/bmalloc/bmalloc/SmallTraits.h
r167502 r167546 41 41 42 42 static const size_t lineSize = smallLineSize; 43 static const size_t minimumObjectSize = xSmallMax +alignment;43 static const size_t minimumObjectSize = alignment; 44 44 static const size_t chunkSize = smallChunkSize; 45 45 static const size_t chunkOffset = smallChunkOffset; -
trunk/Source/bmalloc/bmalloc/VMHeap.cpp
r167502 r167546 37 37 } 38 38 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 46 39 void VMHeap::allocateSmallChunk() 47 40 { -
trunk/Source/bmalloc/bmalloc/VMHeap.h
r167540 r167546 35 35 #include "SmallChunk.h" 36 36 #include "Vector.h" 37 #include "XSmallChunk.h"38 37 39 38 namespace bmalloc { … … 47 46 VMHeap(); 48 47 49 XSmallPage* allocateXSmallPage();50 48 SmallPage* allocateSmallPage(); 51 49 MediumPage* allocateMediumPage(); 52 50 Range allocateLargeRange(size_t); 53 51 54 void deallocateXSmallPage(std::unique_lock<StaticMutex>&, XSmallPage*);55 52 void deallocateSmallPage(std::unique_lock<StaticMutex>&, SmallPage*); 56 53 void deallocateMediumPage(std::unique_lock<StaticMutex>&, MediumPage*); … … 58 55 59 56 private: 60 void allocateXSmallChunk();61 57 void allocateSmallChunk(); 62 58 void allocateMediumChunk(); 63 59 Range allocateLargeChunk(); 64 60 65 Vector<XSmallPage*> m_xSmallPages;66 61 Vector<SmallPage*> m_smallPages; 67 62 Vector<MediumPage*> m_mediumPages; 68 63 SegregatedFreeList m_largeRanges; 69 64 }; 70 71 inline XSmallPage* VMHeap::allocateXSmallPage()72 {73 if (!m_xSmallPages.size())74 allocateXSmallChunk();75 76 return m_xSmallPages.pop();77 }78 65 79 66 inline SmallPage* VMHeap::allocateSmallPage() … … 99 86 range = allocateLargeChunk(); 100 87 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);110 88 } 111 89 -
trunk/Source/bmalloc/bmalloc/bmalloc.h
r167540 r167546 51 51 52 52 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)) { 60 54 case Small: { 61 55 // We don't have an exact size, but we can calculate a maximum.
Note:
See TracChangeset
for help on using the changeset viewer.