I have a fairly simple Java GUI application and I'm trying to be able to get the Windows HWND to it so I can attach a child. Basically, what I notice is that any time I use JAWT resources in my native code, it crashes. It doesn't even necessarily crash on my code and it doesn't even have to hit the JAWT code. Linking in the jawt.dll/jawt.lib seems to be enough. For example, I've seen numerous crashes in the class sun.java2d.loops.DrawGlyphListLCD.DrawGlyphListLCD(Lsun/java2d/SunGraphics2D;Lsun/java2d/SurfaceData;Lsun/font/GlyphList;)V+0 in Java's fontmanager.dll when my Swing GUI is being rendered. Full hs_err_pid9108.log available here: http://pastebin.com/2QS0fDuf
Some interesting notes:
If I switch my JRE to Java 1.6.0_33 instead of Java 1.7.0_05, the application no longer crashes
If I remove all references to JAWT in my native code, the application no longer crashes
If I remove all my business logic and do nothing but instantiate JAWT in my native code, it still crashes
I don't even actually have to make a native call in my code. Loading the DLL linked to jawt.lib via System.load(...) is enough. My application will still crash while rendering its GUI (with JRE 7).
I've distilled the code down as much as I can to an example that will still fail. Here's the Java class:
public class JawtTestApp
private final JFrame frame;
frame = new JFrame();
frame.getContentPane().add(new JLabel("Please stop crashing!"));
public native void testJawt(Object o);
public static void main(final String args)
System.load("C:\\Users\\brenash\\Documents\\Visual Studio 2005\\Projects\\JawtTestApp\\debug\\JawtTestApp.dll");
JawtTestApp app = new JawtTestApp();
//NOTE: I don't actually even have to call the native method! System.load is enough
Keep in mind you'll have to include JDK/include and JDK/include/win32 when you compile and JDK/lib/jawt.lib when you link.
I'm still working on testing across platforms, JDKs, etc., but based on this information, does anyone have any ideas? Is there a magical compiler flag I'm missing? Is there a Java patch? I'm running out of ideas here.
Here's my system info:
OS: Windows 7 , 64 bit Build 7601 Service Pack 1
CPU:total 4 (2 cores per cpu, 2 threads per core) family 6 model 37 stepping 2, cmov, cx8, fxsr, mmx, sse, sse2, sse3, ssse3, sse4.1, sse4.2, popcnt, ht, tsc, tscinvbit
I've changed that particular field to awt.version = JAWT_VERSION_1_7; to see if it makes a difference, but it doesn't seem to. The problem is that in my example, I never even call that native function, so that code never executes. The crash seems to occur somewhere in the bowels of the graphics drawing code for Swing; not in my code at all.
It's curious that awt.dll is loaded twice, once via the JDK and once via the JRE, and that jawt.dll is loaded from the JRE not the JDK. It's also curious that your own DLL doesn't show up as being loaded at all. I would adjust your PATH so that the JDK comes first.