* src/native/jni.cpp (GetObjectClass): Remove null pointer check.
[cacao.git] / src / native / jni.cpp
index 6e850fd2bac0db539175b06ad3fe7c06ea6b6b8a..bf1401a65938524be30623e3d156548fbdf9a221 100644 (file)
@@ -1,6 +1,6 @@
 /* src/native/jni.cpp - implementation of the Java Native Interface functions
 
-   Copyright (C) 1996-2005, 2006, 2007, 2008, 2009
+   Copyright (C) 1996-2012
    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
 
    This file is part of CACAO.
@@ -881,8 +881,31 @@ jclass jni_FindClass(JNIEnv *env, const char *name)
 
        if (cc == NULL)
                c = load_class_from_sysloader(u);
-       else
-               c = load_class_from_classloader(u, cc->classloader);
+       else {
+               classloader_t *cl = cc->classloader;
+#if defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
+               /* See jni_FindClass in Hotspot's src/share/vm/prims/jni.cpp */
+               if (!cl && cc->name == utf_java_lang_ClassLoader_NativeLibrary)
+               {
+                       methodinfo *m = class_resolveclassmethod(
+                               cc,
+                               utf_new_char("getFromClass"),
+                               utf_new_char("()Ljava/lang/Class;"),
+                               NULL,
+                               true);
+
+                       java_handle_t *h;
+                       if (m)
+                               h = vm_call_method(m, NULL);
+
+                       if (m && exceptions_get_exception() == NULL)
+                               cl = ((classinfo *) LLNI_UNWRAP(h))->classloader;
+                       else
+                               return NULL;
+               }
+#endif
+               c = load_class_from_classloader(u, cl);
+       }
 
        if (c == NULL) {
                resolve_handle_pending_exception(true);
@@ -1402,9 +1425,6 @@ jclass jni_GetObjectClass(JNIEnv *env, jobject obj)
 
        o = (java_handle_t *) obj;
 
-       if ((o == NULL) || (LLNI_vftbl_direct(o) == NULL))
-               return NULL;
-
        LLNI_class_get(o, c);
 
        java_handle_t* h = LLNI_classinfo_wrap(c);
@@ -3565,7 +3585,8 @@ void* jni_GetDirectBufferAddress(JNIEnv *env, jobject buf)
 
 jlong jni_GetDirectBufferCapacity(JNIEnv* env, jobject buf)
 {
-#if defined(ENABLE_JAVASE) && defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
+#if defined(ENABLE_JAVASE)
+# if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
        TRACEJNICALLS(("jni_GetDirectBufferCapacity(env=%p, buf=%p)", env, buf));
 
        java_handle_t* h = (java_handle_t *) buf;
@@ -3577,6 +3598,23 @@ jlong jni_GetDirectBufferCapacity(JNIEnv* env, jobject buf)
        jlong capacity = b.get_cap();
 
        return capacity;
+# elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
+
+       TRACEJNICALLS(("jni_GetDirectBufferCapacity(env=%p, buf=%p)", env, buf));
+
+       java_nio_Buffer jnb(buf);
+
+       if (!builtin_instanceof(jnb.get_handle(), class_sun_nio_ch_DirectBuffer))
+               return -1;
+
+       jlong capacity = jnb.get_capacity();
+
+       return capacity;
+
+# else
+#  error unknown classpath configuration
+# endif
+
 #else
        vm_abort("jni_GetDirectBufferCapacity: not implemented in this configuration");