< prev index next >

src/java.base/share/classes/jdk/internal/ref/SoftCleanable.java

Print this page




  46     /**
  47      * Links to previous and next in a doubly-linked list.
  48      */
  49     SoftCleanable<?> prev = this, next = this;
  50 
  51     /**
  52      * The list of SoftCleanable; synchronizes insert and remove.
  53      */
  54     private final SoftCleanable<?> list;
  55 
  56     /**
  57      * Constructs new {@code SoftCleanableReference} with
  58      * {@code non-null referent} and {@code non-null cleaner}.
  59      * The {@code cleaner} is not retained by this reference; it is only used
  60      * to register the newly constructed {@link Cleaner.Cleanable Cleanable}.
  61      *
  62      * @param referent the referent to track
  63      * @param cleaner  the {@code Cleaner} to register with
  64      */
  65     public SoftCleanable(T referent, Cleaner cleaner) {
  66         super(Objects.requireNonNull(referent), CleanerImpl.getCleanerImpl(cleaner).queue);
  67         list = CleanerImpl.getCleanerImpl(cleaner).softCleanableList;
  68         insert();
  69 
  70         // Ensure referent and cleaner remain accessible
  71         Reference.reachabilityFence(referent);
  72         Reference.reachabilityFence(cleaner);
  73     }
  74 
  75     /**
  76      * Construct a new root of the list; not inserted.
  77      */
  78     SoftCleanable() {
  79         super(null, null);
  80         this.list = this;
  81     }
  82 
  83     /**
  84      * Insert this SoftCleanableReference after the list head.
  85      */
  86     private void insert() {
  87         synchronized (list) {




  46     /**
  47      * Links to previous and next in a doubly-linked list.
  48      */
  49     SoftCleanable<?> prev = this, next = this;
  50 
  51     /**
  52      * The list of SoftCleanable; synchronizes insert and remove.
  53      */
  54     private final SoftCleanable<?> list;
  55 
  56     /**
  57      * Constructs new {@code SoftCleanableReference} with
  58      * {@code non-null referent} and {@code non-null cleaner}.
  59      * The {@code cleaner} is not retained by this reference; it is only used
  60      * to register the newly constructed {@link Cleaner.Cleanable Cleanable}.
  61      *
  62      * @param referent the referent to track
  63      * @param cleaner  the {@code Cleaner} to register with
  64      */
  65     public SoftCleanable(T referent, Cleaner cleaner) {
  66         super(Objects.requireNonNull(referent), ((CleanerImpl)cleaner).queue());
  67         list = ((CleanerImpl)cleaner).softCleanableList();
  68         insert();
  69 
  70         // Ensure referent and cleaner remain accessible
  71         Reference.reachabilityFence(referent);
  72         Reference.reachabilityFence(cleaner);
  73     }
  74 
  75     /**
  76      * Construct a new root of the list; not inserted.
  77      */
  78     SoftCleanable() {
  79         super(null, null);
  80         this.list = this;
  81     }
  82 
  83     /**
  84      * Insert this SoftCleanableReference after the list head.
  85      */
  86     private void insert() {
  87         synchronized (list) {


< prev index next >