void clearKeyReferenceQueue() { while (keyReferenceQueue.poll() != null) {} }
<T> void clearReferenceQueue(ReferenceQueue<T> referenceQueue) { while (referenceQueue.poll() != null) {} }
void clearValueReferenceQueue() { while (valueReferenceQueue.poll() != null) {} }
private void removeWeaklyReachableReferences() { // WeakReferences are enqueued as soon as the object to which they point to becomes weakly // reachable. This is before finalization or garbage collection has actually happened. KeyedWeakReference ref; while ((ref = (KeyedWeakReference) queue.poll()) != null) { retainedKeys.remove(ref.key); } } }
/** * Remove cleared (inactive) SoftRefs from our set. Gc may have cleared one or more, * and made them inactive. We minimize contention by keeping synchronized sections short: * the poll/remove methods */ private void removeSoftRefsClearedByGc() { SoftReference<?> clearedSoftRef; while ((clearedSoftRef = (SoftReference<?>) _refQueue.poll()) != null) { // uses reference-equality, quick, and O(1) removal by HashSet _trackedRecyclers.remove(clearedSoftRef); } }
/** * Remove cleared (inactive) SoftRefs from our set. Gc may have cleared one or more, * and made them inactive. We minimize contention by keeping synchronized sections short: * the poll/remove methods */ private void removeSoftRefsClearedByGc() { SoftReference<?> clearedSoftRef; while ((clearedSoftRef = (SoftReference<?>) _refQueue.poll()) != null) { // uses reference-equality, quick, and O(1) removal by HashSet _trackedRecyclers.remove(clearedSoftRef); } }
private void processQueue() { SoftValueRef ref; while ((ref = (SoftValueRef)queue.poll()) != null) { if (ref == (SoftValueRef)hash.get(ref.key)) { // only remove if it is the *exact* same WeakValueRef // hash.remove(ref.key); } } }
private void drainQueue() { Reference<? extends L> ref; while ((ref = queue.poll()) != null) { // We only ever register ArrayReferences with the queue so this is always safe. ArrayReference<? extends L> arrayRef = (ArrayReference<? extends L>) ref; // Try to clear out the array slot, n.b. if we fail that is fine, in either case the // arrayRef will be out of the array after this step. locks.compareAndSet(arrayRef.index, arrayRef, null); } }
private void clearRefQueue() { for (;;) { @SuppressWarnings("unchecked") DefaultResourceLeak ref = (DefaultResourceLeak) refQueue.poll(); if (ref == null) { break; } ref.dispose(); } }
private void drainQueue() { Reference<? extends L> ref; while ((ref = queue.poll()) != null) { // We only ever register ArrayReferences with the queue so this is always safe. ArrayReference<? extends L> arrayRef = (ArrayReference<? extends L>) ref; // Try to clear out the array slot, n.b. if we fail that is fine, in either case the // arrayRef will be out of the array after this step. locks.compareAndSet(arrayRef.index, arrayRef, null); } }
private void clearRefQueue() { for (;;) { @SuppressWarnings("unchecked") DefaultResourceLeak ref = (DefaultResourceLeak) refQueue.poll(); if (ref == null) { break; } ref.dispose(); } }
@GuardedBy("this") void drainValueReferenceQueue() { Reference<? extends V> ref; int i = 0; while ((ref = valueReferenceQueue.poll()) != null) { @SuppressWarnings("unchecked") ValueReference<K, V> valueReference = (ValueReference<K, V>) ref; map.reclaimValue(valueReference); if (++i == DRAIN_MAX) { break; } } }
@GuardedBy("this") void drainKeyReferenceQueue(ReferenceQueue<K> keyReferenceQueue) { Reference<? extends K> ref; int i = 0; while ((ref = keyReferenceQueue.poll()) != null) { @SuppressWarnings("unchecked") E entry = (E) ref; map.reclaimKey(entry); if (++i == DRAIN_MAX) { break; } } }
@GuardedBy("this") void drainKeyReferenceQueue() { Reference<? extends K> ref; int i = 0; while ((ref = keyReferenceQueue.poll()) != null) { @SuppressWarnings("unchecked") ReferenceEntry<K, V> entry = (ReferenceEntry<K, V>) ref; map.reclaimKey(entry); if (++i == DRAIN_MAX) { break; } } }
@GuardedBy("this") void drainValueReferenceQueue(ReferenceQueue<V> valueReferenceQueue) { Reference<? extends V> ref; int i = 0; while ((ref = valueReferenceQueue.poll()) != null) { @SuppressWarnings("unchecked") WeakValueReference<K, V, E> valueReference = (WeakValueReference<K, V, E>) ref; map.reclaimValue(valueReference); if (++i == DRAIN_MAX) { break; } } }
/** * Repeatedly dequeues references from the queue and invokes {@link * FinalizableReference#finalizeReferent()} on them until the queue is empty. This method is a * no-op if the background thread was created successfully. */ void cleanUp() { if (threadStarted) { return; } Reference<?> reference; while ((reference = queue.poll()) != null) { /* * This is for the benefit of phantom references. Weak and soft references will have already * been cleared by this point. */ reference.clear(); try { ((FinalizableReference) reference).finalizeReferent(); } catch (Throwable t) { logger.log(Level.SEVERE, "Error cleaning up after reference.", t); } } }
@GuardedBy("this") void drainValueReferenceQueue() { Reference<? extends V> ref; int i = 0; while ((ref = valueReferenceQueue.poll()) != null) { @SuppressWarnings("unchecked") ValueReference<K, V> valueReference = (ValueReference<K, V>) ref; map.reclaimValue(valueReference); if (++i == DRAIN_MAX) { break; } } }
@Override protected boolean removeExpiredEntries() { while (true) { CachedValueReference value = (CachedValueReference) queue.poll(); if (value == null) { break; } map.remove(value.getOwner().getKey(), value.getOwner()); } return super.removeExpiredEntries(); }
@Override protected boolean removeExpiredEntries() { while (true) { CachedValueReference value = (CachedValueReference) queue.poll(); if (value == null) { break; } map.remove(value.getOwner().getKey(), value.getOwner()); } return super.removeExpiredEntries(); }
public void testDrainKeyReferenceQueueOnWrite() { for (MapMaker maker : allWeakKeyStrengthMakers()) { MapMakerInternalMap<Object, Object, ?, ?> map = makeMap(maker.concurrencyLevel(1)); if (maker.getKeyStrength() == Strength.WEAK) { Segment<Object, Object, ?, ?> segment = map.segments[0]; Object keyOne = new Object(); int hashOne = map.hash(keyOne); Object valueOne = new Object(); Object keyTwo = new Object(); Object valueTwo = new Object(); map.put(keyOne, valueOne); InternalEntry<Object, Object, ?> entry = segment.getEntry(keyOne, hashOne); @SuppressWarnings("unchecked") Reference<Object> reference = (Reference) entry; reference.enqueue(); map.put(keyTwo, valueTwo); assertFalse(map.containsKey(keyOne)); assertFalse(map.containsValue(valueOne)); assertNull(map.get(keyOne)); assertEquals(1, map.size()); assertNull(segment.getKeyReferenceQueueForTesting().poll()); } } }