boolean replace(K key, int hash, V oldValue, V newValue) { lock(); try { removeStale(); HashEntry<K, V> e = getFirst(hash); while(e != null && (e.hash != hash || !key.equals(e.keyRef.get()))) e = e.next; boolean replaced = false; if(e != null && oldValue.equals(e.value)) { replaced = true; e.value = newValue; } return replaced; } finally { unlock(); } }
sum += segments[i].count; for(int i = 0; i < segments.length; ++i) segments[i].unlock();
sum += segments[i].count; for(int i = 0; i < segments.length; ++i) segments[i].unlock();
segments[i].unlock();
segments[i].unlock();
void clear() { if(count != 0) { lock(); try { HashEntry<K, V>[] tab = table; for(int i = 0; i < tab.length; i++) tab[i] = null; ++modCount; // replace the reference queue to avoid unnecessary stale cleanups refQueue = new ReferenceQueue<K>(); count = 0; // write-volatile } finally { unlock(); } } } }
V replace(K key, int hash, V newValue) { lock(); try { removeStale(); HashEntry<K, V> e = getFirst(hash); while(e != null && (e.hash != hash || !key.equals(e.keyRef.get()))) e = e.next; V oldValue = null; if(e != null) { oldValue = e.value; e.value = newValue; } return oldValue; } finally { unlock(); } }
/** * Reads value field of an entry under lock. Called if value * field ever appears to be null. This is possible only if a * compiler happens to reorder a HashEntry initialization with * its table assignment, which is legal under memory model * but is not known to ever occur. */ V readValueUnderLock(HashEntry<K, V> e) { lock(); try { removeStale(); return e.value; } finally { unlock(); } }
void clear() { if(count != 0) { lock(); try { HashEntry<K, V>[] tab = table; for(int i = 0; i < tab.length; i++) tab[i] = null; ++modCount; // replace the reference queue to avoid unnecessary stale cleanups refQueue = new ReferenceQueue<K>(); count = 0; // write-volatile } finally { unlock(); } } } }
V replace(K key, int hash, V newValue) { lock(); try { removeStale(); HashEntry<K, V> e = getFirst(hash); while(e != null && (e.hash != hash || !key.equals(e.keyRef.get()))) e = e.next; V oldValue = null; if(e != null) { oldValue = e.value; e.value = newValue; } return oldValue; } finally { unlock(); } }
boolean replace(K key, int hash, V oldValue, V newValue) { lock(); try { removeStale(); HashEntry<K, V> e = getFirst(hash); while(e != null && (e.hash != hash || !key.equals(e.keyRef.get()))) e = e.next; boolean replaced = false; if(e != null && oldValue.equals(e.value)) { replaced = true; e.value = newValue; } return replaced; } finally { unlock(); } }
/** * Reads value field of an entry under lock. Called if value * field ever appears to be null. This is possible only if a * compiler happens to reorder a HashEntry initialization with * its table assignment, which is legal under memory model * but is not known to ever occur. */ V readValueUnderLock(HashEntry<K, V> e) { lock(); try { removeStale(); return e.value; } finally { unlock(); } }