[kaffe] Re: kaffe and java-gnome (it works!)

Mark Wielaard mark@klomp.org
Sat Jul 5 02:04:01 2003


--=-B8s2sOE2l2z6hLHUKpzH
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hi,

On Sat, 2003-07-05 at 01:35, Mark Wielaard wrote:
> java-gnome uses more JNI 1.2 stuff like ExceptionCheck(). When changing
> those calls in java-gnome to use the less efficient JNI 1.1 method
> ExceptionOccured() my program seems to actually work!

And attached is the complete (admittedly minimal) patch that I use to
get kaffe (configure --with-threads=unix-pthreads) to run an unpatched
java-gnome build.

Cheers,

Mark

--=-B8s2sOE2l2z6hLHUKpzH
Content-Disposition: inline; filename=jni.patch
Content-Type: text/x-patch; name=jni.patch; charset=iso-8859-1
Content-Transfer-Encoding: 7bit

Index: include/jni.h
===================================================================
RCS file: /cvs/kaffe/kaffe/include/jni.h,v
retrieving revision 1.18
diff -u -r1.18 jni.h
--- include/jni.h	18 May 2003 19:20:58 -0000	1.18
+++ include/jni.h	5 Jul 2003 08:55:44 -0000
@@ -75,26 +75,26 @@
 	jint	(*GetVersion)			(JNIEnv*);
 	jclass	(*DefineClass)			(JNIEnv*, jobject, const jbyte*, jsize);
 	jclass	(*FindClass)			(JNIEnv*, const char*);
-	void*	reserved4;
-	void*	reserved5;
-	void*	reserved6;
+	void*	reserved4; // FromReflectedMethod
+	void*	reserved5; // FromReflectedField
+	void*	reserved6; // ToReflectedMethod
 	jclass	(*GetSuperclass)		(JNIEnv*, jclass);
 	jboolean	(*IsAssignableFrom)		(JNIEnv*, jclass, jclass);
-	void*	reserved7;
+	void*	reserved7; // ToReflectedField
 	jint	(*Throw)			(JNIEnv*, jobject);
 	jint	(*ThrowNew)			(JNIEnv*, jclass, const char*);
 	jthrowable (*ExceptionOccurred)		(JNIEnv*);
 	void	(*ExceptionDescribe)		(JNIEnv*);
 	void	(*ExceptionClear)		(JNIEnv*);
 	void	(*FatalError)			(JNIEnv*, const char*);
-	void*	reserved8;
-	void*	reserved9;
+	void*	reserved8; // PushLocalFrame
+	void*	reserved9; // PopLocalFrame
 	jref	(*NewGlobalRef)			(JNIEnv*, jref);
 	void	(*DeleteGlobalRef)		(JNIEnv*, jref);
 	void	(*DeleteLocalRef)		(JNIEnv*, jref);
 	jboolean	(*IsSameObject)			(JNIEnv*, jobject, jobject);
-	void*	reserved10;
-	void*	reserved11;
+	void*	reserved10; // NewLocalRef
+	void*	reserved11; // EnsureLocalCapacity
 	jobject	(*AllocObject)			(JNIEnv*, jclass);
 	jobject	(*NewObject)			(JNIEnv*, jclass, jmethodID, ...);
 	jobject	(*NewObjectV)			(JNIEnv*, jclass, jmethodID, va_list);
@@ -289,6 +289,23 @@
 	jint	(*MonitorExit)			(JNIEnv*, jobject);
 	jint	(*GetJavaVM)			(JNIEnv*, JavaVM**);
 
+	// New JNI 1.2 functions
+	
+	void* reserved12; // GetStringRegion
+	void* reserved13; // GetStringUTFRegion
+	void* reserved14; // GetPrimitiveArrayCritical
+	void* reserved15; // ReleasePromitiveArrayCritical
+	void* reserved16; // GetStringCritical
+	void* reserved17; // ReleaseStringCritical
+	void* reserved18; // NewWeakGlobalRef
+	void* reserved19; // DeleteWeakGlobalRef
+	jboolean	(*ExceptionCheck)	(JNIEnv*);
+
+	// New JNI 1.4 functions
+	
+	void* reserved20; // NewDirectByteBuffer
+	void* reserved21; // GetDirectBufferAddress
+	void* reserved22; // GetDirectBufferCapacity
 };
 
 struct JavaVMAttachArgs {
@@ -309,6 +326,7 @@
 	jint	(*AttachCurrentThread)		(JavaVM*, JNIEnv**, ThreadAttachArgs*);
 	jint	(*DetachCurrentThread)		(JavaVM*);
 	jint	(*GetEnv)			(JavaVM*, void**, jint);
+	void*	reserved3; // AttachCurrentThreadAsDaemon
 };
 
 struct JNIEnv_ {
@@ -522,6 +540,7 @@
 	jint MonitorEnter(jobject);
 	jint MonitorExit(jobject);
 	jint GetJavaVM(JavaVM**);
+	jboolean ExceptionCheck(void);
 #endif
 };
 
Index: include/jni_cpp.h
===================================================================
RCS file: /cvs/kaffe/kaffe/include/jni_cpp.h,v
retrieving revision 1.4
diff -u -r1.4 jni_cpp.h
--- include/jni_cpp.h	6 Apr 1999 19:13:56 -0000	1.4
+++ include/jni_cpp.h	5 Jul 2003 08:55:44 -0000
@@ -1201,4 +1201,9 @@
 	return (functions->GetJavaVM(this, a));
 }
 
+inline jboolean JNIEnv::CheckException(void)
+{
+	return (functions->CheckException(this));
+}
+
 #endif
Index: kaffe/kaffevm/external.c
===================================================================
RCS file: /cvs/kaffe/kaffe/kaffe/kaffevm/external.c,v
retrieving revision 1.46
diff -u -r1.46 external.c
--- kaffe/kaffevm/external.c	11 Jun 2003 16:54:14 -0000	1.46
+++ kaffe/kaffevm/external.c	5 Jul 2003 08:55:44 -0000
@@ -115,6 +115,8 @@
 
 extern jint Kaffe_JNI_native(Method*);
 
+extern JavaVM Kaffe_JavaVM;
+
 /*
  * Error stub function.  Point unresolved link errors here to avoid
  * problems.
@@ -316,6 +318,12 @@
 #if defined(KAFFE_FEEDBACK)
 	feedbackLibrary(path, true);
 #endif
+
+	void *func = loadNativeLibrarySym("JNI_OnLoad");
+	if (func != NULL) {
+	    JavaVM *jvm = &Kaffe_JavaVM;
+	    jint vers = ((jint(JNICALL *)(JavaVM *, void *))func)(jvm, NULL);
+	}
 
 	return index;
 }
Index: kaffe/kaffevm/jni.c
===================================================================
RCS file: /cvs/kaffe/kaffe/kaffe/kaffevm/jni.c,v
retrieving revision 1.84
diff -u -r1.84 jni.c
--- kaffe/kaffevm/jni.c	30 Jun 2003 19:30:27 -0000	1.84
+++ kaffe/kaffevm/jni.c	5 Jul 2003 08:55:47 -0000
@@ -435,6 +435,21 @@
 	return (obj);
 }
 
+static jboolean
+Kaffe_ExceptionCheck(JNIEnv* env)
+{
+	jboolean result;
+	jobject obj;
+
+	BEGIN_EXCEPTION_HANDLING(0);
+
+	obj = unhand(getCurrentThread())->exceptObj;
+	result = (obj == NULL) ? JNI_FALSE : JNI_TRUE;
+
+	END_EXCEPTION_HANDLING();
+	return (result);
+}
+
 static void
 Kaffe_ExceptionDescribe(JNIEnv* env)
 {
@@ -4347,6 +4362,18 @@
 	Kaffe_MonitorEnter,
 	Kaffe_MonitorExit,
 	Kaffe_GetJavaVM,
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	Kaffe_ExceptionCheck,
+	NULL,
+	NULL,
+	NULL,
 
 };
 

--=-B8s2sOE2l2z6hLHUKpzH--