Add lru-cache module: LinkedHashMap and hand-rolled DLL LRU, coarse-lock/striped thread-safe variants, broken ReadWriteLock demo, Caffeine reference, 43 tests, JMH harness

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017ic4b4VQVEJWetTT1dYzyJ
This commit is contained in:
2026-10-29 05:52:27 +00:00
co-authored by Claude Sonnet 5.5
parent 4a376b94e9
commit 0457cf4bfb
31 changed files with 1425 additions and 0 deletions
+25
View File
@@ -0,0 +1,25 @@
#!/usr/bin/env bash
# Short JMH run: INDICATIVE only. One fork, 3 x 1s warmup, 5 x 2s measurement per cell.
# On a shared 2-vCPU sandbox the absolute numbers move 10-30% between runs; read the ORDER and
# the SHAPE (who collapses with more threads), not the third digit.
set -euo pipefail
cd "$(dirname "$0")/.."
mkdir -p output
mvn -B -q -T1 compile
mvn -B -q dependency:build-classpath -Dmdep.outputFile=target/cp.txt
CP="target/classes:$(cat target/cp.txt)"
J="java -cp $CP org.openjdk.jmh.Main LruBenchmark -f 1 -wi 3 -w 1 -i 5 -r 2 -tu us"
{
echo "JMH 1.37 / $(java -version 2>&1 | grep -v Picked | head -1)"
echo "cores=$(nproc) loadavg-at-start=$(cut -d' ' -f1-3 /proc/loadavg) (shared sandbox: INDICATIVE)"
echo "workload: get; on miss put. Keys uniform over 2048, capacity 1024. ops/microsecond, higher is better."
echo
echo "### 1 thread, all implementations"
$J -t 1 2>&1 | grep -E '^LruBenchmark|^Benchmark'
for t in 2 4; do
echo
echo "### $t threads, thread-safe implementations only"
$J -t $t -p "impl=synchronizedMap(LinkedHashMap),synchronized,reentrantlock,striped16,striped16-lowbits,caffeine" 2>&1 | grep -E '^LruBenchmark|^Benchmark'
done
} > output/10-jmh-indicative.txt
cat output/10-jmh-indicative.txt