[kaffe] CVS kaffe (guilhem): Invocation API fixes + Static lock initializer fixes + Kaffe main cleanup.

Kaffe CVS cvs-commits at kaffe.org
Tue Jun 15 10:49:13 PDT 2004


PatchSet 4846 
Date: 2004/06/15 17:44:45
Author: guilhem
Branch: HEAD
Tag: (none) 
Log:
Invocation API fixes + Static lock initializer fixes + Kaffe main cleanup.

        * kaffe/kaffevm/baseClasses.c
        (kaffeLangAppClassLoaderClass): New class reference for the kaffe's
        class loader.
        (appClassLoader): New reference to the VM's wide user class loader.
        (initBaseClasses): Preload kaffe/lang/AppClassLoader and initialize
        appClassLoader.

        * kaffe/kaffevm/baseClasses.h
        (kaffeLangAppClassLoaderClass): New class reference for the kaffe's
        class loader.
        (appClassLoader): New reference to the VM's wide user class loader.
        (APPCLASSLOADERCLASS): New macro for the name of the user class
        loader.

        * kaffe/kaffevm/classPool.c, kaffe/kaffevm/findInJar.c,
        kaffe/kaffevm/jar.c, kaffe/kaffevm/string.c, kaffe/kaffevm/thread.c,
        kaffe/kaffevm/utf8const.c:
        Use KAFFE_STATIC_LOCK_INITIALIZER to have all static locks
        rightfully initialized at startup.

        * kaffe/kaffevm/jni.c
        (tryClassForName): New function to be able to catch exceptions.
        (Kaffe_FindClass): Initialize a user class loader and use it to load
        a class if it has not been found by the default classloader.

        * kaffe/kaffevm/locks.h
        (KAFFE_STATIC_LOCK_INITIALIZER): New macro to initialize static locks.

        * kaffe/kaffevm/string.c
        (stringUninternString): Check twice "interned" to prevent race
        conditions.

        * kaffe/kaffevm/thread.c
        (initNativeThreads): Use "fprintf(stderr," instead of "dprintf" to be
        sure all users will see the issued warning.

        * kaffe/kaffe/main.c
        (main): Removed the call to INIT_MD as it is already done in
        initialiseKaffe.
        (main2): The application class loader is now directly managed by the
        core VM.

Members: 
	ChangeLog:1.2413->1.2414 
	kaffe/kaffe/main.c:1.55->1.56 
	kaffe/kaffevm/baseClasses.c:1.51->1.52 
	kaffe/kaffevm/baseClasses.h:1.16->1.17 
	kaffe/kaffevm/classPool.c:1.24->1.25 
	kaffe/kaffevm/findInJar.c:1.57->1.58 
	kaffe/kaffevm/jar.c:1.28->1.29 
	kaffe/kaffevm/jni.c:1.113->1.114 
	kaffe/kaffevm/locks.h:1.23->1.24 
	kaffe/kaffevm/string.c:1.31->1.32 
	kaffe/kaffevm/thread.c:1.66->1.67 
	kaffe/kaffevm/utf8const.c:1.37->1.38 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.2413 kaffe/ChangeLog:1.2414
--- kaffe/ChangeLog:1.2413	Tue Jun 15 17:39:07 2004
+++ kaffe/ChangeLog	Tue Jun 15 17:44:45 2004
@@ -1,3 +1,47 @@
+2004-06-15  Guilhem Lavaux <guilhem at kaffe.org>
+
+	* kaffe/kaffevm/baseClasses.c
+	(kaffeLangAppClassLoaderClass): New class reference for the kaffe's
+	class loader.
+	(appClassLoader): New reference to the VM's wide user class loader.
+	(initBaseClasses): Preload kaffe/lang/AppClassLoader and initialize
+	appClassLoader.
+
+	* kaffe/kaffevm/baseClasses.h
+	(kaffeLangAppClassLoaderClass): New class reference for the kaffe's
+	class loader.
+	(appClassLoader): New reference to the VM's wide user class loader.
+	(APPCLASSLOADERCLASS): New macro for the name of the user class
+	loader.
+
+	* kaffe/kaffevm/classPool.c, kaffe/kaffevm/findInJar.c,
+	kaffe/kaffevm/jar.c, kaffe/kaffevm/string.c, kaffe/kaffevm/thread.c,
+	kaffe/kaffevm/utf8const.c:
+	Use KAFFE_STATIC_LOCK_INITIALIZER to have all static locks
+	rightfully initialized at startup.
+
+	* kaffe/kaffevm/jni.c
+	(tryClassForName): New function to be able to catch exceptions.
+	(Kaffe_FindClass): Initialize a user class loader and use it to load
+	a class if it has not been found by the default classloader.
+	
+	* kaffe/kaffevm/locks.h
+	(KAFFE_STATIC_LOCK_INITIALIZER): New macro to initialize static locks.
+
+	* kaffe/kaffevm/string.c
+	(stringUninternString): Check twice "interned" to prevent race
+	conditions.
+
+	* kaffe/kaffevm/thread.c
+	(initNativeThreads): Use "fprintf(stderr," instead of "dprintf" to be
+	sure all users will see the issued warning.
+
+	* kaffe/kaffe/main.c
+	(main): Removed the call to INIT_MD as it is already done in
+	initialiseKaffe.
+	(main2): The application class loader is now directly managed by the
+	core VM.
+
 2003-06-15  Dalibor Topic  <robilad at kaffe.org>
 
 	* libraries/javalib/java/nio/Buffer.java,
Index: kaffe/kaffe/kaffe/main.c
diff -u kaffe/kaffe/kaffe/main.c:1.55 kaffe/kaffe/kaffe/main.c:1.56
--- kaffe/kaffe/kaffe/main.c:1.55	Thu Jun 10 18:19:37 2004
+++ kaffe/kaffe/kaffe/main.c	Tue Jun 15 17:44:47 2004
@@ -87,10 +87,6 @@
 	textdomain(PACKAGE);
 #endif
 
-#if defined(MAIN_MD)
-	/* Machine specific main first */
-	MAIN_MD;
-#endif
 	vmargs.version = JAVA_VERSION_HEX;
 
 #if defined(KAFFE_PROFILER)
@@ -260,57 +256,16 @@
 	/* Executable is a JAR?  Use the JAR launcher */
 	if (isJar != 0) {
 		exec = "kaffe.jar.ExecJar";
-		
-		mcls = (*env)->FindClass(env, exec);
-		if (checkException())
-			goto done;
 	}
 	else {
 		exec = argv[farg];
 		farg++;
 		argc--;
-
-		/* Get the application class loader class */
-		lcls = (*env)->FindClass(env, "kaffe.lang.AppClassLoader");
-		if (checkException())
-			goto done;
-		
-		/* ... and then get the singleton. */
-		cmth = (*env)->GetStaticMethodID(env,
-						 lcls,
-						 "getSingleton",
-						 "()Ljava/lang/ClassLoader;");
-		if (checkException())
-			goto done;
-		
-		loader = (*env)->CallStaticObjectMethod(env,
-							lcls,
-							cmth);
-		if (checkException())
-			goto done;
-		
-		/* Load the main class into the AppClassLoader */
-		lmth = (*env)->GetMethodID(env,
-					   lcls,
-					   "loadClass",
-					   "(Ljava/lang/String;Z)Ljava/lang/Class;");
-		if (checkException())
-			goto done;
-		
-DBG(VMCLASSLOADER,
-    /* Announce when VM calls class loaders.. */
-    dprintf("Calling user-defined \"startup\" class loader "
-	    "kaffe/lang/AppClassLoader - loadClass(%s)\n", exec);
-    )
-	
-		mcls = (*env)->CallObjectMethod(env,
-						loader,
-						lmth,
-						(*env)->NewStringUTF(env, exec),
-						false);
-		if (checkException())
-			goto done;
 	}
+	
+	mcls = (*env)->FindClass(env, exec);
+	if (checkException())
+		goto done;
 	
 	/* ... and run main. */
 	mmth = (*env)->GetStaticMethodID(env,
Index: kaffe/kaffe/kaffevm/baseClasses.c
diff -u kaffe/kaffe/kaffevm/baseClasses.c:1.51 kaffe/kaffe/kaffevm/baseClasses.c:1.52
--- kaffe/kaffe/kaffevm/baseClasses.c:1.51	Thu Jun 10 18:19:40 2004
+++ kaffe/kaffe/kaffevm/baseClasses.c	Tue Jun 15 17:44:47 2004
@@ -73,6 +73,7 @@
 Hjava_lang_Class* javaLangLongClass;
 Hjava_lang_Class* javaLangFloatClass;
 Hjava_lang_Class* javaLangDoubleClass;
+Hjava_lang_Class* kaffeLangAppClassLoaderClass;
 
 Hjava_lang_Class* javaLangThrowable;
 Hjava_lang_Class* javaLangVMThrowable;
@@ -87,6 +88,8 @@
 /* Let's not load this if we can't open Klasses.jar */
 Hjava_lang_Class* javaIoIOException;
 
+Hjava_lang_ClassLoader* appClassLoader;
+
 #define SYSTEMCLASS "java/lang/System"
 #define	SERIALCLASS "java/io/Serializable"
 #define	CLONECLASS  "java/lang/Cloneable"
@@ -280,6 +283,7 @@
 	loadStaticClass(&javaLangDoubleClass, "java/lang/Double");
 	loadStaticClass(&PtrClass, PTRCLASS);
 	loadStaticClass(&ClassLoaderClass, LOADERCLASS);
+	loadStaticClass(&kaffeLangAppClassLoaderClass, APPCLASSLOADERCLASS);
 
 	/* Exception handling types */
 	loadStaticClass(&javaLangThrowable, "java/lang/Throwable");
@@ -301,5 +305,7 @@
 	
 	if (!processClass(StringClass, CSTATE_COMPLETE, &einfo))
 		abortWithEarlyClassFailure(&einfo);
+
+	appClassLoader = NULL;
 }
 
Index: kaffe/kaffe/kaffevm/baseClasses.h
diff -u kaffe/kaffe/kaffevm/baseClasses.h:1.16 kaffe/kaffe/kaffevm/baseClasses.h:1.17
--- kaffe/kaffe/kaffevm/baseClasses.h:1.16	Tue Aug  5 15:06:37 2003
+++ kaffe/kaffe/kaffevm/baseClasses.h	Tue Jun 15 17:44:47 2004
@@ -18,6 +18,7 @@
 #define	STRINGCLASS	"java/lang/String"
 #define	OBJECTCLASS	"java/lang/Object"
 #define	CLASSCLASS	"java/lang/Class"
+#define	APPCLASSLOADERCLASS "kaffe/lang/AppClassLoader"
 
 #define	OBJECTCLASSSIG	"Ljava/lang/Object;"
 
@@ -35,6 +36,7 @@
 extern struct Hjava_lang_Class*	CloneClass;
 extern struct Hjava_lang_Class* PtrClass;
 extern struct Hjava_lang_Class* ClassLoaderClass;
+extern struct Hjava_lang_Class* kaffeLangAppClassLoaderClass;
 
 extern struct Hjava_lang_Class*	javaLangVoidClass;
 extern struct Hjava_lang_Class*	javaLangBooleanClass;
@@ -56,5 +58,7 @@
 extern struct Hjava_lang_Class* javaLangClassNotFoundException;
 extern struct Hjava_lang_Class* javaLangNoClassDefFoundError;
 extern struct Hjava_lang_Class* javaLangStackOverflowError;
+
+extern struct Hjava_lang_ClassLoader *appClassLoader;
 
 #endif
Index: kaffe/kaffe/kaffevm/classPool.c
diff -u kaffe/kaffe/kaffevm/classPool.c:1.24 kaffe/kaffe/kaffevm/classPool.c:1.25
--- kaffe/kaffe/kaffevm/classPool.c:1.24	Fri Apr  2 21:27:44 2004
+++ kaffe/kaffe/kaffevm/classPool.c	Tue Jun 15 17:44:47 2004
@@ -29,7 +29,7 @@
 #include "md.h"
 
 #define	CLASSHASHSZ	256	/* Must be a power of two */
-static iStaticLock	classHashLock;
+static iStaticLock	classHashLock = KAFFE_STATIC_LOCK_INITIALIZER;
 static classEntry* classEntryPool[CLASSHASHSZ];
 #if defined(KAFFE_STATS)
 statobject classStats;
@@ -250,7 +250,7 @@
 }
 
 static nameDependency *dependencies;
-static iStaticLock	mappingLock;
+static iStaticLock	mappingLock = KAFFE_STATIC_LOCK_INITIALIZER;
 
 static
 nameDependency *findNameDependency(jthread_t jt)
Index: kaffe/kaffe/kaffevm/findInJar.c
diff -u kaffe/kaffe/kaffevm/findInJar.c:1.57 kaffe/kaffe/kaffevm/findInJar.c:1.58
--- kaffe/kaffe/kaffevm/findInJar.c:1.57	Sun Apr 18 13:57:26 2004
+++ kaffe/kaffe/kaffevm/findInJar.c	Tue Jun 15 17:44:47 2004
@@ -180,7 +180,7 @@
 {
 	char *buf;
 	int fp;
-	static iStaticLock	jarlock;
+	static iStaticLock	jarlock = KAFFE_STATIC_LOCK_INITIALIZER;
 	classpathEntry* ptr;
 	int i;
 	int rc;
Index: kaffe/kaffe/kaffevm/jar.c
diff -u kaffe/kaffe/kaffevm/jar.c:1.28 kaffe/kaffe/kaffevm/jar.c:1.29
--- kaffe/kaffe/kaffevm/jar.c:1.28	Sun Apr 18 13:57:26 2004
+++ kaffe/kaffe/kaffevm/jar.c	Tue Jun 15 17:44:47 2004
@@ -66,14 +66,21 @@
  * jarFiles in memory longer than we should but it helps to avoid the
  * constant opening/closing some java code does.
  */
-static struct _jarCache {
+struct _jarCache {
 #if !defined(KAFFEH)
 	iStaticLock	lock;
 #endif
 	jarFile *files;
 #define JAR_FILE_CACHE_MAX 12
 	unsigned int count;
-} jarCache;
+};
+
+static struct _jarCache jarCache = {
+#if !defined(KAFFEH)
+	KAFFE_STATIC_LOCK_INITIALIZER,
+#endif
+	NULL, 0
+};
 
 /*
  * Hash a file name, the hash value is stored in what `hash' points to.
Index: kaffe/kaffe/kaffevm/jni.c
diff -u kaffe/kaffe/kaffevm/jni.c:1.113 kaffe/kaffe/kaffevm/jni.c:1.114
--- kaffe/kaffe/kaffevm/jni.c:1.113	Thu Jun 10 18:19:41 2004
+++ kaffe/kaffe/kaffevm/jni.c	Tue Jun 15 17:44:47 2004
@@ -362,12 +362,30 @@
  * use based on the calling method, which requires examining the
  * stack backtrace.
  */
+
+static jclass
+tryClassForName(jstring nameString)
+{
+	jvalue retval;
+
+	BEGIN_EXCEPTION_HANDLING(0);
+
+	/* Call Class.forName() */
+	retval = do_execute_java_class_method("java.lang.Class", NULL,
+	    "forName", "(Ljava/lang/String;)Ljava/lang/Class;", nameString);
+
+	END_EXCEPTION_HANDLING();
+
+	return retval.l;
+}
+
 static jclass
-Kaffe_FindClass(JNIEnv* env UNUSED, const char* name)
+Kaffe_FindClass(JNIEnv* env, const char* name)
 {
 	jstring nameString;
 	Utf8Const* utf8;
-	jvalue retval;
+	jobject retval;
+	jobject exc;
 
 	BEGIN_EXCEPTION_HANDLING(0);
 
@@ -377,13 +395,45 @@
 	utf8ConstRelease(utf8);
 	checkPtr(nameString);
 
-	/* Call Class.forName() */
-	retval = do_execute_java_class_method("java.lang.Class", NULL,
-	    "forName", "(Ljava/lang/String;)Ljava/lang/Class;", nameString);
+	retval = tryClassForName(nameString);
+
+	exc = thread_data->exceptObj;
+	if (exc != NULL)
+	{
+		if (soft_instanceof(javaLangClassNotFoundException, exc))
+		{
+			int iLockRoot;
+			static iStaticLock appLock = KAFFE_STATIC_LOCK_INITIALIZER;
+
+			thread_data->exceptObj = NULL;
+			if (appClassLoader == NULL)
+			{
+				lockStaticMutex(&appLock);
+				if (appClassLoader == NULL)
+					appClassLoader = do_execute_java_method(kaffeLangAppClassLoaderClass, "getSingleton", "()Ljava/lang/ClassLoader;", NULL, true).l;
+				unlockStaticMutex(&appLock);
+
+				if (thread_data->exceptObj != NULL)
+				{
+					fprintf(stderr,
+						"ERROR: The default user class loader "
+					       	APPCLASSLOADERCLASS " can not be loaded.\n"
+						"Aborting...\n");
+					ABORT();
+				}
+			}
+
+			
+			retval = do_execute_java_class_method("java.lang.Class", NULL,
+			    "forName", "(Ljava/lang/String;ZLjava/lang/ClassLoader;)Ljava/lang/Class;", nameString, true, appClassLoader).l;
+			ADD_REF(retval);
+		}
+	} else {
+		ADD_REF(retval);
+	}
 
-	ADD_REF(retval.l);
 	END_EXCEPTION_HANDLING();
-	return (retval.l);
+	return (retval);
 }
 
 static jclass
Index: kaffe/kaffe/kaffevm/locks.h
diff -u kaffe/kaffe/kaffevm/locks.h:1.23 kaffe/kaffe/kaffevm/locks.h:1.24
--- kaffe/kaffe/kaffevm/locks.h:1.23	Sun Feb  1 22:14:53 2004
+++ kaffe/kaffe/kaffevm/locks.h	Tue Jun 15 17:44:47 2004
@@ -53,6 +53,8 @@
 	iLock	heavyLock; 
 } iStaticLock;
 
+#define KAFFE_STATIC_LOCK_INITIALIZER { NULL }
+
 #define	LOCKINPROGRESS	((iLock*)-1)
 #define	LOCKFREE	((iLock*)0)
 
Index: kaffe/kaffe/kaffevm/string.c
diff -u kaffe/kaffe/kaffevm/string.c:1.31 kaffe/kaffe/kaffevm/string.c:1.32
--- kaffe/kaffe/kaffevm/string.c:1.31	Sun Apr 18 13:57:27 2004
+++ kaffe/kaffe/kaffevm/string.c	Tue Jun 15 17:44:47 2004
@@ -23,8 +23,8 @@
 
 /* Internal variables */
 static hashtab_t	hashTable;	/* intern hash table */
-static iStaticLock	stringLock;	/* mutex on all intern operations */
-static int *            stringLockRoot;	/* the string lock is not a monitor */
+static iStaticLock	stringLock = KAFFE_STATIC_LOCK_INITIALIZER; /* mutex on all intern operations */
+static int *            stringLockRoot = NULL;	/* the string lock is not a monitor */
 
 /* Internal functions */
 static int		stringHashValue(const void *ptr);
@@ -351,6 +351,11 @@
 	int iLockRoot;
 
 	lockStaticMutex(&stringLock);
+	if (!unhand(string)->interned)
+	{
+	  unlockStaticMutex(&stringLock);
+	  return;
+	}
 	stringLockRoot = &iLockRoot;
 	hashRemove(hashTable, string);
 	unhand(string)->interned = false;
Index: kaffe/kaffe/kaffevm/thread.c
diff -u kaffe/kaffe/kaffevm/thread.c:1.66 kaffe/kaffe/kaffevm/thread.c:1.67
--- kaffe/kaffe/kaffevm/thread.c:1.66	Mon Jun  7 19:14:27 2004
+++ kaffe/kaffe/kaffevm/thread.c	Tue Jun 15 17:44:48 2004
@@ -58,7 +58,7 @@
 static void firstStartThread(void*);
 static void runfinalizer(void);
 
-static iStaticLock	thread_start_lock;
+static iStaticLock	thread_start_lock = KAFFE_STATIC_LOCK_INITIALIZER;
 
 /*
  * How do I get memory?
@@ -719,8 +719,8 @@
 
 	if (stackSize == KAFFEMD_STACK_ERROR)
 	  {
-	    dprintf("WARNING: Impossible to retrieve the real stack size\n");
-	    dprintf("WARNING: You may experience deadlocks\n");
+	    fprintf(stderr, "WARNING: Impossible to retrieve the real stack size\n");
+	    fprintf(stderr, "WARNING: You may experience deadlocks\n");
 	  }
 	else if (stackSize == KAFFEMD_STACK_INFINITE || stackSize > threadStackSize)
 	  {
@@ -730,7 +730,8 @@
 	  }
 	else
 	  {
-	    dprintf("NOTE: It is impossible to set the main thread stack\n"
+	    fprintf(stderr, 
+	            "NOTE: It is impossible to set the main thread stack\n"
 		    "NOTE: size because the system stack size is too low\n");
 	  }
 #else
Index: kaffe/kaffe/kaffevm/utf8const.c
diff -u kaffe/kaffe/kaffevm/utf8const.c:1.37 kaffe/kaffe/kaffevm/utf8const.c:1.38
--- kaffe/kaffe/kaffevm/utf8const.c:1.37	Thu Apr 22 09:22:38 2004
+++ kaffe/kaffe/kaffevm/utf8const.c	Tue Jun 15 17:44:48 2004
@@ -37,7 +37,7 @@
 /* Internal variables */
 #ifndef KAFFEH				/* Yuk! */
 static hashtab_t	hashTable;
-static iStaticLock	utf8Lock;	/* mutex on all intern operations */
+static iStaticLock	utf8Lock = KAFFE_STATIC_LOCK_INITIALIZER;	/* mutex on all intern operations */
 
 /*
  * Used to keep track of the current utf8Lock holder's stack




More information about the kaffe mailing list