[llvm-commits] CVS: llvm-poolalloc/runtime/FL2Allocator/FreeListAllocator.cpp

Chris Lattner lattner at cs.uiuc.edu
Wed Mar 2 08:00:41 PST 2005



Changes in directory llvm-poolalloc/runtime/FL2Allocator:

FreeListAllocator.cpp updated: 1.33 -> 1.34
---
Log message:

Don't lazily create the pool slabs on the first allocation.  This will
break code like this:


   pooldesc PD;
   poolinit(&PD ...);

   void *Base = PD.Base;

   ...

Because no allocation happens before the load of the pool base.



---
Diffs of the changes:  (+23 -26)

 FreeListAllocator.cpp |   49 +++++++++++++++++++++++--------------------------
 1 files changed, 23 insertions(+), 26 deletions(-)


Index: llvm-poolalloc/runtime/FL2Allocator/FreeListAllocator.cpp
diff -u llvm-poolalloc/runtime/FL2Allocator/FreeListAllocator.cpp:1.33 llvm-poolalloc/runtime/FL2Allocator/FreeListAllocator.cpp:1.34
--- llvm-poolalloc/runtime/FL2Allocator/FreeListAllocator.cpp:1.33	Tue Mar  1 23:46:59 2005
+++ llvm-poolalloc/runtime/FL2Allocator/FreeListAllocator.cpp	Wed Mar  2 10:00:28 2005
@@ -708,6 +708,27 @@
 void poolinit_pc(PoolTy *Pool, unsigned NodeSize, unsigned ObjAlignment) {
   poolinit(Pool, NodeSize, ObjAlignment);
   Pool->isPtrCompPool = true;
+
+  // Create the pool.  We have to do this eagerly (instead of on the first
+  // allocation), because code may want to eagerly copy the pool base into a
+  // register.
+
+  // If we already have a pool mmap'd, reuse it.
+  for (unsigned i = 0; i != 4; ++i)
+    if (Pools[i]) {
+      Pool->Slabs = Pools[i];
+      Pools[i] = 0;
+      break;
+    }
+
+  if (Pool->Slabs == 0) {
+    // Didn't find an existing pool, create one.
+    Pool->Slabs = (PoolSlab*)mmap(0, POOLSIZE, PROT_READ|PROT_WRITE,
+                                 MAP_PRIVATE|MAP_NORESERVE|MAP_ANONYMOUS, 0, 0);
+    DO_IF_TRACE(fprintf(stderr, "RESERVED ADDR SPACE: %p -> %p\n",
+                        Pool->Slabs, (char*)Pool->Slabs+POOLSIZE));
+  }
+  PoolSlab::create_for_ptrcomp(Pool, Pool->Slabs, POOLSIZE);
 }
 
 void pooldestroy_pc(PoolTy *Pool) {
@@ -732,32 +753,8 @@
 }
 
 unsigned long poolalloc_pc(PoolTy *Pool, unsigned NumBytes) {
-  if (Pool->Slabs == 0)
-    goto AllocPool;
-Continue:
-  {
-    void *Result = poolalloc(Pool, NumBytes);
-    return (char*)Result-(char*)Pool->Slabs;
-  }
-
-AllocPool:
-  // This is the first allocation out of this pool.  If we already have a pool
-  // mmapp'd, reuse it.
-  for (unsigned i = 0; i != 4; ++i)
-    if (Pools[i]) {
-      Pool->Slabs = Pools[i];
-      Pools[i] = 0;
-      break;
-    }
-  if (Pool->Slabs == 0) {
-    // Didn't find an existing pool, create one.
-    Pool->Slabs = (PoolSlab*)mmap(0, POOLSIZE, PROT_READ|PROT_WRITE,
-                                 MAP_PRIVATE|MAP_NORESERVE|MAP_ANONYMOUS, 0, 0);
-    DO_IF_TRACE(fprintf(stderr, "RESERVED ADDR SPACE: %p -> %p\n",
-                        Pool->Slabs, (char*)Pool->Slabs+POOLSIZE));
-  }
-  PoolSlab::create_for_ptrcomp(Pool, Pool->Slabs, POOLSIZE);
-  goto Continue;
+  void *Result = poolalloc(Pool, NumBytes);
+  return (char*)Result-(char*)Pool->Slabs;
 }
 
 void poolfree_pc(PoolTy *Pool, unsigned long Node) {






More information about the llvm-commits mailing list