[kaffe] CVS kaffe (guilhem): Kaffe-GC fixes.

Kaffe CVS cvs-commits at kaffe.org
Tue Aug 31 02:34:16 PDT 2004


PatchSet 5125 
Date: 2004/08/31 09:30:24
Author: guilhem
Branch: HEAD
Tag: (none) 
Log:
Kaffe-GC fixes.

        * kaffe/kaffevm/kaffe-gc/gc-incremental.c
        (gcRunning): Default value set to -1.
        (gcInvokeGC): Wait for gcRunning to be 0 before starting
        the real work.

        * kaffe/kaffevm/kaffe-gc/gc-mem.c
        (gc_heap_check): Check the full integrity of the primitive block
        list.
        (gc_primitive_free): Separated the initialization of blk from the
        the if condition. Check that the block is actually being used.
        (gc_block_alloc): Update primitive block list if realloc gives a
        different pointer.
        (gc_heap_grow): Always set gc_last_block to blk. Fake a used block
        for gc_primitive_free.
        Various new assertion checkings and codestyle cleanups.

Members: 
	ChangeLog:1.2681->1.2682 
	kaffe/kaffevm/kaffe-gc/gc-incremental.c:1.3->1.4 
	kaffe/kaffevm/kaffe-gc/gc-mem.c:1.2->1.3 
	kaffe/kaffevm/kaffe-gc/gc-mem.h:1.2->1.3 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.2681 kaffe/ChangeLog:1.2682
--- kaffe/ChangeLog:1.2681	Mon Aug 30 13:43:42 2004
+++ kaffe/ChangeLog	Tue Aug 31 09:30:24 2004
@@ -1,3 +1,21 @@
+2004-08-31  Guilhem Lavaux  <guilhem at kaffe.org>
+
+	* kaffe/kaffevm/kaffe-gc/gc-incremental.c
+	(gcRunning): Default value set to -1.
+	(gcInvokeGC): Wait for gcRunning to be 0 before starting
+	the real work.
+
+	* kaffe/kaffevm/kaffe-gc/gc-mem.c
+	(gc_heap_check): Check the full integrity of the primitive block
+	list.
+	(gc_primitive_free): Separated the initialization of blk from the
+	the if condition. Check that the block is actually being used.
+	(gc_block_alloc): Update primitive block list if realloc gives a
+	different pointer.
+	(gc_heap_grow): Always set gc_last_block to blk. Fake a used block
+	for gc_primitive_free.
+	Various new assertion checkings and codestyle cleanups.
+	
 2004-08-30  Dalibor Topic  <robilad at kaffe.org>
 
 	* config/i386/linux/md.c: Added missing md.h include.
Index: kaffe/kaffe/kaffevm/kaffe-gc/gc-incremental.c
diff -u kaffe/kaffe/kaffevm/kaffe-gc/gc-incremental.c:1.3 kaffe/kaffe/kaffevm/kaffe-gc/gc-incremental.c:1.4
--- kaffe/kaffe/kaffevm/kaffe-gc/gc-incremental.c:1.3	Fri Aug 27 08:41:00 2004
+++ kaffe/kaffe/kaffevm/kaffe-gc/gc-incremental.c	Tue Aug 31 09:30:26 2004
@@ -58,7 +58,7 @@
 
 static int gc_init = 0;
 static volatile int gcDisabled = 0;
-static volatile int gcRunning = 0;
+static volatile int gcRunning = -1;
 static volatile bool finalRunning = false;
 #if defined(KAFFE_STATS)
 static timespent gc_time;
@@ -953,6 +953,9 @@
 gcInvokeGC(Collector* gcif UNUSED, int mustgc)
 {
 	int iLockRoot;
+
+	while (gcRunning < 0)
+		jthread_yield();
 
 	lockStaticMutex(&gcman);
 	if (gcRunning == 0) {
Index: kaffe/kaffe/kaffevm/kaffe-gc/gc-mem.c
diff -u kaffe/kaffe/kaffevm/kaffe-gc/gc-mem.c:1.2 kaffe/kaffe/kaffevm/kaffe-gc/gc-mem.c:1.3
--- kaffe/kaffe/kaffevm/kaffe-gc/gc-mem.c:1.2	Fri Jul 23 17:02:55 2004
+++ kaffe/kaffe/kaffevm/kaffe-gc/gc-mem.c	Tue Aug 31 09:30:26 2004
@@ -39,6 +39,7 @@
 #define MAX(A,B) ((A) > (B) ? (A) : (B))
 #endif
 
+static gc_block *gc_last_block;
 static iStaticLock	gc_heap_lock;
 
 #if defined(KAFFE_STATS)
@@ -154,7 +155,6 @@
 		totalsmallobjs, totalslack, totalslack/(double)totalsmallobjs);
 }
 
-
 /*
  * check whether the heap is still in a consistent state
  */
@@ -163,6 +163,28 @@
 {
 	int i; 
 
+	gc_block *chk_blk = gc_last_block;
+
+	while (chk_blk->pprev != NULL)
+	  {
+	    if (chk_blk->pprev != NULL && chk_blk->pprev->pnext != chk_blk)
+	      {
+		dprintf("Major failure in the Garbage Collector. Primitive block list trashed\n");
+		abort();
+	      }
+	    chk_blk = chk_blk->pprev;
+	  }
+
+	while (chk_blk != gc_last_block)
+	  {
+	    if (chk_blk->pnext != NULL && chk_blk->pnext->pprev != chk_blk)
+	      {
+		dprintf("Major failure in the Garbage Collector (2). Primitive block list trashed\n");
+		abort();
+	      }
+	    chk_blk = chk_blk->pnext;
+	  }
+	
 	for (i = 0; i < NR_FREELISTS; i++) {
 		gc_block* blk = freelist[i].list;
 		if (blk == 0 || blk == (gc_block*)-1) {
@@ -464,6 +486,7 @@
 
 			info->size = gc_pgsize;
 			gc_primitive_free(info);
+
 		} else if (info->avail==1) {
 			/*
 			 * If this block contains no free sub-blocks yet, attach
@@ -504,6 +527,8 @@
 	int i;
 	int nr;
 
+	assert(sz >= sizeof(gc_block *));
+
 	info = gc_primitive_alloc(gc_pgsize);
 	if (info == 0) {
 		return (0);
@@ -628,8 +653,7 @@
  */
 #define KGC_PRIM_LIST_COUNT 20
 
-uintp gc_block_base;
-static gc_block *gc_last_block;
+uintp gc_block_base = 0;
 static gc_block *gc_prim_freelist[KGC_PRIM_LIST_COUNT+1];
 
 #ifndef PROT_NONE
@@ -854,6 +878,7 @@
 	gc_block *blk;
 
 	assert(mem->size % gc_pgsize == 0);
+	assert(GCBLOCKINUSE(mem));
 
 	/* Remove from object hash */
 	gc_block_rm(mem);
@@ -865,7 +890,9 @@
 	 * We need to do the gc_block_end check, since the heap may not be a continuous
 	 * memory area and thus two consecutive blocks need not be mergable. 
 	 */
-	if ((blk=mem->pnext) &&
+	
+        blk = mem->pnext;
+	if ((blk != NULL) &&
 	    !GCBLOCKINUSE(blk) &&
 	    gc_block_end(mem)==blk) {
 		DBG(GCPRIM, dprintf ("gc_primitive_free: merging %p with its successor (%p, %u)\n", mem, blk, blk->size);)
@@ -875,18 +902,19 @@
 		gc_merge_with_successor (mem);
 	}
 
-	if ((blk=mem->pprev) &&
+	blk = mem->pprev;
+	if ((blk != NULL) &&
 	    !GCBLOCKINUSE(blk) &&
 	    gc_block_end(blk)==mem) {
 		DBG(GCPRIM, dprintf ("gc_primitive_free: merging %p with its predecessor (%p, %u)\n", mem, blk, blk->size); )
 
 		gc_remove_from_prim_freelist(blk);
-
+		  
 		mem = blk;
 
 		gc_merge_with_successor (mem);
 	}
-
+	
 	gc_add_to_prim_freelist (mem);
 
 	DBG(GCPRIM, dprintf ("gc_primitive_free: added 0x%x bytes @ %p to freelist %u @ %p\n", mem->size, mem,
@@ -969,7 +997,7 @@
 
         ptr = malloc(size);
 	CHECK_OUT_OF_MEMORY(ptr);
-	ptr = (void*)((((uintp)ptr) + gc_pgsize - 1) & -gc_pgsize);
+	ptr = (void*)((((uintp)ptr) + gc_pgsize - 1) & (uintp)-gc_pgsize);
 
 #endif
 	mprotect(ptr, size, ALL_PROT);
@@ -1075,13 +1103,19 @@
 		   now. */ 
 		if (gc_block_base != old_blocks) {
 			int i;
-			gc_block *b = (void *) gc_block_base;
+			gc_block *b = (gc_block *) gc_block_base;
 			uintp delta = gc_block_base - old_blocks;
 #define R(X) if (X) ((uintp) (X)) += delta
 
 			DBG(GCSYSALLOC,
 			    dprintf("relocating gc_block array\n"));
-			for (i = 0; i < onb; i++) R(b[i].next);
+			for (i = 0; i < onb; i++) 
+			  {
+			    R(b[i].next);
+			    R(b[i].pprev);
+			    R(b[i].pnext);
+			  }
+
 			memset(b + onb, 0,
 			       (nblocks - onb) * sizeof(gc_block));
 
@@ -1167,11 +1201,12 @@
 	if (gc_last_block) {
 		gc_last_block->pnext = blk;
 		blk->pprev = gc_last_block;
-	} else {
-		gc_last_block = blk;
 	}
+	
+	gc_last_block = blk;
 
 	/* Free block into the system */
+	blk->nr = 1;
 	gc_primitive_free(blk);
 
 	unlockStaticMutex(&gc_heap_lock);
Index: kaffe/kaffe/kaffevm/kaffe-gc/gc-mem.h
diff -u kaffe/kaffe/kaffevm/kaffe-gc/gc-mem.h:1.2 kaffe/kaffe/kaffevm/kaffe-gc/gc-mem.h:1.3
--- kaffe/kaffe/kaffevm/kaffe-gc/gc-mem.h:1.2	Mon Aug  2 10:45:02 2004
+++ kaffe/kaffe/kaffevm/kaffe-gc/gc-mem.h	Tue Aug 31 09:30:26 2004
@@ -158,8 +158,7 @@
  * Evaluates to the gc_block that contains address @M.
  *
  */
-#define GCMEM2BLOCK(M)		(KGC_BLOCKS + ((((uintp) M) - gc_heap_base) \
-					      >> gc_pgbits))
+#define GCMEM2BLOCK(M)		(KGC_BLOCKS + ( ( ((uintp) (M)) - gc_heap_base) >> gc_pgbits))
 
 /**
  * Evaluates to the first usable address in gc_block @B.




More information about the kaffe mailing list