llvm.org GIT mirror llvm / b9a99d4
[Allocator] Finally, finish nuking the redundant code that led me here by removing the MallocSlabAllocator entirely and just using MallocAllocator directly. This makes all off these allocators expose and utilize the same core interface. The only ugly part of this is that it exposes the fact that the JIT allocator has no real handling of alignment, any more than the malloc allocator does. =/ It would be nice to fix both of these to support alignments, and then to leverage that in the BumpPtrAllocator to do less over allocation in order to manually align pointers. But, that's another patch for another day. This patch has no functional impact, it just removes the somewhat meaningless wrapper around MallocAllocator. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206267 91177308-0d34-0410-b5e6-96231b3b80d8 Chandler Carruth 6 years ago
3 changed file(s) with 12 addition(s) and 25 deletion(s). Raw diff Collapse all Expand all
134134 void PrintStats() const {}
135135 };
136136
137 /// MallocSlabAllocator - The default slab allocator for the bump allocator
138 /// is an adapter class for MallocAllocator that just forwards the method
139 /// calls and translates the arguments.
140 class MallocSlabAllocator {
141 /// Allocator - The underlying allocator that we forward to.
142 ///
143 MallocAllocator Allocator;
144
145 public:
146 void *Allocate(size_t Size) { return Allocator.Allocate(Size, 0); }
147 void Deallocate(void *Slab, size_t Size) { Allocator.Deallocate(Slab, Size); }
148 };
149
150137 namespace detail {
151138
152139 // We call out to an external function to actually print the message as the
166153 /// Note that this also has a threshold for forcing allocations above a certain
167154 /// size into their own slab.
168155 ///
169 /// The BumpPtrAllocatorImpl template defaults to using a MallocSlabAllocator
156 /// The BumpPtrAllocatorImpl template defaults to using a MallocAllocator
170157 /// object, which wraps malloc, to allocate memory, but it can be changed to
171158 /// use a custom allocator.
172 template SlabAllocator, size_t SlabSize = 4096,
159 template Allocator, size_t SlabSize = 4096,
173160 size_t SizeThreshold = SlabSize>
174161 class BumpPtrAllocatorImpl
175162 : public AllocatorBase<
240227 // If Size is really big, allocate a separate slab for it.
241228 size_t PaddedSize = Size + Alignment - 1;
242229 if (PaddedSize > SizeThreshold) {
243 void *NewSlab = Allocator.Allocate(PaddedSize);
230 void *NewSlab = Allocator.Allocate(PaddedSize, 0);
244231 CustomSizedSlabs.push_back(std::make_pair(NewSlab, PaddedSize));
245232
246233 Ptr = alignPtr((char *)NewSlab, Alignment);
318305 void StartNewSlab() {
319306 size_t AllocatedSlabSize = computeSlabSize(Slabs.size());
320307
321 void *NewSlab = Allocator.Allocate(AllocatedSlabSize);
308 void *NewSlab = Allocator.Allocate(AllocatedSlabSize, 0);
322309 Slabs.push_back(NewSlab);
323310 CurPtr = (char *)(NewSlab);
324311 End = ((char *)NewSlab) + AllocatedSlabSize;
268268
269269 class DefaultJITMemoryManager;
270270
271 class JITSlabAllocator {
271 class JITAllocator {
272272 DefaultJITMemoryManager &JMM;
273273 public:
274 JITSlabAllocator(DefaultJITMemoryManager &jmm) : JMM(jmm) { }
275 void *Allocate(size_t Size);
274 JITAllocator(DefaultJITMemoryManager &jmm) : JMM(jmm) { }
275 void *Allocate(size_t Size, size_t /*Alignment*/);
276276 void Deallocate(void *Slab, size_t Size);
277277 };
278278
311311 // Memory slabs allocated by the JIT. We refer to them as slabs so we don't
312312 // confuse them with the blocks of memory described above.
313313 std::vector CodeSlabs;
314 BumpPtrAllocatorImplSlabAllocator, DefaultSlabSize,
314 BumpPtrAllocatorImplAllocator, DefaultSlabSize,
315315 DefaultSizeThreshold> StubAllocator;
316 BumpPtrAllocatorImplSlabAllocator, DefaultSlabSize,
316 BumpPtrAllocatorImplAllocator, DefaultSlabSize,
317317 DefaultSizeThreshold> DataAllocator;
318318
319319 // Circular list of free blocks.
567567 };
568568 }
569569
570 void *JITSlabAllocator::Allocate(size_t Size) {
570 void *JITAllocator::Allocate(size_t Size, size_t /*Alignment*/) {
571571 sys::MemoryBlock B = JMM.allocateNewSlab(Size);
572572 return B.base();
573573 }
574574
575 void JITSlabAllocator::Deallocate(void *Slab, size_t Size) {
575 void JITAllocator::Deallocate(void *Slab, size_t Size) {
576576 sys::MemoryBlock B(Slab, Size);
577577 sys::Memory::ReleaseRWX(B);
578578 }
107107 public:
108108 ~MockSlabAllocator() { }
109109
110 void *Allocate(size_t Size) {
110 void *Allocate(size_t Size, size_t /*Alignment*/) {
111111 // Allocate space for the alignment, the slab, and a void* that goes right
112112 // before the slab.
113113 size_t Alignment = 4096;