This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Re: JNI_GetCreatedJavaVMs() troubles...
- From: Bryce McKinlay <mckinlay at redhat dot com>
- To: James Lee <jlee23 at umbc dot edu>
- Cc: java at gcc dot gnu dot org
- Date: Mon, 27 Jun 2005 14:06:53 -0400
- Subject: Re: JNI_GetCreatedJavaVMs() troubles...
- References: <loom.20050626T014457-427@post.gmane.org>
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
2005-06-27 Bryce McKinlay <mckinlay@redhat.com>
* jni.cc (JNI_GetCreatedJavaVMs): Check for NULL n_vms before setting
it.
Index: jni.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/jni.cc,v
retrieving revision 1.99
diff -u -r1.99 jni.cc
--- jni.cc 13 Jun 2005 20:23:11 -0000 1.99
+++ jni.cc 27 Jun 2005 18:02:30 -0000
@@ -2529,15 +2529,17 @@
{
if (buf_len <= 0)
return JNI_ERR;
+ jsize vm_count = 0;
// We only support a single VM.
if (the_vm != NULL)
{
vm_buffer[0] = the_vm;
- *n_vms = 1;
+ vm_count = 1;
}
- else
- *n_vms = 0;
+
+ if (n_vms != NULL)
+ *n_vms = vm_count;
return 0;
}