wood burning stoves 2.0*
The moose likes Other JSE/JEE APIs and the fly likes 64-bit JNI C++ to JAVA invocation multiple threads classloader problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "64-bit JNI C++ to JAVA invocation multiple threads classloader problem" Watch "64-bit JNI C++ to JAVA invocation multiple threads classloader problem" New topic
Author

64-bit JNI C++ to JAVA invocation multiple threads classloader problem

triet kha
Greenhorn

Joined: Dec 15, 2009
Posts: 3
Hi ALL,

I have a C++ app that invokes Java classes on 64-bit Solaris 10 with 64-bit JVM.

Here is the problem:
The native non-main (not the thread that initializes the JVM) threads would not be able to find any user-define class and run into StackOverflowError.

Here are the symptoms and observations:
1. The "main thread" that instantiates the JVM has no problem finding and loading any class or method
2. But the other threads (non-main threads) would not be able to find the user-defined classes unless the classes were already loaded by the main thread.
3. The non-main threads can find the "standard" java classes with no problem
4. The same app ran fine on 32-bit system.
5. Except for the JVM reference is global, I already have each thread acquired JNIEnv by either GetEnv() or AttachCurrentThread().
6. JNIEnv::ExceptionDescribe() showed the following StackOverflowError:

7. Here is the sample code that reproduces the problem:

Any idea why it is a problem with 64-bit?

I really appreciate it if anyone can provide any help/suggestion.

Regards,

- Triet
triet kha
Greenhorn

Joined: Dec 15, 2009
Posts: 3
I did more testing and found that the observation regarding 32-bit was incorrect. The simple class finding program provided above ran fine in 32-bit, but when I added more complicated operations, such as doing some work with Apache JackRabbit, I would get StackOverflowError as well.
triet kha
Greenhorn

Joined: Dec 15, 2009
Posts: 3
It turned out that I made a very stupid mistake. I had only focused on tuning the Java stack size and neglected the native thread stack size which was hidden by the internal thread wrapper, which has a default 64k stack size, I used. After changing the stack size to 256k, everything ran just fine.

Thanks to those who have tried to help out. I really appreciate it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: 64-bit JNI C++ to JAVA invocation multiple threads classloader problem