This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Re: jni fixlet
- From: Marco Trudel <mtrudel at gmx dot ch>
- To: David Daney <ddaney at avtrex dot com>
- Cc: Java Patch List <java-patches at gcc dot gnu dot org>
- Date: Thu, 01 Feb 2007 21:47:27 +0100
- Subject: Re: jni fixlet
- References: <45C24A32.8060807@gmx.ch> <45C24E56.6020605@avtrex.com>
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);