46 /** 47 * Links to previous and next in a doubly-linked list. 48 */ 49 WeakCleanable<?> prev = this, next = this; 50 51 /** 52 * The list of WeakCleanable; synchronizes insert and remove. 53 */ 54 private final WeakCleanable<?> list; 55 56 /** 57 * Constructs new {@code WeakCleanableReference} 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 new reference with 64 */ 65 public WeakCleanable(T referent, Cleaner cleaner) { 66 super(Objects.requireNonNull(referent), CleanerImpl.getCleanerImpl(cleaner).queue); 67 list = CleanerImpl.getCleanerImpl(cleaner).weakCleanableList; 68 insert(); 69 70 // Ensure referent and cleaner remain accessible 71 Reference.reachabilityFence(referent); 72 Reference.reachabilityFence(cleaner); 73 74 } 75 76 /** 77 * Construct a new root of the list; not inserted. 78 */ 79 WeakCleanable() { 80 super(null, null); 81 this.list = this; 82 } 83 84 /** 85 * Insert this WeakCleanableReference after the list head. 86 */ 87 private void insert() { | 46 /** 47 * Links to previous and next in a doubly-linked list. 48 */ 49 WeakCleanable<?> prev = this, next = this; 50 51 /** 52 * The list of WeakCleanable; synchronizes insert and remove. 53 */ 54 private final WeakCleanable<?> list; 55 56 /** 57 * Constructs new {@code WeakCleanableReference} 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 new reference with 64 */ 65 public WeakCleanable(T referent, Cleaner cleaner) { 66 super(Objects.requireNonNull(referent), ((CleanerImpl)cleaner).queue()); 67 list = ((CleanerImpl)cleaner).weakCleanableList(); 68 insert(); 69 70 // Ensure referent and cleaner remain accessible 71 Reference.reachabilityFence(referent); 72 Reference.reachabilityFence(cleaner); 73 74 } 75 76 /** 77 * Construct a new root of the list; not inserted. 78 */ 79 WeakCleanable() { 80 super(null, null); 81 this.list = this; 82 } 83 84 /** 85 * Insert this WeakCleanableReference after the list head. 86 */ 87 private void insert() { |