< prev index next >

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

Print this page




  77      *     in queue, or this if at end of list.
  78      *
  79      *     Inactive: queue = ReferenceQueue.NULL; next = this.
  80      *
  81      * With this scheme the collector need only examine the next field in order
  82      * to determine whether a Reference instance requires special treatment: If
  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 




  77      *     in queue, or this if at end of list.
  78      *
  79      *     Inactive: queue = ReferenceQueue.NULL; next = this.
  80      *
  81      * With this scheme the collector need only examine the next field in order
  82      * to determine whether a Reference instance requires special treatment: If
  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 a Reference is de-queued from ReferenceQueue, Reference.next
  98      * points to this object.
  99      */
 100     private static class Dequeued extends Reference<Void> { Dequeued() { super(null); } }
 101     static final Reference DEQUEUED = new Dequeued();
 102 
 103     /* When active:   NULL
 104      *     pending:   this
 105      *    Enqueued:   next reference in queue (or this if last)
 106      *    Inactive:   DEQUEUED
 107      */
 108     @SuppressWarnings("rawtypes")
 109     Reference next;
 110 
 111     /* When active:   next element in a discovered reference list maintained by GC (or this if last)
 112      *     pending:   next element in the pending list (or null if last)
 113      *   otherwise:   NULL
 114      */
 115     transient private Reference<T> discovered;  /* used by VM */
 116 
 117 
 118     /* Object used to synchronize with the garbage collector.  The collector
 119      * must acquire this lock at the beginning of each collection cycle.  It is
 120      * therefore critical that any code holding this lock complete as quickly
 121      * as possible, allocate no new objects, and avoid calling user code.
 122      */
 123     static private class Lock { }
 124     private static Lock lock = new Lock();
 125 
 126 


< prev index next >