This is the mail archive of the java-patches@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 fixlet


David Daney wrote:
Marco Trudel wrote:
Attached a jni fixlet.


2007-02-01 Marco Trudel <mtrudel@gmx.ch>


* jni.cc (_Jv_JNI_DeleteWeakGlobalRef): Check for NULL objects.


Question? Comments?

What was the undesirable behavior you observed that this patch fixes?

A compiled application crashed with "Aborted". A native lib called "_Jv_JNI_DeleteWeakGlobalRef" with a null obj what in the end causes a segmentation fault in unmark_for_gc:
jint val = refcount->intValue() - 1; (refcount null)



How did you test it?

I played a little with gdb, saw the segfault, added a check, compiled my app again and was happy that it worked.
Ah, and I then ran the library I use which does this null call in a Sun JVM to ensure that there _Jv_JNI_DeleteWeakGlobalRef is also called with NULL. It is...



Attached the version with the comment on the second line.



Marco
Index: jni.cc
===================================================================
--- jni.cc	(revision 121467)
+++ jni.cc	(working copy)
@@ -1750,6 +1750,9 @@
 void JNICALL
 _Jv_JNI_DeleteWeakGlobalRef (JNIEnv *, jweak obj)
 {
+  if(obj == NULL)
+    return; // behaviour of a Sun JVM
+
   using namespace gnu::gcj::runtime;
   JNIWeakRef *ref = reinterpret_cast<JNIWeakRef *> (obj);
   unmark_for_gc (ref, global_ref_table);

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