[kaffe] CVS kaffe (guilhem): Kaffe-GC fix for heap growing.

Kaffe CVS cvs-commits at kaffe.org
Sat Sep 24 12:05:37 PDT 2005


PatchSet 6931 
Date: 2005/09/24 19:00:43
Author: guilhem
Branch: HEAD
Tag: (none) 
Log:
Kaffe-GC fix for heap growing.

        * kaffe/kaffevm/kaffe-gc/gc-mem.c
        (gc_block_alloc): Handle heap growing backward. Fixed initialization
        of the block array.
        (gc_heap_grow): If blocks are prepended update gc_first_block and not
        gc_last_block.
        (gc_first_block): New pointer to hold the first block in the primitive block
        list.

Members: 
	ChangeLog:1.4453->1.4454 
	kaffe/kaffevm/kaffe-gc/gc-mem.c:1.33->1.34 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.4453 kaffe/ChangeLog:1.4454
--- kaffe/ChangeLog:1.4453	Fri Sep 23 16:31:52 2005
+++ kaffe/ChangeLog	Sat Sep 24 19:00:43 2005
@@ -1,3 +1,13 @@
+2005-09-24  Guilhem Lavaux  <guilhem at kaffe.org>
+
+	* kaffe/kaffevm/kaffe-gc/gc-mem.c
+	(gc_block_alloc): Handle heap growing backward. Fixed initialization
+	of the block array.
+	(gc_heap_grow): If blocks are prepended update gc_first_block and not
+	gc_last_block.
+	(gc_first_block): New pointer to hold the first block in the primitive block
+	list.
+
 2005-09-23  Gwenole Beauchesne  <gbeauchesne at mandriva.com>
 
 	* libraries/clib/fdlibm/: Such an ancient code assumed "long" as a
Index: kaffe/kaffe/kaffevm/kaffe-gc/gc-mem.c
diff -u kaffe/kaffe/kaffevm/kaffe-gc/gc-mem.c:1.33 kaffe/kaffe/kaffevm/kaffe-gc/gc-mem.c:1.34
--- kaffe/kaffe/kaffevm/kaffe-gc/gc-mem.c:1.33	Sat Aug 20 22:59:43 2005
+++ kaffe/kaffe/kaffevm/kaffe-gc/gc-mem.c	Sat Sep 24 19:00:45 2005
@@ -40,6 +40,7 @@
 #endif
 
 static gc_block *gc_last_block;
+static gc_block *gc_first_block;
 static gc_block *gc_reserve_pages;
 static iStaticLock	gc_heap_lock;
 
@@ -1181,8 +1182,22 @@
 			memcpy(gc_block_base, old_blocks, onb * sizeof(gc_block));
 			free(old_blocks);
 		}
-
 		DBG(GCSYSALLOC, dprintf("old block_base = %p, new block_base = %p\n", old_blocks, gc_block_base));
+		if (heap_addr < gc_heap_base) {
+		  int32 i, j, oldBase;
+		  gc_block *b = (gc_block *) gc_block_base;
+
+		  oldBase = (gc_heap_base - heap_addr) >> gc_pgbits;
+
+		  for (i=(onb-1),j=(oldBase+onb-1); i >= 0; i--,j--)
+		  	memcpy(&b[j], &b[i], sizeof(gc_block));
+
+		  memset((gc_block *)gc_block_base, 0,
+		         (gc_num_blocks - onb) * sizeof(gc_block));
+		} else {
+		  memset(((gc_block *)gc_block_base) + onb, 0,
+		         (gc_num_blocks - onb) * sizeof(gc_block));
+		}
 		/* If the array's address has changed, we have to fix
 		   up the pointers in the gc_blocks, as well as all
 		   external pointers to the gc_blocks.  We can only
@@ -1206,9 +1221,6 @@
 				R(gc_freeobj, b[i].free);
 			  }
 
-			memset(b + onb, 0,
-			       (gc_num_blocks - onb) * sizeof(gc_block));
-
 			for (i = 0; i<=KGC_PRIM_LIST_COUNT; i++)
 				R(gc_block, gc_prim_freelist[i]);
 
@@ -1217,6 +1229,7 @@
 
 			R(gc_block, gc_reserve_pages);
 			R(gc_block, gc_last_block);
+			R(gc_block, gc_first_block);
 #undef R
 		}
 		KTHREAD(spinoff)(NULL);
@@ -1225,6 +1238,9 @@
 	gc_num_live_pages += size_pg;
 	last_addr = MAX(last_addr, heap_addr + size);
 	gc_heap_range = last_addr - gc_heap_base;
+	if (gc_heap_base > heap_addr)
+	  gc_heap_base = heap_addr;
+
 	DBG(GCSYSALLOC, dprintf("%ld unused bytes in heap addr range\n",
 				(long) (gc_heap_range - gc_heap_total)));
 #if defined(KAFFE_VMDEBUG)
@@ -1291,8 +1307,15 @@
 
 	/* maintain list of primitive blocks */
 	if (gc_last_block) {
-		gc_last_block->pnext = blk;
-		blk->pprev = gc_last_block;
+		if (gc_last_block < blk) {
+			gc_last_block->pnext = blk;
+			blk->pprev = gc_last_block;
+		} else {
+			assert(gc_first_block->pprev == NULL);
+			gc_first_block->pprev = blk;
+			blk->pnext = gc_first_block;
+			gc_first_block = blk;
+		}
 	}
 	
 	gc_last_block = blk;



More information about the kaffe mailing list