Patch to fix Reference/natReference.
Tom Tromey
tromey@redhat.com
Thu Aug 21 18:10:00 GMT 2003
David> If Reference.clear() is called and then the Reference is finalized
David> before its referent, a dangling pointer is created in the object_list
David> structure in natReference.cc. This happens because the 'copy' field
David> of the Reference is cleared and that is what is used to find the slot
David> in the object_list table.
Could you try the appended patch instead?
I can't try it right now, since I've got other patches in my tree
that break things all over.
This is based on the idea that we shouldn't clear `copy'. It also
removes the disappearing link registration; I think that is a leftover
from an earlier implementation where `referent' was an Object (and
thus traced by the GC). If this works I think we can remove
_Jv_GCRegisterDisappearingLink altogether.
Tom
Index: java/lang/ref/Reference.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/ref/Reference.java,v
retrieving revision 1.4
diff -u -r1.4 Reference.java
--- java/lang/ref/Reference.java 19 Nov 2002 21:59:40 -0000 1.4
+++ java/lang/ref/Reference.java 21 Aug 2003 18:05:06 -0000
@@ -1,5 +1,5 @@
/* java.lang.ref.Reference
- Copyright (C) 1999, 2002 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2002, 2003 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -85,8 +85,8 @@
* This is like REFERENT but is not scanned by the GC. We keep a
* copy around so that we can see when clear() has been called.
* GCJ LOCAL:
- * This field doesn't exist in Classpath; we use it to detect
- * clearing.
+ * This field doesn't exist in Classpath; we use it to let us clean
+ * up some internal data structures after clearing.
* END GCJ LOCAL
*/
gnu.gcj.RawData copy;
@@ -167,7 +167,6 @@
public void clear()
{
referent = null;
- copy = null;
}
/**
Index: java/lang/ref/natReference.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/ref/natReference.cc,v
retrieving revision 1.4
diff -u -r1.4 natReference.cc
--- java/lang/ref/natReference.cc 20 Aug 2003 15:30:04 -0000 1.4
+++ java/lang/ref/natReference.cc 21 Aug 2003 18:05:06 -0000
@@ -258,10 +258,16 @@
{
java::lang::ref::Reference *ref
= reinterpret_cast<java::lang::ref::Reference *> (head->reference);
- // If the copy is already NULL then the user must have
+ // If reference is already NULL then the user must have
// called Reference.clear().
- if (ref->copy != NULL)
- ref->enqueue ();
+ if (ref->referent != NULL)
+ {
+ // The JDK doesn't appear to call clear() internally,
+ // so we don't either.
+ if (w != PHANTOM)
+ ref->referent = NULL;
+ ref->enqueue ();
+ }
object_list *next = head->next;
_Jv_Free (head);
@@ -303,8 +309,6 @@
// finalizer for ourselves as well.
_Jv_RegisterFinalizer (this, finalize_reference);
_Jv_RegisterFinalizer (referent, finalize_referred_to_object);
- jobject *objp = reinterpret_cast<jobject *> (&referent);
- _Jv_GCRegisterDisappearingLink (objp);
add_to_hash (this);
}
}
More information about the Java
mailing list