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 builder = CollisionCache .withCapacity(maximumSize) diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/product/Ehcache3Policy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/product/Ehcache3Policy.java index fb6047dc0c..e5563179b7 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/product/Ehcache3Policy.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/product/Ehcache3Policy.java @@ -40,8 +40,9 @@ public final class Ehcache3Policy implements KeyOnlyPolicy { private final Cache cache; private final CacheManager cacheManager; private final PolicyStats policyStats; - private final int maximumSize; - private int size; + private final long maximumSize; + + private long size; @SuppressWarnings("PMD.CloseResource") public Ehcache3Policy(Config config) { diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/product/ExpiringMapPolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/product/ExpiringMapPolicy.java index c77646a7ae..64f0916d7b 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/product/ExpiringMapPolicy.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/product/ExpiringMapPolicy.java @@ -24,6 +24,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 net.jodah.expiringmap.ExpirationPolicy; @@ -42,8 +43,8 @@ public ExpiringMapPolicy(Config config) { policyStats = new PolicyStats("product.ExpiringMap"); ExpiringMapSettings settings = new ExpiringMapSettings(config); cache = ExpiringMap.builder() + .maxSize(Ints.checkedCast(settings.maximumSize())) .expirationPolicy(settings.policy()) - .maxSize(settings.maximumSize()) .build(); } diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/product/GuavaPolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/product/GuavaPolicy.java index e787f62144..5ba54da092 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/product/GuavaPolicy.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/product/GuavaPolicy.java @@ -43,7 +43,6 @@ public GuavaPolicy(Config config) { BasicSettings settings = new BasicSettings(config); cache = CacheBuilder.newBuilder() .maximumWeight(settings.maximumSize()) - .initialCapacity(settings.maximumSize()) .weigher((Long key, AccessEvent value) -> value.weight()) .removalListener(notification -> policyStats.recordEviction()) .build(); diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/product/OhcPolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/product/OhcPolicy.java index dda9742274..410ee550cd 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/product/OhcPolicy.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/product/OhcPolicy.java @@ -55,8 +55,8 @@ public OhcPolicy(OhcSettings settings, Eviction policy) { .keySerializer(longSerializer) .eviction(policy) .build(); - policyStats = new PolicyStats(String.format("product.OHC (%s)", - (policy == Eviction.LRU) ? "Lru" : "W-TinyLfu")); + policyStats = new PolicyStats("product.OHC (%s)", + (policy == Eviction.LRU) ? "Lru" : "W-TinyLfu"); } /** Returns all variations of this policy based on the configuration parameters. */ diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/product/TCachePolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/product/TCachePolicy.java index 84429c2c5f..e5b6427a65 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/product/TCachePolicy.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/product/TCachePolicy.java @@ -24,6 +24,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.trivago.triava.tcache.Cache; import com.trivago.triava.tcache.TCacheFactory; import com.trivago.triava.tcache.eviction.EvictionInterface; @@ -44,7 +45,7 @@ public TCachePolicy(Config config) { TCacheSettings settings = new TCacheSettings(config); policyStats = new PolicyStats("product.TCache"); cache = TCacheFactory.standardFactory().builder() - .setMaxElements(settings.maximumSize()) + .setMaxElements(Ints.checkedCast(settings.maximumSize())) .setEvictionClass(settings.policy()) .setStatistics(true) .build(); diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sampled/SampledPolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sampled/SampledPolicy.java index 643700e19e..5fc8f1194d 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sampled/SampledPolicy.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sampled/SampledPolicy.java @@ -34,6 +34,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; @@ -69,10 +70,10 @@ public SampledPolicy(Admission admission, EvictionPolicy policy, Config config) this.admittor = admission.from(config, policyStats); SampledSettings settings = new SampledSettings(config); + this.maximumSize = Ints.checkedCast(settings.maximumSize()); this.sampleStrategy = settings.sampleStrategy(); this.random = new Random(settings.randomSeed()); this.data = new Long2ObjectOpenHashMap<>(); - this.maximumSize = settings.maximumSize(); this.sampleSize = settings.sampleSize(); this.table = new Node[maximumSize + 1]; this.policy = policy; diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/WindowTinyLfuPolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/WindowTinyLfuPolicy.java index 18fa19558f..68c7a392f4 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/WindowTinyLfuPolicy.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/WindowTinyLfuPolicy.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; @@ -67,15 +68,14 @@ public final class WindowTinyLfuPolicy implements KeyOnlyPolicy { private int sizeProtected; public WindowTinyLfuPolicy(double percentMain, WindowTinyLfuSettings settings) { - String name = String.format("sketch.WindowTinyLfu (%.0f%%)", 100 * (1.0d - percentMain)); - this.policyStats = new PolicyStats(name); + this.policyStats = new PolicyStats("sketch.WindowTinyLfu (%.0f%%)", 100 * (1.0d - percentMain)); this.admittor = new TinyLfu(settings.config(), policyStats); + this.maximumSize = Ints.checkedCast(settings.maximumSize()); - int maxMain = (int) (settings.maximumSize() * percentMain); + int maxMain = (int) (maximumSize * percentMain); this.maxProtected = (int) (maxMain * settings.percentMainProtected()); - this.maxWindow = settings.maximumSize() - maxMain; this.data = new Long2ObjectOpenHashMap<>(); - this.maximumSize = settings.maximumSize(); + this.maxWindow = maximumSize - maxMain; this.headProtected = new Node(); this.headProbation = new Node(); this.headWindow = new Node(); diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/HillClimberWindowTinyLfuPolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/HillClimberWindowTinyLfuPolicy.java index c9329961d2..0ab5ec6113 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/HillClimberWindowTinyLfuPolicy.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/HillClimberWindowTinyLfuPolicy.java @@ -39,6 +39,7 @@ import com.github.benmanes.caffeine.cache.simulator.policy.sketch.climbing.HillClimber.Adaptation; import com.github.benmanes.caffeine.cache.simulator.policy.sketch.climbing.HillClimber.QueueType; import com.google.common.base.MoreObjects; +import com.google.common.primitives.Ints; import com.typesafe.config.Config; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; @@ -75,12 +76,12 @@ public final class HillClimberWindowTinyLfuPolicy implements KeyOnlyPolicy { public HillClimberWindowTinyLfuPolicy(HillClimberType strategy, double percentMain, HillClimberWindowTinyLfuSettings settings) { - - int maxMain = (int) (settings.maximumSize() * percentMain); + this.maximumSize = Ints.checkedCast(settings.maximumSize()); + int maxMain = (int) (maximumSize * percentMain); this.maxProtected = (int) (maxMain * settings.percentMainProtected()); - this.maxWindow = settings.maximumSize() - maxMain; + this.maxWindow = maximumSize - maxMain; + this.data = new Long2ObjectOpenHashMap<>(); - this.maximumSize = settings.maximumSize(); this.headProtected = new Node(); this.headProbation = new Node(); this.headWindow = new Node(); diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/gradient/Adam.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/gradient/Adam.java index 35a824eb0c..c56ebde708 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/gradient/Adam.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/gradient/Adam.java @@ -19,6 +19,7 @@ import com.github.benmanes.caffeine.cache.simulator.BasicSettings; import com.github.benmanes.caffeine.cache.simulator.policy.sketch.climbing.AbstractClimber; +import com.google.common.primitives.Ints; import com.typesafe.config.Config; /** @@ -40,8 +41,9 @@ public final class Adam extends AbstractClimber { public Adam(Config config) { AdamSettings settings = new AdamSettings(config); - sampleSize = (int) (settings.percentSample() * settings.maximumSize()); - stepSize = (int) (settings.percentPivot() * settings.maximumSize()); + int maximumSize = Ints.checkedCast(settings.maximumSize()); + sampleSize = (int) (settings.percentSample() * maximumSize); + stepSize = (int) (settings.percentPivot() * maximumSize); epsilon = settings.epsilon(); beta1 = settings.beta1(); beta2 = settings.beta2(); diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/gradient/AmsGrad.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/gradient/AmsGrad.java index 306bb0df98..7f7419b9a7 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/gradient/AmsGrad.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/gradient/AmsGrad.java @@ -19,6 +19,7 @@ import com.github.benmanes.caffeine.cache.simulator.BasicSettings; import com.github.benmanes.caffeine.cache.simulator.policy.sketch.climbing.AbstractClimber; +import com.google.common.primitives.Ints; import com.typesafe.config.Config; /** @@ -41,8 +42,9 @@ public final class AmsGrad extends AbstractClimber { public AmsGrad(Config config) { AmsGradSettings settings = new AmsGradSettings(config); - sampleSize = (int) (settings.percentSample() * settings.maximumSize()); - stepSize = (int) (settings.percentPivot() * settings.maximumSize()); + int maximumSize = Ints.checkedCast(settings.maximumSize()); + sampleSize = (int) (settings.percentSample() * maximumSize); + stepSize = (int) (settings.percentPivot() * maximumSize); epsilon = settings.epsilon(); beta1 = settings.beta1(); beta2 = settings.beta2(); diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/gradient/Nadam.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/gradient/Nadam.java index ce7e35dba5..96159c8d02 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/gradient/Nadam.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/gradient/Nadam.java @@ -19,6 +19,7 @@ import com.github.benmanes.caffeine.cache.simulator.BasicSettings; import com.github.benmanes.caffeine.cache.simulator.policy.sketch.climbing.AbstractClimber; +import com.google.common.primitives.Ints; import com.typesafe.config.Config; /** @@ -41,8 +42,9 @@ public final class Nadam extends AbstractClimber { public Nadam(Config config) { NadamSettings settings = new NadamSettings(config); - sampleSize = (int) (settings.percentSample() * settings.maximumSize()); - stepSize = (int) (settings.percentPivot() * settings.maximumSize()); + int maximumSize = Ints.checkedCast(settings.maximumSize()); + sampleSize = (int) (settings.percentSample() * maximumSize); + stepSize = (int) (settings.percentPivot() * maximumSize); epsilon = settings.epsilon(); beta1 = settings.beta1(); beta2 = settings.beta2(); diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/gradient/Stochastic.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/gradient/Stochastic.java index 06e0f73723..12d90fe9bc 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/gradient/Stochastic.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/gradient/Stochastic.java @@ -21,6 +21,7 @@ import com.github.benmanes.caffeine.cache.simulator.BasicSettings; import com.github.benmanes.caffeine.cache.simulator.policy.sketch.climbing.AbstractClimber; +import com.google.common.primitives.Ints; import com.typesafe.config.Config; /** @@ -52,8 +53,9 @@ public final class Stochastic extends AbstractClimber { public Stochastic(Config config) { StochasticSettings settings = new StochasticSettings(config); - sampleSize = (int) (settings.percentSample() * settings.maximumSize()); - stepSize = (int) (settings.percentPivot() * settings.maximumSize()); + int maximumSize = Ints.checkedCast(settings.maximumSize()); + sampleSize = (int) (settings.percentSample() * maximumSize); + stepSize = (int) (settings.percentPivot() * maximumSize); acceleration = settings.acceleration(); beta = settings.beta(); } diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/hill/SimpleClimber.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/hill/SimpleClimber.java index 9869974792..5bbda302b3 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/hill/SimpleClimber.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/hill/SimpleClimber.java @@ -17,6 +17,7 @@ import com.github.benmanes.caffeine.cache.simulator.BasicSettings; import com.github.benmanes.caffeine.cache.simulator.policy.sketch.climbing.AbstractClimber; +import com.google.common.primitives.Ints; import com.typesafe.config.Config; /** @@ -37,8 +38,9 @@ public final class SimpleClimber extends AbstractClimber { public SimpleClimber(Config config) { SimpleClimberSettings settings = new SimpleClimberSettings(config); - this.initialSampleSize = (int) (settings.percentSample() * settings.maximumSize()); - this.initialStepSize = settings.percentPivot() * settings.maximumSize(); + int maximumSize = Ints.checkedCast(settings.maximumSize()); + this.initialSampleSize = (int) (settings.percentSample() * maximumSize); + this.initialStepSize = settings.percentPivot() * maximumSize; this.restartThreshold = settings.restartThreshold(); this.sampleDecayRate = settings.sampleDecayRate(); this.stepDecayRate = settings.stepDecayRate(); diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/hill/SimulatedAnnealingClimber.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/hill/SimulatedAnnealingClimber.java index b09f4492b7..4c7f6f9091 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/hill/SimulatedAnnealingClimber.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/hill/SimulatedAnnealingClimber.java @@ -19,6 +19,7 @@ import com.github.benmanes.caffeine.cache.simulator.BasicSettings; import com.github.benmanes.caffeine.cache.simulator.policy.sketch.climbing.AbstractClimber; +import com.google.common.primitives.Ints; import com.typesafe.config.Config; /** @@ -40,8 +41,9 @@ public final class SimulatedAnnealingClimber extends AbstractClimber { public SimulatedAnnealingClimber(Config config) { SimulatedAnnealingSettings settings = new SimulatedAnnealingSettings(config); - this.initialStepSize = (int) (settings.percentPivot() * settings.maximumSize()); - this.sampleSize = (int) (settings.percentSample() * settings.maximumSize()); + int maximumSize = Ints.checkedCast(settings.maximumSize()); + this.initialStepSize = (int) (settings.percentPivot() * maximumSize); + this.sampleSize = (int) (settings.percentSample() * maximumSize); this.coolDownTolerance = 100 * settings.coolDownTolerance(); this.restartTolerance = 100 * settings.restartTolerance(); this.random = new Random(settings.randomSeed()); diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/inference/IndicatorClimber.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/inference/IndicatorClimber.java index f8f0ab4b4e..389526ce90 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/inference/IndicatorClimber.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/inference/IndicatorClimber.java @@ -18,6 +18,7 @@ import com.github.benmanes.caffeine.cache.simulator.policy.sketch.Indicator; import com.github.benmanes.caffeine.cache.simulator.policy.sketch.climbing.HillClimber; import com.github.benmanes.caffeine.cache.simulator.policy.sketch.climbing.HillClimberWindowTinyLfuPolicy.HillClimberWindowTinyLfuSettings; +import com.google.common.primitives.Ints; import com.typesafe.config.Config; /** @@ -33,8 +34,8 @@ public final class IndicatorClimber implements HillClimber { public IndicatorClimber(Config config) { HillClimberWindowTinyLfuSettings settings = new HillClimberWindowTinyLfuSettings(config); + this.cacheSize = Ints.checkedCast(settings.maximumSize()); this.prevPercent = 1 - settings.percentMain().get(0); - this.cacheSize = settings.maximumSize(); this.indicator = new Indicator(config); } diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/sim/MiniSimClimber.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/sim/MiniSimClimber.java index 88aeb948ef..a28484b22c 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/sim/MiniSimClimber.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/climbing/sim/MiniSimClimber.java @@ -23,6 +23,7 @@ import com.github.benmanes.caffeine.cache.simulator.policy.sketch.climbing.HillClimber; import com.google.common.hash.HashFunction; import com.google.common.hash.Hashing; +import com.google.common.primitives.Ints; import com.typesafe.config.Config; import com.typesafe.config.ConfigFactory; @@ -50,12 +51,12 @@ public final class MiniSimClimber implements HillClimber { public MiniSimClimber(Config config) { MiniSimSettings settings = new MiniSimSettings(config); - R = (settings.maximumSize() / 1000) > 100 ? 1000 : (settings.maximumSize() / 100); + this.cacheSize = Ints.checkedCast(settings.maximumSize()); + R = (cacheSize / 1000) > 100 ? 1000 : (cacheSize / 100); WindowTinyLfuSettings simulationSettings = new WindowTinyLfuSettings(ConfigFactory - .parseString("maximum-size = " + settings.maximumSize() / R) + .parseString("maximum-size = " + cacheSize / R) .withFallback(config)); this.prevPercent = 1 - settings.percentMain().get(0); - this.cacheSize = settings.maximumSize(); this.period = settings.minisimPeriod(); this.minis = new WindowTinyLfuPolicy[101]; this.prevMisses = new long[101]; diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/feedback/FeedbackTinyLfuPolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/feedback/FeedbackTinyLfuPolicy.java index 655580eb77..42d4da7685 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/feedback/FeedbackTinyLfuPolicy.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/feedback/FeedbackTinyLfuPolicy.java @@ -29,6 +29,7 @@ import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; +import com.google.common.primitives.Ints; import com.typesafe.config.Config; import com.typesafe.config.ConfigFactory; @@ -66,9 +67,9 @@ public final class FeedbackTinyLfuPolicy implements KeyOnlyPolicy { public FeedbackTinyLfuPolicy(Config config) { FeedbackTinyLfuSettings settings = new FeedbackTinyLfuSettings(config); this.policyStats = new PolicyStats("sketch.FeedbackTinyLfu"); + this.maximumSize = Ints.checkedCast(settings.maximumSize()); this.admittor = new TinyLfu(settings.config(), policyStats); this.data = new Long2ObjectOpenHashMap<>(); - this.maximumSize = settings.maximumSize(); this.head = new Node(); maxGain = Math.min(15, settings.maximumInsertionGain()); diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/feedback/FeedbackWindowTinyLfuPolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/feedback/FeedbackWindowTinyLfuPolicy.java index eb962f2350..dd82ed40fe 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/feedback/FeedbackWindowTinyLfuPolicy.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/feedback/FeedbackWindowTinyLfuPolicy.java @@ -30,6 +30,7 @@ import com.github.benmanes.caffeine.cache.simulator.policy.PolicyStats; import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableMap; +import com.google.common.primitives.Ints; import com.typesafe.config.Config; import com.typesafe.config.ConfigFactory; @@ -79,15 +80,15 @@ public final class FeedbackWindowTinyLfuPolicy implements KeyOnlyPolicy { boolean trace; public FeedbackWindowTinyLfuPolicy(double percentMain, FeedbackWindowTinyLfuSettings settings) { - this.policyStats = new PolicyStats(String.format( - "sketch.FeedbackWindowTinyLfu (%.0f%%)", 100 * (1.0d - percentMain))); + this.policyStats = new PolicyStats( + "sketch.FeedbackWindowTinyLfu (%.0f%%)", 100 * (1.0d - percentMain)); this.admittor = new TinyLfu(settings.config(), policyStats); + this.maximumSize = Ints.checkedCast(settings.maximumSize()); - int maxMain = (int) (settings.maximumSize() * percentMain); + int maxMain = (int) (maximumSize * percentMain); this.maxProtected = (int) (maxMain * settings.percentMainProtected()); - this.maxWindow = Math.min(settings.maximumWindowSize(), settings.maximumSize() - maxMain); + this.maxWindow = Math.min(settings.maximumWindowSize(), maximumSize - maxMain); this.data = new Long2ObjectOpenHashMap<>(); - this.maximumSize = settings.maximumSize(); this.headProtected = new Node(); this.headProbation = new Node(); this.headWindow = new Node(); diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/segment/FullySegmentedWindowTinyLfuPolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/segment/FullySegmentedWindowTinyLfuPolicy.java index 124af32321..e9819562d9 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/segment/FullySegmentedWindowTinyLfuPolicy.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/segment/FullySegmentedWindowTinyLfuPolicy.java @@ -29,6 +29,7 @@ import com.github.benmanes.caffeine.cache.simulator.policy.PolicyStats; import com.github.benmanes.caffeine.cache.simulator.policy.linked.SegmentedLruPolicy; import com.google.common.base.MoreObjects; +import com.google.common.primitives.Ints; import com.typesafe.config.Config; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; @@ -62,16 +63,15 @@ public final class FullySegmentedWindowTinyLfuPolicy implements KeyOnlyPolicy { public FullySegmentedWindowTinyLfuPolicy( double percentMain, FullySegmentedWindowTinyLfuSettings settings) { - String name = String.format( + this.policyStats = new PolicyStats( "sketch.FullySegmentedWindowTinyLfu (%.0f%%)", 100 * (1.0d - percentMain)); - this.policyStats = new PolicyStats(name); - int maxMain = (int) (settings.maximumSize() * percentMain); - this.maxWindow = settings.maximumSize() - maxMain; + this.maximumSize = Ints.checkedCast(settings.maximumSize()); + int maxMain = (int) (maximumSize * percentMain); + this.maxWindow = maximumSize - maxMain; this.maxMainProtected = (int) (maxMain * settings.percentMainProtected()); this.maxWindowProtected = (int) (maxWindow * settings.percentWindowProtected()); this.admittor = new TinyLfu(settings.config(), policyStats); this.data = new Long2ObjectOpenHashMap<>(); - this.maximumSize = settings.maximumSize(); this.headWindowProbation = new Node(); this.headWindowProtected = new Node(); this.headMainProbation = new Node(); diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/segment/LruWindowTinyLfuPolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/segment/LruWindowTinyLfuPolicy.java index da52b98448..34181c09ce 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/segment/LruWindowTinyLfuPolicy.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/segment/LruWindowTinyLfuPolicy.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; @@ -52,13 +53,13 @@ public final class LruWindowTinyLfuPolicy implements KeyOnlyPolicy { private int sizeMain; public LruWindowTinyLfuPolicy(double percentMain, LruWindowTinyLfuSettings settings) { - String name = String.format("sketch.LruWindowTinyLfu (%.0f%%)", 100 * (1.0d - percentMain)); - this.policyStats = new PolicyStats(name); - + this.policyStats = new PolicyStats( + "sketch.LruWindowTinyLfu (%.0f%%)", 100 * (1.0d - percentMain)); + int maximumSize = Ints.checkedCast(settings.maximumSize()); this.admittor = new TinyLfu(settings.config(), policyStats); - this.maxMain = (int) (settings.maximumSize() * percentMain); - this.maxWindow = settings.maximumSize() - maxMain; + this.maxMain = (int) (maximumSize * percentMain); this.data = new Long2ObjectOpenHashMap<>(); + this.maxWindow = maximumSize - maxMain; this.headWindow = new Node(); this.headMain = new Node(); } diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/segment/RandomWindowTinyLfuPolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/segment/RandomWindowTinyLfuPolicy.java index c7c8f94723..eeb7da0485 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/segment/RandomWindowTinyLfuPolicy.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/segment/RandomWindowTinyLfuPolicy.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; @@ -51,13 +52,12 @@ public final class RandomWindowTinyLfuPolicy implements KeyOnlyPolicy { int mainSize; public RandomWindowTinyLfuPolicy(double percentMain, RandomWindowTinyLfuSettings settings) { - String name = String.format("sketch.RandomWindowTinyLfu (%.0f%%)", 100 * (1.0d - percentMain)); - policyStats = new PolicyStats(name); - + policyStats = new PolicyStats( + "sketch.RandomWindowTinyLfu (%.0f%%)", 100 * (1.0d - percentMain)); + maximumSize = Ints.checkedCast(settings.maximumSize()); admittor = new TinyLfu(settings.config(), policyStats); random = new Random(settings.randomSeed()); data = new Long2ObjectOpenHashMap<>(); - maximumSize = settings.maximumSize(); int maxMain = (int) (maximumSize * percentMain); window = new Node[maximumSize - maxMain + 1]; diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/segment/S4WindowTinyLfuPolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/segment/S4WindowTinyLfuPolicy.java index 116f201c8c..80509bbded 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/segment/S4WindowTinyLfuPolicy.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/segment/S4WindowTinyLfuPolicy.java @@ -29,6 +29,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,10 @@ public final class S4WindowTinyLfuPolicy implements KeyOnlyPolicy { private int sizeWindow; public S4WindowTinyLfuPolicy(double percentMain, S4WindowTinyLfuSettings settings) { - String name = String.format("sketch.S4WindowTinyLfu (%.0f%%)", 100 * (1.0d - percentMain)); - this.policyStats = new PolicyStats(name); + this.policyStats = new PolicyStats( + "sketch.S4WindowTinyLfu (%.0f%%)", 100 * (1.0d - percentMain)); this.admittor = new TinyLfu(settings.config(), policyStats); - - this.maximumSize = settings.maximumSize(); + this.maximumSize = Ints.checkedCast(settings.maximumSize()); this.maxMain = (int) (maximumSize * percentMain); this.maxWindow = maximumSize - maxMain; this.data = new Long2ObjectOpenHashMap<>(); diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/tinycache/TinyCachePolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/tinycache/TinyCachePolicy.java index 4d7db520e5..ba918211c2 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/tinycache/TinyCachePolicy.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/tinycache/TinyCachePolicy.java @@ -23,6 +23,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; /** @@ -35,7 +36,8 @@ public final class TinyCachePolicy implements KeyOnlyPolicy { public TinyCachePolicy(Config config) { BasicSettings settings = new BasicSettings(config); this.policyStats = new PolicyStats("sketch.TinyCache"); - tinyCache = new TinyCache((int) Math.ceil(settings.maximumSize() / 64.0), + int maximumSize = Ints.checkedCast(settings.maximumSize()); + tinyCache = new TinyCache((int) Math.ceil(maximumSize / 64.0), 64, settings.randomSeed()); } diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/tinycache/TinyCacheWithGhostCachePolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/tinycache/TinyCacheWithGhostCachePolicy.java index 5a0836891e..713e844791 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/tinycache/TinyCacheWithGhostCachePolicy.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/tinycache/TinyCacheWithGhostCachePolicy.java @@ -23,6 +23,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; /** @@ -34,8 +35,9 @@ public final class TinyCacheWithGhostCachePolicy implements KeyOnlyPolicy { public TinyCacheWithGhostCachePolicy(Config config) { BasicSettings settings = new BasicSettings(config); + int maximumSize = Ints.checkedCast(settings.maximumSize()); this.policyStats = new PolicyStats("sketch.TinyCache_GhostCache"); - tinyCache = new TinyCacheWithGhostCache((int) Math.ceil(settings.maximumSize() / 64.0), + tinyCache = new TinyCacheWithGhostCache((int) Math.ceil(maximumSize / 64.0), 64, settings.randomSeed()); } diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/tinycache/WindowTinyCachePolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/tinycache/WindowTinyCachePolicy.java index 5dcee2cd27..3602c11e29 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/tinycache/WindowTinyCachePolicy.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sketch/tinycache/WindowTinyCachePolicy.java @@ -24,6 +24,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; /** @@ -37,15 +38,15 @@ public final class WindowTinyCachePolicy implements KeyOnlyPolicy { public WindowTinyCachePolicy(Config config) { BasicSettings settings = new BasicSettings(config); this.policyStats = new PolicyStats("sketch.WindowTinyCache"); - int maxSize = settings.maximumSize(); + int maxSize = Ints.checkedCast(settings.maximumSize()); if (maxSize <= 64) { window = null; } else { maxSize -= 64; window = new TinyCache(1, 64, 0); } - tinyCache = new TinyCacheWithGhostCache((int) Math.ceil(maxSize / 64.0), - 64, settings.randomSeed()); + tinyCache = new TinyCacheWithGhostCache( + (int) Math.ceil(maxSize / 64.0), 64, settings.randomSeed()); } /** Returns all variations of this policy based on the configuration parameters. */ diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/two_queue/TuQueuePolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/two_queue/TuQueuePolicy.java index 1febca584a..5745a40e02 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/two_queue/TuQueuePolicy.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/two_queue/TuQueuePolicy.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,9 +76,9 @@ public TuQueuePolicy(Config config) { this.headHot = new Node(); this.headWarm = new Node(); this.headCold = new Node(); - this.maximumSize = settings.maximumSize(); this.data = new Long2ObjectOpenHashMap<>(); this.policyStats = new PolicyStats("two-queue.TuQueue"); + this.maximumSize = Ints.checkedCast(settings.maximumSize()); this.maxHot = (int) (maximumSize * settings.percentHot()); this.maxWarm = (int) (maximumSize * settings.percentWarm()); } diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/two_queue/TwoQueuePolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/two_queue/TwoQueuePolicy.java index 3a02cef967..eabeb4614d 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/two_queue/TwoQueuePolicy.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/two_queue/TwoQueuePolicy.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; @@ -67,10 +68,10 @@ public TwoQueuePolicy(Config config) { this.headIn = new Node(); this.headOut = new Node(); this.headMain = new Node(); - this.maximumSize = settings.maximumSize(); this.data = new Long2ObjectOpenHashMap<>(); - this.maxIn = (int) (maximumSize * settings.percentIn()); this.policyStats = new PolicyStats("two-queue.TwoQueue"); + this.maximumSize = Ints.checkedCast(settings.maximumSize()); + this.maxIn = (int) (maximumSize * settings.percentIn()); this.maxOut = (int) (maximumSize * settings.percentOut()); }