diff --git a/gradle/dependencies.gradle b/gradle/dependencies.gradle
index 2a68413cd9..44c5d99a7d 100644
--- a/gradle/dependencies.gradle
+++ b/gradle/dependencies.gradle
@@ -26,7 +26,7 @@
ext {
versions = [
akka: '2.6.8',
- cache2k: '1.3.2.Alpha',
+ cache2k: '1.3.3.Alpha',
checkerFramework: '3.6.0',
coherence: '20.06',
collision: '0.3.3',
diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/BasicSettings.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/BasicSettings.java
index c0d6aa6ee9..58e415b049 100644
--- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/BasicSettings.java
+++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/BasicSettings.java
@@ -76,8 +76,8 @@ public TinyLfuSettings tinyLfu() {
return new TinyLfuSettings();
}
- public int maximumSize() {
- return config().getInt("maximum-size");
+ public long maximumSize() {
+ return config().getLong("maximum-size");
}
public boolean isFiles() {
diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/admission/countmin64/CountMin64TinyLfu.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/admission/countmin64/CountMin64TinyLfu.java
index 845b061770..8f67db4c8d 100644
--- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/admission/countmin64/CountMin64TinyLfu.java
+++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/admission/countmin64/CountMin64TinyLfu.java
@@ -17,6 +17,7 @@
import com.github.benmanes.caffeine.cache.simulator.BasicSettings;
import com.github.benmanes.caffeine.cache.simulator.admission.Frequency;
+import com.google.common.primitives.Ints;
import com.typesafe.config.Config;
/**
@@ -45,8 +46,8 @@ public CountMin64TinyLfu(Config config) {
BasicSettings settings = new BasicSettings(config);
sketch = new CountMin64(settings.tinyLfu().countMin64().eps(),
settings.tinyLfu().countMin64().confidence(), settings.randomSeed());
+ sampleSize = Ints.checkedCast(10 * settings.maximumSize());
conservative = settings.tinyLfu().conservative();
- sampleSize = 10 * settings.maximumSize();
}
/** Returns the estimated usage frequency of the item. */
diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/admission/perfect/PerfectFrequency.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/admission/perfect/PerfectFrequency.java
index 17a10d8764..e25c13e1c7 100644
--- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/admission/perfect/PerfectFrequency.java
+++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/admission/perfect/PerfectFrequency.java
@@ -17,6 +17,7 @@
import com.github.benmanes.caffeine.cache.simulator.BasicSettings;
import com.github.benmanes.caffeine.cache.simulator.admission.Frequency;
+import com.google.common.primitives.Ints;
import com.typesafe.config.Config;
import it.unimi.dsi.fastutil.longs.Long2IntMap;
@@ -34,7 +35,8 @@ public final class PerfectFrequency implements Frequency {
private int size;
public PerfectFrequency(Config config) {
- sampleSize = 10 * new BasicSettings(config).maximumSize();
+ BasicSettings settings = new BasicSettings(config);
+ sampleSize = Ints.checkedCast(10 * settings.maximumSize());
counts = new Long2IntOpenHashMap();
}
diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/admission/table/RandomRemovalFrequencyTable.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/admission/table/RandomRemovalFrequencyTable.java
index 1332bb7fe8..d5e84edd85 100644
--- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/admission/table/RandomRemovalFrequencyTable.java
+++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/admission/table/RandomRemovalFrequencyTable.java
@@ -23,6 +23,7 @@
import com.github.benmanes.caffeine.cache.simulator.BasicSettings;
import com.github.benmanes.caffeine.cache.simulator.admission.Frequency;
+import com.google.common.primitives.Ints;
import com.typesafe.config.Config;
/**
@@ -49,7 +50,7 @@ public final class RandomRemovalFrequencyTable implements Frequency {
public RandomRemovalFrequencyTable(Config config) {
BasicSettings settings = new BasicSettings(config);
- maxSum = sampleFactor * settings.maximumSize();
+ maxSum = Ints.checkedCast(sampleFactor * settings.maximumSize());
random = new Random(settings.randomSeed());
table = new HashMap<>(maxSum);
}
diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/admission/tinycache/TinyCacheAdapter.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/admission/tinycache/TinyCacheAdapter.java
index aa675dc17e..4167788a4c 100644
--- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/admission/tinycache/TinyCacheAdapter.java
+++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/admission/tinycache/TinyCacheAdapter.java
@@ -17,6 +17,7 @@
import com.github.benmanes.caffeine.cache.simulator.BasicSettings;
import com.github.benmanes.caffeine.cache.simulator.admission.Frequency;
+import com.google.common.primitives.Ints;
import com.typesafe.config.Config;
/**
@@ -37,7 +38,8 @@ public final class TinyCacheAdapter implements Frequency {
*/
public TinyCacheAdapter(Config config) {
BasicSettings settings = new BasicSettings(config);
- int nrSets = sampleFactor * settings.maximumSize() / 64; // number of (independent sets)
+ // number of (independent sets)
+ int nrSets = Ints.checkedCast(sampleFactor * settings.maximumSize() / 64);
tcs = new TinyCacheSketch(nrSets, 64,settings.randomSeed());
}
diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/adapt_size/AdaptSizeTraceReader.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/adapt_size/AdaptSizeTraceReader.java
index 4a0b3a6f49..31262786c7 100644
--- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/adapt_size/AdaptSizeTraceReader.java
+++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/adapt_size/AdaptSizeTraceReader.java
@@ -25,10 +25,14 @@
import com.github.benmanes.caffeine.cache.simulator.policy.AccessEvent;
import com.github.benmanes.caffeine.cache.simulator.policy.Policy.Characteristic;
import com.google.common.collect.Sets;
+import com.google.common.hash.Hashing;
/**
* A reader for the trace files provided by the authors of the AdaptSize algorithm. See
* traces.
+ *
+ * The AdaptSize simulator treats identical keys with different weights as unique entries, rather
+ * than as an update to that entry's size. This behavior is emulated by a key hash.
*
* @author ben.manes@gmail.com (Ben Manes)
*/
@@ -47,7 +51,12 @@ public Set characteristics() {
public Stream events() throws IOException {
return lines()
.map(line -> line.split(" ", 3))
- .map(array -> AccessEvent.forKeyAndWeight(
- Long.parseLong(array[1]), Integer.parseInt(array[2])));
+ .map(array -> {
+ long key = Long.parseLong(array[1]);
+ int weight = Integer.parseInt(array[2]);
+ long hashKey = Hashing.murmur3_128().newHasher()
+ .putLong(key).putInt(weight).hash().asLong();
+ return AccessEvent.forKeyAndWeight(hashKey, weight);
+ });
}
}
diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/AccessEvent.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/AccessEvent.java
index a25e7636da..0015125832 100644
--- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/AccessEvent.java
+++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/AccessEvent.java
@@ -101,7 +101,7 @@ private static final class WeightedAccessEvent extends AccessEvent {
private final int weight;
WeightedAccessEvent(long key, int weight) {
- super(cantorHashCode(key, weight));
+ super(key);
this.weight = weight;
checkArgument(weight >= 0);
}
@@ -112,11 +112,6 @@ public int weight() {
}
}
- /** Cantor pairing function. */
- private static long cantorHashCode(long key, int weight) {
- return (key + weight) * (key + weight + 1) / 2 + weight;
- }
-
private static final class PenaltiesAccessEvent extends AccessEvent {
private final double missPenalty;
private final double hitPenalty;
diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/adaptive/ArcPolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/adaptive/ArcPolicy.java
index 85c6a38f89..a5b8e6b643 100644
--- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/adaptive/ArcPolicy.java
+++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/adaptive/ArcPolicy.java
@@ -25,6 +25,7 @@
import com.github.benmanes.caffeine.cache.simulator.policy.PolicyStats;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableSet;
+import com.google.common.primitives.Ints;
import com.typesafe.config.Config;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
@@ -75,8 +76,8 @@ public final class ArcPolicy implements KeyOnlyPolicy {
public ArcPolicy(Config config) {
BasicSettings settings = new BasicSettings(config);
+ this.maximumSize = Ints.checkedCast(settings.maximumSize());
this.policyStats = new PolicyStats("adaptive.Arc");
- this.maximumSize = settings.maximumSize();
this.data = new Long2ObjectOpenHashMap<>();
this.headT1 = new Node();
this.headT2 = new Node();
diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/adaptive/CarPolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/adaptive/CarPolicy.java
index d81f54e36f..5f0ef3de67 100644
--- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/adaptive/CarPolicy.java
+++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/adaptive/CarPolicy.java
@@ -25,6 +25,7 @@
import com.github.benmanes.caffeine.cache.simulator.policy.PolicyStats;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableSet;
+import com.google.common.primitives.Ints;
import com.typesafe.config.Config;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
@@ -61,9 +62,9 @@ public final class CarPolicy implements KeyOnlyPolicy {
public CarPolicy(Config config) {
BasicSettings settings = new BasicSettings(config);
+ this.maximumSize = Ints.checkedCast(settings.maximumSize());
this.policyStats = new PolicyStats("adaptive.Car");
this.data = new Long2ObjectOpenHashMap<>();
- this.maximumSize = settings.maximumSize();
this.headT1 = new Node();
this.headT2 = new Node();
this.headB1 = new Node();
diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/adaptive/CartPolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/adaptive/CartPolicy.java
index bc6f969aaa..f3b78b7303 100644
--- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/adaptive/CartPolicy.java
+++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/adaptive/CartPolicy.java
@@ -25,6 +25,7 @@
import com.github.benmanes.caffeine.cache.simulator.policy.PolicyStats;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableSet;
+import com.google.common.primitives.Ints;
import com.typesafe.config.Config;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
@@ -65,9 +66,9 @@ public final class CartPolicy implements KeyOnlyPolicy {
public CartPolicy(Config config) {
BasicSettings settings = new BasicSettings(config);
+ this.maximumSize = Ints.checkedCast(settings.maximumSize());
this.policyStats = new PolicyStats("adaptive.Cart");
this.data = new Long2ObjectOpenHashMap<>();
- this.maximumSize = settings.maximumSize();
this.headT1 = new Node();
this.headT2 = new Node();
this.headB1 = new Node();
diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/irr/ClockProPolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/irr/ClockProPolicy.java
index f7ba43de79..46636fe418 100644
--- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/irr/ClockProPolicy.java
+++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/irr/ClockProPolicy.java
@@ -25,6 +25,7 @@
import com.github.benmanes.caffeine.cache.simulator.policy.Policy.KeyOnlyPolicy;
import com.github.benmanes.caffeine.cache.simulator.policy.PolicyStats;
import com.google.common.collect.ImmutableSet;
+import com.google.common.primitives.Ints;
import com.typesafe.config.Config;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
@@ -86,10 +87,10 @@ public final class ClockProPolicy implements KeyOnlyPolicy {
public ClockProPolicy(Config config) {
BasicSettings settings = new BasicSettings(config);
+ maximumSize = Ints.checkedCast(settings.maximumSize());
policyStats = new PolicyStats("irr.ClockPro");
- maximumColdSize = settings.maximumSize();
data = new Long2ObjectOpenHashMap<>();
- maximumSize = settings.maximumSize();
+ maximumColdSize = maximumSize;
// All the hands move in the clockwise direction
handHot = handCold = handTest = null;
diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/irr/DClockPolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/irr/DClockPolicy.java
index d8d59c44fc..48fbdb342a 100644
--- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/irr/DClockPolicy.java
+++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/irr/DClockPolicy.java
@@ -27,6 +27,7 @@
import com.github.benmanes.caffeine.cache.simulator.policy.Policy.KeyOnlyPolicy;
import com.github.benmanes.caffeine.cache.simulator.policy.PolicyStats;
import com.google.common.base.MoreObjects;
+import com.google.common.primitives.Ints;
import com.typesafe.config.Config;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
@@ -66,9 +67,9 @@ public final class DClockPolicy implements KeyOnlyPolicy {
public DClockPolicy(DClockSettings settings, double percentActive) {
this.policyStats = new PolicyStats("irr.DClock (active: %d%%)", (int) (100 * percentActive));
- this.maxActive = (int) (percentActive * settings.maximumSize());
+ this.maximumSize = Ints.checkedCast(settings.maximumSize());
+ this.maxActive = (int) (percentActive * maximumSize);
this.data = new Long2ObjectOpenHashMap<>();
- this.maximumSize = settings.maximumSize();
this.headNonResident = new Node();
this.headInactive = new Node();
this.headActive = new Node();
diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/irr/FrdPolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/irr/FrdPolicy.java
index db47cf72d5..9ea3ca0ab0 100644
--- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/irr/FrdPolicy.java
+++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/irr/FrdPolicy.java
@@ -25,6 +25,7 @@
import com.github.benmanes.caffeine.cache.simulator.policy.PolicyStats;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableSet;
+import com.google.common.primitives.Ints;
import com.typesafe.config.Config;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
@@ -62,11 +63,11 @@ public final class FrdPolicy implements KeyOnlyPolicy {
public FrdPolicy(Config config) {
FrdSettings settings = new FrdSettings(config);
- this.maximumMainResidentSize = (int) (settings.maximumSize() * settings.percentMain());
- this.maximumFilterSize = settings.maximumSize() - maximumMainResidentSize;
+ this.maximumSize = Ints.checkedCast(settings.maximumSize());
+ this.maximumMainResidentSize = (int) (maximumSize * settings.percentMain());
+ this.maximumFilterSize = maximumSize - maximumMainResidentSize;
this.policyStats = new PolicyStats("irr.Frd");
this.data = new Long2ObjectOpenHashMap<>();
- this.maximumSize = settings.maximumSize();
this.headFilter = new Node();
this.headMain = new Node();
}
diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/irr/HillClimberFrdPolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/irr/HillClimberFrdPolicy.java
index 0e576ae7e5..96d487a676 100644
--- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/irr/HillClimberFrdPolicy.java
+++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/irr/HillClimberFrdPolicy.java
@@ -25,6 +25,7 @@
import com.github.benmanes.caffeine.cache.simulator.policy.PolicyStats;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableSet;
+import com.google.common.primitives.Ints;
import com.typesafe.config.Config;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
@@ -60,16 +61,16 @@ public final class HillClimberFrdPolicy implements KeyOnlyPolicy {
public HillClimberFrdPolicy(Config config) {
FrdSettings settings = new FrdSettings(config);
- this.maximumMainResidentSize = (int) (settings.maximumSize() * settings.percentMain());
- this.maximumFilterSize = settings.maximumSize() - maximumMainResidentSize;
+ this.maximumSize = Ints.checkedCast(settings.maximumSize());
+ this.maximumMainResidentSize = (int) (maximumSize * settings.percentMain());
+ this.maximumFilterSize = maximumSize - maximumMainResidentSize;
this.policyStats = new PolicyStats("irr.AdaptiveFrd");
this.data = new Long2ObjectOpenHashMap<>();
- this.maximumSize = settings.maximumSize();
this.headFilter = new Node();
this.headMain = new Node();
- this.sampleSize = 10 * settings.maximumSize();
- this.pivot = (int) (0.05 * settings.maximumSize());
+ this.pivot = (int) (0.05 * maximumSize);
+ this.sampleSize = 10 * maximumSize;
this.tolerance = 100d * 0;
}
diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/irr/IndicatorFrdPolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/irr/IndicatorFrdPolicy.java
index 1cc7c0afee..e6ead44c78 100644
--- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/irr/IndicatorFrdPolicy.java
+++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/irr/IndicatorFrdPolicy.java
@@ -26,6 +26,7 @@
import com.github.benmanes.caffeine.cache.simulator.policy.sketch.Indicator;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableSet;
+import com.google.common.primitives.Ints;
import com.typesafe.config.Config;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
@@ -54,11 +55,11 @@ public final class IndicatorFrdPolicy implements KeyOnlyPolicy {
public IndicatorFrdPolicy(Config config) {
FrdSettings settings = new FrdSettings(config);
this.period = settings.period();
- this.maximumMainResidentSize = (int) (settings.maximumSize() * settings.percentMain());
- this.maximumFilterSize = settings.maximumSize() - maximumMainResidentSize;
+ this.maximumSize = Ints.checkedCast(settings.maximumSize());
+ this.maximumMainResidentSize = (int) (maximumSize * settings.percentMain());
+ this.maximumFilterSize = maximumSize - maximumMainResidentSize;
this.policyStats = new PolicyStats("irr.AdaptiveFrd");
this.data = new Long2ObjectOpenHashMap<>();
- this.maximumSize = settings.maximumSize();
this.headFilter = new Node();
this.headMain = new Node();
this.indicator = new Indicator(config);
diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/irr/LirsPolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/irr/LirsPolicy.java
index ad6be10804..bc1d74a9f4 100644
--- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/irr/LirsPolicy.java
+++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/irr/LirsPolicy.java
@@ -27,6 +27,7 @@
import com.github.benmanes.caffeine.cache.simulator.policy.PolicyStats;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableSet;
+import com.google.common.primitives.Ints;
import com.typesafe.config.Config;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
@@ -78,11 +79,11 @@ public final class LirsPolicy implements KeyOnlyPolicy {
public LirsPolicy(Config config) {
LirsSettings settings = new LirsSettings(config);
- this.maximumNonResidentSize = (int) (settings.maximumSize() * settings.nonResidentMultiplier());
- this.maximumHotSize = (int) (settings.maximumSize() * settings.percentHot());
+ this.maximumSize = Ints.checkedCast(settings.maximumSize());
+ this.maximumNonResidentSize = (int) (maximumSize * settings.nonResidentMultiplier());
+ this.maximumHotSize = (int) (maximumSize * settings.percentHot());
this.policyStats = new PolicyStats("irr.Lirs");
this.data = new Long2ObjectOpenHashMap<>();
- this.maximumSize = settings.maximumSize();
this.evicted = new ArrayList<>();
this.headNR = new Node();
this.headS = new Node();
diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/linked/FrequentlyUsedPolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/linked/FrequentlyUsedPolicy.java
index 71cd9c5757..fce5acd722 100644
--- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/linked/FrequentlyUsedPolicy.java
+++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/linked/FrequentlyUsedPolicy.java
@@ -30,6 +30,7 @@
import com.github.benmanes.caffeine.cache.simulator.policy.Policy.KeyOnlyPolicy;
import com.github.benmanes.caffeine.cache.simulator.policy.PolicyStats;
import com.google.common.base.MoreObjects;
+import com.google.common.primitives.Ints;
import com.typesafe.config.Config;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
@@ -50,11 +51,11 @@ public final class FrequentlyUsedPolicy implements KeyOnlyPolicy {
final int maximumSize;
public FrequentlyUsedPolicy(Admission admission, EvictionPolicy policy, Config config) {
+ BasicSettings settings = new BasicSettings(config);
this.policyStats = new PolicyStats(admission.format("linked." + policy.label()));
+ this.maximumSize = Ints.checkedCast(settings.maximumSize());
this.admittor = admission.from(config, policyStats);
- BasicSettings settings = new BasicSettings(config);
this.data = new Long2ObjectOpenHashMap<>();
- this.maximumSize = settings.maximumSize();
this.policy = requireNonNull(policy);
this.freq0 = new FrequencyNode();
}
diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/linked/LinkedPolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/linked/LinkedPolicy.java
index 50e41591a0..882af8bc6a 100644
--- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/linked/LinkedPolicy.java
+++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/linked/LinkedPolicy.java
@@ -15,11 +15,10 @@
*/
package com.github.benmanes.caffeine.cache.simulator.policy.linked;
+import static com.github.benmanes.caffeine.cache.simulator.policy.Policy.Characteristic.WEIGHTED;
import static java.util.Locale.US;
import static java.util.stream.Collectors.toSet;
-import static com.github.benmanes.caffeine.cache.simulator.policy.Policy.Characteristic.WEIGHTED;
-
import java.util.Set;
import org.apache.commons.lang3.StringUtils;
@@ -29,7 +28,6 @@
import com.github.benmanes.caffeine.cache.simulator.admission.Admittor;
import com.github.benmanes.caffeine.cache.simulator.policy.AccessEvent;
import com.github.benmanes.caffeine.cache.simulator.policy.Policy;
-import com.github.benmanes.caffeine.cache.simulator.policy.Policy.Characteristic;
import com.github.benmanes.caffeine.cache.simulator.policy.PolicyStats;
import com.google.common.base.MoreObjects;
import com.google.common.collect.Sets;
@@ -49,13 +47,14 @@ public final class LinkedPolicy implements Policy {
final PolicyStats policyStats;
final EvictionPolicy policy;
final Admittor admittor;
- final int maximumSize;
+ final long maximumSize;
final Node sentinel;
- int currentSize;
+ long currentSize;
public LinkedPolicy(Admission admission, EvictionPolicy policy, Config config) {
this.policyStats = new PolicyStats(admission.format("linked." + policy.label()));
this.admittor = admission.from(config, policyStats);
+
BasicSettings settings = new BasicSettings(config);
this.data = new Long2ObjectOpenHashMap<>();
this.maximumSize = settings.maximumSize();
@@ -73,14 +72,14 @@ public static Set policies(Config config, EvictionPolicy policy) {
@Override
public Set characteristics() {
- return Sets.immutableEnumSet(WEIGHTED);
+ return Sets.immutableEnumSet(WEIGHTED);
}
@Override
public PolicyStats stats() {
return policyStats;
}
-
+
@Override
public void record(AccessEvent event) {
final int weight = event.weight();
@@ -100,7 +99,11 @@ public void record(AccessEvent event) {
evict(node);
} else {
policyStats.recordWeightedHit(weight);
+ currentSize += (weight - old.weight);
+ old.weight = weight;
+
policy.onAccess(old, policyStats);
+ evict(old);
}
}
@@ -110,7 +113,7 @@ private void evict(Node candidate) {
while (currentSize > maximumSize) {
Node victim = policy.findVictim(sentinel, policyStats);
policyStats.recordEviction();
-
+
boolean admit = admittor.admit(candidate.key, victim.key);
if (admit) {
evictEntry(victim);
diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/linked/MultiQueuePolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/linked/MultiQueuePolicy.java
index a9267c5660..c4e59c7dc6 100644
--- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/linked/MultiQueuePolicy.java
+++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/linked/MultiQueuePolicy.java
@@ -27,6 +27,7 @@
import com.github.benmanes.caffeine.cache.simulator.policy.PolicyStats;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableSet;
+import com.google.common.primitives.Ints;
import com.typesafe.config.Config;
import it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap;
@@ -65,12 +66,12 @@ public final class MultiQueuePolicy implements KeyOnlyPolicy {
public MultiQueuePolicy(Config config) {
MultiQueueSettings settings = new MultiQueueSettings(config);
+ maximumSize = Ints.checkedCast(settings.maximumSize());
policyStats = new PolicyStats("linked.MultiQueue");
threshold = new long[settings.numberOfQueues()];
headQ = new Node[settings.numberOfQueues()];
out = new Long2ObjectLinkedOpenHashMap<>();
data = new Long2ObjectOpenHashMap<>();
- maximumSize = settings.maximumSize();
lifetime = settings.lifetime();
Arrays.setAll(headQ, Node::sentinel);
diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/linked/S4LruPolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/linked/S4LruPolicy.java
index 2465855084..9f302a7d87 100644
--- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/linked/S4LruPolicy.java
+++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/linked/S4LruPolicy.java
@@ -28,6 +28,7 @@
import com.github.benmanes.caffeine.cache.simulator.policy.Policy.KeyOnlyPolicy;
import com.github.benmanes.caffeine.cache.simulator.policy.PolicyStats;
import com.google.common.base.MoreObjects;
+import com.google.common.primitives.Ints;
import com.typesafe.config.Config;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
@@ -55,11 +56,11 @@ public final class S4LruPolicy implements KeyOnlyPolicy {
private final int levels;
public S4LruPolicy(Admission admission, Config config) {
+ S4LruSettings settings = new S4LruSettings(config);
this.policyStats = new PolicyStats(admission.format("linked.S4Lru"));
+ this.maximumSize = Ints.checkedCast(settings.maximumSize());
this.admittor = admission.from(config, policyStats);
- S4LruSettings settings = new S4LruSettings(config);
this.data = new Long2ObjectOpenHashMap<>();
- this.maximumSize = settings.maximumSize();
this.levels = settings.levels();
this.headQ = new Node[levels];
this.sizeQ = new int[levels];
diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/linked/SegmentedLruPolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/linked/SegmentedLruPolicy.java
index 095115c3ba..820f28bf45 100644
--- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/linked/SegmentedLruPolicy.java
+++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/linked/SegmentedLruPolicy.java
@@ -27,6 +27,7 @@
import com.github.benmanes.caffeine.cache.simulator.policy.Policy.KeyOnlyPolicy;
import com.github.benmanes.caffeine.cache.simulator.policy.PolicyStats;
import com.google.common.base.MoreObjects;
+import com.google.common.primitives.Ints;
import com.typesafe.config.Config;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
@@ -70,8 +71,8 @@ public SegmentedLruPolicy(Admission admission, Config config) {
SegmentedLruSettings settings = new SegmentedLruSettings(config);
this.headProtected = new Node();
this.headProbation = new Node();
- this.maximumSize = settings.maximumSize();
this.data = new Long2ObjectOpenHashMap<>();
+ this.maximumSize = Ints.checkedCast(settings.maximumSize());
this.maxProtected = (int) (maximumSize * settings.percentProtected());
}
diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/opt/ClairvoyantPolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/opt/ClairvoyantPolicy.java
index 1af29a66bd..aafb18e745 100644
--- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/opt/ClairvoyantPolicy.java
+++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/opt/ClairvoyantPolicy.java
@@ -24,6 +24,7 @@
import com.github.benmanes.caffeine.cache.simulator.policy.Policy;
import com.github.benmanes.caffeine.cache.simulator.policy.PolicyStats;
import com.google.common.collect.ImmutableSet;
+import com.google.common.primitives.Ints;
import com.typesafe.config.Config;
import it.unimi.dsi.fastutil.ints.IntArrayFIFOQueue;
@@ -51,10 +52,10 @@ public final class ClairvoyantPolicy implements Policy {
public ClairvoyantPolicy(Config config) {
BasicSettings settings = new BasicSettings(config);
+ maximumSize = Ints.checkedCast(settings.maximumSize());
policyStats = new PolicyStats("opt.Clairvoyant");
accessTimes = new Long2ObjectOpenHashMap<>();
infiniteTimestamp = Integer.MAX_VALUE;
- maximumSize = settings.maximumSize();
future = new ArrayDeque<>(maximumSize);
data = new IntRBTreeSet();
}
diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/product/Cache2kPolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/product/Cache2kPolicy.java
index 399c3cdccc..6703a3532b 100644
--- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/product/Cache2kPolicy.java
+++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/product/Cache2kPolicy.java
@@ -43,7 +43,7 @@ public final class Cache2kPolicy implements Policy {
private final Cache cache;
private final PolicyStats policyStats;
- private final int maximumSize;
+ private final long maximumSize;
public Cache2kPolicy(Config config) {
logger.setLevel(Level.WARNING);
diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/product/CaffeinePolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/product/CaffeinePolicy.java
index 2a313cc8c8..1b2d0aaa14 100644
--- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/product/CaffeinePolicy.java
+++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/product/CaffeinePolicy.java
@@ -28,6 +28,7 @@
import com.github.benmanes.caffeine.cache.simulator.policy.PolicyStats;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
+import com.google.common.primitives.Ints;
import com.typesafe.config.Config;
/**
@@ -51,7 +52,7 @@ public CaffeinePolicy(Config config, Set characteristics) {
builder.weigher((key, value) -> value.weight());
} else {
builder.maximumSize(settings.maximumSize());
- builder.initialCapacity(settings.maximumSize());
+ builder.initialCapacity(Ints.saturatedCast(settings.maximumSize()));
}
cache = builder.build();
}
diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/product/CollisionPolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/product/CollisionPolicy.java
index 7983ebdca6..1f6a0a994e 100644
--- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/product/CollisionPolicy.java
+++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/product/CollisionPolicy.java
@@ -27,6 +27,7 @@
import com.github.benmanes.caffeine.cache.simulator.policy.Policy;
import com.github.benmanes.caffeine.cache.simulator.policy.Policy.KeyOnlyPolicy;
import com.github.benmanes.caffeine.cache.simulator.policy.PolicyStats;
+import com.google.common.primitives.Ints;
import com.typesafe.config.Config;
import systems.comodal.collision.cache.CollisionBuilder;
@@ -45,9 +46,9 @@ public final class CollisionPolicy implements KeyOnlyPolicy {
private int trackedSize;
public CollisionPolicy(CollisionSettings settings, Density density) {
- policyStats = new PolicyStats(String.format("product.Collision (%s)",
- StringUtils.capitalize(density.name().toLowerCase(US))));
- maximumSize = settings.maximumSize();
+ policyStats = new PolicyStats("product.Collision (%s)",
+ StringUtils.capitalize(density.name().toLowerCase(US)));
+ maximumSize = Ints.checkedCast(settings.maximumSize());
CollisionBuilder