classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] Bug in java_nio_VMDirectByteBuffer.c


From: Archie Cobbs
Subject: [cp-patches] Bug in java_nio_VMDirectByteBuffer.c
Date: Tue, 15 Mar 2005 22:25:50 -0600
User-agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.7.3) Gecko/20041129

There is a bug in java_nio_VMDirectByteBuffer.c in the function
Java_java_nio_VMDirectByteBuffer_init().

This function sets "classRawData", which is a static variable of type
jclass, from the result of calling (*env)->FindClass(), and then returns,
and then other JNI functions try to use this variable from within different
JNI invocations.

This is broken because the local native reference that was created by
(*env)->FindClass() goes away when Java_java_nio_VMDirectByteBuffer_init()
returns (not to mention that it could be used from a different thread).

The solution is to put a global native reference around "classRawData".
This fixes the problem for me. I'll commit the attached patch unless
there are issues.

2005-03-15  Archie Cobbs  <address@hidden>

        * native/jni/java-nio/java_nio_VMDirectByteBuffer.c: use
        global native reference to wrap persistent jclass variable.

-Archie

__________________________________________________________________________
Archie Cobbs      *        CTO, Awarix        *      http://www.awarix.com
Index: native/jni/java-nio/java_nio_VMDirectByteBuffer.c
===================================================================
RCS file: 
/cvsroot/classpath/classpath/native/jni/java-nio/java_nio_VMDirectByteBuffer.c,v
retrieving revision 1.2
diff -u -r1.2 java_nio_VMDirectByteBuffer.c
--- native/jni/java-nio/java_nio_VMDirectByteBuffer.c   8 Feb 2005 19:13:03 
-0000       1.2
+++ native/jni/java-nio/java_nio_VMDirectByteBuffer.c   16 Mar 2005 04:24:54 
-0000
@@ -135,6 +135,14 @@
 #else
 #error unsupported pointer size
 #endif
+
+  /* We need to wrap the jclass in global reference to make it persistent */
+  if ((classRawData = (*env)->NewGlobalRef(env, classRawData)) == NULL)
+    {
+      JCL_ThrowException(env, "java/lang/InternalError",
+                             "failed to create global reference");
+      return;
+    }
 }
 
 JNIEXPORT jobject JNICALL

reply via email to

[Prev in Thread] Current Thread [Next in Thread]