[kaffe] CVS kaffe (hkraemer): tweaks for gc and system properties

Kaffe CVS cvs-commits at kaffe.org
Wed Apr 21 03:20:05 PDT 2004


PatchSet 4669 
Date: 2004/04/21 10:15:05
Author: hkraemer
Branch: HEAD
Tag: (none) 
Log:
tweaks for gc and system properties

* autodetect user.language and user.region using setlocale ()
* fix some warnings in the gc

Members: 
	ChangeLog:1.2245->1.2246 
	kaffe/kaffevm/gc.h:1.23->1.24 
	kaffe/kaffevm/mem/gc-incremental.c:1.79->1.80 
	kaffe/kaffevm/mem/gc-mem.c:1.56->1.57 
	libraries/clib/native/System.c:1.44->1.45 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.2245 kaffe/ChangeLog:1.2246
--- kaffe/ChangeLog:1.2245	Tue Apr 20 16:53:22 2004
+++ kaffe/ChangeLog	Wed Apr 21 10:15:05 2004
@@ -1,3 +1,24 @@
+2004-04-20  Helmer Kraemer  <hkraemer at freenet.de>
+
+	* libraries/clib/native/System.c:
+	(java_lang_System_initProperties) autodetect user.language and
+	user.region using setlocale()
+
+	* kaffe/kaffevm/gc.h: 
+	(registerFixedTypeByIndex, registerGcTypeByIndex): change type
+	of gc_index parameter to gc_alloc_type_t
+
+	* kaffe/kaffevm/mem/gc-mem.c:
+	(gc_large_block): initialize all gc_blocks covered by the large block,
+	so the GCMEM2* macros work for addresses inside a large block
+	
+	* kaffe/kaffevm/mem/gc-incremental.c:
+	(nrTypes): removed
+	(registerTypeByIndex, gcRegisterFixedTypeByIndex, gcRegisterGcTypeByIndex):
+	adapted to modified prototypes in gc.h
+	(gcGetObjectBase): simplified since GCMEM2* macros now work for
+	addresses inside large blocks
+
 2004-04-20  Guilhem Lavaux <guilhem at kaffe.org>
 
 	* kaffe/kaffevm/ksem.h
Index: kaffe/kaffe/kaffevm/gc.h
diff -u kaffe/kaffe/kaffevm/gc.h:1.23 kaffe/kaffe/kaffevm/gc.h:1.24
--- kaffe/kaffe/kaffevm/gc.h:1.23	Wed Mar 24 21:22:05 2004
+++ kaffe/kaffe/kaffevm/gc.h	Wed Apr 21 10:15:06 2004
@@ -121,10 +121,10 @@
 			const void* addr, uint32 length);
 
 	void	(*registerFixedTypeByIndex)(Collector *, 
-			int gc_index, const char *description);
+			gc_alloc_type_t gc_index, const char *description);
 
 	void 	(*registerGcTypeByIndex)(Collector *, 
-			int gc_index,
+			gc_alloc_type_t gc_index,
 			walk_func_t walk, final_func_t final, 
 			destroy_func_t destroy, const char
 					 *description);
Index: kaffe/kaffe/kaffevm/mem/gc-incremental.c
diff -u kaffe/kaffe/kaffevm/mem/gc-incremental.c:1.79 kaffe/kaffe/kaffevm/mem/gc-incremental.c:1.80
--- kaffe/kaffe/kaffevm/mem/gc-incremental.c:1.79	Sun Apr 18 13:57:27 2004
+++ kaffe/kaffe/kaffevm/mem/gc-incremental.c	Wed Apr 21 10:15:07 2004
@@ -163,9 +163,6 @@
 /* Standard GC function sets.  We call them "allocation types" now */
 static gcFuncs gcFunctions[GC_ALLOC_MAX_INDEX];
 
-/* Number of registered allocation types */
-static int nrTypes;
-
 /*
  * register an allocation type under a certain index
  * NB: we could instead return a pointer to the record describing the
@@ -173,22 +170,19 @@
  * allow us to use compile-time constants.
  */
 static void
-registerTypeByIndex(int index, walk_func_t walk, final_func_t final,
+registerTypeByIndex(gc_alloc_type_t idx, walk_func_t walk, final_func_t final,
 	destroy_func_t destroy,
 	const char *description)
 {
 	/* once only, please */
-	assert (gcFunctions[index].description == 0);
+	assert (gcFunctions[idx].description == 0);
 	/* don't exceed bounds */
-	assert (index >= 0 && 
-		index < sizeof(gcFunctions)/sizeof(gcFunctions[0]));
-	gcFunctions[index].walk = walk;
-	gcFunctions[index].final = final;
-	gcFunctions[index].destroy = destroy;
-	gcFunctions[index].description = description;
-	if (index >= nrTypes) {
-		nrTypes = index + 1;
-	}
+	assert (idx < sizeof(gcFunctions)/sizeof(gcFunctions[0]));
+
+	gcFunctions[idx].walk = walk;
+	gcFunctions[idx].final = final;
+	gcFunctions[idx].destroy = destroy;
+	gcFunctions[idx].description = description;
 }
 
 /*
@@ -197,9 +191,9 @@
  */
 static void
 gcRegisterFixedTypeByIndex(Collector* gcif UNUSED, 
-	int index, const char *description)
+	gc_alloc_type_t idx, const char *description)
 {
-	registerTypeByIndex(index, 0, GC_OBJECT_FIXED, 0, description);
+	registerTypeByIndex(idx, 0, GC_OBJECT_FIXED, 0, description);
 }
 
 /*
@@ -207,11 +201,11 @@
  */
 static void
 gcRegisterGcTypeByIndex(Collector* gcif UNUSED,
-	int index, walk_func_t walk, final_func_t final,
+	gc_alloc_type_t idx, walk_func_t walk, final_func_t final,
 	destroy_func_t destroy,
 	const char *description)
 {
-	registerTypeByIndex(index, walk, final, destroy, description);
+	registerTypeByIndex(idx, walk, final, destroy, description);
 }
 
 struct _gcStats gcStats;
@@ -226,17 +220,16 @@
 gc_heap_isobject(gc_block *info, gc_unit *unit)
 {
 	uintp p = (uintp) UTOMEM(unit) - gc_heap_base;
-	int idx;
 
 	if (!(p & (MEMALIGN - 1)) && p < gc_heap_range && GCBLOCKINUSE(info)) {
 		/* Make sure 'unit' refers to the beginning of an
 		 * object.  We do this by making sure it is correctly
 		 * aligned within the block.
 		 */
-		idx = GCMEM2IDX(info, unit);
-		if (idx < info->nr && GCBLOCK2MEM(info, idx) == unit
-		    && (GC_GET_COLOUR(info, idx) & GC_COLOUR_INUSE) ==
-		    GC_COLOUR_INUSE) {
+		uint16 idx = GCMEM2IDX(info, unit);
+		if (idx < info->nr &&
+		    GCBLOCK2MEM(info, idx) == unit &&
+		    (GC_GET_COLOUR(info, idx) & GC_COLOUR_INUSE) == GC_COLOUR_INUSE) {
 			return 1;
 		}
 	}
@@ -381,20 +374,12 @@
 		return (0);
 	}
 
+	/* the allocator initializes all block infos of a large
+	   object using the address of the first page allocated
+	   for the large object. Hence, simply using GCMEM2* works
+	   even for large blocks
+	  */
 	info = GCMEM2BLOCK(mem);
-	if (!GCBLOCKINUSE(info)) {
-		/* go down block list to find out whether we were hitting
-		 * in a large object
-		 */
-		while (!GCBLOCKINUSE(info) && (uintp)info > (uintp)gc_block_base) {
-			info--;
-		}
-		/* must be a large block, hence nr must be 1 */
-		if (!GCBLOCKINUSE(info) || info->nr != 1) {
-			return (0);
-		}
-	}
-
 	idx = GCMEM2IDX(info, mem);
 
 	/* report fixed objects as well */
@@ -1016,7 +1001,7 @@
 	int times = 0;
 
 	assert(gc_init != 0);
-	assert(fidx < nrTypes && size != 0);
+	assert(gcFunctions[fidx].description != NULL && size != 0);
 
 	size += sizeof(gc_unit);
 
@@ -1037,7 +1022,7 @@
 					adviseGC();
 					lockStaticMutex(&gc_lock);
 				}
-				break;	  
+				break;
 
 			case 2:
 				/* Grow the heap */
@@ -1194,7 +1179,7 @@
 	int idx;
 	void* newmem;
 	gc_unit* unit;
-	int osize;
+	size_t osize;
 	int iLockRoot;
 
 	assert(gcFunctions[fidx].final == GC_OBJECT_FIXED);
@@ -1312,7 +1297,7 @@
 	info = GCMEM2BLOCK(unit);
 	idx = GC_GET_FUNCS(info, GCMEM2IDX(info, unit));
 
-	assert(idx >= 0 && idx < nrTypes);
+	assert(idx >= 0 && gcFunctions[idx].description!=NULL);
 	gcFunctions[idx].nr += diff * 1;
 	gcFunctions[idx].mem += diff * GCBLOCKSIZE(info);
 }
@@ -1326,7 +1311,7 @@
 	dprintf("Memory statistics:\n");
 	dprintf("------------------\n");
 
-	while (cnt < nrTypes) {
+	while (gcFunctions[cnt].description != NULL) {
 		dprintf("%14.14s: Nr %6d  Mem %6dK",
 			gcFunctions[cnt].description, 
 			gcFunctions[cnt].nr, 
Index: kaffe/kaffe/kaffevm/mem/gc-mem.c
diff -u kaffe/kaffe/kaffevm/mem/gc-mem.c:1.56 kaffe/kaffe/kaffevm/mem/gc-mem.c:1.57
--- kaffe/kaffe/kaffevm/mem/gc-mem.c:1.56	Sat Apr  3 00:06:13 2004
+++ kaffe/kaffe/kaffevm/mem/gc-mem.c	Wed Apr 21 10:15:07 2004
@@ -544,6 +544,7 @@
 {
 	gc_block* info;
 	size_t msz;
+	size_t block_count;
 
 	/* Add in management overhead */
 	msz = sz+2+ROUNDUPALIGN(1);
@@ -555,6 +556,11 @@
 		return (0);
 	}
 
+	/* number of pages allocated for block */
+	block_count = msz >> gc_pgbits;
+	
+	DBG(GCPRIM, dprintf ("large block covers %x pages\n", block_count); )
+
 	/* Setup the meta-data for the block */
 	DBG(GCDIAG, gc_set_magic_marker(info));
 
@@ -569,6 +575,18 @@
 	DBG(GCDIAG, memset(info->data, 0, sz));
 
 	GCBLOCK2FREE(info, 0)->next = 0;
+
+	/* now initialize the other blocks that were allocated */
+	while (--block_count > 0) {
+
+		info[block_count].size  = sz;
+		info[block_count].nr    = 1;
+		info[block_count].avail = 0;
+		info[block_count].funcs = info[0].funcs;
+		info[block_count].state = info[0].state;
+		info[block_count].data  = info[0].data;
+		info[block_count].free  = 0;
+	}
 
 	/*
 	 * XXX gc_large_block only called during a block allocation.
Index: kaffe/libraries/clib/native/System.c
diff -u kaffe/libraries/clib/native/System.c:1.44 kaffe/libraries/clib/native/System.c:1.45
--- kaffe/libraries/clib/native/System.c:1.44	Sun Apr 18 13:57:29 2004
+++ kaffe/libraries/clib/native/System.c	Wed Apr 21 10:15:07 2004
@@ -44,6 +44,8 @@
 #include <native.h>
 #include <jni.h>
 
+#include <locale.h>
+
 static char cwdpath[MAXPATHLEN];
 
 extern char* realClassPath;
@@ -168,7 +170,6 @@
 	char* jhome;
 	char* cpath;
 	char* dir;
-	char* tzone;
 	userProperty* prop;
 #if defined(HAVE_SYS_UTSNAME_H)
 	struct utsname system;
@@ -326,6 +327,30 @@
 	{
 		setProperty(p, "user.name", "Unknown");
 		setProperty(p, "user.home", "Unknown");
+	}
+	
+	{
+	char *tmp;
+	char *locale;
+	char lang[3];
+
+	locale = setlocale (LC_ALL, "");
+
+	tmp = strchr (locale, '_');
+
+	if (tmp != NULL) {
+		lang[2] = '\0';
+
+		strncpy (lang, locale, 2);
+		setProperty (p, "user.language", lang);
+
+		strncpy (lang, tmp+1, 2);
+		setProperty (p, "user.region", lang);
+	} else {
+		/* locale not set or not of the form <lang>_<region> */
+		setProperty (p, "user.language", "en");
+		setProperty (p, "user.region", "US");
+	}	
 	}
 
 	setProperty(p, "file.encoding.pkg", "kaffe.io");




More information about the kaffe mailing list