Source:
private void ensureSize() { if (currentSize <= maxSize) { return; } while (true) { long addressToRemove; Lock entryWriteLock; OffHeapConcurrentMap map; lruLock.lock(); try { if (currentSize <= maxSize) { break; } assert firstAddress > 0; byte[] key = offHeapEntryFactory.getKey(firstAddress); map = getMapThatContainsKey(key); if (map != null) { int hashCode = offHeapEntryFactory.getHashCode(firstAddress); entryWriteLock = map.getWriteLock(hashCode).asWriteLock(); if (entryWriteLock.tryLock()) { addressToRemove = firstAddress; } else { addressToRemove = 0; } } else { continue; } } finally { lruLock.unlock(); } if (addressToRemove == 0) { entryWriteLock.lock(); try { lruLock.lock(); try { if (currentSize <= maxSize) { break; } byte[] key = offHeapEntryFactory.getKey(firstAddress); OffHeapConcurrentMap protectedMap = getMapThatContainsKey(key); if (protectedMap == map) { int hashCode = offHeapEntryFactory.getHashCode(firstAddress); Lock innerLock = map.getWriteLock(hashCode).asWriteLock(); if (innerLock == entryWriteLock) { addressToRemove = firstAddress; } } } finally { lruLock.unlock(); } } finally { if (addressToRemove == 0) { entryWriteLock.unlock(); } } } if (addressToRemove != 0) { if (trace) { log.tracef("Removing entry: 0x%016x due to eviction due to size %d being larger than maximum of %d", addressToRemove, currentSize, maxSize); } try { InternalCacheEntry<WrappedBytes, WrappedBytes> ice = offHeapEntryFactory.fromMemory(addressToRemove); map.remove(ice.getKey(), addressToRemove); AbstractInternalDataContainer.handleEviction(ice, orderer, passivator.running(), evictionManager, this, null); } finally { entryWriteLock.unlock(); } } } }

Target:
private void ensureSize() { if (currentSize <= maxSize) { return; } while (true) { long addressToRemove; StampedLock stampedLock; long writeStamp; OffHeapConcurrentMap map; lruLock.lock(); try { if (currentSize <= maxSize) { break; } assert firstAddress > 0; byte[] key = offHeapEntryFactory.getKey(firstAddress); map = getMapThatContainsKey(key); if (map != null) { int hashCode = offHeapEntryFactory.getHashCode(firstAddress); stampedLock = map.getStampedLock(hashCode); if ((writeStamp = stampedLock.tryWriteLock()) != 0) { addressToRemove = firstAddress; } else { addressToRemove = 0; } } else { continue; } } finally { lruLock.unlock(); } if (addressToRemove == 0) { writeStamp = stampedLock.writeLock(); try { lruLock.lock(); try { if (currentSize <= maxSize) { break; } byte[] key = offHeapEntryFactory.getKey(firstAddress); OffHeapConcurrentMap protectedMap = getMapThatContainsKey(key); if (protectedMap == map) { int hashCode = offHeapEntryFactory.getHashCode(firstAddress); StampedLock innerLock = map.getStampedLock(hashCode); if (innerLock == stampedLock) { addressToRemove = firstAddress; } } } finally { lruLock.unlock(); } } finally { if (addressToRemove == 0) { stampedLock.unlockWrite(writeStamp); } } } if (addressToRemove != 0) { if (trace) { log.tracef("Removing entry: 0x%016x due to eviction due to size %d being larger than maximum of %d", addressToRemove, currentSize, maxSize); } try { InternalCacheEntry<WrappedBytes, WrappedBytes> ice = offHeapEntryFactory.fromMemory(addressToRemove); map.remove(ice.getKey(), addressToRemove); AbstractInternalDataContainer.handleEviction(ice, orderer, passivator.running(), evictionManager, this, null); } finally { stampedLock.unlockWrite(writeStamp); } } } }