HHH-15305 Switch size management in BoundedConcurrentHashMap to use an AtomicInteger
This commit is contained in:
parent
7e5c3c8dde
commit
3d4cb14627
|
@ -34,7 +34,7 @@ import java.util.NoSuchElementException;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -332,7 +332,7 @@ public class BoundedConcurrentHashMap<K, V> extends AbstractMap<K, V>
|
||||||
|
|
||||||
private final ConcurrentLinkedQueue<HashEntry<K, V>> accessQueue;
|
private final ConcurrentLinkedQueue<HashEntry<K, V>> accessQueue;
|
||||||
|
|
||||||
private final AtomicLong accessQueueSize;
|
private final AtomicInteger accessQueueSize;
|
||||||
private final Segment<K, V> segment;
|
private final Segment<K, V> segment;
|
||||||
private final int maxBatchQueueSize;
|
private final int maxBatchQueueSize;
|
||||||
private final int trimDownSize;
|
private final int trimDownSize;
|
||||||
|
@ -347,13 +347,13 @@ public class BoundedConcurrentHashMap<K, V> extends AbstractMap<K, V>
|
||||||
this.batchThresholdFactor = batchThresholdFactor;
|
this.batchThresholdFactor = batchThresholdFactor;
|
||||||
this.accessQueue = new ConcurrentLinkedQueue<>();
|
this.accessQueue = new ConcurrentLinkedQueue<>();
|
||||||
this.evicted = new HashSet<>();
|
this.evicted = new HashSet<>();
|
||||||
this.accessQueueSize = new AtomicLong();
|
this.accessQueueSize = new AtomicInteger();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute() {
|
public void execute() {
|
||||||
assert segment.isHeldByCurrentThread();
|
assert segment.isHeldByCurrentThread();
|
||||||
long removed = 0;
|
int removed = 0;
|
||||||
HashEntry<K, V> e;
|
HashEntry<K, V> e;
|
||||||
try {
|
try {
|
||||||
while ((e = accessQueue.poll()) != null) {
|
while ((e = accessQueue.poll()) != null) {
|
||||||
|
@ -385,7 +385,7 @@ public class BoundedConcurrentHashMap<K, V> extends AbstractMap<K, V>
|
||||||
// counter-intuitive:
|
// counter-intuitive:
|
||||||
// Why not placing this *before* appending the entry to the access queue?
|
// Why not placing this *before* appending the entry to the access queue?
|
||||||
// we don't want the eviction to kick-in if the access queue doesn't contain enough entries.
|
// we don't want the eviction to kick-in if the access queue doesn't contain enough entries.
|
||||||
final long size = accessQueueSize.incrementAndGet();
|
final int size = accessQueueSize.incrementAndGet();
|
||||||
return size >= maxBatchQueueSize * batchThresholdFactor;
|
return size >= maxBatchQueueSize * batchThresholdFactor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -402,7 +402,7 @@ public class BoundedConcurrentHashMap<K, V> extends AbstractMap<K, V>
|
||||||
assert segment.isHeldByCurrentThread();
|
assert segment.isHeldByCurrentThread();
|
||||||
remove( e );
|
remove( e );
|
||||||
// we could have multiple instances of e in accessQueue; remove them all
|
// we could have multiple instances of e in accessQueue; remove them all
|
||||||
long removed = 0;
|
int removed = 0;
|
||||||
while ( accessQueue.remove( e ) ) {
|
while ( accessQueue.remove( e ) ) {
|
||||||
removed--;
|
removed--;
|
||||||
}
|
}
|
||||||
|
@ -413,7 +413,7 @@ public class BoundedConcurrentHashMap<K, V> extends AbstractMap<K, V>
|
||||||
public void clear() {
|
public void clear() {
|
||||||
assert segment.isHeldByCurrentThread();
|
assert segment.isHeldByCurrentThread();
|
||||||
super.clear();
|
super.clear();
|
||||||
long removed = 0;
|
int removed = 0;
|
||||||
while (accessQueue.poll() != null) {
|
while (accessQueue.poll() != null) {
|
||||||
removed++;
|
removed++;
|
||||||
}
|
}
|
||||||
|
@ -865,7 +865,7 @@ public class BoundedConcurrentHashMap<K, V> extends AbstractMap<K, V>
|
||||||
*/
|
*/
|
||||||
private final ConcurrentLinkedQueue<LIRSHashEntry<K, V>> accessQueue;
|
private final ConcurrentLinkedQueue<LIRSHashEntry<K, V>> accessQueue;
|
||||||
|
|
||||||
private final AtomicLong accessQueueSize;
|
private final AtomicInteger accessQueueSize;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The maxBatchQueueSize
|
* The maxBatchQueueSize
|
||||||
|
@ -926,7 +926,7 @@ public class BoundedConcurrentHashMap<K, V> extends AbstractMap<K, V>
|
||||||
this.maxBatchQueueSize = maxBatchSize > MAX_BATCH_SIZE ? MAX_BATCH_SIZE : maxBatchSize;
|
this.maxBatchQueueSize = maxBatchSize > MAX_BATCH_SIZE ? MAX_BATCH_SIZE : maxBatchSize;
|
||||||
this.batchThresholdFactor = batchThresholdFactor;
|
this.batchThresholdFactor = batchThresholdFactor;
|
||||||
this.accessQueue = new ConcurrentLinkedQueue<LIRSHashEntry<K, V>>();
|
this.accessQueue = new ConcurrentLinkedQueue<LIRSHashEntry<K, V>>();
|
||||||
this.accessQueueSize = new AtomicLong();
|
this.accessQueueSize = new AtomicInteger();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int calculateLIRSize(int maximumSize) {
|
private static int calculateLIRSize(int maximumSize) {
|
||||||
|
@ -938,7 +938,7 @@ public class BoundedConcurrentHashMap<K, V> extends AbstractMap<K, V>
|
||||||
public void execute() {
|
public void execute() {
|
||||||
assert segment.isHeldByCurrentThread();
|
assert segment.isHeldByCurrentThread();
|
||||||
Set<HashEntry<K, V>> evicted = new HashSet<>();
|
Set<HashEntry<K, V>> evicted = new HashSet<>();
|
||||||
long removed = 0;
|
int removed = 0;
|
||||||
try {
|
try {
|
||||||
LIRSHashEntry<K, V> e;
|
LIRSHashEntry<K, V> e;
|
||||||
while ( (e = accessQueue.poll()) != null ) {
|
while ( (e = accessQueue.poll()) != null ) {
|
||||||
|
@ -1005,7 +1005,7 @@ public class BoundedConcurrentHashMap<K, V> extends AbstractMap<K, V>
|
||||||
// counter-intuitive:
|
// counter-intuitive:
|
||||||
// Why not placing this *before* appending the entry to the access queue?
|
// Why not placing this *before* appending the entry to the access queue?
|
||||||
// we don't want the eviction to kick-in if the access queue doesn't contain enough entries.
|
// we don't want the eviction to kick-in if the access queue doesn't contain enough entries.
|
||||||
final long size = accessQueueSize.incrementAndGet();
|
final int size = accessQueueSize.incrementAndGet();
|
||||||
return size >= maxBatchQueueSize * batchThresholdFactor;
|
return size >= maxBatchQueueSize * batchThresholdFactor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1021,7 +1021,7 @@ public class BoundedConcurrentHashMap<K, V> extends AbstractMap<K, V>
|
||||||
public void onEntryRemove(HashEntry<K, V> e) {
|
public void onEntryRemove(HashEntry<K, V> e) {
|
||||||
assert segment.isHeldByCurrentThread();
|
assert segment.isHeldByCurrentThread();
|
||||||
( (LIRSHashEntry<K, V>) e ).remove();
|
( (LIRSHashEntry<K, V>) e ).remove();
|
||||||
long removed = 0;
|
int removed = 0;
|
||||||
// we could have multiple instances of e in accessQueue; remove them all
|
// we could have multiple instances of e in accessQueue; remove them all
|
||||||
while ( accessQueue.remove( e ) ) {
|
while ( accessQueue.remove( e ) ) {
|
||||||
removed++;
|
removed++;
|
||||||
|
@ -1032,7 +1032,7 @@ public class BoundedConcurrentHashMap<K, V> extends AbstractMap<K, V>
|
||||||
@Override
|
@Override
|
||||||
public void clear() {
|
public void clear() {
|
||||||
assert segment.isHeldByCurrentThread();
|
assert segment.isHeldByCurrentThread();
|
||||||
long removed = 0;
|
int removed = 0;
|
||||||
while (accessQueue.poll() != null) {
|
while (accessQueue.poll() != null) {
|
||||||
removed++;
|
removed++;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue