< prev index next >

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

Print this page




  46     /**
  47      * Links to previous and next in a doubly-linked list.
  48      */
  49     PhantomCleanable<?> prev = this, next = this;
  50 
  51     /**
  52      * The list of PhantomCleanable; synchronizes insert and remove.
  53      */
  54     private final PhantomCleanable<?> list;
  55 
  56     /**
  57      * Constructs new {@code PhantomCleanable} with
  58      * {@code non-null referent} and {@code non-null cleaner}.
  59      * The {@code cleaner} is not retained; it is only used to
  60      * 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 PhantomCleanable(T referent, Cleaner cleaner) {
  66         super(Objects.requireNonNull(referent), CleanerImpl.getCleanerImpl(cleaner).queue);
  67         this.list = CleanerImpl.getCleanerImpl(cleaner).phantomCleanableList;
  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     PhantomCleanable() {
  79         super(null, null);
  80         this.list = this;
  81     }
  82 
  83     /**
  84      * Insert this PhantomCleanable 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     PhantomCleanable<?> prev = this, next = this;
  50 
  51     /**
  52      * The list of PhantomCleanable; synchronizes insert and remove.
  53      */
  54     private final PhantomCleanable<?> list;
  55 
  56     /**
  57      * Constructs new {@code PhantomCleanable} with
  58      * {@code non-null referent} and {@code non-null cleaner}.
  59      * The {@code cleaner} is not retained; it is only used to
  60      * 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 PhantomCleanable(T referent, Cleaner cleaner) {
  66         super(Objects.requireNonNull(referent), ((CleanerImpl)cleaner).queue());
  67         this.list = ((CleanerImpl)cleaner).phantomCleanableList();
  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     PhantomCleanable() {
  79         super(null, null);
  80         this.list = this;
  81     }
  82 
  83     /**
  84      * Insert this PhantomCleanable after the list head.
  85      */
  86     private void insert() {
  87         synchronized (list) {


< prev index next >