* src/native/jni.c (native/include/java_lang_Byte.h,
authorChristian Thalinger <twisti@complang.tuwien.ac.at>
Thu, 30 Aug 2007 14:21:15 +0000 (16:21 +0200)
committerChristian Thalinger <twisti@complang.tuwien.ac.at>
Thu, 30 Aug 2007 14:21:15 +0000 (16:21 +0200)
native/include/java_lang_Character.h,
native/include/java_lang_Short.h,
native/include/java_lang_Integer.h,
native/include/java_lang_Boolean.h,
native/include/java_lang_Long.h,
native/include/java_lang_Float.h,
native/include/java_lang_Double.h): Removed.
[WITH_CLASSPATH_SUN] (class_sun_nio_ch_DirectBuffer)
(class_java_nio_DirectByteBuffer, dbb_init): Added.
(jni_init) [WITH_CLASSPATH_SUN]: Added direct-buffer stuff.
(_Jv_JNI_ExceptionOccurred): Added TRACEJNICALLS.
(_Jv_JNI_ToReflectedMethod): Likewise.
(_Jv_JNI_GetStaticMethodID): Likewise.
(_Jv_JNI_DestroyJavaVM): Likewise.
(_Jv_JNI_ExceptionDescribe): Fixed bug.
(_Jv_JNI_NewDirectByteBuffer) [WITH_CLASSPATH_SUN]: Implemented.
(_Jv_JNI_GetDirectBufferAddress): Likewise.

src/native/jni.c

index 6edb14164f973c356d56835947a3edb99ae2a1a1..9f4ae3e1e500495ec2e238e0ee478c45fc52eb83 100644 (file)
 #endif
 
 #include "native/include/java_lang_Object.h"
-#include "native/include/java_lang_Byte.h"
-#include "native/include/java_lang_Character.h"
-#include "native/include/java_lang_Short.h"
-#include "native/include/java_lang_Integer.h"
-#include "native/include/java_lang_Boolean.h"
-#include "native/include/java_lang_Long.h"
-#include "native/include/java_lang_Float.h"
-#include "native/include/java_lang_Double.h"
 #include "native/include/java_lang_String.h"
 #include "native/include/java_lang_Throwable.h"
 
@@ -146,18 +138,28 @@ static hashtable *hashtable_global_ref; /* hashtable for globalrefs           */
 
 #if defined(ENABLE_JAVASE)
 static classinfo *class_java_nio_Buffer;
+
+# if defined(WITH_CLASSPATH_GNU)
+
 static classinfo *class_java_nio_DirectByteBufferImpl;
 static classinfo *class_java_nio_DirectByteBufferImpl_ReadWrite;
 
-# if defined(WITH_CLASSPATH_GNU)
 #  if SIZEOF_VOID_P == 8
 static classinfo *class_gnu_classpath_Pointer64;
 #  else
 static classinfo *class_gnu_classpath_Pointer32;
 #  endif
-# endif
 
 static methodinfo *dbbirw_init;
+
+# elif defined(WITH_CLASSPATH_SUN)
+
+static classinfo *class_sun_nio_ch_DirectBuffer;
+static classinfo *class_java_nio_DirectByteBuffer;
+
+static methodinfo *dbb_init;
+
+# endif
 #endif
 
 
@@ -192,7 +194,7 @@ bool jni_init(void)
 
 
 #if defined(ENABLE_JAVASE)
-       /* direct buffer stuff */
+       /* Direct buffer stuff. */
 
        if (!(class_java_nio_Buffer =
                  load_class_bootstrap(utf_new_char("java/nio/Buffer"))) ||
@@ -200,6 +202,7 @@ bool jni_init(void)
                return false;
 
 # if defined(WITH_CLASSPATH_GNU)
+
        if (!(class_java_nio_DirectByteBufferImpl =
                  load_class_bootstrap(utf_new_char("java/nio/DirectByteBufferImpl"))) ||
                !link_class(class_java_nio_DirectByteBufferImpl))
@@ -227,7 +230,31 @@ bool jni_init(void)
                !link_class(class_gnu_classpath_Pointer32))
                return false;
 #  endif
+
+# elif defined(WITH_CLASSPATH_SUN)
+
+       if (!(class_sun_nio_ch_DirectBuffer =
+                 load_class_bootstrap(utf_new_char("sun/nio/ch/DirectBuffer"))))
+               vm_abort("jni_init: loading sun/nio/ch/DirectBuffer failed");
+
+       if (!link_class(class_sun_nio_ch_DirectBuffer))
+               vm_abort("jni_init: linking sun/nio/ch/DirectBuffer failed");
+
+       if (!(class_java_nio_DirectByteBuffer =
+                 load_class_bootstrap(utf_new_char("java/nio/DirectByteBuffer"))))
+               vm_abort("jni_init: loading java/nio/DirectByteBuffer failed");
+
+       if (!link_class(class_java_nio_DirectByteBuffer))
+               vm_abort("jni_init: linking java/nio/DirectByteBuffer failed");
+
+       if (!(dbb_init =
+                 class_resolvemethod(class_java_nio_DirectByteBuffer,
+                                                         utf_init,
+                                                         utf_new_char("(JI)V"))))
+               vm_abort("jni_init: resolving java/nio/DirectByteBuffer.init(JI)V failed");
+
 # endif
+
 #endif /* defined(ENABLE_JAVASE) */
 
        return true;
@@ -1123,7 +1150,7 @@ jthrowable _Jv_JNI_ExceptionOccurred(JNIEnv *env)
 {
        java_handle_t *o;
 
-       STATISTICS(jniinvokation());
+       TRACEJNICALLS("_Jv_JNI_ExceptionOccurred(env=%p)", env);
 
        o = exceptions_get_exception();
 
@@ -1144,16 +1171,15 @@ void _Jv_JNI_ExceptionDescribe(JNIEnv *env)
        java_handle_t *o;
        methodinfo    *m;
 
-       STATISTICS(jniinvokation());
+       TRACEJNICALLS("_Jv_JNI_ExceptionDescribe(env=%p)", env);
 
-       o = exceptions_get_exception();
+       /* Clear exception, because we are probably calling Java code
+          again. */
 
-       if (o == NULL) {
-               /* clear exception, because we are calling jit code again */
+       o = exceptions_get_and_clear_exception();
 
-               exceptions_clear_exception();
-
-               /* get printStackTrace method from exception class */
+       if (o != NULL) {
+               /* Get printStackTrace method from exception class. */
 
                m = class_resolveclassmethod(o->vftbl->class,
                                                                         utf_printStackTrace,
@@ -1162,10 +1188,9 @@ void _Jv_JNI_ExceptionDescribe(JNIEnv *env)
                                                                         true);
 
                if (m == NULL)
-                       /* XXX what should we do? */
-                       return;
+                       vm_abort("_Jv_JNI_ExceptionDescribe: could not find printStackTrace");
 
-               /* print the stacktrace */
+               /* Print the stacktrace. */
 
                (void) vm_call_method(m, o);
        }
@@ -1679,7 +1704,7 @@ jobject _Jv_JNI_ToReflectedMethod(JNIEnv* env, jclass cls, jmethodID methodID,
        java_lang_reflect_Constructor *rc;
        java_lang_reflect_Method      *rm;
 
-       STATISTICS(jniinvokation());
+       TRACEJNICALLS("_Jv_JNI_ToReflectedMethod(env=%p, cls=%p, methodID=%p, isStatic=%d)", env, cls, methodID, isStatic);
 
        m = (methodinfo *) methodID;
 
@@ -2268,11 +2293,11 @@ jmethodID _Jv_JNI_GetStaticMethodID(JNIEnv *env, jclass clazz, const char *name,
        utf        *udesc;
        methodinfo *m;
 
-       STATISTICS(jniinvokation());
+       TRACEJNICALLS("_Jv_JNI_GetStaticMethodID(env=%p, clazz=%p, name=%s, sig=%s)", env, clazz, name, sig);
 
        c = LLNI_classinfo_unwrap(clazz);
 
-       if (!c)
+       if (c == NULL)
                return NULL;
 
        if (!(c->state & CLASS_INITIALIZED))
@@ -3555,7 +3580,8 @@ jboolean _Jv_JNI_ExceptionCheck(JNIEnv *env)
 
 jobject _Jv_JNI_NewDirectByteBuffer(JNIEnv *env, void *address, jlong capacity)
 {
-#if defined(ENABLE_JAVASE) && defined(WITH_CLASSPATH_GNU)
+#if defined(ENABLE_JAVASE)
+# if defined(WITH_CLASSPATH_GNU)
        java_handle_t           *nbuf;
 
 # if SIZEOF_VOID_P == 8
@@ -3564,7 +3590,7 @@ jobject _Jv_JNI_NewDirectByteBuffer(JNIEnv *env, void *address, jlong capacity)
        gnu_classpath_Pointer32 *paddress;
 # endif
 
-       STATISTICS(jniinvokation());
+       TRACEJNICALLS("_Jv_JNI_NewDirectByteBuffer(env=%p, address=%p, capacity=%ld", env, address, capacity);
 
        /* alocate a gnu.classpath.Pointer{32,64} object */
 
@@ -3590,6 +3616,31 @@ jobject _Jv_JNI_NewDirectByteBuffer(JNIEnv *env, void *address, jlong capacity)
        /* add local reference and return the value */
 
        return _Jv_JNI_NewLocalRef(env, nbuf);
+
+# elif defined(WITH_CLASSPATH_SUN)
+
+       jobject o;
+       int64_t addr;
+       int32_t cap;
+
+       TRACEJNICALLS("_Jv_JNI_NewDirectByteBuffer(env=%p, address=%p, capacity=%ld", env, address, capacity);
+
+       /* Be paranoid about address sign-extension. */
+
+       addr = (int64_t) ((uintptr_t) address);
+       cap  = (int32_t) capacity;
+
+       o = (*env)->NewObject(env, (jclass) class_java_nio_DirectByteBuffer,
+                                                 (jmethodID) dbb_init, addr, cap);
+
+       /* Add local reference and return the value. */
+
+       return _Jv_JNI_NewLocalRef(env, o);
+
+# else
+#  error unknown classpath configuration
+# endif
+
 #else
        vm_abort("_Jv_JNI_NewDirectByteBuffer: not implemented in this configuration");
 
@@ -3609,29 +3660,31 @@ jobject _Jv_JNI_NewDirectByteBuffer(JNIEnv *env, void *address, jlong capacity)
 
 void *_Jv_JNI_GetDirectBufferAddress(JNIEnv *env, jobject buf)
 {
-#if defined(ENABLE_JAVASE) && defined(WITH_CLASSPATH_GNU)
+#if defined(ENABLE_JAVASE)
+# if defined(WITH_CLASSPATH_GNU)
+
        java_nio_DirectByteBufferImpl *nbuf;
-# if SIZEOF_VOID_P == 8
+#  if SIZEOF_VOID_P == 8
        gnu_classpath_Pointer64       *paddress;
-# else
+#  else
        gnu_classpath_Pointer32       *paddress;
-# endif
+#  endif
        void                          *address;
 
-       STATISTICS(jniinvokation());
+       TRACEJNICALLS("_Jv_JNI_GetDirectBufferAddress(env=%p, buf=%p)", env, buf);
 
-       if (!builtin_instanceof(buf, class_java_nio_Buffer))
+       if ((buf != NULL) && !builtin_instanceof(buf, class_java_nio_Buffer))
                return NULL;
 
        nbuf = (java_nio_DirectByteBufferImpl *) buf;
 
-# if SIZEOF_VOID_P == 8
+#  if SIZEOF_VOID_P == 8
        LLNI_field_get_ref(nbuf, address, paddress);
        /* this was the cast to avaoid warning: (gnu_classpath_Pointer64 *) nbuf->address; */
-# else
+#  else
        LLNI_field_get_ref(nbuf, address, paddress); 
        /* this was the cast to avaoid warning: (gnu_classpath_Pointer32 *) nbuf->address; */
-# endif
+#  endif
 
        if (paddress == NULL)
                return NULL;
@@ -3640,12 +3693,38 @@ void *_Jv_JNI_GetDirectBufferAddress(JNIEnv *env, jobject buf)
        /* this was the cast to avaoid warning: (void *) paddress->data */
 
        return address;
+
+# elif defined(WITH_CLASSPATH_SUN)
+
+       java_nio_Buffer *o;
+       int64_t          address;
+       void            *p;
+
+       TRACEJNICALLS("_Jv_JNI_GetDirectBufferAddress(env=%p, buf=%p)", env, buf);
+
+       if ((buf != NULL) && !builtin_instanceof(buf, class_sun_nio_ch_DirectBuffer))
+               return NULL;
+
+       o = (java_nio_Buffer *) buf;
+
+       LLNI_field_get_val(o, address, address);
+
+       p = (void *) (intptr_t) address;
+
+       return p;
+
+# else
+#  error unknown classpath configuration
+# endif
+
 #else
+
        vm_abort("_Jv_JNI_GetDirectBufferAddress: not implemented in this configuration");
 
        /* keep compiler happy */
 
        return NULL;
+
 #endif
 }
 
@@ -3712,9 +3791,9 @@ jobjectRefType jni_GetObjectRefType(JNIEnv *env, jobject obj)
 
 jint _Jv_JNI_DestroyJavaVM(JavaVM *vm)
 {
-       s4 status;
+       int32_t status;
 
-       STATISTICS(jniinvokation());
+       TRACEJNICALLS("_Jv_JNI_DestroyJavaVM(vm=%p)", vm);
 
     status = vm_destroy(vm);