[kaffe] CVS kaffe (dalibor): Small cleanup of gc code

Kaffe CVS Kaffe Mailing List <kaffe@kaffe.org>
Tue Nov 11 06:37:02 2003


PatchSet 4158 
Date: 2003/11/11 14:34:43
Author: dalibor
Branch: HEAD
Tag: (none) 
Log:
Small cleanup of gc code

Members: 
	ChangeLog:1.1750->1.1751 
	kaffe/kaffevm/mem/gc-mem.c:1.50->1.51 
	kaffe/kaffevm/mem/gc-mem.h:1.17->1.18 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.1750 kaffe/ChangeLog:1.1751
--- kaffe/ChangeLog:1.1750	Thu Nov  6 22:53:42 2003
+++ kaffe/ChangeLog	Tue Nov 11 14:34:43 2003
@@ -1,3 +1,19 @@
+2003-11-11  Dalibor Topic <robilad@kaffe.org>
+
+	* kaffe/kaffevm/mem/gc-mem.c:
+	(gc_magic) new constant.
+	(gc_set_magic_marker, gc_check_magic_marker) New inline functions.
+	(gc_heap_alloc) Use gc_check_magic_marker.
+	(gc_block_end) new function.
+	(gc_get_prim_freelist) Check that index is >= 0 before accessing
+	array.
+	(gc_primitive_alloc) Use gc_block_end. Use gc_set_magic_marker.
+	(gc_primitive_free) Use gc_block_end.
+	(gc_heap_grow) Use gc_set_magic_marker.
+
+	* kaffe/kaffevm/mem/gc-mem.h:
+	(GC_MAGIC, GCBLOCKEND) Removed.
+
 2003-11-06 Ito Kazumitsu <kaz@maczuka.gcd.org>
 
 	libraries/javalib/gnu/xml/aelfred2/SAXDriver.java,
@@ -15,7 +31,6 @@
 	(bind, connect) Same commentary.
 
 2003-11-03  Dalibor Topic  <robilad@kaffe.org>
-
 	* kaffe/kaffeh/support.c:
 	(kaffeh_findClass) Changed type of buf to unsigned char* to
 	fix -pedantic warnings.
Index: kaffe/kaffe/kaffevm/mem/gc-mem.c
diff -u kaffe/kaffe/kaffevm/mem/gc-mem.c:1.50 kaffe/kaffe/kaffevm/mem/gc-mem.c:1.51
--- kaffe/kaffe/kaffevm/mem/gc-mem.c:1.50	Fri Oct 10 20:05:56 2003
+++ kaffe/kaffe/kaffevm/mem/gc-mem.c	Tue Nov 11 14:34:45 2003
@@ -112,6 +112,23 @@
 extern struct Hjava_lang_Thread* garbageman;
 
 #ifdef KAFFE_VMDEBUG
+/* Magic constant used to mark blocks under gc's management */
+static const uint32 gc_magic = 0xD0DECADE;
+
+/* Set the magic marker of a block */
+static inline void
+gc_set_magic_marker(gc_block *b)
+{
+  b->magic = gc_magic;
+}
+
+/* Check the magic marker of a block */
+static inline bool
+gc_check_magic_marker(gc_block *b)
+{
+  return b->magic == gc_magic;
+}
+
 /*
  * analyze the slack incurred by small objects
  */
@@ -332,7 +349,7 @@
 		mem = blk->free;
 
 		DBG(GCDIAG,
-		    assert(blk->magic == GC_MAGIC);
+		    assert(gc_check_magic_marker(blk));
 		    ASSERT_ONBLOCK(mem, blk);
 		    if (mem->next) ASSERT_ONBLOCK(mem->next, blk));
 
@@ -393,7 +410,7 @@
 
 	DBG(GCDIAG,
 	    gc_heap_check();
-	    assert(info->magic == GC_MAGIC);
+	    assert(gc_check_magic_marker(info));
 	    assert(GC_GET_COLOUR(info, idx) != GC_COLOUR_FREE));
 
 	GC_SET_COLOUR(info, idx, GC_COLOUR_FREE);
@@ -486,7 +503,7 @@
 	nr = (gc_pgsize-ROUNDUPALIGN(1))/(sz+2);
 
 	/* Setup the meta-data for the block */
-	DBG(GCDIAG, info->magic = GC_MAGIC);
+	DBG(GCDIAG, gc_set_magic_marker(info));
 
 	info->size = sz;
 	info->nr = nr;
@@ -536,7 +553,7 @@
 	}
 
 	/* Setup the meta-data for the block */
-	DBG(GCDIAG, info->magic = GC_MAGIC);
+	DBG(GCDIAG, gc_set_magic_marker(info));
 
 	info->size = sz;
 	info->nr = 1;
@@ -601,6 +618,17 @@
   b->nr = 0;
 }
 
+/* Get the end a gc block
+ *
+ * This is OK, gc_prim_(alloc|free) never assume GCBLOCKEND is really
+ * a valid block
+ */
+static inline gc_block*
+gc_block_end(gc_block *b)
+{
+  return b + ((b->size+gc_pgsize-1)>>gc_pgbits);
+}
+
 /* return the prim list blk belongs to */
 static inline gc_block **
 gc_get_prim_freelist (gc_block *blk)
@@ -609,6 +637,7 @@
 
 	if (sz <= GC_PRIM_LIST_COUNT)
 	{
+	        assert (sz > 0);
 		return &gc_prim_freelist[sz-1];
 	}
 
@@ -708,13 +737,13 @@
 
 			best_fit->size = sz;
 		
-			nptr = GCBLOCKEND(best_fit);
+			nptr = gc_block_end(best_fit);
 			nptr->size = diff;
 			gc_block_rm (nptr);
 
 			DBG(GCPRIM, dprintf ("gc_primitive_alloc: splitted remaining 0x%x bytes @ %p\n", (unsigned int)diff, nptr); )
 
-			DBG(GCDIAG, nptr->magic = GC_MAGIC);
+			DBG(GCDIAG, gc_set_magic_marker(nptr));
 
 			/* maintain list of primitive blocks */
 			nptr->pnext = best_fit->pnext;
@@ -785,12 +814,12 @@
 
 	/*
 	 * Test whether this block is mergable with its successor.
-	 * We need to do the GCBLOCKEND check, since the heap may not be a continuous
+	 * 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) &&
 	    !GCBLOCKINUSE(blk) &&
-	    GCBLOCKEND(mem)==blk) {
+	    gc_block_end(mem)==blk) {
 		DBG(GCPRIM, dprintf ("gc_primitive_free: merging %p with its successor (%p, %u)\n", mem, blk, blk->size);)
 
 		gc_remove_from_prim_freelist(blk);
@@ -800,7 +829,7 @@
 
 	if ((blk=mem->pprev) &&
 	    !GCBLOCKINUSE(blk) &&
-	    GCBLOCKEND(blk)==mem) {
+	    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);
@@ -1075,7 +1104,7 @@
 	assert(gc_heap_total <= gc_heap_limit);
 
 	/* Place block into the freelist for subsequent use */
-	DBG(GCDIAG, blk->magic = GC_MAGIC);
+	DBG(GCDIAG, gc_set_magic_marker(blk));
 	blk->size = sz;
 
 	/* maintain list of primitive blocks */
Index: kaffe/kaffe/kaffevm/mem/gc-mem.h
diff -u kaffe/kaffe/kaffevm/mem/gc-mem.h:1.17 kaffe/kaffe/kaffevm/mem/gc-mem.h:1.18
--- kaffe/kaffe/kaffevm/mem/gc-mem.h:1.17	Sun Sep 28 19:47:41 2003
+++ kaffe/kaffe/kaffevm/mem/gc-mem.h	Tue Nov 11 14:34:45 2003
@@ -110,8 +110,6 @@
 
 /* ------------------------------------------------------------------------ */
 
-#define	GC_MAGIC		0xD0DECADE
-
 #define GC_BLOCKS		((gc_block *) gc_block_base)
 
 /**
@@ -169,10 +167,6 @@
  */ 
 #define GCBLOCK2BASE(B)		(((char *)gc_heap_base) \
 					 + gc_pgsize * ((B) - GC_BLOCKS))
-
-/* This is OK, gc_prim_(alloc|free) never assume GCBLOCKEND is really
-   a valid block */
-#define GCBLOCKEND(B)		((B) + (((B)->size+gc_pgsize-1)>>gc_pgbits))
 
 #define ASSERT_ONBLOCK(OBJ, BLK) assert(GCMEM2BLOCK(OBJ) == BLK)