GNOME Bugzilla – Bug 321553
Having a swing component instance in a JG application which uses org.gnu.glib.CustomEvents crashes the (sun) jvm
Last modified: 2009-08-15 18:40:50 UTC
Steps to reproduce: By uncommenting the line containing JPanel - the jvm will crash. Java VM: Java HotSpot(TM) Client VM (1.5.0_04-b05 mixed mode, sharing) import javax.swing.JPanel; import org.gnu.glib.CustomEvents; import org.gnu.gtk.Gtk; import org.gnu.gtk.Window; public class CustomEventTest { public static void main(String[] args) { //JPanel panel = new JPanel(); Thread t = new Thread(new Runnable() { public void run() { Gtk.init(null); Gtk.main(); } }); t.start(); CustomEvents.addEvent(new Runnable() { public void run() { Window w = new Window(); w.showAll(); } }); } } Stack trace: Stack: [0xb1a32000,0xb1ab2000), sp=0xb1ab0b70, free space=506k Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code) C [libjava.so+0x118ac] JNU_GetEnv+0x1c C [libgtkjni-2.8.so+0x80086] function+0x16 C [libgtkjni-2.8.so+0x8011d] dispatch+0xd C [libglib-2.0.so.0+0x23a61] g_main_context_dispatch+0x211 C [libglib-2.0.so.0+0x26cb7] C [libglib-2.0.so.0+0x27208] g_main_loop_run+0x1a8 C [libgtk-x11-2.0.so.0+0x12d019] gtk_main+0xb9 C [libgtkjni-2.8.so+0x8f996] Java_org_gnu_gtk_Gtk_gtk_1main+0x16 j org.gnu.gtk.Gtk.gtk_main()V+0 j org.gnu.gtk.Gtk.main()V+6 j CustomEventTest$1.run()V+4 j java.lang.Thread.run()V+11 v ~StubRoutines::call_stub V [libjvm.so+0x16bf8c] V [libjvm.so+0x25e5f8] V [libjvm.so+0x16b7e5] V [libjvm.so+0x16b87e] V [libjvm.so+0x1d0fd5] V [libjvm.so+0x2b76d3] V [libjvm.so+0x25f108] C [libpthread.so.0+0x51ee] Java frames: (J=compiled Java code, j=interpreted, Vv=VM code) j org.gnu.gtk.Gtk.gtk_main()V+0 j org.gnu.gtk.Gtk.main()V+6 j CustomEventTest$1.run()V+4 j java.lang.Thread.run()V+11 v ~StubRoutines::call_stub Other information: The crash happens in JNU_GetEnv. Most probably cached_jvm is null when we have a swing component - but this need to be checked. Note - the above code works fine with gij: java version "1.4.2" gij (GNU libgcj) version 4.0.3 20051023 (prerelease) (Ubuntu 4.0.2-3ubuntu1)
The problem lied in the fact that both the sun jvm and both jg-common provided JNU_GetEnv with different implementation. Sun jvm ended up calling its own JNU_GetEnv when it should have been call the jg-common version. Fixed by renaming JNU_GetEnv to JG_JNU_GetEnv.
Created attachment 54838 [details] [review] rename JNU_GetEnv to JG_JNU_GetEnv. patch against jg-common.
Created attachment 54839 [details] [review] rename JNU_GetEnv to JG_JNU_GetEnv. patch against libgtk-java.
Thanks for the patch. Applied to CVS HEAD.