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]

Patch: FYI: Reference fix


I'm checking this in on the trunk.

This is a patch from the main list to fix an obscure problem with
References.

Tom

Index: ChangeLog
from  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.

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 22:05:48 -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.
 
@@ -83,15 +83,25 @@
 
   /**
    * 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:
-   * This field doesn't exist in Classpath; we use it to detect
-   * clearing.
+   * This field doesn't exist in Classpath.
    * END GCJ LOCAL
    */
   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
    * wasn't registered to any queue or reference was already enqueued.
    */
@@ -166,8 +176,7 @@
    */
   public void clear()
   {
-    referent = null;
-    copy = null;
+    cleared = true;
   }
 
   /**
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 22:05:48 -0000
@@ -258,9 +258,7 @@
 	{
 	  java::lang::ref::Reference *ref
 	    = reinterpret_cast<java::lang::ref::Reference *> (head->reference);
-	  // If the copy is already NULL then the user must have
-	  // called Reference.clear().
-	  if (ref->copy != NULL)
+	  if (! ref->cleared)
 	    ref->enqueue ();
 
 	  object_list *next = head->next;


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