Skip to Main Content

Java HotSpot Virtual Machine

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JNI - How to use the error reporting mechanism?

843811Aug 8 2003 — edited Aug 11 2003
I've developed a C++ DLL which is loaded from a commercial Win32 application (not written by me) as a plug-in for external calculations. On its initialization the C++ DLL launches the Java VM via the JNI invocation interface. When the DLL functions are called by the application, they forward the calls to Java objects inside the Java VM, again via JNI invocation interface.

This works well, but I have encountered a weird error.
From Java I open a JFrame containing a JTextArea as small console for debug output messages. If I turn output to this debug console off (my printToConsole routine checks whether a boolean flag is set), the string concatenation operator may lead to a crash of the Java VM.

For example, if in one of the Java functions called from the
DLL via JNI invocation interface the following is the first statement,
it leads to a crash of the Java VM and the application that loaded the C++ proxy DLL.

String test=""+Math.random(); // String test not used later

Interestingly, if I comment this statement out, the Java code works fine WITHOUT any crash. I've already thought about potential races and synchronization issues in my code, but I don't see where this is the case. And the string concatenation error fails as well, if I insert sleep() statements in front of it and at other places in the code. However, if I turn on log messages printed to my JFrame debug console (containing a JTextArea), the String concatenation works without problems.

So maybe the JNI interface has a bug and affects the Java VM; I don't see where my JNI code is wrong.

One problem is that I do not get any stdout output, as the C++ proxy DLL is loaded by the Windows application, even if I start the Windows application from the DOS command line (under Windows).

Does anyone know how to use the error reporting mechanism?

http://java.sun.com/j2se/1.4.2/docs/guide/vm/error-handling.html


Is it possible that the JVM, when it crashes, writes debug information about the crash into a file instead of stdout/stderr?

My C++ proxy DLL was compiled in debug mode, but the commercial application (which loaded the DLL) is very likely not.

I do not know hot to find the reason why the String concatenation fails inside the Java function called from the C++ DLL via JNI.



Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 8 2003
Added on Aug 8 2003
3 comments
294 views