void PrintStats() const {}
};
-/// MallocSlabAllocator - The default slab allocator for the bump allocator
-/// is an adapter class for MallocAllocator that just forwards the method
-/// calls and translates the arguments.
-class MallocSlabAllocator {
- /// Allocator - The underlying allocator that we forward to.
- ///
- MallocAllocator Allocator;
-
-public:
- void *Allocate(size_t Size) { return Allocator.Allocate(Size, 0); }
- void Deallocate(void *Slab, size_t Size) { Allocator.Deallocate(Slab, Size); }
-};
-
namespace detail {
// We call out to an external function to actually print the message as the
/// Note that this also has a threshold for forcing allocations above a certain
/// size into their own slab.
///
-/// The BumpPtrAllocatorImpl template defaults to using a MallocSlabAllocator
+/// The BumpPtrAllocatorImpl template defaults to using a MallocAllocator
/// object, which wraps malloc, to allocate memory, but it can be changed to
/// use a custom allocator.
-template <typename AllocatorT = MallocSlabAllocator, size_t SlabSize = 4096,
+template <typename AllocatorT = MallocAllocator, size_t SlabSize = 4096,
size_t SizeThreshold = SlabSize>
class BumpPtrAllocatorImpl
: public AllocatorBase<
// If Size is really big, allocate a separate slab for it.
size_t PaddedSize = Size + Alignment - 1;
if (PaddedSize > SizeThreshold) {
- void *NewSlab = Allocator.Allocate(PaddedSize);
+ void *NewSlab = Allocator.Allocate(PaddedSize, 0);
CustomSizedSlabs.push_back(std::make_pair(NewSlab, PaddedSize));
Ptr = alignPtr((char *)NewSlab, Alignment);
void StartNewSlab() {
size_t AllocatedSlabSize = computeSlabSize(Slabs.size());
- void *NewSlab = Allocator.Allocate(AllocatedSlabSize);
+ void *NewSlab = Allocator.Allocate(AllocatedSlabSize, 0);
Slabs.push_back(NewSlab);
CurPtr = (char *)(NewSlab);
End = ((char *)NewSlab) + AllocatedSlabSize;
class DefaultJITMemoryManager;
- class JITSlabAllocator {
+ class JITAllocator {
DefaultJITMemoryManager &JMM;
public:
- JITSlabAllocator(DefaultJITMemoryManager &jmm) : JMM(jmm) { }
- void *Allocate(size_t Size);
+ JITAllocator(DefaultJITMemoryManager &jmm) : JMM(jmm) { }
+ void *Allocate(size_t Size, size_t /*Alignment*/);
void Deallocate(void *Slab, size_t Size);
};
// Memory slabs allocated by the JIT. We refer to them as slabs so we don't
// confuse them with the blocks of memory described above.
std::vector<sys::MemoryBlock> CodeSlabs;
- BumpPtrAllocatorImpl<JITSlabAllocator, DefaultSlabSize,
+ BumpPtrAllocatorImpl<JITAllocator, DefaultSlabSize,
DefaultSizeThreshold> StubAllocator;
- BumpPtrAllocatorImpl<JITSlabAllocator, DefaultSlabSize,
+ BumpPtrAllocatorImpl<JITAllocator, DefaultSlabSize,
DefaultSizeThreshold> DataAllocator;
// Circular list of free blocks.
};
}
-void *JITSlabAllocator::Allocate(size_t Size) {
+void *JITAllocator::Allocate(size_t Size, size_t /*Alignment*/) {
sys::MemoryBlock B = JMM.allocateNewSlab(Size);
return B.base();
}
-void JITSlabAllocator::Deallocate(void *Slab, size_t Size) {
+void JITAllocator::Deallocate(void *Slab, size_t Size) {
sys::MemoryBlock B(Slab, Size);
sys::Memory::ReleaseRWX(B);
}