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 Invocation issues (Threading)

843829Mar 18 2009 — edited Mar 31 2009
We have a native application from which we invoke the JVM. We then instantiate a class and constantly call methods on it, during the whole runtime of the application. The Java class we call the methods on, works ok as long as it is really simple (eg: doing only internal calculations and callbacks to our native application). Problems start to arise when we use eg Swing. My guess is, that it has to do with multi threading, but i can not really see how i should find out more about it.

The problem:
sometimes after a few hundred, and sometimes only after 1 or 2 thousand calls from native to java, we get a SIGSEGV, about 10 to 15 stack frames into the jvm, on a call to (*env)->CallIntMethod(...). When using less Swing stuff in Java, the SIGSEGVs get less frequent. Also to mention: I debug in GDB, and when continuing after one of these SIGSEGVs, the application, including the JVM and all our java code continues to run wihtout a problem.

The same thing happens on two different machines, one with windows, the other with linux, and both operated by different people, so it must be a problem wiht the design of our code, not the system.
After reading through various sources on the net, i made sure to not store the JNIEnv in a global variable, and i reattachThread before i call the Java methods by JNI, plus i checked through the code to see that local/global references are treadet as they should (though, that part is not 100% water proof). I am pretty sure that the calls by JNI are always correct, as they work well most of the time wiht java, and alwyas when we send the same arguments to native code (none are NULL eg).

The whole application is quite complex, and it would be a lot of work to generate something simpler that coudl reproduce the problem, i think. so i do not expect you to test the code or something. i just though you could probably give me hints on what could be causing these problems.

i also did this:
	public int ourJavaMethod(int x) {

		try {
			<here we do things>
		} catch (Throwable t) {
			log.log(Level.SEVERE, "error!", t);
		}

		return 0;
	}
but error is never logged.
also, CheckException(...) returns false, even after the calls that cause a SIGSEGV.

i am tired now, so sorry if i gave to vague info. please tell me what more you had to know.

JDK 1.6.0_10
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 28 2009
Added on Mar 18 2009
13 comments
939 views