[llvm-commits] CVS: poolalloc/runtime/HeapFrag/HeapFrag.c Makefile

Chris Lattner lattner at cs.uiuc.edu
Mon May 10 17:15:03 PDT 2004


Changes in directory poolalloc/runtime/HeapFrag:

HeapFrag.c added (r1.1)
Makefile added (r1.1)

---
Log message:

Initial checking of a simple heap fragmenter.  It's not even a 
particularly good one.


---
Diffs of the changes:  (+56 -0)

Index: poolalloc/runtime/HeapFrag/HeapFrag.c
diff -c /dev/null poolalloc/runtime/HeapFrag/HeapFrag.c:1.1
*** /dev/null	Mon May 10 17:15:09 2004
--- poolalloc/runtime/HeapFrag/HeapFrag.c	Mon May 10 17:14:58 2004
***************
*** 0 ****
--- 1,47 ----
+ /*===- HeapFrag.c - Routine to fragment the heap --------------------------===//
+ //
+ //                       The LLVM Compiler Infrastructure
+ //
+ // This file was developed by the LLVM research group and is distributed under
+ // the University of Illinois Open Source License. See LICENSE.TXT for details.
+ // 
+ //===----------------------------------------------------------------------===//
+ //
+ // This file defines a function 'EnsureHeapFragmentation', which is used to
+ // artificially fragment the heap, to show the value of pool allocator even for
+ // silly benchmarks that never free memory and thus have no fragmentation at
+ // all.
+ //
+ //===----------------------------------------------------------------------===*/
+ 
+ #include <stdlib.h>
+ 
+ static void **AllocateNodes(unsigned N, unsigned Size) {
+   void **Spine = (void**)malloc(N*sizeof(void*));
+   unsigned i;
+   for (i = 0; i != N; ++i)
+     Spine[i] = malloc(Size);
+   return Spine;
+ }
+ 
+ static void DeallocateNodes(void **Spine, unsigned N, unsigned Stride) {
+   unsigned i;
+   for (i = 0; i < N; i += Stride) {
+     free(Spine[i]);
+     Spine[i] = 0;
+   }
+ }
+ 
+ 
+ void EnsureHeapFragmentation() {
+   void **DS1 = AllocateNodes(10000, 16);
+   void **DS2;
+   void *A, *B, *C;
+   DeallocateNodes(DS1+9000, 1000, 1);  /* Free last elements */
+   DS2 = AllocateNodes(40000, 40);
+   DeallocateNodes(DS1, 9000, 2);
+   DeallocateNodes(DS2, 40000, 2);
+   DS1 = AllocateNodes(2000, 8);
+   DeallocateNodes(DS1, 2000, 2);
+   DeallocateNodes(DS1, 2000, 3);
+ }


Index: poolalloc/runtime/HeapFrag/Makefile
diff -c /dev/null poolalloc/runtime/HeapFrag/Makefile:1.1
*** /dev/null	Mon May 10 17:15:09 2004
--- poolalloc/runtime/HeapFrag/Makefile	Mon May 10 17:14:59 2004
***************
*** 0 ****
--- 1,9 ----
+ LEVEL = ../..
+ #BYTECODE_LIBRARY=1
+ #SHARED_LIBRARY=1
+ LIBRARYNAME=heapfrag
+ 
+ include $(LEVEL)/Makefile.common
+ 
+ # Always build optimized and debug versions
+ all:: $(LIBNAME_OBJO) $(LIBNAME_OBJG)





More information about the llvm-commits mailing list