[llvm-commits] [poolalloc] r57784 - in /poolalloc/trunk/include/poolalloc_runtime: PoolAllocator.h test.ex
Andrew Lenharth
alenhar2 at cs.uiuc.edu
Sun Oct 19 08:20:13 PDT 2008
Author: alenhar2
Date: Sun Oct 19 10:20:12 2008
New Revision: 57784
URL: http://llvm.org/viewvc/llvm-project?rev=57784&view=rev
Log:
Compound slab manager to dispatch to fixed sized allocators and variable sized allocators
Modified:
poolalloc/trunk/include/poolalloc_runtime/PoolAllocator.h
poolalloc/trunk/include/poolalloc_runtime/test.ex
Modified: poolalloc/trunk/include/poolalloc_runtime/PoolAllocator.h
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/include/poolalloc_runtime/PoolAllocator.h?rev=57784&r1=57783&r2=57784&view=diff
==============================================================================
--- poolalloc/trunk/include/poolalloc_runtime/PoolAllocator.h (original)
+++ poolalloc/trunk/include/poolalloc_runtime/PoolAllocator.h Sun Oct 19 10:20:12 2008
@@ -23,13 +23,8 @@
return p;
}
- // Allocate an object of size objsize
- void* alloc() {
- return slab_alloc(1);
- }
-
- // Allocate an array with num objects of size objsize
- void* alloc_array(unsigned num) {
+ // Allocate num objects of size objsize
+ void* alloc(unsigned num = 1) {
return slab_alloc(num);
}
@@ -73,7 +68,7 @@
dealloc_actor(MallocSlabManager* _m) : m(_m) {}
};
- protected:
+ public:
MallocSlabManager(unsigned Osize, unsigned Alignment) : objsize(Osize) {}
~MallocSlabManager() {
dealloc_actor act(this);
@@ -199,7 +194,7 @@
}
}
- protected:
+ public:
BitMaskSlabManager(unsigned Osize, unsigned Alignment)
:objsize(Osize), CurAllocSlab(0), totalslots(0), totalallocs(0)
{}
@@ -254,6 +249,42 @@
}
};
+template<class FixedAllocator, class VarAllocator>
+class CompoundSlabManager {
+ FixedAllocator FixedAlloc;
+ VarAllocator VarAlloc;
+ unsigned objsize;
+ public:
+ CompoundSlabManager(unsigned Osize, unsigned Alignment)
+ :FixedAlloc(Osize, Alignment), VarAlloc(1, Alignment), objsize(Osize)
+ {}
+ void* slab_alloc(unsigned num) {
+ if (num == 1)
+ return FixedAlloc.slab_alloc(1);
+ else
+ return VarAlloc.slab_alloc(num * sizeof(objsize * num));
+ }
+ void slab_free(void* obj) {
+ if (FixedAlloc.slab_managed(obj))
+ FixedAlloc.slab_free(obj);
+ else
+ VarAlloc.slab_free(obj);
+ }
+ bool slab_valid(void* obj) {
+ return FixedAlloc.slab_valid(obj) || VarAlloc.slab_valid(obj);
+ }
+ bool slab_managed(void* obj) {
+ return FixedAlloc.slab_managed(obj) || VarAlloc.slab_managed(obj);
+ }
+ bool slab_getbounds(void* obj, void*& start, void*& end) {
+ if (FixedAlloc.slab_getbounds(obj, start, end))
+ return true;
+ if (VarAlloc.slab_getbounds(obj, start, end))
+ return true;
+ return false;
+ }
+};
+
class LinuxMmap {
public:
enum d {pageSize = 4096};
Modified: poolalloc/trunk/include/poolalloc_runtime/test.ex
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/include/poolalloc_runtime/test.ex?rev=57784&r1=57783&r2=57784&view=diff
==============================================================================
--- poolalloc/trunk/include/poolalloc_runtime/test.ex (original)
+++ poolalloc/trunk/include/poolalloc_runtime/test.ex Sun Oct 19 10:20:12 2008
@@ -4,6 +4,8 @@
PoolAllocator<MallocSlabManager<> > a(10, 16);
PoolAllocator<BitMaskSlabManager<LinuxMmap> > b(8, 8);
+PoolAllocator<CompoundSlabManager<BitMaskSlabManager<LinuxMmap>, MallocSlabManager<> > > c(8, 8);
+
RangeSplayMap<unsigned> x;
int main() {
@@ -14,6 +16,15 @@
x = b.alloc();
std::cerr << b.isAllocated(x) << " " << b.isAllocated((char*)x + 5) << " " << b.isAllocated((char*)x + 10) << "\n";
b.dealloc(x);
+
+ x = c.alloc();
+ std::cerr << c.isAllocated(x) << " " << c.isAllocated((char*)x + 5) << " " << c.isAllocated((char*)x + 10) << "\n";
+ void* y = c.alloc(4);
+ std::cerr << c.isAllocated(y) << " " << c.isAllocated((char*)y + 5) << " " << c.isAllocated((char*)y + 10) << " " << c.isAllocated((char*)y + 50) << "\n";
+ c.dealloc(x);
+ c.dealloc(y);
+
+
return 0;
}
More information about the llvm-commits
mailing list