JNI_GetCreatedJavaVMs() troubles...

Bryce McKinlay mckinlay@redhat.com
Mon Jun 27 18:06:00 GMT 2005


James Lee wrote:

>I have the following function in one my JNI libraries
>
>JNIEnv* GetEnv() {
>        JavaVM *jvm;
>        JNIEnv *env;
>
>        JNI_GetCreatedJavaVMs(&jvm, 1, NULL);
>        (*jvm)->AttachCurrentThread(jvm, (void**) &env, NULL);
>
>        return env;
>}
>
>to get a JNIEnv for a non-Java thread to use.  This code worked works well for
>me in blackdown-jdk 1.4, and worked well for me when I had GCJ 3.4.  I have
>since upgraded to 4.0, and my whole program locks up at the
>JNI_GetCreatedJavaVMs function call.  I'm not too sure how to debug it, but it's
>definitely not the expected behavior.  Has anyone else come across this?
>  
>

James,

It looks like GCJ's JNI_GetCreatedJavaVMs will crash if you give it a 
NULL n_vms pointer, where as Sun-derived implementations will accept this.

The patch below should fix the problem. You should also be able to work 
around it by giving it a non-NULL n_vms.

Bryce


-------------- next part --------------
A non-text attachment was scrubbed...
Name: libjava-jni-GetCreatedJavaVMs.patch
Type: text/x-patch
Size: 707 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/java/attachments/20050627/6e192338/attachment.bin>


More information about the Java mailing list