Runnable jcstress + JUnit companion for the ankurm.com post on the Java Memory Model, double-checked locking, and the volatile fix.
43 lines
1.7 KiB
Bash
Executable File
43 lines
1.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Regenerates every file in output/. Run from the jmm/ directory after `mvn package`.
|
|
#
|
|
# Needs a JDK 25 on PATH (or set JAVA_HOME below) - jcstress-core 0.16's annotation
|
|
# processor is NOT auto-discovered by javac on JDK 25 without -processorpath, which is
|
|
# why the pom's <annotationProcessorPaths> block exists; see output/04-*.txt.
|
|
#
|
|
# The three jcstress runs below use a fixed, non-default JVM config (-jvmArgs) on
|
|
# purpose: without it, jcstress auto-detects and iterates over several compiler-flag
|
|
# combinations, multiplying the number of forked JVMs far past what this sandbox's
|
|
# 2 CPUs can get through in a reasonable time. -f 2 -iters 15 -time 1000 with a fixed
|
|
# JVM config took about 4m45s per test on that hardware.
|
|
set -euo pipefail
|
|
cd "$(dirname "$0")/.."
|
|
|
|
JAR=target/jcstress.jar
|
|
[ -f "$JAR" ] || { echo "Run 'mvn package' first."; exit 1; }
|
|
|
|
run_test() {
|
|
local test_class="$1" out_file="$2"
|
|
echo "==> $test_class"
|
|
{
|
|
echo "\$ java -jar target/jcstress.jar -t $test_class -jvmArgs \"-Xmx256m\" -f 2 -iters 15 -time 1000"
|
|
echo
|
|
} > "$out_file"
|
|
java -jar "$JAR" -t "$test_class" -jvmArgs "-Xmx256m" -f 2 -iters 15 -time 1000 -v 2>/dev/null \
|
|
| awk '/^RUN RESULTS:/{p=1} p==1 && /VM error stream:/{exit} p' >> "$out_file"
|
|
}
|
|
|
|
run_test PlainPublicationTest output/01-plain-publication.txt
|
|
run_test VolatilePublicationTest output/02-volatile-publication.txt
|
|
run_test FinalFieldPublicationTest output/03-final-field-publication.txt
|
|
|
|
echo "==> SingletonBehaviorTest (JUnit)"
|
|
mvn -q test
|
|
{
|
|
echo '$ mvn -q test'
|
|
echo
|
|
cat target/surefire-reports/com.ankurm.jmm.SingletonBehaviorTest.txt
|
|
} > output/05-singleton-behavior.txt
|
|
|
|
echo "Done. output/ regenerated."
|