Skip to content

Commit

Permalink
minor clean ups
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-manes committed Jan 2, 2024
1 parent 580d124 commit 3e12130
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 84 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
org.gradle.jvmargs=-Xmx2g -XX:+UseParallelGC -XX:+HeapDumpOnOutOfMemoryError
org.gradle.jvmargs=-Xmx2g -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.java.installations.fromEnv=JDK_CI
systemProp.sonar.gradle.skipCompile=true
org.gradle.configuration-cache=true
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ bouncycastle = "1.70"
cache2k = "2.6.1.Final"
caffeine = "3.1.8"
checker-framework = "3.42.0"
checkstyle = "10.12.6"
checkstyle = "10.12.7"
coherence = "22.06.2"
commons-collections4 = "4.4"
commons-compress = "1.25.0"
Expand Down
2 changes: 1 addition & 1 deletion gradle/plugins/src/main/kotlin/ProjectExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ fun Project.version(major: Int, minor: Int, patch: Int, releaseBuild: Boolean) {
}

fun Project.javaExecJvmArgs(): List<String> {
val jvmArgs = mutableListOf("-XX:+UseParallelGC", "-Xmx4g")
val arguments = findProperty("jvmArgs") as String?
val jvmArgs = mutableListOf("-Xmx4g")
if (arguments != null) {
jvmArgs.addAll(arguments.split(","))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,9 @@ tasks.withType<Javadoc>().configureEach {
"https://guava.dev/releases/${libs.versions.guava.get()}/api/docs/")

if (project != project(":caffeine")) {
val caffeineJavadoc = project(":caffeine").tasks.named<Javadoc>("javadoc")
linksOffline("https://static.javadoc.io/$group/caffeine/$version/",
relativePath(caffeineJavadoc.get().destinationDir!!.path))
dependsOn(caffeineJavadoc)
relativePath(project(":caffeine").layout.buildDirectory.dir("docs/javadoc")))
dependsOn(":caffeine:javadoc")
}
}
}
116 changes: 47 additions & 69 deletions simulator/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,15 @@ tasks.named<JavaExec>("run").configure {
}

tasks.register<Simulate>("simulate") {
group = "Application"
description = "Runs multiple simulations and generates an aggregate report"
dependsOn(tasks.processResources, tasks.compileJava)
classpath = sourceSets["main"].runtimeClasspath
systemProperties = caffeineSystemProperties()
defaultJvmArgs = javaExecJvmArgs()
outputs.upToDateWhen { false }
mainClass = "com.github.benmanes.caffeine.cache.simulator.Simulate"
configureSimulatorTask()
}

tasks.register<Rewrite>("rewrite") {
group = "Application"
description = "Rewrite traces into the format used by other simulators"
dependsOn(tasks.processResources, tasks.compileJava)
classpath = sourceSets["main"].runtimeClasspath
outputs.upToDateWhen { false }
mainClass = "com.github.benmanes.caffeine.cache.simulator.parser.Rewriter"
configureSimulatorTask()
}

eclipse.classpath.file.beforeMerged {
Expand All @@ -104,81 +98,65 @@ eclipse.classpath.file.beforeMerged {
}
}

abstract class Simulate @Inject constructor(@Internal val external: ExecOperations,
@Internal val layout: ProjectLayout) : DefaultTask() {
fun JavaExec.configureSimulatorTask() {

Check warning on line 101 in simulator/build.gradle.kts

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused receiver parameter

Receiver parameter is never used
group = "Application"
dependsOn(tasks.processResources, tasks.compileJava)
classpath(sourceSets["main"].runtimeClasspath)
systemProperties(caffeineSystemProperties())
outputs.upToDateWhen { false }
jvmArgs(javaExecJvmArgs())
}

abstract class Simulate @Inject constructor(
@Internal val projectLayout: ProjectLayout) : JavaExec() {
@Input @Option(option = "maximumSize", description = "The maximum sizes")
var maximumSize = ""
var maximumSize: List<String> = emptyList()
@Input @Option(option = "metric", description = "The metric to compare")
var metric = "Hit Rate"
@Input @Option(option = "theme", description = "The chart theme")
var theme = "light"
@Input @Option(option = "title", description = "The chart title")
var title = ""
@get:Input
abstract val systemProperties: MapProperty<String, Any>
@get:Input
abstract val defaultJvmArgs: ListProperty<String>
@get:InputFiles @get:Classpath
abstract val classpath: Property<FileCollection>
@get:OutputDirectory
val reportDir = File(layout.buildDirectory.get().asFile, "/reports/$name")
@OutputDirectory
val reportDir = File(projectLayout.buildDirectory.get().asFile, "/reports/$name")

@TaskAction
fun run() {
external.javaexec {
mainClass = "com.github.benmanes.caffeine.cache.simulator.Simulate"
systemProperties(this@Simulate.systemProperties.get())
classpath(this@Simulate.classpath)
jvmArgs(defaultJvmArgs.get())

if (maximumSize.isNotEmpty()) {
args("--maximumSize", maximumSize)
}
args("--outputDir", reportDir)
args("--metric", metric)
args("--title", title)
args("--theme", theme)
override fun exec() {
if (maximumSize.isNotEmpty()) {
args("--maximumSize", maximumSize.joinToString(","))
}
args("--outputDir", reportDir)
args("--metric", metric)
args("--title", title)
args("--theme", theme)
super.exec()
}
}

abstract class Rewrite @Inject constructor(@Internal val external: ExecOperations) : DefaultTask() {
@Input @Optional @Option(option = "inputFiles", description = "The trace input files")
abstract class Rewrite : JavaExec() {
@Input @Option(option = "inputFiles", description = "The trace input files")
var inputFiles: List<String> = emptyList()
@get:Input @get:Optional @get:Option(option = "inputFormat", description = "The input format")
abstract val inputFormat: Property<String>
@get:Input @get:Optional @get:Option(option = "outputFile", description = "The output file")
abstract val outputFile: Property<String>
@get:Input @get:Optional @get:Option(option = "outputFormat", description = "The output format")
abstract val outputFormat: Property<String>
@get:InputFiles @get:Classpath
abstract val classpath: Property<FileCollection>
@Input @Option(option = "inputFormat", description = "The input format")
var inputFormat: String = ""
@Input @Option(option = "outputFile", description = "The output file")
var outputFile: String = ""
@Input @Option(option = "outputFormat", description = "The output format")
var outputFormat: String = ""

@TaskAction
fun run() {
external.javaexec {
var help = true
classpath(this@Rewrite.classpath)
mainClass = "com.github.benmanes.caffeine.cache.simulator.parser.Rewriter"
if (inputFiles.isNotEmpty()) {
args("--inputFiles", inputFiles.joinToString(","))
help = false
}
if (inputFormat.isPresent) {
args("--inputFormat", inputFormat.get())
help = false
}
if (outputFile.isPresent) {
args("--outputFile", outputFile.get())
help = false
}
if (outputFormat.isPresent) {
args("--outputFormat", outputFormat.get())
help = false
}
if (help) {
args("--help")
}
override fun exec() {
if (inputFiles.isNotEmpty()) {
args("--inputFiles", inputFiles.joinToString(","))
}
if (outputFormat.isNotEmpty()) {
args("--outputFormat", outputFormat)
}
if (inputFormat.isNotEmpty()) {
args("--inputFormat", inputFormat)
}
if (outputFile.isNotEmpty()) {
args("--outputFile", outputFile)
}
super.exec()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private void onHit(AccessEvent event, Node node) {
node.weight = event.weight();
node.visited = true;

while (size >= maximumSize) {
while (size > maximumSize) {
evict();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
* main region. The small and main regions uses an n-bit clock eviction policy.
* <p>
* This implementation is based on the code provided by the authors in their
* <a href="https://github.com/cacheMon/libCacheSim">repository</a> and the pseudo code in their
* <a href="https://github.com/cacheMon/libCacheSim">repository</a> and the pseudo code in their
* paper <a href="https://dl.acm.org/doi/10.1145/3600006.3613147">FIFO queues are all you need for
* cache eviction</a>. It does not use any of the paper's proposed adaptations for space saving or
* concurrency because that may impact the hit rate. An implementor is encouraged to use a more
Expand Down Expand Up @@ -111,7 +111,7 @@ private void onHit(AccessEvent event, Node node, IntConsumer sizeAdjuster) {
node.weight = event.weight();

policyStats.recordWeightedHit(event.weight());
while ((sizeSmall + sizeMain) >= maximumSize) {
while ((sizeSmall + sizeMain) > maximumSize) {
evict();
}
}
Expand Down Expand Up @@ -147,10 +147,12 @@ private Node insertSmall(long key, int weight) {
return node;
}

@CanIgnoreReturnValue
private Node insertGhost(long key, int weight) {
private void insertGhost(long key, int weight) {
// Bound the number of non-resident entries. While not included in the paper's pseudo code, the
// author's reference implementation adds a similar constraint to avoid uncontrolled growth.
if (weight > maxGhost) {
return;
}
while ((sizeGhost + weight) > maxGhost) {
evictFromGhost();
}
Expand All @@ -159,11 +161,10 @@ private Node insertGhost(long key, int weight) {
node.appendAtHead(sentinelGhost);
dataGhost.put(key, node);
sizeGhost += node.weight;
return node;
}

private void evict() {
if (sizeSmall >= maxSmall) {
if ((sizeSmall >= maxSmall) || dataMain.isEmpty()) {
evictFromSmall();
} else {
evictFromMain();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import com.github.benmanes.caffeine.cache.simulator.policy.PolicyStats.Metric;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedSet;
import com.typesafe.config.Config;

/**
Expand Down Expand Up @@ -78,7 +77,7 @@ private ImmutableList<PolicyStats> getSortedStats(Collection<PolicyStats> result
.filter(header -> header.toLowerCase(US).equals(settings.report().sortBy().toLowerCase(US)))
.findAny().orElseThrow(() -> new IllegalArgumentException(
"Unknown sort order: " + settings.report().sortBy()));
return ImmutableSortedSet.copyOf(comparator(sortBy), results).asList();
return ImmutableList.sortedCopyOf(comparator(sortBy), results);
}

/** Returns the column headers in declaration order. */
Expand Down

0 comments on commit 3e12130

Please sign in to comment.