[kaffe] CVS kaffe (guilhem): Important fix for JNI functions NewDirectByteBuffer & GetDirectBufferAddress.

Kaffe CVS cvs-commits at kaffe.org
Fri Dec 16 12:16:09 PST 2005


PatchSet 7005 
Date: 2005/12/16 19:56:55
Author: guilhem
Branch: HEAD
Tag: (none) 
Log:
Important fix for JNI functions NewDirectByteBuffer & GetDirectBufferAddress.

        * kaffe/kaffevm/baseClasses.c
        kaffe/kaffevm/baseClasses.h
        (initBaseClasses): Resolve java.nio.DirectByteBufferImpl and
        java.nio.DirectByteBufferImpl$ReadWrite and gnu.classpath.Pointer.
        Also resolve the inner address field.

        * kaffe/kaffevm/support.c,
        kaffe/kaffevm/support.h
        (KNI_lookupFieldC): New function to help resolve fields in a class
        using a C string.

        * kaffe/kaffevm/jni_i.h,
        kaffe/kaffevm/jni/jni-fields.c:
        (GET_STATIC_FIELD, SET_STATIC_FIELD, GET_FIELD, SET_FIELD): Moved
        to jni_i.h and renamed to KNI_*

        * kaffe/kaffevm/jni/jni-helpers.c
        (KaffeJNI_NewDirectByteBuffer,
        KaffeJNI_GetDirectBufferAddress): Use gnu/classpath/Pointer and
        not RawData as this class has disappeated. These functions uses
        KNI directly now.

Members: 
	kaffe/kaffevm/baseClasses.c:1.69->1.70 
	kaffe/kaffevm/baseClasses.h:1.23->1.24 
	kaffe/kaffevm/support.c:1.90->1.91 
	kaffe/kaffevm/support.h:1.43->1.44 
	kaffe/kaffevm/jni/jni-fields.c:1.7->1.8 
	kaffe/kaffevm/jni/jni-helpers.c:1.9->1.10 
	kaffe/kaffevm/jni/jni_i.h:1.10->1.11 

Index: kaffe/kaffe/kaffevm/baseClasses.c
diff -u kaffe/kaffe/kaffevm/baseClasses.c:1.69 kaffe/kaffe/kaffevm/baseClasses.c:1.70
--- kaffe/kaffe/kaffevm/baseClasses.c:1.69	Wed Oct 19 20:10:35 2005
+++ kaffe/kaffe/kaffevm/baseClasses.c	Fri Dec 16 19:56:55 2005
@@ -87,6 +87,13 @@
 Hjava_lang_Class* javaLangFloatClass;
 Hjava_lang_Class* javaLangDoubleClass;
 
+Hjava_lang_Class *javaNioDirectByteBufferImplClass;
+Hjava_lang_Class *javaNioDirectByteBufferImplReadWriteClass;
+Hjava_lang_Class *gnuClasspathPointerClass;
+
+Field *gnuClasspathPointerAddress;
+Field *directByteBufferImplAddress;
+
 Hjava_lang_Class* javaLangThrowable;
 Hjava_lang_Class* javaLangVMThrowable;
 Hjava_lang_Class* javaLangStackTraceElement;
@@ -373,11 +380,33 @@
 	loadStaticClass(&javaLangRefSoftReference, "java/lang/ref/SoftReference");
 	loadStaticClass(&javaLangRefPhantomReference, "java/lang/ref/PhantomReference");
 
+	/* NIO helpers */
+	loadStaticClass(&javaNioDirectByteBufferImplClass, "java/nio/DirectByteBufferImpl");
+	loadStaticClass(&javaNioDirectByteBufferImplReadWriteClass, "java/nio/DirectByteBufferImpl$ReadWrite");
+#if SIZEOF_VOID_P == 4
+	loadStaticClass(&gnuClasspathPointerClass, "gnu/classpath/Pointer32");
+#elif SIZEOF_VOID_P == 8
+	loadStaticClass(&gnuClasspathPointerClass, "gnu/classpath/Pointer64");
+#else
+#error "Unknown pointer size"
+#endif
+
 	DBG(INIT, dprintf("initBaseClasses() done\n"); );
 
 	for (i = 0; stateCompleteClass[i] != NULL; i++) {
 	    if (!processClass(*stateCompleteClass[i], CSTATE_COMPLETE, &einfo))
 	      abortWithEarlyClassFailure(&einfo);
-	}
+	}	
+
+	/* Preresolve some fields which will be used in JNI. */	
+	gnuClasspathPointerAddress = KNI_lookupFieldC(gnuClasspathPointerClass, "data", false, &einfo);
+	directByteBufferImplAddress = KNI_lookupFieldC(javaNioDirectByteBufferImplClass, "address", false, &einfo);
+
+	if (gnuClasspathPointerAddress == NULL ||
+	    directByteBufferImplAddress == NULL)
+	  {
+	    DBG(INIT, dprintf("Cannot resolve fields necessary for NIO operations\n"); );
+	    KAFFEVM_EXIT(-1);
+	  }
 }
 
Index: kaffe/kaffe/kaffevm/baseClasses.h
diff -u kaffe/kaffe/kaffevm/baseClasses.h:1.23 kaffe/kaffe/kaffevm/baseClasses.h:1.24
--- kaffe/kaffe/kaffevm/baseClasses.h:1.23	Wed Oct 19 20:10:35 2005
+++ kaffe/kaffe/kaffevm/baseClasses.h	Fri Dec 16 19:56:55 2005
@@ -51,6 +51,13 @@
 extern struct Hjava_lang_Class*	javaLangFloatClass;
 extern struct Hjava_lang_Class*	javaLangDoubleClass;
 
+extern struct Hjava_lang_Class *javaNioDirectByteBufferImplClass;
+extern struct Hjava_lang_Class *javaNioDirectByteBufferImplReadWriteClass;
+extern struct Hjava_lang_Class *gnuClasspathPointerClass;
+
+extern Field *gnuClasspathPointerAddress;
+extern Field *directByteBufferImplAddress;
+
 extern struct Hjava_lang_Class* javaLangThrowable;
 extern struct Hjava_lang_Class* javaLangVMThrowable;
 extern struct Hjava_lang_Class* javaLangStackTraceElement;
Index: kaffe/kaffe/kaffevm/support.c
diff -u kaffe/kaffe/kaffevm/support.c:1.90 kaffe/kaffe/kaffevm/support.c:1.91
--- kaffe/kaffe/kaffevm/support.c:1.90	Sun Sep 25 02:46:52 2005
+++ kaffe/kaffe/kaffevm/support.c	Fri Dec 16 19:56:55 2005
@@ -56,6 +56,26 @@
 userProperty* userProperties = NULL;
 
 /**
+ * This function is an helper for lookupField. It creates a UTF string and invoke lookupField
+ * with it.
+ *
+ *
+ */
+Field*  KNI_lookupFieldC(struct Hjava_lang_Class* clazz, const char* fieldName, 
+			 bool isStatic, errorInfo* einfo)
+{
+  Utf8Const *fieldUTF;
+  Field *field;
+
+  checkPtr(fieldUTF = utf8ConstNew(fieldName, -1));
+  field = lookupClassField(clazz, fieldUTF, isStatic, einfo);
+  utf8ConstRelease(fieldUTF);
+
+  return field;
+}
+
+
+/**
  * Call a Java method from native code.
  *
  * @param obj the obj or 0 if the method is static
@@ -329,6 +349,10 @@
     
   END_EXCEPTION_HANDLING();
 }
+
+/**
+ * q::
+ */
 
 /**
  * Lookup a method given class, name and signature.
Index: kaffe/kaffe/kaffevm/support.h
diff -u kaffe/kaffe/kaffevm/support.h:1.43 kaffe/kaffe/kaffevm/support.h:1.44
--- kaffe/kaffe/kaffevm/support.h:1.43	Fri Aug 19 20:54:43 2005
+++ kaffe/kaffe/kaffevm/support.h	Fri Dec 16 19:56:55 2005
@@ -135,8 +135,9 @@
 extern void	KaffeVM_callMethodV(struct _jmethodID*, void*, void*, va_list, jvalue*);
 extern void     KaffeVM_safeCallMethodA(struct _jmethodID*, void*, void*, jvalue*, jvalue*, int);
 extern void     KaffeVM_safeCallMethodV(struct _jmethodID*, void*, void*, va_list, jvalue*);
-extern struct _jmethodID*	lookupClassMethod(struct Hjava_lang_Class*, const char*, const char*, struct _errorInfo*);
-extern struct _jmethodID*	lookupObjectMethod(struct Hjava_lang_Object*, const char*, const char*, struct _errorInfo*);
+extern Method*	lookupClassMethod(struct Hjava_lang_Class*, const char*, const char*, struct _errorInfo*);
+extern Method*	lookupObjectMethod(struct Hjava_lang_Object*, const char*, const char*, struct _errorInfo*);
+extern Field*   KNI_lookupFieldC(struct Hjava_lang_Class*, const char*, bool, struct _errorInfo*);
 
 struct _strconst;
 extern void SignalError(const char *, const char *);
Index: kaffe/kaffe/kaffevm/jni/jni-fields.c
diff -u kaffe/kaffe/kaffevm/jni/jni-fields.c:1.7 kaffe/kaffe/kaffevm/jni/jni-fields.c:1.8
--- kaffe/kaffe/kaffevm/jni/jni-fields.c:1.7	Thu Aug 18 22:31:31 2005
+++ kaffe/kaffe/kaffevm/jni/jni-fields.c	Fri Dec 16 19:56:56 2005
@@ -21,11 +21,6 @@
 #include "classMethod.h"
 #include "jni_funcs.h"
 
-#define	GET_FIELD(T,O,F)	*(T*)((char*)(O) + FIELD_BOFFSET((Field*)(F)))
-#define	SET_FIELD(T,O,F,V)	*(T*)((char*)(O) + FIELD_BOFFSET((Field*)(F))) = (V)
-#define	GET_STATIC_FIELD(T,F)	*(T*)FIELD_ADDRESS((Field*)F)
-#define	SET_STATIC_FIELD(T,F,V)	*(T*)FIELD_ADDRESS((Field*)F) = (V)
-
 /* ------------------------------------------------------------------------------
  * GetField functions
  * ------------------------------------------------------------------------------
@@ -40,7 +35,7 @@
   BEGIN_EXCEPTION_HANDLING(NULL);
 
   obj_local = unveil(obj);
-  nobj = GET_FIELD(jobject, obj_local, fld);
+  nobj = KNI_GET_FIELD(jobject, obj_local, fld);
 
   ADD_REF(nobj);
   END_EXCEPTION_HANDLING();
@@ -56,7 +51,7 @@
   BEGIN_EXCEPTION_HANDLING(0);
 
   obj_local = unveil(obj);
-  r = GET_FIELD(jboolean, obj_local, fld);
+  r = KNI_GET_FIELD(jboolean, obj_local, fld);
 
   END_EXCEPTION_HANDLING();
   return (r);
@@ -70,7 +65,7 @@
   BEGIN_EXCEPTION_HANDLING(0);
 
   obj_local = unveil(obj);
-  r = GET_FIELD(jbyte, obj_local, fld);
+  r = KNI_GET_FIELD(jbyte, obj_local, fld);
 
   END_EXCEPTION_HANDLING();
   return (r);
@@ -84,7 +79,7 @@
   BEGIN_EXCEPTION_HANDLING(0);
 
   obj_local = unveil(obj);
-  r = GET_FIELD(jchar, obj_local, fld);
+  r = KNI_GET_FIELD(jchar, obj_local, fld);
 
   END_EXCEPTION_HANDLING();
   return (r);
@@ -98,7 +93,7 @@
   BEGIN_EXCEPTION_HANDLING(0);
 
   obj_local = unveil(obj);
-  r = GET_FIELD(jshort, obj_local, fld);
+  r = KNI_GET_FIELD(jshort, obj_local, fld);
 
   END_EXCEPTION_HANDLING();
   return (r);
@@ -112,7 +107,7 @@
   BEGIN_EXCEPTION_HANDLING(0);
 
   obj_local = unveil(obj);
-  r = GET_FIELD(jint, obj_local, fld);
+  r = KNI_GET_FIELD(jint, obj_local, fld);
 
   END_EXCEPTION_HANDLING();
   return (r);
@@ -126,7 +121,7 @@
   BEGIN_EXCEPTION_HANDLING(0);
 
   obj_local = unveil(obj);
-  r = GET_FIELD(jlong, obj_local, fld);
+  r = KNI_GET_FIELD(jlong, obj_local, fld);
 
   END_EXCEPTION_HANDLING();
   return (r);
@@ -140,7 +135,7 @@
   BEGIN_EXCEPTION_HANDLING(0);
 
   obj_local = unveil(obj);
-  r = GET_FIELD(jfloat, obj_local, fld);
+  r = KNI_GET_FIELD(jfloat, obj_local, fld);
 
   END_EXCEPTION_HANDLING();
   return (r);
@@ -154,7 +149,7 @@
   BEGIN_EXCEPTION_HANDLING(0);
 
   obj_local = unveil(obj);
-  r = GET_FIELD(jdouble, obj_local, fld);
+  r = KNI_GET_FIELD(jdouble, obj_local, fld);
 
   END_EXCEPTION_HANDLING();
   return (r);
@@ -174,7 +169,7 @@
 
   obj_local = unveil(obj);
   val_local = unveil(val);
-  SET_FIELD(jobject, obj_local, fld, val_local);
+  KNI_SET_FIELD(jobject, obj_local, fld, val_local);
 
   END_EXCEPTION_HANDLING();
 }
@@ -186,7 +181,7 @@
   BEGIN_EXCEPTION_HANDLING_VOID();
 
   obj_local = unveil(obj);
-  SET_FIELD(jboolean, obj_local, fld, val);
+  KNI_SET_FIELD(jboolean, obj_local, fld, val);
 
   END_EXCEPTION_HANDLING();
 }
@@ -198,7 +193,7 @@
   BEGIN_EXCEPTION_HANDLING_VOID();
 
   obj_local = unveil(obj);
-  SET_FIELD(jbyte, obj_local, fld, val);
+  KNI_SET_FIELD(jbyte, obj_local, fld, val);
 
   END_EXCEPTION_HANDLING();
 }
@@ -210,7 +205,7 @@
   BEGIN_EXCEPTION_HANDLING_VOID();
 
   obj_local = unveil(obj);
-  SET_FIELD(jchar, obj_local, fld, val);
+  KNI_SET_FIELD(jchar, obj_local, fld, val);
 
   END_EXCEPTION_HANDLING();
 }
@@ -222,7 +217,7 @@
   BEGIN_EXCEPTION_HANDLING_VOID();
 
   obj_local = unveil(obj);
-  SET_FIELD(jshort, obj_local, fld, val);
+  KNI_SET_FIELD(jshort, obj_local, fld, val);
 
   END_EXCEPTION_HANDLING();
 }
@@ -234,7 +229,7 @@
   BEGIN_EXCEPTION_HANDLING_VOID();
 
   obj_local = unveil(obj);
-  SET_FIELD(jint, obj_local, fld, val);
+  KNI_SET_FIELD(jint, obj_local, fld, val);
 
   END_EXCEPTION_HANDLING();
 }
@@ -246,7 +241,7 @@
   BEGIN_EXCEPTION_HANDLING_VOID();
 
   obj_local = unveil(obj);
-  SET_FIELD(jlong, obj_local, fld, val);
+  KNI_SET_FIELD(jlong, obj_local, fld, val);
 
   END_EXCEPTION_HANDLING();
 }
@@ -258,7 +253,7 @@
   BEGIN_EXCEPTION_HANDLING_VOID();
 
   obj_local = unveil(obj);
-  SET_FIELD(jfloat, obj_local, fld, val);
+  KNI_SET_FIELD(jfloat, obj_local, fld, val);
 
   END_EXCEPTION_HANDLING();
 }
@@ -270,7 +265,7 @@
   BEGIN_EXCEPTION_HANDLING_VOID();
 
   obj_local = unveil(obj);
-  SET_FIELD(jdouble, obj_local, fld, val);
+  KNI_SET_FIELD(jdouble, obj_local, fld, val);
 
   END_EXCEPTION_HANDLING();
 }
@@ -288,7 +283,7 @@
 
   BEGIN_EXCEPTION_HANDLING(NULL);
 
-  obj = GET_STATIC_FIELD(jobject, fld);
+  obj = KNI_GET_STATIC_FIELD(jobject, fld);
 
   ADD_REF(obj);
   END_EXCEPTION_HANDLING();
@@ -301,7 +296,7 @@
   jboolean r;
   BEGIN_EXCEPTION_HANDLING(0);
 
-  r = GET_STATIC_FIELD(jboolean, fld);
+  r = KNI_GET_STATIC_FIELD(jboolean, fld);
 
   END_EXCEPTION_HANDLING();
   return (r);
@@ -313,7 +308,7 @@
   jbyte r;
   BEGIN_EXCEPTION_HANDLING(0);
 
-  r = GET_STATIC_FIELD(jbyte, fld);
+  r = KNI_GET_STATIC_FIELD(jbyte, fld);
 
   END_EXCEPTION_HANDLING();
   return (r);
@@ -325,7 +320,7 @@
   jchar r;
   BEGIN_EXCEPTION_HANDLING(0);
 
-  r = GET_STATIC_FIELD(jchar, fld);
+  r = KNI_GET_STATIC_FIELD(jchar, fld);
 
   END_EXCEPTION_HANDLING();
   return (r);
@@ -337,7 +332,7 @@
   jint r;
   BEGIN_EXCEPTION_HANDLING(0);
 
-  r = GET_STATIC_FIELD(jshort, fld);
+  r = KNI_GET_STATIC_FIELD(jshort, fld);
 
   END_EXCEPTION_HANDLING();
   return (r);
@@ -349,7 +344,7 @@
   jint r;
   BEGIN_EXCEPTION_HANDLING(0);
 
-  r = GET_STATIC_FIELD(jint, fld);
+  r = KNI_GET_STATIC_FIELD(jint, fld);
 
   END_EXCEPTION_HANDLING();
   return (r);
@@ -361,7 +356,7 @@
   jlong r;
   BEGIN_EXCEPTION_HANDLING(0);
 
-  r = GET_STATIC_FIELD(jlong, fld);
+  r = KNI_GET_STATIC_FIELD(jlong, fld);
 
   END_EXCEPTION_HANDLING();
   return (r);
@@ -373,7 +368,7 @@
   jfloat r;
   BEGIN_EXCEPTION_HANDLING(0);
 
-  r = GET_STATIC_FIELD(jfloat, fld);
+  r = KNI_GET_STATIC_FIELD(jfloat, fld);
 
   END_EXCEPTION_HANDLING();
   return (r);
@@ -385,7 +380,7 @@
   jdouble r;
   BEGIN_EXCEPTION_HANDLING(0);
 
-  r = GET_STATIC_FIELD(jdouble, fld);
+  r = KNI_GET_STATIC_FIELD(jdouble, fld);
 
   END_EXCEPTION_HANDLING();
   return (r);
@@ -403,7 +398,7 @@
   BEGIN_EXCEPTION_HANDLING_VOID();
 
   val_local = unveil(val);
-  SET_STATIC_FIELD(jobject, fld, val_local);
+  KNI_SET_STATIC_FIELD(jobject, fld, val_local);
 
   END_EXCEPTION_HANDLING();
 }
@@ -413,7 +408,7 @@
 {
   BEGIN_EXCEPTION_HANDLING_VOID();
 
-  SET_STATIC_FIELD(jboolean, fld, val);
+  KNI_SET_STATIC_FIELD(jboolean, fld, val);
 
   END_EXCEPTION_HANDLING();
 }
@@ -423,7 +418,7 @@
 {
   BEGIN_EXCEPTION_HANDLING_VOID();
 
-  SET_STATIC_FIELD(jbyte, fld, val);
+  KNI_SET_STATIC_FIELD(jbyte, fld, val);
 
   END_EXCEPTION_HANDLING();
 }
@@ -433,7 +428,7 @@
 {
   BEGIN_EXCEPTION_HANDLING_VOID();
 
-  SET_STATIC_FIELD(jchar, fld, val);
+  KNI_SET_STATIC_FIELD(jchar, fld, val);
 
   END_EXCEPTION_HANDLING();
 }
@@ -443,7 +438,7 @@
 {
   BEGIN_EXCEPTION_HANDLING_VOID();
 
-  SET_STATIC_FIELD(jshort, fld, val);
+  KNI_SET_STATIC_FIELD(jshort, fld, val);
 
   END_EXCEPTION_HANDLING();
 }
@@ -453,7 +448,7 @@
 {
   BEGIN_EXCEPTION_HANDLING_VOID();
 
-  SET_STATIC_FIELD(jint, fld, val);
+  KNI_SET_STATIC_FIELD(jint, fld, val);
 
   END_EXCEPTION_HANDLING();
 }
@@ -463,7 +458,7 @@
 {
   BEGIN_EXCEPTION_HANDLING_VOID();
 
-  SET_STATIC_FIELD(jlong, fld, val);
+  KNI_SET_STATIC_FIELD(jlong, fld, val);
 
   END_EXCEPTION_HANDLING();
 }
@@ -473,7 +468,7 @@
 {
   BEGIN_EXCEPTION_HANDLING_VOID();
 
-  SET_STATIC_FIELD(jfloat, fld, val);
+  KNI_SET_STATIC_FIELD(jfloat, fld, val);
 
   END_EXCEPTION_HANDLING();
 }
@@ -483,7 +478,7 @@
 {
   BEGIN_EXCEPTION_HANDLING_VOID();
 
-  SET_STATIC_FIELD(jdouble, fld, val);
+  KNI_SET_STATIC_FIELD(jdouble, fld, val);
 
   END_EXCEPTION_HANDLING();
 }
Index: kaffe/kaffe/kaffevm/jni/jni-helpers.c
diff -u kaffe/kaffe/kaffevm/jni/jni-helpers.c:1.9 kaffe/kaffe/kaffevm/jni/jni-helpers.c:1.10
--- kaffe/kaffe/kaffevm/jni/jni-helpers.c:1.9	Thu Aug 18 22:31:32 2005
+++ kaffe/kaffe/kaffevm/jni/jni-helpers.c	Fri Dec 16 19:56:56 2005
@@ -22,61 +22,51 @@
 #include "reflect.h"
 #include "java_lang_reflect_Method.h"
 #include "java_lang_reflect_Field.h"
+#include "soft.h"
+#include "baseClasses.h"
 
-jobject KaffeJNI_NewDirectByteBuffer(JNIEnv *env, void *buffer, jlong size)
+jobject KaffeJNI_NewDirectByteBuffer(JNIEnv *env UNUSED, void *buffer, jlong size)
 {
-  jclass clazz;
-  jclass clazz_rawdata;
-  jmethodID constructor;
-  jmethodID constructor_rawdata;
   jobject bbuf;
-  jobject rawdata;
+  jobject pointer;
 
   BEGIN_EXCEPTION_HANDLING(NULL);
 
-  clazz = (*env)->FindClass(env, "java/nio/DirectByteBufferImpl$ReadWrite");
-  constructor = (*env)->GetMethodID(env, clazz, "<init>", "(Ljava/lang/Object;Lgnu/classpath/RawData;III)V");
+  /* We cannot use FindClass as it uses the loader from the stack trace and we
+   * want to use the bootstrap class loader
+   */
 #if SIZEOF_VOID_P == 4
-  clazz_rawdata = (*env)->FindClass(env, "gnu/classpath/RawData32");
-  constructor_rawdata = (*env)->GetMethodID(env, clazz_rawdata, "<init>", "(I)V");
+  pointer = execute_java_constructor(NULL, NULL, gnuClasspathPointerClass, "(I)V", (jint)buffer);
 #elif SIZEOF_VOID_P == 8
-  clazz_rawdata = (*env)->FindClass(env, "gnu/classpath/RawData64");
-  constructor_rawdata = (*env)->GetMethodID(env, clazz_rawdata, "<init>", "(L)V");
+  pointer = execute_java_constructor(NULL, NULL, gnuClasspathPointerClass, "(J)V", (jlong)buffer);
 #else
 #error "Unknown void pointer width"
 #endif
 
-  rawdata = (*env)->NewObject(env, clazz_rawdata, constructor_rawdata, buffer);
-  
-  bbuf = (*env)->NewObject(env, clazz, constructor, NULL, rawdata, (jint)size, (jint)size, (jint)0);
+  bbuf = execute_java_constructor(NULL, NULL, javaNioDirectByteBufferImplReadWriteClass, "(Ljava/lang/Object;Lgnu/classpath/Pointer;III)V",
+				  NULL, pointer, (jint)size, (jint)size, (jint)0);
 
   END_EXCEPTION_HANDLING();
 
   return bbuf;
 }
 
-void *KaffeJNI_GetDirectBufferAddress(JNIEnv *env, jobject buffer)
+void *KaffeJNI_GetDirectBufferAddress(JNIEnv *env UNUSED, jobject buffer)
 {
-  jfieldID address_field;
+  jobject address_obj;
   void *address;
-  jclass clazz;
-  jobject buffer_local;
+  Hjava_lang_Object *buffer_local;
 
   BEGIN_EXCEPTION_HANDLING(NULL);
 
-  buffer_local = unveil(buffer);
+  buffer_local = (Hjava_lang_Object *)unveil(buffer);
 
-  clazz = (*env)->FindClass(env, "java/nio/DirectByteBufferImpl");
-
-  if (!(*env)->IsInstanceOf(env, buffer_local, clazz))
+  if (!instanceof(javaNioDirectByteBufferImplClass, OBJECT_CLASS(buffer_local)))
     address = NULL;
   else
     {
-      clazz = (*env)->GetObjectClass(env, buffer_local);
-      address_field = (*env)->GetFieldID(env, clazz, "address",
-					 "Lgnu/classpath/RawData;");
-      address = (void *)((*env)->GetObjectField(env, buffer_local,
-						address_field));
+      address_obj = KNI_GET_FIELD(Hjava_lang_Object *, buffer_local, directByteBufferImplAddress);
+      address = KNI_GET_FIELD(void *, address_obj, gnuClasspathPointerAddress);
     }
 
   END_EXCEPTION_HANDLING();
Index: kaffe/kaffe/kaffevm/jni/jni_i.h
diff -u kaffe/kaffe/kaffevm/jni/jni_i.h:1.10 kaffe/kaffe/kaffevm/jni/jni_i.h:1.11
--- kaffe/kaffe/kaffevm/jni/jni_i.h:1.10	Tue Jul  5 17:35:12 2005
+++ kaffe/kaffe/kaffevm/jni/jni_i.h	Fri Dec 16 19:56:56 2005
@@ -84,5 +84,13 @@
 
 #define	END_EXCEPTION_HANDLING()			\
 	thread_data->exceptPtr = ebuf.prev
+
+
+#define	KNI_GET_FIELD(T,O,F)	*(T*)((char*)(O) + FIELD_BOFFSET((Field*)(F)))
+#define	KNI_SET_FIELD(T,O,F,V)	*(T*)((char*)(O) + FIELD_BOFFSET((Field*)(F))) = (V)
+#define	KNI_GET_STATIC_FIELD(T,F)	*(T*)FIELD_ADDRESS((Field*)F)
+#define	KNI_SET_STATIC_FIELD(T,F,V)	*(T*)FIELD_ADDRESS((Field*)F) = (V)
+
+
 #endif
 




More information about the kaffe mailing list