[kaffe] CVS kaffe (guilhem): Added JNI references and java.lang.ref support.

Kaffe CVS cvs-commits at kaffe.org
Sun Jan 30 04:48:07 PST 2005


PatchSet 5949 
Date: 2005/01/30 12:42:34
Author: guilhem
Branch: HEAD
Tag: (none) 
Log:
Added JNI references and java.lang.ref support.

	* include/Makefile.in,
	kaffe/kaffevm/Makefile.in,
	libraries/clib/native/Makefile.in,
	test/regression/Makefile.in,
	libraries/javalib/Makefile.am,
	libraries/javalib/Makefile.in: Regenerated.

	* include/Makefile.am: Build java_lang_ref_Reference.h.

	* include/native.h
	(Hjava_lang_Object): Added finalizer_call.

	* kaffe/kaffevm/Makefile.am: Added reference.[ch].

	* kaffe/kaffevm/locks.c
	(slowUnlockMutex): Clear holder if heavylock is static.

	* kaffe/kaffevm/baseClasses.c
	(javaLangRefReference, javaLangRefSoftReference,
	javaLangRefWeakReference, javaLangRefPhantomReference): New static
	classes.
	(initBaseClasses): Invoke KaffeVM_referenceInit.

	* kaffe/kaffevm/baseClasses.h: Likewise.

	* kaffe/kaffevm/reference.c, kaffe/kaffevm/reference.h: New files
	to handle java references.

	* kaffe/kaffevm/classMethod.c
	(processClass): Do not use JNI anymore.
	(userLoadClass): Set retval to NULL if an exception is raised.

	* kaffe/kaffevm/classMethod.h:
	(Hjava_lang_Class): New field finalizer_call to handle different
	type of object finalizing whether it is referenced or not.

	* kaffe/kaffevm/exception.h: Fixed documentation.

	* kaffe/kaffevm/gcFuncs.c
	(finalizeObject): Invoke finalizer_call for finalization process.

	* kaffe/kaffevm/intrp/machine.c:
	(virtualMachine) Updated function prefix.

	* kaffe/kaffevm/jit/native-wrapper.c:
	(startJNIcall) Always handle JNI references now.
	(Kaffe_wrapper) Updated function prefix and handle JNI references.

	* kaffe/kaffevm/intrp/method-calls.c
	(startJNIcall, finishJNIcall): Copied from jit/method-calls.c.
	(engine_callMethod): Use startJNIcall and finishJNIcall.

	* kaffe/kaffevm/jni/jni-base.c
	(JNI_CreateJavaVM): Build a JNI reference table for the invoking
	thread.

	* kaffe/kaffevm/jni/jni-callmethod.c: Updated function prefix.

	* kaffe/kaffevm/jni.c
	(KaffeJNI_addJNIref, KaffeJNI_removeJNIref): Fixed and activated
	JNI references counting.

	* kaffe/kaffevm/jni/jni_i.h: Externalized addJNIref and
	removeJNIref.

	* kaffe/kaffevm/jni/jnirefs.h: Updated to handle multiple frames
	by thread.

	* kaffe/kaffevm/kaffe-gc/gc-refs.c: Protected the access to the
	weaek and strong reference lists.

	* kaffe/kaffevm/object.c:
	(newObjectChecked, newClass, newArrayChecked): Set the finalizer type
	to the newly created object.

	* kaffe/kaffevm/support.c,
	kaffe/kaffevm/support.h
	(KaffeVM_safeCallMethodA, KaffeVM_safeCallMethodV): New functions.
	(KaffeVM_callMethodA, KaffeVM_callMethodV): Renamed.

	* kaffe/kaffevm/thread.c
	(linkNativeAndJavaThread): Initialize jnireferences.

	* kaffe/kaffevm/threadData.h
	(jnireferences): New field.

	* kaffe/kaffevm/utf8const.c
	(utfLockRoot): Initialize it to NULL.

	* libraries/clib/native/Makefile.am: Added new file
	java_lang_ref_Reference.c.

	* libraries/clib/native/java_lang_ref_Reference.c:
	New file.

	* libraries/javalib/bootstrap.classlist: Updated.

	* libraries/javalib/java/lang/ref/PhantomReference.java,
	libraries/javalib/java/lang/ref/Reference.java,
	libraries/javalib/java/lang/ref/ReferenceQueue.java,
	libraries/javalib/java/lang/ref/SoftReference.java,
	libraries/javalib/java/lang/ref/WeakReference.java:
	Imported from GNU Classpath.

	* test/regression/Makefile.am: Added new regression test RefTest.

	* test/regression/RefTest.java: New test.

Members: 
	ChangeLog:1.3488->1.3489 
	include/Makefile.am:1.87->1.88 
	include/Makefile.in:1.209->1.210 
	include/native.h:1.17->1.18 
	kaffe/kaffevm/Makefile.am:1.69->1.70 
	kaffe/kaffevm/Makefile.in:1.186->1.187 
	kaffe/kaffevm/baseClasses.c:1.57->1.58 
	kaffe/kaffevm/baseClasses.h:1.18->1.19 
	kaffe/kaffevm/classMethod.c:1.131->1.132 
	kaffe/kaffevm/classMethod.h:1.75->1.76 
	kaffe/kaffevm/exception.h:1.28->1.29 
	kaffe/kaffevm/gcFuncs.c:1.63->1.64 
	kaffe/kaffevm/ksem.c:1.10->1.11 
	kaffe/kaffevm/locks.c:1.54->1.55 
	kaffe/kaffevm/object.c:1.31->1.32 
	kaffe/kaffevm/reference.c:INITIAL->1.1 
	kaffe/kaffevm/reference.h:INITIAL->1.1 
	kaffe/kaffevm/support.c:1.80->1.81 
	kaffe/kaffevm/support.h:1.37->1.38 
	kaffe/kaffevm/thread.c:1.90->1.91 
	kaffe/kaffevm/threadData.h:1.5->1.6 
	kaffe/kaffevm/utf8const.c:1.44->1.45 
	kaffe/kaffevm/intrp/machine.c:1.44->1.45 
	kaffe/kaffevm/intrp/methodcalls.c:1.5->1.6 
	kaffe/kaffevm/jit/native-wrapper.c:1.6->1.7 
	kaffe/kaffevm/jni/jni-base.c:1.11->1.12 
	kaffe/kaffevm/jni/jni-callmethod.c:1.5->1.6 
	kaffe/kaffevm/jni/jni.c:1.15->1.16 
	kaffe/kaffevm/jni/jni_i.h:1.5->1.6 
	kaffe/kaffevm/jni/jnirefs.h:1.1->1.2 
	kaffe/kaffevm/kaffe-gc/gc-incremental.c:1.17->1.18 
	kaffe/kaffevm/kaffe-gc/gc-refs.c:1.10->1.11 
	kaffe/kaffevm/systems/unix-pthreads/lock-impl.c:1.16->1.17 
	kaffe/kaffevm/systems/unix-pthreads/thread-internal.h:1.31->1.32 
	libraries/clib/native/Makefile.am:1.38->1.39 
	libraries/clib/native/Makefile.in:1.168->1.169 
	libraries/clib/native/java_lang_ref_Reference.c:INITIAL->1.1 
	libraries/javalib/bootstrap.classlist:1.69->1.70 
	libraries/javalib/java/lang/ref/PhantomReference.java:1.2->1.3 
	libraries/javalib/java/lang/ref/Reference.java:1.4->1.5 
	libraries/javalib/java/lang/ref/ReferenceQueue.java:1.3->1.4 
	libraries/javalib/java/lang/ref/SoftReference.java:1.2->1.3 
	libraries/javalib/java/lang/ref/WeakReference.java:1.2->1.3 
	test/internal/jitBasic.c:1.5->1.6 
	test/regression/Makefile.am:1.91->1.92 
	test/regression/Makefile.in:1.200->1.201 
	test/regression/RefTest.java:INITIAL->1.1 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.3488 kaffe/ChangeLog:1.3489
--- kaffe/ChangeLog:1.3488	Sun Jan 30 12:31:03 2005
+++ kaffe/ChangeLog	Sun Jan 30 12:42:34 2005
@@ -1,3 +1,113 @@
+2005-01-23  Guilhem Lavaux  <guilhem at kaffe.org>
+
+	* include/Makefile.in,
+	kaffe/kaffevm/Makefile.in,
+	libraries/clib/native/Makefile.in,
+	test/regression/Makefile.in,
+	libraries/javalib/Makefile.am,
+	libraries/javalib/Makefile.in: Regenerated.
+		
+	* include/Makefile.am: Build java_lang_ref_Reference.h.
+
+	* include/native.h
+	(Hjava_lang_Object): Added finalizer_call.
+
+	* kaffe/kaffevm/Makefile.am: Added reference.[ch].
+
+	* kaffe/kaffevm/locks.c
+	(slowUnlockMutex): Clear holder if heavylock is static.
+	
+	* kaffe/kaffevm/baseClasses.c
+	(javaLangRefReference, javaLangRefSoftReference,
+	javaLangRefWeakReference, javaLangRefPhantomReference): New static
+	classes.
+	(initBaseClasses): Invoke KaffeVM_referenceInit.
+
+	* kaffe/kaffevm/baseClasses.h: Likewise.
+
+	* kaffe/kaffevm/reference.c, kaffe/kaffevm/reference.h: New files
+	to handle java references.
+	
+	* kaffe/kaffevm/classMethod.c
+	(processClass): Do not use JNI anymore.
+	(userLoadClass): Set retval to NULL if an exception is raised.
+
+	* kaffe/kaffevm/classMethod.h:
+	(Hjava_lang_Class): New field finalizer_call to handle different
+	type of object finalizing whether it is referenced or not.
+
+	* kaffe/kaffevm/exception.h: Fixed documentation.
+
+	* kaffe/kaffevm/gcFuncs.c
+	(finalizeObject): Invoke finalizer_call for finalization process.
+
+	* kaffe/kaffevm/intrp/machine.c:
+	(virtualMachine) Updated function prefix.
+
+	* kaffe/kaffevm/jit/native-wrapper.c:
+	(startJNIcall) Always handle JNI references now.
+	(Kaffe_wrapper) Updated function prefix and handle JNI references.
+
+	* kaffe/kaffevm/intrp/method-calls.c
+	(startJNIcall, finishJNIcall): Copied from jit/method-calls.c.
+	(engine_callMethod): Use startJNIcall and finishJNIcall.
+	
+	* kaffe/kaffevm/jni/jni-base.c
+	(JNI_CreateJavaVM): Build a JNI reference table for the invoking
+	thread.
+
+	* kaffe/kaffevm/jni/jni-callmethod.c: Updated function prefix.
+
+	* kaffe/kaffevm/jni.c
+	(KaffeJNI_addJNIref, KaffeJNI_removeJNIref): Fixed and activated
+	JNI references counting.
+
+	* kaffe/kaffevm/jni/jni_i.h: Externalized addJNIref and
+	removeJNIref.
+
+	* kaffe/kaffevm/jni/jnirefs.h: Updated to handle multiple frames
+	by thread.
+
+	* kaffe/kaffevm/kaffe-gc/gc-refs.c: Protected the access to the
+	weaek and strong reference lists.
+
+	* kaffe/kaffevm/object.c:
+	(newObjectChecked, newClass, newArrayChecked): Set the finalizer type
+	to the newly created object.
+
+	* kaffe/kaffevm/support.c,
+	kaffe/kaffevm/support.h
+	(KaffeVM_safeCallMethodA, KaffeVM_safeCallMethodV): New functions.
+	(KaffeVM_callMethodA, KaffeVM_callMethodV): Renamed.
+	
+	* kaffe/kaffevm/thread.c
+	(linkNativeAndJavaThread): Initialize jnireferences.
+
+	* kaffe/kaffevm/threadData.h
+	(jnireferences): New field.
+
+	* kaffe/kaffevm/utf8const.c
+	(utfLockRoot): Initialize it to NULL.
+
+	* libraries/clib/native/Makefile.am: Added new file
+	java_lang_ref_Reference.c.
+
+	* libraries/clib/native/java_lang_ref_Reference.c:
+	New file.
+
+	* libraries/javalib/bootstrap.classlist: Updated.
+
+	* libraries/javalib/java/lang/ref/PhantomReference.java,
+	libraries/javalib/java/lang/ref/Reference.java,
+	libraries/javalib/java/lang/ref/ReferenceQueue.java,
+	libraries/javalib/java/lang/ref/SoftReference.java,
+	libraries/javalib/java/lang/ref/WeakReference.java:
+	Imported from GNU Classpath.
+
+	* test/regression/Makefile.am: Added new regression test RefTest.
+
+	* test/regression/RefTest.java: New test.
+
 2005-01-29  Dalibor Topic  <robilad at kaffe.org>
 
 	* config/Makefile.am (EXTRA_DIST): Added 
Index: kaffe/include/Makefile.am
diff -u kaffe/include/Makefile.am:1.87 kaffe/include/Makefile.am:1.88
--- kaffe/include/Makefile.am:1.87	Sat Jan 29 12:17:33 2005
+++ kaffe/include/Makefile.am	Sun Jan 30 12:42:37 2005
@@ -214,6 +214,7 @@
 
 NOINSTALL_JNI_DERIVED_HDRS = \
 	java_math_BigInteger.h \
+	java_lang_ref_Reference.h \
 	gnu_classpath_VMSystemProperties.h \
 	gnu_java_nio_channels_FileChannelImpl.h \
 	gnu_java_nio_SelectorImpl.h \
Index: kaffe/include/Makefile.in
diff -u kaffe/include/Makefile.in:1.209 kaffe/include/Makefile.in:1.210
--- kaffe/include/Makefile.in:1.209	Sat Jan 29 12:17:33 2005
+++ kaffe/include/Makefile.in	Sun Jan 30 12:42:37 2005
@@ -556,6 +556,7 @@
 @COND_CLASSPATH_GTK_AWT_TRUE@@COND_NATIVE_AWT_TRUE at MAYBE_LIBGTKPEER_JNI_HDRS = $(LIBGTKPEER_JNI_HDRS)
 NOINSTALL_JNI_DERIVED_HDRS = \
 	java_math_BigInteger.h \
+	java_lang_ref_Reference.h \
 	gnu_classpath_VMSystemProperties.h \
 	gnu_java_nio_channels_FileChannelImpl.h \
 	gnu_java_nio_SelectorImpl.h \
Index: kaffe/include/native.h
diff -u kaffe/include/native.h:1.17 kaffe/include/native.h:1.18
--- kaffe/include/native.h:1.17	Sat Dec 11 20:49:39 2004
+++ kaffe/include/native.h	Sun Jan 30 12:42:39 2005
@@ -36,9 +36,15 @@
 struct _dispatchTable;
 struct _iLock;
 
+
+
 typedef struct Hjava_lang_Object {
 	struct _dispatchTable*  vtable;
 	struct _iLock*		lock;
+	/* This pointer contains the VM function which should be called
+	 * to handle object finalization.
+	 */
+        void*       finalizer_call;
 	/* Data follows on immediately */
 } Hjava_lang_Object;
 
Index: kaffe/kaffe/kaffevm/Makefile.am
diff -u kaffe/kaffe/kaffevm/Makefile.am:1.69 kaffe/kaffe/kaffevm/Makefile.am:1.70
--- kaffe/kaffe/kaffevm/Makefile.am:1.69	Mon Aug  2 10:44:55 2004
+++ kaffe/kaffe/kaffevm/Makefile.am	Sun Jan 30 12:42:40 2005
@@ -112,6 +112,7 @@
 	utf8const.c \
 	gcFuncs.c \
 	reflect.c \
+	reference.c \
 	$(BINRELOC_SOURCES)
 
 noinst_HEADERS = \
@@ -152,6 +153,7 @@
 	threadData.h \
 	utf8const.h \
 	reflect.h \
+	reference.h \
 	../../binreloc/prefix.h
 
 md.c: stamp-h01
Index: kaffe/kaffe/kaffevm/Makefile.in
diff -u kaffe/kaffe/kaffevm/Makefile.in:1.186 kaffe/kaffe/kaffevm/Makefile.in:1.187
--- kaffe/kaffe/kaffevm/Makefile.in:1.186	Fri Jan 28 15:31:08 2005
+++ kaffe/kaffe/kaffevm/Makefile.in	Sun Jan 30 12:42:40 2005
@@ -104,7 +104,7 @@
 	hashtab.c inflate.c itypes.c jar.c ksem.c locks.c lookup.c \
 	object.c readClass.c soft.c stackTrace.c stats.c string.c \
 	stringParsing.c support.c thread.c utf8const.c gcFuncs.c \
-	reflect.c ../../binreloc/prefix.c
+	reflect.c reference.c ../../binreloc/prefix.c
 @ENABLE_BINRELOC_TRUE at am__objects_1 = libkaffevm_la-prefix.lo
 am_libkaffevm_la_OBJECTS = libkaffevm_la-access.lo \
 	libkaffevm_la-baseClasses.lo libkaffevm_la-classMethod.lo \
@@ -123,7 +123,8 @@
 	libkaffevm_la-string.lo libkaffevm_la-stringParsing.lo \
 	libkaffevm_la-support.lo libkaffevm_la-thread.lo \
 	libkaffevm_la-utf8const.lo libkaffevm_la-gcFuncs.lo \
-	libkaffevm_la-reflect.lo $(am__objects_1)
+	libkaffevm_la-reflect.lo libkaffevm_la-reference.lo \
+	$(am__objects_1)
 am__objects_2 = libkaffevm_la-md.lo
 nodist_libkaffevm_la_OBJECTS = $(am__objects_2)
 libkaffevm_la_OBJECTS = $(am_libkaffevm_la_OBJECTS) \
@@ -512,6 +513,7 @@
 	utf8const.c \
 	gcFuncs.c \
 	reflect.c \
+	reference.c \
 	$(BINRELOC_SOURCES)
 
 noinst_HEADERS = \
@@ -552,6 +554,7 @@
 	threadData.h \
 	utf8const.h \
 	reflect.h \
+	reference.h \
 	../../binreloc/prefix.h
 
 CLEANFILES = so_locations
@@ -652,6 +655,7 @@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/libkaffevm_la-object.Plo at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/libkaffevm_la-prefix.Plo at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/libkaffevm_la-readClass.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/libkaffevm_la-reference.Plo at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/libkaffevm_la-reflect.Plo at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/libkaffevm_la-soft.Plo at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/libkaffevm_la-stackTrace.Plo at am__quote@
@@ -920,6 +924,13 @@
 @AMDEP_TRUE@@am__fastdepCC_FALSE@	source='reflect.c' object='libkaffevm_la-reflect.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) $(libkaffevm_la_CFLAGS) $(CFLAGS) -c -o libkaffevm_la-reflect.lo `test -f 'reflect.c' || echo '$(srcdir)/'`reflect.c
+
+libkaffevm_la-reference.lo: reference.c
+ at am__fastdepCC_TRUE@	if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libkaffevm_la_CFLAGS) $(CFLAGS) -MT libkaffevm_la-reference.lo -MD -MP -MF "$(DEPDIR)/libkaffevm_la-reference.Tpo" -c -o libkaffevm_la-reference.lo `test -f 'reference.c' || echo '$(srcdir)/'`reference.c; \
+ at am__fastdepCC_TRUE@	then mv -f "$(DEPDIR)/libkaffevm_la-reference.Tpo" "$(DEPDIR)/libkaffevm_la-reference.Plo"; else rm -f "$(DEPDIR)/libkaffevm_la-reference.Tpo"; exit 1; fi
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	source='reference.c' object='libkaffevm_la-reference.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) $(libkaffevm_la_CFLAGS) $(CFLAGS) -c -o libkaffevm_la-reference.lo `test -f 'reference.c' || echo '$(srcdir)/'`reference.c
 
 libkaffevm_la-prefix.lo: ../../binreloc/prefix.c
 @am__fastdepCC_TRUE@	if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libkaffevm_la_CFLAGS) $(CFLAGS) -MT libkaffevm_la-prefix.lo -MD -MP -MF "$(DEPDIR)/libkaffevm_la-prefix.Tpo" -c -o libkaffevm_la-prefix.lo `test -f '../../binreloc/prefix.c' || echo '$(srcdir)/'`../../binreloc/prefix.c; \
Index: kaffe/kaffe/kaffevm/baseClasses.c
diff -u kaffe/kaffe/kaffevm/baseClasses.c:1.57 kaffe/kaffe/kaffevm/baseClasses.c:1.58
--- kaffe/kaffe/kaffevm/baseClasses.c:1.57	Sat Dec 25 19:09:13 2004
+++ kaffe/kaffe/kaffevm/baseClasses.c	Sun Jan 30 12:42:40 2005
@@ -64,6 +64,11 @@
 Hjava_lang_Class* PtrClass;
 Hjava_lang_Class* ClassLoaderClass;
 
+Hjava_lang_Class* javaLangRefReference;
+Hjava_lang_Class* javaLangRefSoftReference;
+Hjava_lang_Class* javaLangRefWeakReference;
+Hjava_lang_Class* javaLangRefPhantomReference;
+
 Hjava_lang_Class* javaLangVoidClass;
 Hjava_lang_Class* javaLangBooleanClass;
 Hjava_lang_Class* javaLangByteClass;
@@ -162,6 +167,9 @@
 	stringInit();
 	utf8ConstInit();
 
+	/* Initialize the reference tracking subsystem */
+	KaffeVM_referenceInit();
+
 	/* Setup CLASSPATH */
 	initClasspath();
 
@@ -309,6 +317,12 @@
 	loadStaticClass(&javaLangNoClassDefFoundError, "java/lang/NoClassDefFoundError");
 	loadStaticClass(&javaLangStackOverflowError, "java/lang/StackOverflowError");
 	loadStaticClass(&javaIoIOException, "java/io/IOException");
+
+	/* Object references. */
+	loadStaticClass(&javaLangRefReference, "java/lang/ref/Reference");
+	loadStaticClass(&javaLangRefWeakReference, "java/lang/ref/WeakReference");
+	loadStaticClass(&javaLangRefSoftReference, "java/lang/ref/SoftReference");
+	loadStaticClass(&javaLangRefPhantomReference, "java/lang/ref/PhantomReference");
 
 	DBG(INIT, dprintf("initBaseClasses() done\n"); );
 
Index: kaffe/kaffe/kaffevm/baseClasses.h
diff -u kaffe/kaffe/kaffevm/baseClasses.h:1.18 kaffe/kaffe/kaffevm/baseClasses.h:1.19
--- kaffe/kaffe/kaffevm/baseClasses.h:1.18	Sun Sep  5 12:24:48 2004
+++ kaffe/kaffe/kaffevm/baseClasses.h	Sun Jan 30 12:42:40 2005
@@ -38,6 +38,11 @@
 extern struct Hjava_lang_Class* ClassLoaderClass;
 extern struct Hjava_lang_Class* kaffeLangAppClassLoaderClass;
 
+extern struct Hjava_lang_Class* javaLangRefReference;
+extern struct Hjava_lang_Class* javaLangRefSoftReference;
+extern struct Hjava_lang_Class* javaLangRefWeakReference;
+extern struct Hjava_lang_Class* javaLangRefPhantomReference;
+
 extern struct Hjava_lang_Class*	javaLangVoidClass;
 extern struct Hjava_lang_Class*	javaLangBooleanClass;
 extern struct Hjava_lang_Class*	javaLangByteClass;
Index: kaffe/kaffe/kaffevm/classMethod.c
diff -u kaffe/kaffe/kaffevm/classMethod.c:1.131 kaffe/kaffe/kaffevm/classMethod.c:1.132
--- kaffe/kaffe/kaffevm/classMethod.c:1.131	Sat Dec 25 19:09:13 2004
+++ kaffe/kaffe/kaffevm/classMethod.c	Sun Jan 30 12:42:40 2005
@@ -85,17 +85,13 @@
 static void
 determineAllocType(Hjava_lang_Class *class)
 {
-        if (StringClass != 0 && instanceof(StringClass, class)) {
-                class->alloc_type = KGC_ALLOC_JAVASTRING;
-        } else
-        if (ClassLoaderClass != 0 && instanceof(ClassLoaderClass, class)) {
-                class->alloc_type = KGC_ALLOC_JAVALOADER;
-        } else
-        if (class->finalizer != 0) {
-                class->alloc_type = KGC_ALLOC_FINALIZEOBJECT;
-        } else {
-                class->alloc_type = KGC_ALLOC_NORMALOBJECT;
-        }
+  if (StringClass != 0 && StringClass == class)
+    class->alloc_type = KGC_ALLOC_JAVASTRING;
+  else
+    if (ClassLoaderClass != 0 && instanceof(ClassLoaderClass, class))
+      class->alloc_type = KGC_ALLOC_JAVALOADER;
+    else
+      class->alloc_type = KGC_ALLOC_FINALIZEOBJECT;
 }
 
 /*
@@ -510,8 +506,8 @@
 	}
 
 	DO_CLASS_STATE(CSTATE_COMPLETE) {
-		JNIEnv *env = THREAD_JNIENV();
 		jthrowable exc = NULL;
+		jthrowable excpending;
 		JavaVM *vms[1];
 		jsize jniworking;
 
@@ -551,26 +547,15 @@
 		/* give classLock up for the duration of this call */
 		unlockClass(class);
 
-		/* we use JNI to catch possible exceptions, except
-		 * during initialization, when JNI doesn't work yet.
-		 * Should an exception occur at that time, we're
-		 * lost anyway.
+		/* We use here an exception safe call method to be able
+		 * to catch possible exceptions which may occur.
 		 */
-		JNI_GetCreatedJavaVMs(vms, 1, &jniworking);
-		if (jniworking) {
-DBG(STATICINIT,
-			dprintf("using JNI\n");
-);
-			(*env)->ExceptionClear(env);
-			(*env)->CallStaticVoidMethodA(env, class, (jmethodID)meth, NULL);
-			exc = (*env)->ExceptionOccurred(env);
-			(*env)->ExceptionClear(env);
-		} else {
-DBG(STATICINIT,
-			dprintf("using callMethodA\n");
-    );
-			callMethodA(meth, METHOD_NATIVECODE(meth), NULL, NULL, NULL, 1);
-		}
+		excpending = THREAD_DATA()->exceptObj;
+		THREAD_DATA()->exceptObj = NULL;
+
+		KaffeVM_safeCallMethodA(meth, METHOD_NATIVECODE(meth), NULL, NULL, NULL, 0);
+		exc = THREAD_DATA()->exceptObj;
+		THREAD_DATA()->exceptObj = excpending;
 
 		lockClass(class);
 
@@ -1333,44 +1318,58 @@
 	JNIEnv *env = THREAD_JNIENV();
 	Hjava_lang_String *jname;
 	jthrowable excpending;
-	jmethodID meth;
+	Method *meth;
+	Hjava_lang_Class *class_of_loader;
 	
 	/*
 	 * If an exception is already pending, for instance because we're
 	 * resolving one that has occurred, save it and clear it for the
 	 * upcall.
 	 */
-	excpending = (*env)->ExceptionOccurred(env);
-	(*env)->ExceptionClear(env);
+	excpending = THREAD_DATA()->exceptObj;
+	THREAD_DATA()->exceptObj = NULL;
 	
-	if( (jname = utf8Const2JavaReplace(ce->name, '/', '.')) &&
+	class_of_loader = OBJECT_CLASS((Hjava_lang_Object *)loader);
+
+	if( (jname = utf8Const2JavaReplace(ce->name, '/', '.')) )
+	  {
+	    jvalue jretval;
+	    jvalue args[1];
+	    jthrowable excobj;
+
+	    /* If we fail to resolve loadClass then we just have to set retval to NULL.
+	     * einfo is already set.
+	     */
+	    if ((meth = lookupClassMethod(class_of_loader, "loadClass", 
+					 "(Ljava/lang/String;)Ljava/lang/Class;",
+					 einfo)) == NULL)
+	      {
+		retval = NULL;
+		goto userload_done;
+	      }
+	    
+	    if (METHOD_IS_STATIC(meth))
+	      {
+		postExceptionMessage(einfo, "java/lang/NoSuchMethodError",
+				     "loadClass is wrongly a static method in %s", CLASS_CNAME(class_of_loader));
+		retval = NULL;
+		goto userload_done;
+	      }
+
+	    /* ClassLoader is not an interface so we may use NATIVECODE directly. */
+	    args[0].l = jname;
+	    KaffeVM_safeCallMethodA(meth, METHOD_NATIVECODE(meth), loader, args, &jretval, false);
+	    retval = jretval.l;
+
 	    /*
-	     * We use JNI here so that all exceptions are caught and we'll
-	     * always return.
+	     * Check whether an exception occurred.  If one was pending,
+	     * the new exception will override this one.
 	     */
-	    (meth = (*env)->GetMethodID(
-		env,
-		(*env)->GetObjectClass(env, loader),
-		"loadClass",
-		"(Ljava/lang/String;)Ljava/lang/Class;")) )
-	{
-		jthrowable excobj;
-		
-		retval = (Hjava_lang_Class*)
-			(*env)->CallObjectMethod(env,
-						 loader,
-						 meth,
-						 jname);
-		
-		/*
-		 * Check whether an exception occurred.  If one was pending,
-		 * the new exception will override this one.
-		 */
-		excobj = (*env)->ExceptionOccurred(env);
-		(*env)->ExceptionClear(env);
-		
-		if( excobj != 0 )
-		{
+	    excobj = THREAD_DATA()->exceptObj;
+	    THREAD_DATA()->exceptObj = NULL;
+	    
+	    if( excobj != 0 )
+	      {
 			/* There was an exception. */
 			einfo->type = KERR_RETHROW;
 			einfo->throwable = excobj;
@@ -1381,50 +1380,55 @@
 				/* Set this for the verifier. */
 				einfo->type |= KERR_NO_CLASS_FOUND;
 			}
-		}
-		else if( retval == NULL )
-		{
-			/* No class returned. */
-			postExceptionMessage(einfo,
-					     JAVA_LANG(ClassNotFoundException),
-					     "%s",
-					     ce->name->data);
-			/* Set this for the verifier. */
-			einfo->type |= KERR_NO_CLASS_FOUND;
-		}
-		else if( !utf8ConstEqual(retval->name, ce->name) )
-		{
-			/*
-			 * Its a valid class, but the name differs from the one
-			 * that was requested.
+			/* We must clear the return value as safeCallMethod does not
+			 * handle this.
 			 */
-			postExceptionMessage(
-				einfo,
-				JAVA_LANG(ClassNotFoundException),
-				"Bad class name (expect: %s, get: %s)",
-				ce->name->data,
-				retval->name->data);
-			/* Set this for the verifier. */
-			einfo->type |= KERR_NO_CLASS_FOUND;
 			retval = NULL;
-		}
-		else
-		{
-			retval = classMappingLoaded(ce, retval);
-		}
-		
-	}
+	      }
+	    else if( retval == NULL )
+	      {
+		/* No class returned. */
+		postExceptionMessage(einfo,
+				     JAVA_LANG(ClassNotFoundException),
+				     "%s",
+				     ce->name->data);
+		/* Set this for the verifier. */
+		einfo->type |= KERR_NO_CLASS_FOUND;
+	      }
+	    else if( !utf8ConstEqual(retval->name, ce->name) )
+	      {
+		/*
+		 * Its a valid class, but the name differs from the one
+		 * that was requested.
+		 */
+		postExceptionMessage(
+				     einfo,
+				     JAVA_LANG(ClassNotFoundException),
+				     "Bad class name (expect: %s, get: %s)",
+				     ce->name->data,
+				     retval->name->data);
+		/* Set this for the verifier. */
+		einfo->type |= KERR_NO_CLASS_FOUND;
+		retval = NULL;
+	      }
+	    else
+	      {
+		retval = classMappingLoaded(ce, retval);
+	      }
+	  }
 	else
-	{
-		postOutOfMemory(einfo);
-	}
+	  {
+	    postOutOfMemory(einfo);
+	  }
 	
+ userload_done:
 	/* rethrow pending exception */
 	if( excpending != NULL )
 	{
-		(*env)->Throw(env, excpending);
+	  THREAD_DATA()->exceptObj = excpending;
 	}
-	return( retval );
+
+	return retval;
 }
 
 Hjava_lang_Class *loadClass(Utf8Const *name,
@@ -1665,6 +1669,7 @@
 	int maxalign;
 	int oldoffset;
 	int *map;
+	jbool is_reference;
 
 	/* Find start of new fields in this object.  If start is zero, we must
 	 * allow for the object headers.
@@ -1714,6 +1719,10 @@
 	/* recall old offset */
 	offset = oldoffset;
 
+	/* Check whether the class is java.lang.ref.Reference */
+	is_reference =
+	   (strcmp(CLASS_CNAME(class), "java/lang/ref/Reference") == 0);
+
 	/* Now that we know how big that object is going to be, create
 	 * a bitmap to help the gc scan the object.  The first part is
 	 * inherited from the superclass.
@@ -1767,11 +1776,12 @@
 		if (!FIELD_RESOLVED(fld)) {
 			Utf8Const *sig = fld->signature;
 			if ((sig->data[0] == 'L' || sig->data[0] == '[') &&
-			    strcmp(sig->data, PTRCLASSSIG)) {
+			    strcmp(sig->data, PTRCLASSSIG) &&
+			    (!is_reference || strcmp(FIELD_NAME(fld), "referent") != 0)) {
 				BITMAP_SET(map, nbits);
 			}
 		} else {
-			if (FIELD_ISREF(fld)) {
+			if (FIELD_ISREF(fld) ) {
 				BITMAP_SET(map, nbits);
 			}
 		}
Index: kaffe/kaffe/kaffevm/classMethod.h
diff -u kaffe/kaffe/kaffevm/classMethod.h:1.75 kaffe/kaffe/kaffevm/classMethod.h:1.76
--- kaffe/kaffe/kaffevm/classMethod.h:1.75	Sat Jan  1 11:35:43 2005
+++ kaffe/kaffe/kaffevm/classMethod.h	Sun Jan 30 12:42:40 2005
@@ -47,6 +47,7 @@
 struct _jitCodeHeader;
 
 #include <java_lang_ClassLoader.h>
+#include "reference.h"
 
 /**
  * Builtin stab type IDs.
@@ -83,12 +84,13 @@
 	Hjava_lang_Object	head;		/* A class is an object too */
 
 	struct _iLock*		lock;		/* Lock for internal use */
+        void *finalizer_call;
 
 	/* Link to class entry */
 	struct _classEntry*	centry;
 
 	Utf8Const*		name;
-	unsigned int			packageLength;
+	unsigned int		packageLength;
 	char*			sourcefile;	/* source file name if known */
 	accessFlags		accflags;
 
@@ -144,6 +146,9 @@
 	int*			gc_layout;
 	class_state_t		state;
 	void*			processingThread;
+	/* This pointer contains the method which should be called
+	 * at object finalization.
+	 */
 	Method*			finalizer;
 	int			alloc_type;	/* allocation type */
 
@@ -339,7 +344,7 @@
 
 typedef struct _dispatchTable {
 	Hjava_lang_Class*	class;
-	void*			__dummy0; /* For GCJ/C++ compatibility */
+	void*			__dummy0; /* For GCJ/C++ compatibility. */
 	void*			method[1];
 } dispatchTable;
 
@@ -378,6 +383,7 @@
 				 && CLASS_IS_PRIMITIVE(FIELD_TYPE(FLD)))
 #define FIELD_ISREF(FLD)	(!FIELD_ISPRIM(FLD)			\
 				 && FIELD_TYPE(FLD) != PtrClass)
+#define FIELD_NAME(FLD)		((FLD)->name->data)
 
 #define	CLASSMAXSIG		256
 
Index: kaffe/kaffe/kaffevm/exception.h
diff -u kaffe/kaffe/kaffevm/exception.h:1.28 kaffe/kaffe/kaffevm/exception.h:1.29
--- kaffe/kaffe/kaffevm/exception.h:1.28	Tue Oct 12 17:00:10 2004
+++ kaffe/kaffe/kaffevm/exception.h	Sun Jan 30 12:42:40 2005
@@ -56,7 +56,7 @@
 /*
  * A VmExceptHandle is used to handle *any* exception in native code
  * in the core of the VM.  Set up when entering Kaffe_JNI methods, or
- * when callMethodA or callMethodV are invoked.
+ * when KaffeVM_callMethodA or KaffeVM_callMethodV are invoked.
  *
  * Each thread in the system has a exceptPtr, which points
  * to the most recent VmExceptHandler buffer (the buffers
Index: kaffe/kaffe/kaffevm/gcFuncs.c
diff -u kaffe/kaffe/kaffevm/gcFuncs.c:1.63 kaffe/kaffe/kaffevm/gcFuncs.c:1.64
--- kaffe/kaffe/kaffevm/gcFuncs.c:1.63	Sat Dec 25 19:09:13 2004
+++ kaffe/kaffe/kaffevm/gcFuncs.c	Sun Jan 30 12:42:40 2005
@@ -573,8 +573,7 @@
         walkClassEntries(collector, gc_info, (Hjava_lang_ClassLoader*)base);
 }
 
-static
-void
+static void
 /* ARGSUSED */
 finalizeObject(Collector* collector UNUSED, void* ob)
 {
@@ -587,17 +586,8 @@
 		/* Suppose we catch ThreadDeath inside newObject() */
 		return;
 	}
-        objclass = OBJECT_CLASS(obj);
-        final = objclass->finalizer;
-
-	if (!final) {
-		assert(objclass->alloc_type == KGC_ALLOC_JAVALOADER);
-		return;
-	}
-
-	(*env)->CallVoidMethod(env, obj, final);
-	/* ignore any resulting exception */
-	(*env)->ExceptionClear(env);
+	assert(obj->finalizer_call != NULL);
+	((KaffeVM_Finalizer)obj->finalizer_call)(obj);
 }
 
 /*
Index: kaffe/kaffe/kaffevm/ksem.c
diff -u kaffe/kaffe/kaffevm/ksem.c:1.10 kaffe/kaffe/kaffevm/ksem.c:1.11
--- kaffe/kaffe/kaffevm/ksem.c:1.10	Thu Dec 16 06:13:50 2004
+++ kaffe/kaffe/kaffevm/ksem.c	Sun Jan 30 12:42:41 2005
@@ -51,6 +51,8 @@
 	if (timeout == 0)
 		timeout = NOTIMEOUT;
 
+	dprintf("ksem_get sp=%p\n", &r);
+
 	KMUTEX(lock)(&sem->mux);
 	/* If no stored wakeups, then sleep. */
 	if (sem->count == 0) {
Index: kaffe/kaffe/kaffevm/locks.c
diff -u kaffe/kaffe/kaffevm/locks.c:1.54 kaffe/kaffe/kaffevm/locks.c:1.55
--- kaffe/kaffe/kaffevm/locks.c:1.54	Mon Dec 20 02:12:53 2004
+++ kaffe/kaffe/kaffevm/locks.c	Sun Jan 30 12:42:41 2005
@@ -257,6 +257,9 @@
 		if (lk != heavyLock) {
 			gc_free(lk);
 		}
+		else {
+			lk->holder = NULL;
+		}
 		putHeavyLock(lkp, LOCKFREE);
 	}
 	KTHREAD(enable_stop)();
Index: kaffe/kaffe/kaffevm/object.c
diff -u kaffe/kaffe/kaffevm/object.c:1.31 kaffe/kaffe/kaffevm/object.c:1.32
--- kaffe/kaffe/kaffevm/object.c:1.31	Mon Dec 20 02:12:53 2004
+++ kaffe/kaffe/kaffevm/object.c	Sun Jan 30 12:42:41 2005
@@ -51,6 +51,7 @@
 		postOutOfMemory(info);
 	} else {
 	    /* Fill in object information */
+	    KaffeVM_setFinalizer(obj, KGC_DEFAULT_FINALIZER);
 	    obj->vtable = class->vtable;
 
 #if defined(ENABLE_JVMPI)
@@ -114,6 +115,7 @@
 	}
 
         /* Fill in object information */
+	KaffeVM_setFinalizer(cls, KGC_DEFAULT_FINALIZER);
 	cls->head.vtable = ClassClass->vtable;
 done:
 DBG(NEWOBJECT,
@@ -152,6 +154,7 @@
 			}
 		}
 		if (obj != NULL) {
+		        KaffeVM_setFinalizer(obj, KGC_DEFAULT_FINALIZER);
 			obj->vtable = class->vtable;
 			ARRAY_SIZE(obj) = count;
 
===================================================================
Checking out kaffe/kaffe/kaffevm/reference.c
RCS:  /home/cvs/kaffe/kaffe/kaffe/kaffevm/reference.c,v
VERS: 1.1
***************
--- /dev/null	Sun Aug  4 19:57:58 2002
+++ kaffe/kaffe/kaffevm/reference.c	Sun Jan 30 12:48:07 2005
@@ -0,0 +1,257 @@
+/* reference.c
+ * Maintain the table of Java references. 
+ * Implement special finalizer for reclaiming or clearing the references.
+ *
+ * Copyright (c) 2005
+ *      The Kaffe.org's developers. See ChangeLog for details.
+ *
+ * See the file "license.terms" for information on usage and redistribution
+ * of this file.
+ */
+
+#include "gtypes.h"
+#include "hashtab.h"
+#include "baseClasses.h"
+#include "reference.h"
+#include "locks.h"
+#include "gc.h"
+#include "classMethod.h"
+#include "native.h"
+#include "thread.h"
+#include "utf8const.h"
+#include "kaffe/jmalloc.h"
+
+typedef struct _referenceLinkList {
+  jobject reference;
+  kgc_reference_type weight;
+  struct _referenceLinkList *next;
+} referenceLinkList;
+
+typedef struct _referenceLinkListHead {
+  jobject obj;
+  referenceLinkList *references;
+} referenceLinkListHead;
+
+static iStaticLock referencesLock = KAFFE_STATIC_LOCK_INITIALIZER;
+static hashtab_t referencesHashTable;
+static uint32 referentOffset = ~((uint32)0);
+
+static int
+objectHash(const void *p)
+{
+  const referenceLinkListHead *head = (const referenceLinkListHead *)p;
+  void *obj = head->obj;
+
+#if SIZEOF_INT == SIZEOF_VOID_P && SIZEOF_INT == 4
+  return (int)(obj) & ((1UL << 31) - 1);
+#elif SIZEOF_INT == SIZEOF_VOID_P && SIZEOF_INT == 8
+  return (int)(obj) & ((1ULL << 63) - 1);
+#elif SIZEOF_INT == 4 && SIZEOF_VOID_P == 8
+  return (int)( ((uintp)obj >> 32) ^ ((uintp)obj & 0xffffffff));
+#else
+#error "Don't know what to do to build a hash function for objects."
+#endif
+}
+
+static int
+objectComp(const void *p1, const void *p2)
+{
+  const referenceLinkListHead *head1 = (const referenceLinkListHead *)p1;
+  const referenceLinkListHead *head2 = (const referenceLinkListHead *)p2;
+  return !(head1->obj == head2->obj);
+}
+
+void KaffeVM_referenceInit(void)
+{
+  referencesHashTable = hashInit(objectHash, objectComp, NULL, NULL);
+}
+
+void KaffeVM_registerObjectReference(jobject reference, jobject obj, kgc_reference_type reftype)
+{
+  int iLockRoot;
+  referenceLinkList *ll;
+  referenceLinkListHead *head, *temp;
+
+  ll = KMALLOC(sizeof(referenceLinkList));
+  ll->reference = reference;
+  ll->weight = reftype;
+
+  head = KMALLOC(sizeof(referenceLinkListHead));
+  head->references = ll;
+  head->obj = obj;
+  
+  lockStaticMutex(&referencesLock);
+  temp = (referenceLinkListHead *)hashAdd(referencesHashTable, head);
+  /* Check whether the hash entry was already filled by someone. */

*** Patch too long, truncated ***




More information about the kaffe mailing list