We should execute JNI_OnLoad function from library that is being
loaded. This bug was causing the following error to appear on 'jato
-jar frozenBubble.jar':

ERROR:gnu_java_awt_peer_gtk_GtkImage.c:409:setWidthHeight: assertion failed: 
(field != 0)

Signed-off-by: Tomek Grabiec <tgrab...@gmail.com>
---
 include/vm/jni.h |    1 +
 vm/jni.c         |   14 ++++++++++++++
 vm/stack-trace.c |   10 ++++++++++
 3 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/include/vm/jni.h b/include/vm/jni.h
index 5512b26..ccebf9f 100644
--- a/include/vm/jni.h
+++ b/include/vm/jni.h
@@ -72,6 +72,7 @@ typedef struct java_vm JavaVM;
 
 void vm_jni_init(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);
 void *vm_jni_lookup_method(const char *class_name, const char *method_name,
                           const char *method_type);
diff --git a/vm/jni.c b/vm/jni.c
index ff6780f..a864610 100644
--- a/vm/jni.c
+++ b/vm/jni.c
@@ -35,6 +35,7 @@
 
 #include "vm/die.h"
 #include "vm/jni.h"
+#include "vm/stack-trace.h"
 
 #include "lib/string.h"
 
@@ -109,6 +110,8 @@ static int vm_jni_add_object_handle(void *handle)
        return 0;
 }
 
+typedef jint onload_fn(JavaVM *, void *);
+
 int vm_jni_load_object(const char *name)
 {
        void *handle;
@@ -122,6 +125,17 @@ int vm_jni_load_object(const char *name)
                return -ENOMEM;
        }
 
+       onload_fn *onload = dlsym(handle, "JNI_OnLoad");
+       if (!onload)
+               return 0;
+
+       vm_enter_jni(__builtin_frame_address(0), NULL,
+                    (unsigned long) &&call_site);
+ call_site:
+
+       onload(vm_jni_get_current_java_vm(), NULL);
+       vm_leave_jni();
+
        return 0;
 }
 
diff --git a/vm/stack-trace.c b/vm/stack-trace.c
index fc5be9a..cd28274 100644
--- a/vm/stack-trace.c
+++ b/vm/stack-trace.c
@@ -187,6 +187,16 @@ int stack_trace_elem_next(struct stack_trace_elem *elem)
                        &jni_stack[elem->jni_stack_index];
 
                if (tr->vm_frame == elem->frame) {
+                       if (!tr->method) {
+                               /* This happens for JNI_OnLoad invocations */
+                               elem->type = STACK_TRACE_ELEM_TYPE_OTHER;
+                               elem->is_native = true;
+
+                               elem->addr  = tr->return_address;
+                               elem->frame = tr->caller_frame;
+                               return 0;
+                       }
+
                        elem->type = STACK_TRACE_ELEM_TYPE_JNI;
                        elem->is_native = false;
 
-- 
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