We record the class loader reference in jni_object structure.
It may be used in the future to load classes requested
from JNI code originating from particular object.

This fixes the following error for HelloWorldSwing:
vm/jato.c:389: warning: native_vmruntime_native_load not implemented
vm/jato.c:389: warning: native_vmruntime_native_load not implemented
Exception in thread "main" java.awt.AWTError: Cannot load AWT toolkit: 
gnu.java.awt.peer.gtk.GtkToolkit
   at java.awt.Toolkit.getDefaultToolkit(Toolkit.java:607)
   at java.awt.EventQueue.invokeLater(EventQueue.java:444)
   at javax.swing.SwingUtilities.invokeLater(SwingUtilities.java:1079)
   at HelloWorldSwing.main(HelloWorldSwing.java:74)
Caused by: java.lang.ClassNotFoundException: gnu.java.awt.peer.gtk.GtkToolkit
   at java.lang.VMClass.forName(Native Method)
   at java.lang.Class.forName(Class.java:233)
   at java.awt.Toolkit.getDefaultToolkit(Toolkit.java:583)
   ...3 more

Signed-off-by: Tomek Grabiec <tgrab...@gmail.com>
---
 include/vm/jni.h |    2 +-
 vm/jato.c        |    7 +------
 vm/jni.c         |    8 +++++---
 3 files changed, 7 insertions(+), 10 deletions(-)

diff --git a/include/vm/jni.h b/include/vm/jni.h
index 4dd8b1c..6d0d060 100644
--- a/include/vm/jni.h
+++ b/include/vm/jni.h
@@ -74,7 +74,7 @@ void vm_jni_init(void);
 void vm_jni_init_interface(void);
 struct vm_jni_env *vm_jni_get_jni_env(void);
 struct java_vm *vm_jni_get_current_java_vm(void);
-int vm_jni_load_object(const char *name);
+int vm_jni_load_object(const char *name, struct vm_object *classloader);
 void *vm_jni_lookup_method(const char *class_name, const char *method_name,
                           const char *method_type);
 bool vm_jni_check_trap(void *ptr);
diff --git a/vm/jato.c b/vm/jato.c
index b485cff..b3ca8d0 100644
--- a/vm/jato.c
+++ b/vm/jato.c
@@ -385,11 +385,6 @@ native_vmruntime_native_load(struct vm_object *name,
        char *name_str;
        int result;
 
-       if (classloader != NULL) {
-               NOT_IMPLEMENTED;
-               return 0;
-       }
-
        if (!name) {
                signal_new_exception(vm_java_lang_NullPointerException, NULL);
                return 0;
@@ -401,7 +396,7 @@ native_vmruntime_native_load(struct vm_object *name,
                return 0;
        }
 
-       result  = vm_jni_load_object(name_str);
+       result  = vm_jni_load_object(name_str, classloader);
        free(name_str);
 
        return result == 0;
diff --git a/vm/jni.c b/vm/jni.c
index 38e7e62..8ff15d8 100644
--- a/vm/jni.c
+++ b/vm/jni.c
@@ -42,6 +42,7 @@
 
 struct jni_object {
        void *handle; /* returned by dlopen() */
+       struct vm_object *classloader;
 };
 
 static unsigned long jni_object_hash(const void *key, unsigned long size)
@@ -102,7 +103,7 @@ static char *vm_jni_get_mangled_name(const char *name)
        return result;
 }
 
-static int vm_jni_add_object(void *handle)
+static int vm_jni_add_object(void *handle, struct vm_object *classloader)
 {
        struct jni_object *object;
 
@@ -114,6 +115,7 @@ static int vm_jni_add_object(void *handle)
                return -ENOMEM;
 
        object->handle = handle;
+       object->classloader = classloader;
 
        if (hash_map_put(jni_objects, handle, object)) {
                free(object);
@@ -134,7 +136,7 @@ void vm_jni_init(void)
 
 typedef jint onload_fn(JavaVM *, void *);
 
-int vm_jni_load_object(const char *name)
+int vm_jni_load_object(const char *name, struct vm_object *classloader)
 {
        void *handle;
 
@@ -142,7 +144,7 @@ int vm_jni_load_object(const char *name)
        if (!handle)
                return -1;
 
-       if (vm_jni_add_object(handle)) {
+       if (vm_jni_add_object(handle, classloader)) {
                dlclose(handle);
                return -ENOMEM;
        }
-- 
1.6.0.6


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Jatovm-devel mailing list
Jatovm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jatovm-devel

Reply via email to