seg.lock(); try { HashEntry<K, V>[] tab = seg.table;
boolean replace(K key, int hash, V oldValue, V newValue) { lock(); Set<HashEntry<K, V>> evicted = null; try { HashEntry<K, V> e = getFirst( hash ); while ( e != null && ( e.hash != hash || !key.equals( e.key ) ) ) { e = e.next; } boolean replaced = false; if ( e != null && oldValue.equals( e.value ) ) { replaced = true; e.value = newValue; if ( eviction.onEntryHit( e ) ) { evicted = attemptEviction( true ); } } return replaced; } finally { unlock(); notifyEvictionListener( evicted ); } }
lock(); try { int c = count - 1;
segments[i].lock();
sum = 0; for ( int i = 0; i < segments.length; ++i ) { segments[i].lock();
V put(K key, int hash, V value, boolean onlyIfAbsent) { lock(); Set<HashEntry<K, V>> evicted = null; try {
lock(); try { int c = count - 1;
seg.lock(); try { HashEntry<K, V>[] tab = seg.table;
V replace(K key, int hash, V newValue) { lock(); Set<HashEntry<K, V>> evicted = null; try { HashEntry<K, V> e = getFirst( hash ); while ( e != null && ( e.hash != hash || !key.equals( e.key ) ) ) { e = e.next; } V oldValue = null; if ( e != null ) { oldValue = e.value; e.value = newValue; if ( eviction.onEntryHit( e ) ) { evicted = attemptEviction( true ); } } return oldValue; } finally { unlock(); notifyEvictionListener( evicted ); } }
private Set<HashEntry<K, V>> attemptEviction(boolean lockedAlready) { Set<HashEntry<K, V>> evicted = null; boolean obtainedLock = lockedAlready || tryLock(); if ( !obtainedLock && eviction.thresholdExpired() ) { lock(); obtainedLock = true; } if ( obtainedLock ) { try { if ( eviction.thresholdExpired() ) { evicted = eviction.execute(); } } finally { if ( !lockedAlready ) { unlock(); } } } return evicted; }
boolean replace(K key, int hash, V oldValue, V newValue) { lock(); Set<HashEntry<K, V>> evicted = null; try { HashEntry<K, V> e = getFirst( hash ); while ( e != null && ( e.hash != hash || !key.equals( e.key ) ) ) { e = e.next; } boolean replaced = false; if ( e != null && oldValue.equals( e.value ) ) { replaced = true; e.value = newValue; if ( eviction.onEntryHit( e ) ) { evicted = attemptEviction( true ); } } return replaced; } finally { unlock(); notifyEvictionListener( evicted ); } }
void clear() { if ( count != 0 ) { lock(); try { HashEntry<K, V>[] tab = table; for ( int i = 0; i < tab.length; i++ ) { tab[i] = null; } ++modCount; eviction.clear(); count = 0; // write-volatile } 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 { return e.value; } finally { unlock(); } }
segments[i].lock();
sum = 0; for ( int i = 0; i < segments.length; ++i ) { segments[i].lock();
V put(K key, int hash, V value, boolean onlyIfAbsent) { lock(); Set<HashEntry<K, V>> evicted = null; try {
V replace(K key, int hash, V newValue) { lock(); Set<HashEntry<K, V>> evicted = null; try { HashEntry<K, V> e = getFirst( hash ); while ( e != null && ( e.hash != hash || !key.equals( e.key ) ) ) { e = e.next; } V oldValue = null; if ( e != null ) { oldValue = e.value; e.value = newValue; if ( eviction.onEntryHit( e ) ) { evicted = attemptEviction( true ); } } return oldValue; } finally { unlock(); notifyEvictionListener( evicted ); } }
private Set<HashEntry<K, V>> attemptEviction(boolean lockedAlready) { Set<HashEntry<K, V>> evicted = null; boolean obtainedLock = lockedAlready || tryLock(); if ( !obtainedLock && eviction.thresholdExpired() ) { lock(); obtainedLock = true; } if ( obtainedLock ) { try { if ( eviction.thresholdExpired() ) { evicted = eviction.execute(); } } finally { if ( !lockedAlready ) { unlock(); } } } return evicted; }
void clear() { if ( count != 0 ) { lock(); try { HashEntry<K, V>[] tab = table; for ( int i = 0; i < tab.length; i++ ) { tab[i] = null; } ++modCount; eviction.clear(); count = 0; // write-volatile } 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 { return e.value; } finally { unlock(); } }