[llvm-commits] CVS: poolalloc/runtime/FreeListAllocator/PoolAllocator.cpp PoolAllocator.h PoolSlab.h

John Criswell criswell at cs.uiuc.edu
Tue Nov 11 20:47:01 PST 2003


Changes in directory poolalloc/runtime/FreeListAllocator:

PoolAllocator.cpp updated: 1.12 -> 1.13
PoolAllocator.h updated: 1.4 -> 1.5
PoolSlab.h updated: 1.1 -> 1.2

---
Log message:

Fixed the API to match the BitMap PoolAllocator API.  This is the one used
by the LLVM Pool Allocation passes.
Decreased the complexity and (hopefully) increased the speed of allocation.
Ensure that arrays larger than a block are not freed upon pool destruction
(as they are not managed by the PageManager).
Make sure that we don't use memory that we just deallocated (we were doing
this in pooldestroy).



---
Diffs of the changes:  (+50 -11)

Index: poolalloc/runtime/FreeListAllocator/PoolAllocator.cpp
diff -u poolalloc/runtime/FreeListAllocator/PoolAllocator.cpp:1.12 poolalloc/runtime/FreeListAllocator/PoolAllocator.cpp:1.13
--- poolalloc/runtime/FreeListAllocator/PoolAllocator.cpp:1.12	Tue Nov 11 14:43:40 2003
+++ poolalloc/runtime/FreeListAllocator/PoolAllocator.cpp	Tue Nov 11 20:46:21 2003
@@ -51,9 +51,17 @@
   //
   // If we can't fit a node into a page, give up.
   //
+  if (NodeSize > PageSize)
+  {
+    fprintf (stderr, "Node size is too big.\n");
+    fflush (stderr);
+    abort();
+  }
+
   if (MaxNodesPerPage == 0)
   {
     fprintf (stderr, "Node size is too large\n");
+    fflush (stderr);
     abort();
   }
 
@@ -66,19 +74,23 @@
     if (NewSlab == NULL)
     {
       fprintf (stderr, "Failed large allocation\n");
+      fflush (stderr);
       abort();
     }
     NewSlab->IsArray = 1;
+    NewSlab->IsManaged = 0;
   }
   else
   {
     NewSlab = (struct SlabHeader *) AllocatePage ();
     if (NewSlab == NULL)
     {
-      fprintf (stderr, "Failed regular allocation");
+      fprintf (stderr, "Failed regular allocation\n");
+      fflush (stderr);
       abort();
     }
     NewSlab->IsArray = 0;
+    NewSlab->IsManaged = 1;
 
     //
     // Bump the number of nodes in the slab up to the maximum.
@@ -90,7 +102,6 @@
   NewSlab->NextFreeData = NewSlab->LiveNodes = 0;
   NewSlab->Next = NULL;
   NewSlab->Data = (unsigned char *)NewSlab + sizeof (struct SlabHeader) + ((NodesPerSlab) * sizeof (NodePointer));
-
   return NewSlab;
 }
 
@@ -187,27 +198,48 @@
 {
   // Pointer to scan Slab list
   struct SlabHeader * Slabp;
+  struct SlabHeader * Nextp;
 
   assert(Pool && "Null pool pointer passed in to pooldestroy!\n");
-  for (Slabp = Pool->Slabs; Slabp != NULL; Slabp=Slabp->Next)
+
+  //
+  // Deallocate all of the pages.
+  //
+  Slabp = Pool->Slabs;
+  while (Slabp != NULL)
   {
-    FreePage (Slabp);
+    // Record the next step
+    Nextp = Slabp->Next;
+
+    // Deallocate the memory if it is managed.
+    if (Slabp->IsManaged)
+    {
+      FreePage (Slabp);
+    }
+
+    // Move to the next node.
+    Slabp = Nextp;
   }
 
   return;
 }
 
 void *
-poolalloc(PoolTy *Pool)
+poolalloc(PoolTy *Pool, unsigned NodeSize)
 {
+  void * Data;
   assert(Pool && "Null pool pointer passed in to poolalloc!\n");
+  assert((NodeSize <= Pool->NodeSize) && "Wrong Node Size!\n");
 
   //
-  // Check to see if we have a slab.  If we don't, get one.
+  // If we don't have a slab, this is our first initialization.  Do some
+  // quick stuff.
   //
   if (Pool->Slabs == NULL)
   {
     Pool->Slabs = createSlab (Pool->NodeSize);
+    (Pool->Slabs->NextFreeData)++;
+    return (Pool->Slabs->Data);
   }
 
   //
@@ -218,7 +250,9 @@
     //
     // Return the block and increment the index of the next free data block.
     //
-    return (Pool->Slabs->Data + (Pool->NodeSize * Pool->Slabs->NextFreeData++));
+    Data = (Pool->Slabs->Data + (Pool->NodeSize * Pool->Slabs->NextFreeData));
+    (Pool->Slabs->NextFreeData)++;
+    return (Data);
   }
 
   //
@@ -234,10 +268,12 @@
     NewSlab->Next = Pool->Slabs;
     Pool->Slabs = NewSlab;
 
+    (NewSlab->NextFreeData)++;
+
     //
     // Return the block and increment the index of the next free data block.
     //
-    return (Pool->Slabs->Data + (Pool->NodeSize * Pool->Slabs->NextFreeData++));
+    return (Pool->Slabs->Data);
   }
 
   //
@@ -255,7 +291,7 @@
   //
   // Find the data block that corresponds with this pointer.
   //
-  void * Data = (slabp->Data + (Pool->NodeSize * (Pool->FreeList.Next - &(slabp->BlockList[0]))));
+  Data = (slabp->Data + (Pool->NodeSize * (Pool->FreeList.Next - &(slabp->BlockList[0]))));
 
   //
   // Unlink the first block.


Index: poolalloc/runtime/FreeListAllocator/PoolAllocator.h
diff -u poolalloc/runtime/FreeListAllocator/PoolAllocator.h:1.4 poolalloc/runtime/FreeListAllocator/PoolAllocator.h:1.5
--- poolalloc/runtime/FreeListAllocator/PoolAllocator.h:1.4	Tue Nov 11 09:59:55 2003
+++ poolalloc/runtime/FreeListAllocator/PoolAllocator.h	Tue Nov 11 20:46:21 2003
@@ -40,7 +40,7 @@
   void poolinit(PoolTy *Pool, unsigned NodeSize);
   void poolmakeunfreeable(PoolTy *Pool);
   void pooldestroy(PoolTy *Pool);
-  void *poolalloc(PoolTy *Pool);
+  void *poolalloc(PoolTy *Pool, unsigned NodeSize);
   void poolfree(PoolTy *Pool, void *Node);
   void* poolallocarray(PoolTy* Pool, unsigned Size);
 }


Index: poolalloc/runtime/FreeListAllocator/PoolSlab.h
diff -u poolalloc/runtime/FreeListAllocator/PoolSlab.h:1.1 poolalloc/runtime/FreeListAllocator/PoolSlab.h:1.2
--- poolalloc/runtime/FreeListAllocator/PoolSlab.h:1.1	Tue Nov 11 09:59:55 2003
+++ poolalloc/runtime/FreeListAllocator/PoolSlab.h	Tue Nov 11 20:46:21 2003
@@ -55,7 +55,10 @@
 struct SlabHeader
 {
   // Flags whether this is an array
-  unsigned int IsArray;
+  unsigned char IsArray;
+
+  // Flags whether this is managed by the Page Manager
+  unsigned char IsManaged;
 
   // Number of nodes per slab
   unsigned int NodesPerSlab;





More information about the llvm-commits mailing list