This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: JNI_GetCreatedJavaVMs() troubles...


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;
 }
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]