Commit c9a61d5a by David Daney Committed by Tom Tromey

re PR libgcj/12013 (Calling Reference.clear() can cause runtime to crash.)

2003-08-21  David Daney  <ddaney@avtrex.com>

	Fix for PR libgcj/12013:
	* java/lang/ref/natReference.cc (finalize_referred_to_object):
	Check `cleared' field.
	* java/lang/ref/Reference.java (copy): Updated comments.
	(cleared): New field.
	(clear): Rewrote.

From-SVN: r70668
parent aa779cf3
2003-08-21 David Daney <ddaney@avtrex.com>
Fix for PR libgcj/12013:
* java/lang/ref/natReference.cc (finalize_referred_to_object):
Check `cleared' field.
* java/lang/ref/Reference.java (copy): Updated comments.
(cleared): New field.
(clear): Rewrote.
2003-08-21 Scott Gilbertson <scottg@mantatest.com> 2003-08-21 Scott Gilbertson <scottg@mantatest.com>
Thomas Fitzsimmons <fitzsim@redhat.com> Thomas Fitzsimmons <fitzsim@redhat.com>
......
/* java.lang.ref.Reference /* 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. This file is part of GNU Classpath.
...@@ -83,15 +83,25 @@ public abstract class Reference ...@@ -83,15 +83,25 @@ public abstract class Reference
/** /**
* This is like REFERENT but is not scanned by the GC. We keep a * 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. * copy around so that we can clean up our internal data structure
* even after clear() is called.
* GCJ LOCAL: * GCJ LOCAL:
* This field doesn't exist in Classpath; we use it to detect * This field doesn't exist in Classpath.
* clearing.
* END GCJ LOCAL * END GCJ LOCAL
*/ */
gnu.gcj.RawData copy; gnu.gcj.RawData copy;
/** /**
* Set to true if {@link #clear()} is called.
* GCJ LOCAL:
* This field doesn't exist in Classpath. It is used internally in
* natReference.cc, which enqueues the reference unless it is true
* (has been cleared).
* END GCJ LOCAL
*/
boolean cleared = false;
/**
* The queue this reference is registered on. This is null, if this * The queue this reference is registered on. This is null, if this
* wasn't registered to any queue or reference was already enqueued. * wasn't registered to any queue or reference was already enqueued.
*/ */
...@@ -166,8 +176,7 @@ public abstract class Reference ...@@ -166,8 +176,7 @@ public abstract class Reference
*/ */
public void clear() public void clear()
{ {
referent = null; cleared = true;
copy = null;
} }
/** /**
......
...@@ -258,9 +258,7 @@ finalize_referred_to_object (jobject obj) ...@@ -258,9 +258,7 @@ finalize_referred_to_object (jobject obj)
{ {
java::lang::ref::Reference *ref java::lang::ref::Reference *ref
= reinterpret_cast<java::lang::ref::Reference *> (head->reference); = reinterpret_cast<java::lang::ref::Reference *> (head->reference);
// If the copy is already NULL then the user must have if (! ref->cleared)
// called Reference.clear().
if (ref->copy != NULL)
ref->enqueue (); ref->enqueue ();
object_list *next = head->next; object_list *next = head->next;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment