[kaffe] CVS kaffe (hkraemer): merged java.lang.ClassLoader from GNU Classpath

Kaffe CVS cvs-commits at kaffe.org
Tue Dec 21 08:56:33 PST 2004


PatchSet 5700 
Date: 2004/12/21 16:51:01
Author: hkraemer
Branch: HEAD
Tag: (none) 
Log:
merged java.lang.ClassLoader from GNU Classpath

Members: 
	ChangeLog:1.3245->1.3246 
	include/Makefile.am:1.79->1.80 
	include/Makefile.in:1.197->1.198 
	kaffe/kaffe/main.c:1.73->1.74 
	kaffe/kaffevm/classMethod.h:1.72->1.73 
	kaffe/kaffevm/classPool.c:1.31->1.32 
	kaffe/kaffevm/external.c:1.73->1.74 
	kaffe/kaffevm/external.h:1.9->1.10 
	kaffe/kaffevm/gcFuncs.c:1.61->1.62 
	kaffe/kaffevm/thread.c:1.87->1.88 
	libraries/clib/native/Class.c:1.77->1.78 
	libraries/clib/native/ClassLoader.c:1.39->1.40 
	libraries/clib/native/Makefile.am:1.37->1.38 
	libraries/clib/native/Makefile.in:1.163->1.164 
	libraries/clib/native/NativeLibrary.c:1.6->1.7(DEAD) 
	libraries/clib/native/Runtime.c:1.29->1.30 
	libraries/javalib/Makefile.am:1.278->1.279 
	libraries/javalib/Makefile.in:1.359->1.360 
	libraries/javalib/all.files:1.59->1.60 
	libraries/javalib/bootstrap.classlist:1.65->1.66 
	libraries/javalib/gnu/java/util/DoubleEnumeration.java:INITIAL->1.1 
	libraries/javalib/java/lang/Class.java:1.50->1.51 
	libraries/javalib/java/lang/ClassLoader.java:1.34->1.35 
	libraries/javalib/java/lang/NativeLibrary.java:1.5->1.6(DEAD) 
	libraries/javalib/java/lang/Runtime.java:1.30->1.31 
	libraries/javalib/java/lang/System.java:1.42->1.43 
	libraries/javalib/java/lang/VMClassLoader.java:INITIAL->1.1 
	libraries/javalib/kaffe/lang/PrimordialClassLoader.java:1.6->1.7 
	libraries/javalib/kaffe/lang/ThreadStack.java:1.3->1.4 
	test/regression/KaffeInternal.java:1.1->1.2 
	test/regression/Makefile.am:1.90->1.91 
	test/regression/Makefile.in:1.195->1.196 
	test/regression/PrimordialLoaderTest.java:INITIAL->1.1 
	test/regression/ProcessClassInst.java:1.11->1.12 
	test/regression/ProcessClassStop.java:1.10->1.11 
	test/regression/ProhibitedClass.java:1.5->1.6 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.3245 kaffe/ChangeLog:1.3246
--- kaffe/ChangeLog:1.3245	Tue Dec 21 11:46:51 2004
+++ kaffe/ChangeLog	Tue Dec 21 16:51:01 2004
@@ -1,5 +1,52 @@
 2004-12-21  Helmer Kraemer  <hkraemer at freenet.de>
 
+	Merged java.lang.ClassLoader from GNU Classpath
+
+	* kaffe/kaffevm/external.c, kaffe/kaffevm/external.h, kaffe/kaffevm/classPool.c,
+	kaffe/kaffe/main.c: keep track of the associated class loader of a native library;
+	unload native libraries when a class loader is gced, throw an exception if a
+	library is loaded by more than one class loader
+	
+	* kaffe/kaffevm/gcFuncs.c, kaffe/kaffevm/classMethod.h: add protectionDomain field
+	to Hjava_lang_Class
+
+	* libraries/javalib/kaffe/lang/ThreadStack.java, kaffe/kaffevm/thread.c: use
+	ClassLoader.getSystemClassLoader instead of AppClassLoader.getSingleton so we
+	don't mess up the initialization order of the runtime library
+
+	* libraries/javalib/java/lang/ClassLoader.java, gnu/java/util/DoubleEnumeration.java:
+	new files, taken from GNU classpath
+
+	* libraries/javalib/java/lang/VMClassLoader.java: new file
+
+	* libraries/javalib/java/lang/Class.java, libraries/clib/native/Class.c,
+	libraries/clib/native/ClassLoader.c: updated to class loader changes
+
+	* libraries/javalib/kaffe/lang/PrimordialClassLoader.java: deny loading of classes
+	from the gnu.classpath package
+	
+	* libraries/javalib/java/lang/System.java, libraries/javalib/java/lang/Runtime.java:
+	moved handling of native libraries into java.lang.Runtime.
+	
+	* libraries/javalib/java/lang/NativeLibrary.java,
+	libraries/clib/native/NativeLibrary.c: removed
+
+	* libraries/javalib/bootstrap.classlist, libraries/javalib/all.files,
+	libraries/javalib/Makefile.am, libraries/javalib/Makefile.in, include/Makefile.am,
+	include/Makefile.in: updated
+
+	* test/regression/ProcessClassInst.java, test/regression/ProcessClassStop.java,
+	ProhibitedClass.java: updated expected output
+
+	* test/regression/KaffeInternal.java: check that access to gnu.classpath
+	package is denied for non-bootstrap classes
+
+	* test/regression/Makefile.am, test/regression/Makefile.in,
+	test/regression/PrimordialLoaderTest.java: new test case for the java
+	interface to the primordial class loader
+
+2004-12-21  Helmer Kraemer  <hkraemer at freenet.de>
+
 	* kaffe/kaffevm/threadData.h (THREAD_DATA_INITIALIZED): new macro
 
 	* kaffe/kaffevm/kaffe-gc/gc-refs.c (liveThreadWalker): properly handle
Index: kaffe/include/Makefile.am
diff -u kaffe/include/Makefile.am:1.79 kaffe/include/Makefile.am:1.80
--- kaffe/include/Makefile.am:1.79	Wed Dec  8 07:22:07 2004
+++ kaffe/include/Makefile.am	Tue Dec 21 16:51:11 2004
@@ -67,7 +67,6 @@
 	java_lang_Integer.h \
 	java_lang_Long.h \
 	java_lang_Math.h \
-	java_lang_NativeLibrary.h \
 	java_lang_Runtime.h \
 	java_lang_Short.h \
 	java_lang_System.h \
Index: kaffe/include/Makefile.in
diff -u kaffe/include/Makefile.in:1.197 kaffe/include/Makefile.in:1.198
--- kaffe/include/Makefile.in:1.197	Wed Dec  8 07:22:07 2004
+++ kaffe/include/Makefile.in	Tue Dec 21 16:51:11 2004
@@ -416,7 +416,6 @@
 	java_lang_Integer.h \
 	java_lang_Long.h \
 	java_lang_Math.h \
-	java_lang_NativeLibrary.h \
 	java_lang_Runtime.h \
 	java_lang_Short.h \
 	java_lang_System.h \
Index: kaffe/kaffe/kaffe/main.c
diff -u kaffe/kaffe/kaffe/main.c:1.73 kaffe/kaffe/kaffe/main.c:1.74
--- kaffe/kaffe/kaffe/main.c:1.73	Sat Dec 18 07:45:34 2004
+++ kaffe/kaffe/kaffe/main.c	Tue Dec 21 16:51:10 2004
@@ -198,7 +198,7 @@
 			libargs += 1;
 		}
 		
-		i = loadNativeLibrary(libpath, errbuf, sizeof(errbuf));
+		i = loadNativeLibrary(libpath, NULL, errbuf, sizeof(errbuf));
 		if( i > 0 )
 		{
 			jint (*onload_func)(JavaVM *jvm, char *, void *);
Index: kaffe/kaffe/kaffevm/classMethod.h
diff -u kaffe/kaffe/kaffevm/classMethod.h:1.72 kaffe/kaffe/kaffevm/classMethod.h:1.73
--- kaffe/kaffe/kaffevm/classMethod.h:1.72	Tue Dec 21 05:49:59 2004
+++ kaffe/kaffe/kaffevm/classMethod.h	Tue Dec 21 16:51:05 2004
@@ -156,6 +156,7 @@
 	short			nr_inner_classes;
 	struct _innerClass*	inner_classes;
 
+	/* misc other stuff */
 	void*			gcjPeer;	/* only needed if GCJ_SUPPORT */
 #ifdef KAFFE_VMDEBUG
 	int			live_count;
@@ -167,6 +168,9 @@
 
 	/** The array of 'signer' objects; usually Certificates. */
 	HArrayOfObject*		signers;
+
+	/** The protection domain */
+	struct Hjava_lang_Object*	protectionDomain;
 };
 
 #ifndef __DEFINED_CLASS
Index: kaffe/kaffe/kaffevm/classPool.c
diff -u kaffe/kaffe/kaffevm/classPool.c:1.31 kaffe/kaffe/kaffevm/classPool.c:1.32
--- kaffe/kaffe/kaffevm/classPool.c:1.31	Sun Dec 19 06:25:07 2004
+++ kaffe/kaffe/kaffevm/classPool.c	Tue Dec 21 16:51:05 2004
@@ -242,6 +242,7 @@
         int rmoved;
 
         rmoved = removeClassEntries(loader);
+	unloadNativeLibraries(loader);
 
 	if (Kaffe_JavaVMArgs.enableVerboseGC > 0) {
 		dprintf("<GC: destroying classloader "
Index: kaffe/kaffe/kaffevm/external.c
diff -u kaffe/kaffe/kaffevm/external.c:1.73 kaffe/kaffe/kaffevm/external.c:1.74
--- kaffe/kaffe/kaffevm/external.c:1.73	Tue Dec 21 05:49:59 2004
+++ kaffe/kaffe/kaffevm/external.c	Tue Dec 21 16:51:05 2004
@@ -40,6 +40,7 @@
 #include "jthread.h"
 #include "jsignal.h"
 #include "stats.h"
+#include "locks.h"
 #if defined(KAFFE_FEEDBACK)
 #include "feedback.h"
 #endif
@@ -68,40 +69,11 @@
 static struct _libHandle {
 	LIBRARYHANDLE	desc;
 	char*		name;
-	int		ref;
+	Hjava_lang_ClassLoader*		loader;
 } libHandle[MAXLIBS];
 
-static inline void *
-findLibraryFunction(const char *name) {
-  int i = 0;
-  void *ptr = NULL;
-  
-  while (!ptr && libHandle[i].ref && i < MAXLIBS) {
-    ptr = KaffeLib_GetSymbol(libHandle[i].desc, name);
-
-DBG(NATIVELIB,
-    if (ptr == NULL) {
-	dprintf("Couldn't find %s in library handle %d == %s.\nError message is %s.\n",
-		name,
-		i,
-		lt_dlgetinfo(libHandle[i].desc) == NULL ? "unknown" : lt_dlgetinfo(libHandle[i].desc)->name,
-		lt_dlerror());
-    }
-    else {
-	dprintf("Found %s in library handle %d == %s.\n",
-		name,
-        	i,
-        	lt_dlgetinfo(libHandle[i].desc) == NULL ? "unknown" : lt_dlgetinfo(libHandle[i].desc)->name);
-    }
-);
-
-    ++i;
-  }
-
-  return ptr;
-}
-
-static char *libraryPath = NULL;
+static iStaticLock	libraryLock = KAFFE_STATIC_LOCK_INITIALIZER; /* mutex on all intern operations */
+static const char *libraryPath = NULL;
 
 extern JavaVM Kaffe_JavaVM;
 
@@ -206,7 +178,7 @@
 
 	       	DBG(INIT, dprintf("trying to load %s\n", lib); );
 
-		if (loadNativeLibrary(lib, NULL, 0) >= 0) {
+		if (loadNativeLibrary(lib, NULL, NULL, 0) >= 0) {
 			DBG(INIT, dprintf("initNative() done\n"); );
 			return;
 		}
@@ -218,26 +190,20 @@
 	EXIT(1);
 }
 
-int
-loadNativeLibrary(char* lib, char *errbuf, size_t errsiz)
-{
-	int retval;
-
-	retval = loadNativeLibrary2(lib, 1, errbuf, errsiz);
-	return( retval );
-}
-
 /*
  * Link in a native library. If successful, returns an index >= 0 that
  * can be passed to unloadNativeLibrary(). Otherwise, returns -1 and
  * fills errbuf (if not NULL) with the error message. Assumes synchronization.
  */
 int
-loadNativeLibrary2(char* path, int default_refs, char *errbuf, size_t errsiz)
+loadNativeLibrary(char* path, struct Hjava_lang_ClassLoader* loader, char *errbuf, size_t errsiz)
 {
 	struct _libHandle *lib;
 	int libIndex;
 	void *func;
+	int iLockRoot;
+
+	lockStaticMutex(&libraryLock);
 
 	/* Find a library handle.  If we find the library has already
 	 * been loaded, don't bother to get it again, just increase the
@@ -248,15 +214,24 @@
 		if (lib->desc == 0) {
 			goto open;
 		}
-		if (strcmp(lib->name, path) == 0) {
-			lib->ref++;
+		if (strcmp(lib->name, path) != 0)
+			continue;
+
+		if (lib->loader != loader) {
+			if (errbuf != NULL) {
+				strncpy(errbuf, "Already loaded\n", errsiz);
+			}
+			unlockStaticMutex(&libraryLock);
+			return -1;
+		}
+
 DBG(NATIVELIB,
 			dprintf("Native lib %s\n"
-			    "\tLOAD desc=%p index=%d ++ref=%d\n",
-			    lib->name, lib->desc, libIndex, lib->ref);
+			    "\tLOAD desc=%p index=%d loader=%p\n",
+			    lib->name, lib->desc, libIndex, lib->loader);
     );
-			return libIndex;
-		}
+		unlockStaticMutex(&libraryLock); 
+		return libIndex;
 	}
 	if (errbuf != 0) {
 		assert(errsiz > 0);
@@ -264,6 +239,7 @@
 		strncpy(errbuf, "Too many open libraries", errsiz);
 		errbuf[errsiz - 1] = '\0';
 	}
+	unlockStaticMutex(&libraryLock);
 	return -1;
 
 	/* Open the library */
@@ -283,10 +259,9 @@
 /* if we tested for existence here, libltdl wouldn't be able to look
    for system-dependent library names */
 
-	blockAsyncSignals();
 	{
                 lib->desc = KaffeLib_Load(path);
-                if (lib->desc == 0)	
+                if (lib->desc == NULL)	
 			{
 				const char *err = KaffeLib_GetError();
 
@@ -322,25 +297,26 @@
 					if (errbuf != 0)
 						strncpy(errbuf, err, errsiz);
 				}
+			
+				unlockStaticMutex(&libraryLock);
+				return -1;
 			}
 		}
-	unblockAsyncSignals();
-
-	if (lib->desc == 0) {
-		return -1;
-	}
 
         lib->name = gc_malloc(strlen(path)+1, KGC_ALLOC_NATIVELIB);
         strcpy (lib->name, path);
 
-	lib->ref = default_refs;
+	lib->loader = loader;
 	addToCounter(&ltmem, "vmmem-libltdl", 1, GCSIZEOF(lib->name));
 
+	unlockStaticMutex(&libraryLock);
+
 DBG(NATIVELIB,
 	dprintf("Native lib %s\n"
-	    "\tLOAD desc=%p index=%d ++ref=%d\n",
-	    lib->name, lib->desc, libIndex, lib->ref);
+	    "\tLOAD desc=%p index=%d loader=%p\n",
+	    lib->name, lib->desc, libIndex, lib->loader);
     );
+
 #if defined(KAFFE_FEEDBACK)
 	feedbackLibrary(path, true);
 #endif
@@ -361,28 +337,37 @@
  * never be unloaded. So index should never equal zero here.
  */
 void
-unloadNativeLibrary(int libIndex)
+unloadNativeLibraries(struct Hjava_lang_ClassLoader* loader)
 {
-	struct _libHandle *lib;
+	int libIndex;
+	int iLockRoot;
+
+	lockStaticMutex(&libraryLock);
+
+	/* we should never ever unload libraries of the bootstrap loader */
+	assert (loader != NULL);
+
+	for (libIndex = 0; libIndex < MAXLIBS; libIndex++) {
+		struct _libHandle* lib = &libHandle[libIndex];
+
+		if (lib->desc == NULL)
+			continue;
 
-	assert(libIndex > 0 && libIndex < MAXLIBS);
-	lib = &libHandle[libIndex];
+		if (lib->loader != loader)
+			continue;
 
 DBG(NATIVELIB,
-	dprintf("Native lib %s\n"
-	    "\tUNLOAD desc=%p index=%d --ref=%d\n",
-	    lib->name, lib->desc, libIndex, lib->ref - 1);
+    dprintf("Native lib %s\n"
+	    "\tUNLOAD desc=%p index=%d loader=%p\n",
+	    lib->name, lib->desc, libIndex, lib->loader);
     );
 
-	assert(lib->desc != 0);
-	assert(lib->ref > 0);
-	if (--lib->ref == 0) {
-		blockAsyncSignals();
 		KaffeLib_Unload(lib->desc);
-		unblockAsyncSignals();
 		KFREE(lib->name);
 		lib->desc = NULL;
 	}
+
+	unlockStaticMutex(&libraryLock);
 }
 
 /*
@@ -393,10 +378,11 @@
 {
   int i = 0;
   void* func = NULL;;
+  int iLockRoot;
 
-  blockAsyncSignals();
+  lockStaticMutex(&libraryLock);
   
-  while (!func && libHandle[i].ref && i < MAXLIBS) {
+  while (!func && i < MAXLIBS && libHandle[i].desc!=NULL) {
     func = KaffeLib_GetSymbol(libHandle[i].desc, name);
     
 DBG(NATIVELIB,
@@ -418,7 +404,7 @@
     ++i;
   }
 
-  unblockAsyncSignals();
+  unlockStaticMutex(&libraryLock);
 
   return func;
 }
Index: kaffe/kaffe/kaffevm/external.h
diff -u kaffe/kaffe/kaffevm/external.h:1.9 kaffe/kaffe/kaffevm/external.h:1.10
--- kaffe/kaffe/kaffevm/external.h:1.9	Wed Dec  8 07:22:07 2004
+++ kaffe/kaffe/kaffevm/external.h	Tue Dec 21 16:51:05 2004
@@ -28,9 +28,8 @@
 struct _errorInfo;
 
 void	initNative(void);
-int	loadNativeLibrary(char*, char*, size_t);
-int	loadNativeLibrary2(char*, int, char*, size_t);
-void	unloadNativeLibrary(int);
+int	loadNativeLibrary(char*, struct Hjava_lang_ClassLoader*, char*, size_t);
+void	unloadNativeLibraries(struct Hjava_lang_ClassLoader*);
 void*	loadNativeLibrarySym(const char*);
 nativecode*	native(struct _methods*, struct _errorInfo*);
 void	addNativeFunc(char*, void*);
Index: kaffe/kaffe/kaffevm/gcFuncs.c
diff -u kaffe/kaffe/kaffevm/gcFuncs.c:1.61 kaffe/kaffe/kaffevm/gcFuncs.c:1.62
--- kaffe/kaffe/kaffevm/gcFuncs.c:1.61	Tue Dec 21 08:06:36 2004
+++ kaffe/kaffe/kaffevm/gcFuncs.c	Tue Dec 21 16:51:05 2004
@@ -376,6 +376,8 @@
                 walkMethods(collector, gc_info, CLASS_METHODS(class), CLASS_NMETHODS(class));
         }
         KGC_markObject(collector, gc_info, class->loader);
+	KGC_markObject(collector, gc_info, class->signers);
+	KGC_markObject(collector, gc_info, class->protectionDomain);
 }
 
 /*****************************************************************************
Index: kaffe/kaffe/kaffevm/thread.c
diff -u kaffe/kaffe/kaffevm/thread.c:1.87 kaffe/kaffe/kaffevm/thread.c:1.88
--- kaffe/kaffe/kaffevm/thread.c:1.87	Tue Dec 21 05:49:59 2004
+++ kaffe/kaffe/kaffevm/thread.c	Tue Dec 21 16:51:05 2004
@@ -249,12 +249,19 @@
         /*
 	 * set context class loader of primordial thread to app classloader
 	 * must not be done earlier, since getCurrentThread() won't work
-         * before the KTHREAD(createfirst) and the jthreadID assignment
+         * before the KTHREAD(createfirst) and the jthreadID assignment.
+	 *
+	 * If we're creating the Thread instance of the main thread, this
+	 * will trigger the initialization process of the java part of the
+	 * runtime. One pitfall during initialization is that java.lang.System
+	 * has to be initialized before kaffe.lang.AppClassLoader. Therefore,
+	 * we cannot call AppClassLoader.getSingleton() here, since that would
+	 * cause System and AppClassLoader to be initialized in the wrong order.
 	 */
-	  do_execute_java_class_method (&retval, "kaffe/lang/AppClassLoader",
-					NULL,
-					"getSingleton",
-					"()Ljava/lang/ClassLoader;");
+	do_execute_java_class_method (&retval, "java/lang/ClassLoader",
+				      NULL,
+				      "getSystemClassLoader",
+				      "()Ljava/lang/ClassLoader;");
         unhand(tid)->contextClassLoader = (struct Hjava_lang_ClassLoader *) retval.l;
 
 	/* Attach thread to threadGroup */
Index: kaffe/libraries/clib/native/Class.c
diff -u kaffe/libraries/clib/native/Class.c:1.77 kaffe/libraries/clib/native/Class.c:1.78
--- kaffe/libraries/clib/native/Class.c:1.77	Tue Dec 21 05:49:58 2004
+++ kaffe/libraries/clib/native/Class.c	Tue Dec 21 16:51:13 2004
@@ -289,7 +289,13 @@
 void
 java_lang_Class_setSigners(struct Hjava_lang_Class* this, HArrayOfObject* sigs)
 {
-	this->signers = sigs;
+	unhand(this)->signers = sigs;
+}
+
+struct Hjava_lang_Object*
+java_lang_Class_getProtectionDomain (struct Hjava_lang_Class* this)
+{
+	return unhand(this)->protectionDomain;
 }
 
 /*
Index: kaffe/libraries/clib/native/ClassLoader.c
diff -u kaffe/libraries/clib/native/ClassLoader.c:1.39 kaffe/libraries/clib/native/ClassLoader.c:1.40
--- kaffe/libraries/clib/native/ClassLoader.c:1.39	Fri May 21 15:19:24 2004
+++ kaffe/libraries/clib/native/ClassLoader.c	Tue Dec 21 16:51:13 2004
@@ -31,7 +31,8 @@
  * Translate an array of bytes into a class.
  */
 struct Hjava_lang_Class*
-java_lang_ClassLoader_defineClass0(struct Hjava_lang_ClassLoader* this, struct Hjava_lang_String* name, HArrayOfByte* data, jint offset, jint length)
+java_lang_VMClassLoader_defineClass(struct Hjava_lang_ClassLoader* this, struct Hjava_lang_String* name,
+				    HArrayOfByte* data, jint offset, jint length, struct Hjava_lang_Object* protectionDomain)
 {
 	Hjava_lang_Class *clazz, *dup_clazz;
 	classFile hand;
@@ -67,6 +68,9 @@
 		throwError(&info);
 	}
 
+	/* set protection domain of new class */
+	unhand(clazz)->protectionDomain = protectionDomain;
+
 	/*
 	 * See if an entry for that name and class loader already exists
 	 * create one if not.
@@ -116,9 +120,10 @@
  * Resolve classes reference by this class.
  */
 void
-java_lang_ClassLoader_resolveClass0(struct Hjava_lang_ClassLoader* this UNUSED, struct Hjava_lang_Class* class)
+java_lang_VMClassLoader_resolveClass(struct Hjava_lang_Class* class)
 {
 	errorInfo info;
+
 	if (processClass(class, CSTATE_COMPLETE, &info) == false) {
 		throwError(&info);
 	}
Index: kaffe/libraries/clib/native/Makefile.am
diff -u kaffe/libraries/clib/native/Makefile.am:1.37 kaffe/libraries/clib/native/Makefile.am:1.38
--- kaffe/libraries/clib/native/Makefile.am:1.37	Wed Dec  8 07:22:12 2004
+++ kaffe/libraries/clib/native/Makefile.am	Tue Dec 21 16:51:13 2004
@@ -29,7 +29,6 @@
 		Float.c \
 		Math.c \
 		MemoryAdvice.c \
-		NativeLibrary.c \
 		Object.c \
 		PrimordialClassLoader.c \
 		Runtime.c \
Index: kaffe/libraries/clib/native/Makefile.in
diff -u kaffe/libraries/clib/native/Makefile.in:1.163 kaffe/libraries/clib/native/Makefile.in:1.164
--- kaffe/libraries/clib/native/Makefile.in:1.163	Wed Dec  8 07:22:12 2004
+++ kaffe/libraries/clib/native/Makefile.in	Tue Dec 21 16:51:13 2004
@@ -95,7 +95,7 @@
 am__objects_2 = libnative_la-Class.lo libnative_la-ClassLoader.lo \
 	libnative_la-Double.lo libnative_la-Float.lo \
 	libnative_la-Math.lo libnative_la-MemoryAdvice.lo \
-	libnative_la-NativeLibrary.lo libnative_la-Object.lo \
+	libnative_la-Object.lo \
 	libnative_la-PrimordialClassLoader.lo libnative_la-Runtime.lo \
 	libnative_la-String.lo libnative_la-System.lo \
 	libnative_la-Thread.lo libnative_la-ThreadStack.lo \
@@ -412,7 +412,6 @@
 		Float.c \
 		Math.c \
 		MemoryAdvice.c \
-		NativeLibrary.c \
 		Object.c \
 		PrimordialClassLoader.c \
 		Runtime.c \
@@ -548,7 +547,6 @@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/libnative_la-Math.Plo at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/libnative_la-MemoryAdvice.Plo at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/libnative_la-Method.Plo at am__quote@
- at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/libnative_la-NativeLibrary.Plo at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/libnative_la-Object.Plo at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/libnative_la-PrimordialClassLoader.Plo at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/libnative_la-Runtime.Plo at am__quote@
@@ -653,13 +651,6 @@
 @AMDEP_TRUE@@am__fastdepCC_FALSE@	source='MemoryAdvice.c' object='libnative_la-MemoryAdvice.lo' libtool=yes @AMDEPBACKSLASH@
 @AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@	$(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnative_la_CFLAGS) $(CFLAGS) -c -o libnative_la-MemoryAdvice.lo `test -f 'MemoryAdvice.c' || echo '$(srcdir)/'`MemoryAdvice.c
-
-libnative_la-NativeLibrary.lo: NativeLibrary.c
- at am__fastdepCC_TRUE@	if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnative_la_CFLAGS) $(CFLAGS) -MT libnative_la-NativeLibrary.lo -MD -MP -MF "$(DEPDIR)/libnative_la-NativeLibrary.Tpo" -c -o libnative_la-NativeLibrary.lo `test -f 'NativeLibrary.c' || echo '$(srcdir)/'`NativeLibrary.c; \
- at am__fastdepCC_TRUE@	then mv -f "$(DEPDIR)/libnative_la-NativeLibrary.Tpo" "$(DEPDIR)/libnative_la-NativeLibrary.Plo"; else rm -f "$(DEPDIR)/libnative_la-NativeLibrary.Tpo"; exit 1; fi
- at AMDEP_TRUE@@am__fastdepCC_FALSE@	source='NativeLibrary.c' object='libnative_la-NativeLibrary.lo' libtool=yes @AMDEPBACKSLASH@
- at AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
- at am__fastdepCC_FALSE@	$(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnative_la_CFLAGS) $(CFLAGS) -c -o libnative_la-NativeLibrary.lo `test -f 'NativeLibrary.c' || echo '$(srcdir)/'`NativeLibrary.c
 
 libnative_la-Object.lo: Object.c
 @am__fastdepCC_TRUE@	if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnative_la_CFLAGS) $(CFLAGS) -MT libnative_la-Object.lo -MD -MP -MF "$(DEPDIR)/libnative_la-Object.Tpo" -c -o libnative_la-Object.lo `test -f 'Object.c' || echo '$(srcdir)/'`Object.c; \
===================================================================
Checking out kaffe/libraries/clib/native/NativeLibrary.c
RCS:  /home/cvs/kaffe/kaffe/libraries/clib/native/Attic/NativeLibrary.c,v
VERS: 1.6
***************
--- kaffe/libraries/clib/native/NativeLibrary.c	Tue Dec 21 16:56:29 2004
+++ /dev/null	Sun Aug  4 19:57:58 2002
@@ -1,95 +0,0 @@
-
-/*
- * java.lang.NativeLibrary.c
- *
- * Copyright (c) 2000
- *	Archie L. Cobbs.  All rights reserved.
- * Copyright (c) 2000
- *	Transvirtual Technologies, Inc.  All rights reserved.
- *
- * See the file "license.terms" for information on usage and redistribution 
- * of this file. 
- */
-
-#include "config.h"
-#include "config-std.h"
-#include "config-io.h"
-#include "config-mem.h"
-#include "defs.h"
-#include "gtypes.h"
-#include "object.h"
-#include "constants.h"
-#include "support.h"
-#include "external.h"
-#include "java_lang_String.h"
-#include "java_lang_NativeLibrary.h"
-#include <native.h>
-
-#ifndef LIBRARYPREFIX
-#define	LIBRARYPREFIX	"lib"
-#endif
-
-#ifndef LIBRARYSUFFIX
-#define LIBRARYSUFFIX	""
-#endif
-
-/*
- * Return prefix to prepend to library names
- */
-struct Hjava_lang_String*
-java_lang_NativeLibrary_getLibPrefix(void)
-{
-	return checkPtr(stringC2Java(LIBRARYPREFIX));
-}
-
-/*
- * Return suffix to append to library names
- */
-struct Hjava_lang_String*
-java_lang_NativeLibrary_getLibSuffix(void)
-{
-	return checkPtr(stringC2Java(LIBRARYSUFFIX));
-}
-
-/*
- * Attempt to link in a shared library. Throws an UnsatisfiedLinkError
- * if the attempt fails.
- */
-int
-java_lang_NativeLibrary_linkLibrary(struct Hjava_lang_String *jpath)
-{
-	char path[MAXPATHLEN];
-	char errbuf[128];
-	errorInfo einfo;
-	int i = -1;
-
-	stringJava2CBuf(jpath, path, sizeof(path));
-	if ((i = loadNativeLibrary(path, errbuf, sizeof(errbuf))) < 0) {
- 		if( strstr(errbuf, "File not found") ) {
- 			postExceptionMessage(&einfo,
- 					     JAVA_IO(FileNotFoundException),
- 					     "%s",
- 					     path);
- 		} else {
-			postExceptionMessage(&einfo, 
-					     JAVA_LANG(UnsatisfiedLinkError),
-					     "%s",
-					     errbuf);
-			throwError(&einfo);
-		}
-	}
- 	if( i == -1 )
- 		throwError(&einfo);
-
-	return i;
-}
-
-/*
- * Unlink a shared library.
- */
-void
-java_lang_NativeLibrary_unlinkLibrary(int i)
-{
-	unloadNativeLibrary(i);
-}
-
Index: kaffe/libraries/clib/native/Runtime.c
diff -u kaffe/libraries/clib/native/Runtime.c:1.29 kaffe/libraries/clib/native/Runtime.c:1.30
--- kaffe/libraries/clib/native/Runtime.c:1.29	Mon Dec 20 03:40:03 2004
+++ kaffe/libraries/clib/native/Runtime.c	Tue Dec 21 16:51:15 2004
@@ -17,11 +17,21 @@
 #include "files.h"
 #include "defs.h"
 #include "java_io_File.h"
+#include "java_lang_String.h"
 #include "java_lang_Runtime.h"
 #include "external.h"
 #include "gc.h"
 #include "support.h"
 #include "stringSupport.h"
+#include "external.h"
+
+#ifndef LIBRARYPREFIX
+#define	LIBRARYPREFIX	"lib"
+#endif
+
+#ifndef LIBRARYSUFFIX
+#define LIBRARYSUFFIX	""
+#endif
 
 extern jboolean runFinalizerOnExit;
 
@@ -130,4 +140,47 @@
 java_lang_Runtime_runFinalizersOnExit(jboolean on)
 {
 	runFinalizerOnExit = on;
+}
+
+
+/*
+ * Attempt to link in a shared library. Throws an UnsatisfiedLinkError
+ * if the attempt fails.
+ */
+jboolean
+java_lang_Runtime_linkLibrary(struct Hjava_lang_String *jpath, struct Hjava_lang_ClassLoader* loader)
+{
+	char path[MAXPATHLEN];
+	char errbuf[128];
+	errorInfo einfo;
+
+	stringJava2CBuf(jpath, path, sizeof(path));
+	if (loadNativeLibrary(path, loader, errbuf, sizeof(errbuf)) < 0) {
+ 		if( strstr(errbuf, ": not found") ) {
+			/* simply proceed if file was not found, java part
+			 * will throw an exception later if library could
+			 * not be found.
+			 */
+			return false;
+ 		} else {
+			postExceptionMessage(&einfo, 
+					     JAVA_LANG(UnsatisfiedLinkError),
+					     "%s",
+					     errbuf);
+			throwError(&einfo);
+		}
+	}
+	return true;
+}
+
+struct Hjava_lang_String*
+java_lang_Runtime_getLibPrefix()
+{
+	return checkPtr(stringC2Java(LIBRARYPREFIX));
+}
+
+struct Hjava_lang_String*
+java_lang_Runtime_getLibSuffix()
+{
+	return checkPtr(stringC2Java(LIBRARYSUFFIX));
 }
Index: kaffe/libraries/javalib/Makefile.am
diff -u kaffe/libraries/javalib/Makefile.am:1.278 kaffe/libraries/javalib/Makefile.am:1.279
--- kaffe/libraries/javalib/Makefile.am:1.278	Tue Dec 21 08:47:11 2004
+++ kaffe/libraries/javalib/Makefile.am	Tue Dec 21 16:51:06 2004
@@ -1508,6 +1508,7 @@
 	gnu/java/text/StringFormatBuffer.java \
 	gnu/java/text/WordBreakIterator.java
 gnu_java_util_SRCS = \
+	gnu/java/util/DoubleEnumeration.java \
 	gnu/java/util/EmptyEnumeration.java
 gnu_java_util_prefs_SRCS = \
 	gnu/java/util/prefs/FileBasedFactory.java \
@@ -2300,7 +2301,6 @@
 	java/lang/LinkageError.java \
 	java/lang/Long.java \
 	java/lang/Math.java \
-	java/lang/NativeLibrary.java \
 	java/lang/NegativeArraySizeException.java \
 	java/lang/NoClassDefFoundError.java \
 	java/lang/NoSuchFieldError.java \
@@ -2338,6 +2338,9 @@
 	java/lang/UnsatisfiedLinkError.java \
 	java/lang/UnsupportedClassVersionError.java \
 	java/lang/UnsupportedOperationException.java \
+	java/lang/VerifyError.java \
+	java/lang/VirtualMachineError.java \
+	java/lang/VMClassLoader.java \
 	java/lang/VMCompiler.java \
 	java/lang/VMObject.java \
 	java/lang/VMSecurityManager.java \
Index: kaffe/libraries/javalib/Makefile.in
diff -u kaffe/libraries/javalib/Makefile.in:1.359 kaffe/libraries/javalib/Makefile.in:1.360
--- kaffe/libraries/javalib/Makefile.in:1.359	Tue Dec 21 08:47:14 2004
+++ kaffe/libraries/javalib/Makefile.in	Tue Dec 21 16:51:07 2004
@@ -1945,6 +1945,7 @@
 	gnu/java/text/WordBreakIterator.java
 
 gnu_java_util_SRCS = \
+	gnu/java/util/DoubleEnumeration.java \
 	gnu/java/util/EmptyEnumeration.java
 
 gnu_java_util_prefs_SRCS = \
@@ -2772,7 +2773,6 @@
 	java/lang/LinkageError.java \
 	java/lang/Long.java \
 	java/lang/Math.java \
-	java/lang/NativeLibrary.java \
 	java/lang/NegativeArraySizeException.java \
 	java/lang/NoClassDefFoundError.java \
 	java/lang/NoSuchFieldError.java \
@@ -2810,6 +2810,9 @@
 	java/lang/UnsatisfiedLinkError.java \
 	java/lang/UnsupportedClassVersionError.java \
 	java/lang/UnsupportedOperationException.java \
+	java/lang/VerifyError.java \
+	java/lang/VirtualMachineError.java \
+	java/lang/VMClassLoader.java \
 	java/lang/VMCompiler.java \
 	java/lang/VMObject.java \
 	java/lang/VMSecurityManager.java \
Index: kaffe/libraries/javalib/all.files
diff -u kaffe/libraries/javalib/all.files:1.59 kaffe/libraries/javalib/all.files:1.60
--- kaffe/libraries/javalib/all.files:1.59	Tue Dec 21 08:47:15 2004
+++ kaffe/libraries/javalib/all.files	Tue Dec 21 16:51:08 2004
@@ -1838,7 +1838,6 @@
 java/lang/LinkageError.java
 java/lang/Long.java
 java/lang/Math.java
-java/lang/NativeLibrary.java
 java/lang/NegativeArraySizeException.java
 java/lang/NoClassDefFoundError.java
 java/lang/NoSuchFieldError.java
Index: kaffe/libraries/javalib/bootstrap.classlist
diff -u kaffe/libraries/javalib/bootstrap.classlist:1.65 kaffe/libraries/javalib/bootstrap.classlist:1.66
--- kaffe/libraries/javalib/bootstrap.classlist:1.65	Wed Dec  8 08:05:29 2004
+++ kaffe/libraries/javalib/bootstrap.classlist	Tue Dec 21 16:51:08 2004
@@ -98,7 +98,6 @@
 java/lang/LinkageError.class
 java/lang/Long.class
 java/lang/Math.class
-java/lang/NativeLibrary.class
 java/lang/NegativeArraySizeException.class
 java/lang/NoClassDefFoundError.class
 java/lang/NoSuchMethodException.class
===================================================================
Checking out kaffe/libraries/javalib/gnu/java/util/DoubleEnumeration.java
RCS:  /home/cvs/kaffe/kaffe/libraries/javalib/gnu/java/util/DoubleEnumeration.java,v
VERS: 1.1
***************
--- /dev/null	Sun Aug  4 19:57:58 2002
+++ kaffe/libraries/javalib/gnu/java/util/DoubleEnumeration.java	Tue Dec 21 16:56:33 2004
@@ -0,0 +1,138 @@
+/* gnu.java.util.DoubleEnumeration
+   Copyright (C) 1998, 1999, 2001 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.java.util;
+
+import java.util.Enumeration;
+import java.util.NoSuchElementException;
+
+
+/**
+ * This is a helper class that combines two Enumerations.
+ * It returns the elements of the first Enumeration until it has
+ * no more elements and then returns the elements of the second
+ * Enumeration.<br>
+ * 
+ * In the default case:
+ * <pre>
+ * doubleEnum = new DoubleEnumeration(enum1, enum2);
+ * while (doubleEnum.hasMoreElements()) {
+ *    Object o = doubleEnum.nextElement();
+ *    do_something(o);
+ * }
+ * </pre>
+ * it calls hasMoreElements of the Enumerations as few times as
+ * possible.
+ * The references to the Enumerations are cleared as soon as they have no
+ * more elements to help garbage collecting.
+ *
+ * @author Jochen Hoenicke
+ * @author Mark Wielaard (mark at klomp.org)
+ */
+public class DoubleEnumeration implements Enumeration
+{
+  /**
+   * This is true as long as one of the enumerations has more
+   * elements.  
+   * Only valid when hasChecked is true.
+   * Set in <code>hasMoreElements()</code>
+   */
+  private boolean hasMore;
+  /**
+   * This is true, if it is sure that hasMore indicates wether there are
+   * more elements.
+   * Set to true in <code>hasMoreElements()</code>.
+   * Set to false in <code>getNextElement()</code>.
+   */
+  private boolean hasChecked;
+  /**
+   * The first enumeration.
+   */
+  private Enumeration e1;
+  /**
+   * The second enumeration.
+   */
+  private Enumeration e2;
+
+  /**
+   * Creates a new Enumeration combining the given two enumerations.
+   * The enumerations mustn't be accessed by other classes.
+   */
+  public DoubleEnumeration(Enumeration e1, Enumeration e2)
+  {
+    this.e1 = e1;
+    this.e2 = e2;
+    hasChecked = false;
+  }
+
+  /**
+   * Returns true, if at least one of the two enumerations has more
+   * elements.
+   */
+  public boolean hasMoreElements()
+  {
+    if (hasChecked)
+      return hasMore;
+
+    hasMore = (e1 != null && e1.hasMoreElements());
+
+    if (!hasMore) {
+      e1 = e2;
+      e2 = null;
+      hasMore = (e1 != null && e1.hasMoreElements());
+    }
+
+    hasChecked = true;
+    return hasMore;
+  }
+
+  /**
+   * Returns the next element.  This returns the next element of the
+   * first enumeration, if it has more elements, otherwise the next
+   * element of the second enumeration. If both enumeration don't have
+   * any elements it throws a <code>NoSuchElementException</code>.
+   */
+  public Object nextElement()
+  {
+    if (!hasMoreElements())
+      throw new NoSuchElementException();
+    else {
+      hasChecked = false;

*** Patch too long, truncated ***




More information about the kaffe mailing list