src/java.base/share/classes/java/lang/ref/Reference.java

Print this page




  83      * the next field is null then the instance is active; if it is non-null,
  84      * then the collector should treat the instance normally.
  85      *
  86      * To ensure that a concurrent collector can discover active Reference
  87      * objects without interfering with application threads that may apply
  88      * the enqueue() method to those objects, collectors should link
  89      * discovered objects through the discovered field. The discovered
  90      * field is also used for linking Reference objects in the pending list.
  91      */
  92 
  93     private T referent;         /* Treated specially by GC */
  94 
  95     volatile ReferenceQueue<? super T> queue;
  96 
  97     /* When active:   NULL
  98      *     pending:   this
  99      *    Enqueued:   next reference in queue (or this if last)
 100      *    Inactive:   this
 101      */
 102     @SuppressWarnings("rawtypes")
 103     Reference next;
 104 
 105     /* When active:   next element in a discovered reference list maintained by GC (or this if last)
 106      *     pending:   next element in the pending list (or null if last)
 107      *   otherwise:   NULL
 108      */
 109     transient private Reference<T> discovered;  /* used by VM */
 110 
 111 
 112     /* Object used to synchronize with the garbage collector.  The collector
 113      * must acquire this lock at the beginning of each collection cycle.  It is
 114      * therefore critical that any code holding this lock complete as quickly
 115      * as possible, allocate no new objects, and avoid calling user code.
 116      */
 117     static private class Lock { }
 118     private static Lock lock = new Lock();
 119 
 120 
 121     /* List of References waiting to be enqueued.  The collector adds
 122      * References to this list, while the Reference-handler thread removes
 123      * them.  This list is protected by the above lock object. The




  83      * the next field is null then the instance is active; if it is non-null,
  84      * then the collector should treat the instance normally.
  85      *
  86      * To ensure that a concurrent collector can discover active Reference
  87      * objects without interfering with application threads that may apply
  88      * the enqueue() method to those objects, collectors should link
  89      * discovered objects through the discovered field. The discovered
  90      * field is also used for linking Reference objects in the pending list.
  91      */
  92 
  93     private T referent;         /* Treated specially by GC */
  94 
  95     volatile ReferenceQueue<? super T> queue;
  96 
  97     /* When active:   NULL
  98      *     pending:   this
  99      *    Enqueued:   next reference in queue (or this if last)
 100      *    Inactive:   this
 101      */
 102     @SuppressWarnings("rawtypes")
 103     volatile Reference next;
 104 
 105     /* When active:   next element in a discovered reference list maintained by GC (or this if last)
 106      *     pending:   next element in the pending list (or null if last)
 107      *   otherwise:   NULL
 108      */
 109     transient private Reference<T> discovered;  /* used by VM */
 110 
 111 
 112     /* Object used to synchronize with the garbage collector.  The collector
 113      * must acquire this lock at the beginning of each collection cycle.  It is
 114      * therefore critical that any code holding this lock complete as quickly
 115      * as possible, allocate no new objects, and avoid calling user code.
 116      */
 117     static private class Lock { }
 118     private static Lock lock = new Lock();
 119 
 120 
 121     /* List of References waiting to be enqueued.  The collector adds
 122      * References to this list, while the Reference-handler thread removes
 123      * them.  This list is protected by the above lock object. The