bmalloc: allocate small and medium objects using the same bump pointer class
[WebKit-https.git] / Source / bmalloc / bmalloc / Allocator.h
index fa76d10f62ddcd4fb54541fa234b086fdc265849..65f149af8fb56b890332ef59a4f63eae82c76655 100644 (file)
 #ifndef Allocator_h
 #define Allocator_h
 
+#include "BumpAllocator.h"
 #include "FixedVector.h"
 #include "MediumAllocator.h"
 #include "Sizes.h"
-#include "SmallAllocator.h"
+#include "SmallLine.h"
 #include <array>
 
 namespace bmalloc {
@@ -46,42 +47,28 @@ public:
     void* allocate(size_t);
     bool allocateFastCase(size_t, void*&);
     void* allocateSlowCase(size_t);
+    
+    void scavenge();
 
 private:
-    SmallAllocator& smallAllocatorFor(size_t);
-    void* allocateFastCase(SmallAllocator&);
+    void* allocateFastCase(BumpAllocator&);
 
     void* allocateMedium(size_t);
     void* allocateLarge(size_t);
     void* allocateXLarge(size_t);
     
-    void log(SmallAllocator&);
-    void log(MediumAllocator&);
-
-    void processSmallAllocatorLog();
-    void processMediumAllocatorLog();
-
     Deallocator& m_deallocator;
 
-    std::array<SmallAllocator, smallMax / alignment> m_smallAllocators;
-    MediumAllocator m_mediumAllocator;
-
-    FixedVector<std::pair<SmallLine*, unsigned char>, smallAllocatorLogCapacity> m_smallAllocatorLog;
-    FixedVector<std::pair<MediumLine*, unsigned char>, mediumAllocatorLogCapacity> m_mediumAllocatorLog;
+    std::array<BumpAllocator, smallMax / alignment> m_smallAllocators;
+    std::array<BumpAllocator, mediumMax / alignment> m_mediumAllocators;
 };
 
-inline SmallAllocator& Allocator::smallAllocatorFor(size_t size)
-{
-    size_t index = mask((size - 1ul) / alignment, m_smallAllocators.size() - 1);
-    return m_smallAllocators[index];
-}
-
 inline bool Allocator::allocateFastCase(size_t size, void*& object)
 {
     if (size > smallMax)
         return false;
 
-    SmallAllocator& allocator = smallAllocatorFor(size);
+    BumpAllocator& allocator = m_smallAllocators[smallSizeClassFor(size)];
     if (!allocator.canAllocate())
         return false;