Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b44MquEzmd9QMkZCd7
127 lines
14 KiB
Bash
Executable File
127 lines
14 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Regenerates every file in output/. Needs JDK 25, 27 and a 28 early-access build on disk.
|
|
# JDK25=/path JDK27=/path JDK28=/path ./run.sh [step ...] (no step = all)
|
|
# Timings are machine dependent: read them as shape, not as results. Everything else is stable.
|
|
set -u
|
|
unset JAVA_TOOL_OPTIONS _JAVA_OPTIONS # sandbox proxy banner is noise in a transcript
|
|
HERE="$(cd "$(dirname "$0")" && pwd)"
|
|
JDK25="${JDK25:-/tmp/tools/j25}"; JDK27="${JDK27:-/tmp/tools/j27}"; JDK28="${JDK28:-/tmp/tools/j28}"
|
|
OUT="$HERE/output"; CLS="$HERE/target/classes"; mkdir -p "$OUT" "$CLS"
|
|
"$JDK25/bin/javac" -Xlint:deprecation -d "$CLS" "$HERE"/src/*.java 2>&1 | sed "s#$HERE/##" > "$OUT/00-javac-warnings.txt"
|
|
J() { local v=$1; shift; "$(eval echo \$JDK$v)/bin/java" "$@"; } # J 25 -cp ... Main
|
|
ver() { "$(eval echo \$JDK$1)/bin/java" -version 2>&1 | sed -n '2p'; }
|
|
say() { printf '\n## %s\n' "$*"; }
|
|
|
|
step_01() { { echo "# Which collector does the JVM pick when you name none? (emulating a 1, 2 and 4 CPU machine with -XX:ActiveProcessorCount)"
|
|
for v in 25 27 28; do say "JDK $v: $(ver $v)"
|
|
for p in 1 2 4; do echo "\$ java -XX:ActiveProcessorCount=$p Which"; J $v -XX:ActiveProcessorCount=$p -cp "$CLS" Which 2>&1 | grep -v 'processors seen\|max heap'; done
|
|
done; } > "$OUT/01-default-collector.txt"; }
|
|
|
|
step_02() { { echo "# The memory half of the rule cannot be emulated with -XX:MaxRAM on 27 or later"
|
|
for v in 25 27 28; do say "JDK $v"; echo "\$ java -XX:MaxRAM=1g -XX:+PrintFlagsFinal -version | grep MaxRAM"; J $v -XX:MaxRAM=1g -XX:+PrintFlagsFinal -version 2>&1 | grep -E ' MaxRAM |Ignoring option|Unrecognized VM|Could not create' | sed 's/ */ /g' | head -3; done; } > "$OUT/02-maxram.txt"; }
|
|
|
|
step_03() { { echo "# Shenandoah: which mode is the default, and is the generational mode still experimental? (mode read from -Xlog:gc+init)"
|
|
for v in 25 27 28; do say "JDK $v, no mode flag"; echo "\$ java -XX:+UseShenandoahGC -Xlog:gc+init -version | grep Mode"; J $v -XX:+UseShenandoahGC -Xlog:gc+init -version 2>&1 | grep -E 'Mode:|warning'; done
|
|
say "JDK 25: generational mode without -XX:+UnlockExperimentalVMOptions"; echo "\$ java -XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational -Xlog:gc+init -version"; J 25 -XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational -Xlog:gc+init -version 2>&1 | grep -E 'Mode:|rror|warning|Unlock'
|
|
say "JDK 24-style spelling on 25 (the unlock flag is now unnecessary but harmless)"; J 25 -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational -Xlog:gc+init -version 2>&1 | grep -E 'Mode:|rror|warning'
|
|
say "JDK 28 early access: asking for the old mode explicitly"; echo "\$ java -XX:+UseShenandoahGC -XX:ShenandoahGCMode=satb -Xlog:gc+init -version"; J 28 -XX:+UseShenandoahGC -XX:ShenandoahGCMode=satb -Xlog:gc+init -version 2>&1 | grep -E 'Mode:|rror|warning|eprecat'; echo "(no deprecation warning is printed by this early-access build)"
|
|
} > "$OUT/03-shenandoah-modes.txt"; }
|
|
|
|
step_04() { { echo "# ZGC: the non-generational mode is gone, and what 28 adds"
|
|
say "JDK 25: ask for the old mode"; echo "\$ java -XX:+UseZGC -XX:-ZGenerational -version"; J 25 -XX:+UseZGC -XX:-ZGenerational -version 2>&1 | head -2
|
|
say "JDK 25: plain ZGC"; J 25 -XX:+UseZGC -cp "$CLS" Which 2>&1 | grep -v 'processors\|max heap'
|
|
say "ZGC flags present on 28 early access but not on 27 (diff of -XX:+PrintFlagsFinal -XX:+UseZGC, names only)"
|
|
J 27 -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseZGC -XX:+PrintFlagsFinal -version 2>/dev/null | awk '$2 ~ /^Z/ {print $2}' | sort > /tmp/z27.txt
|
|
J 28 -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+UseZGC -XX:+PrintFlagsFinal -version 2>/dev/null | awk '$2 ~ /^Z/ {print $2}' | sort > /tmp/z28.txt
|
|
echo "only on 28:"; comm -13 /tmp/z27.txt /tmp/z28.txt; echo "only on 27:"; comm -23 /tmp/z27.txt /tmp/z28.txt
|
|
say "its default on 28"; J 28 -XX:+UseZGC -XX:+PrintFlagsFinal -version 2>/dev/null | grep -E 'ZAdaptiveHeapSizing|SoftMaxHeapSize' | sed 's/ */ /g'
|
|
} > "$OUT/04-zgc.txt"; }
|
|
|
|
step_05() { { echo "# Reachability observed with weak references (JDK 25)"; J 25 -cp "$CLS" Reach; } > "$OUT/05-reachability.txt"; }
|
|
|
|
step_06() { { echo "# Reading a G1 log: the first lines of -Xlog:gc for the Churn workload (JDK 25, -Xms512m -Xmx512m, 150 MB live)"
|
|
echo "\$ java -Xms512m -Xmx512m -Xlog:gc Churn 150 3"; J 25 -Xms512m -Xmx512m -Xlog:gc -cp "$CLS" Churn 150 3 | grep -E '^\[' | head -24
|
|
echo; echo "# the same run, counting what G1 did"; J 25 -Xms512m -Xmx512m -Xlog:gc -cp "$CLS" Churn 150 3 | grep ' Pause ' | sed -E 's/^\[[^]]*\]\[[^]]*\]\[[^]]*\] GC\([0-9]+\) //; s/[0-9]+M->[0-9]+M\([0-9]+M\)//; s/[0-9.]+ms//' | sed 's/ *$//' | sort | uniq -c | sort -rn
|
|
} > "$OUT/06-g1-log.txt"; }
|
|
|
|
step_07() { { echo "# Same workload, five collectors, JDK 25, -Xms1g -Xmx1g, 450 MB live set of small linked objects that are constantly replaced, 8 s measured after a 1.5 s warm-up, three runs each"
|
|
echo "# (2 vCPU sandbox: shape, not result. 'requests' counts completed loop iterations, a rough throughput signal)"
|
|
for gc in "-XX:+UseSerialGC" "-XX:+UseParallelGC" "-XX:+UseG1GC" "-XX:+UseZGC" "-XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational"; do
|
|
say "$gc"; for r in 1 2 3; do J 25 -Xms1g -Xmx1g $gc -cp "$CLS" Churn 450 8 graph | grep -E 'requests|ticker'| sed 's/^/ run '$r' /' ; done; done; } > "$OUT/07-five-collectors.txt"; }
|
|
|
|
step_08() { { echo "# The defaults on each release, same workload and heap as 07, two runs each"
|
|
for v in 25 27 28; do say "JDK $v: $(ver $v), no collector flag"; for r in 1 2; do J $v -Xms1g -Xmx1g -cp "$CLS" Churn 450 8 graph | grep -E 'collector|requests|ticker' | sed 's/^/ run '$r' /'; done; done
|
|
say "JDK 28 early access, -XX:+UseShenandoahGC with no mode flag"; for r in 1 2; do J 28 -Xms1g -Xmx1g -XX:+UseShenandoahGC -cp "$CLS" Churn 450 8 graph | grep -E 'collector|requests|ticker' | sed 's/^/ run '$r' /'; done; } > "$OUT/08-defaults-by-release.txt"; }
|
|
|
|
step_09() { { echo "# jcmd GC.heap_info on a live process, per collector (JDK 25, 512 MB heap, 150 MB live)"
|
|
for gc in "-XX:+UseParallelGC" "-XX:+UseG1GC" "-XX:+UseZGC" "-XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational"; do
|
|
say "$gc"; rm -f /tmp/churn.out; ( exec "$JDK25/bin/java" -Xms512m -Xmx512m $gc -cp "$CLS" Churn 150 3 flat wait > /tmp/churn.out 2>&1 ) &
|
|
pid=$!; for i in $(seq 1 60); do grep -q READY /tmp/churn.out 2>/dev/null && break; sleep 0.5; done
|
|
"$JDK25/bin/jcmd" $pid GC.heap_info 2>&1 | grep -v "^$pid" ; wait $pid; done; } > "$OUT/09-heap-info.txt"; }
|
|
|
|
step_10() { { echo "# Running out of memory: the message depends on how the collector fails (JDK 25, -Xmx64m)"
|
|
say "G1, 1 MB arrays"; J 25 -Xmx64m -cp "$CLS" Leak big 2>&1 | tail -2
|
|
say "G1, tiny objects"; J 25 -Xmx64m -cp "$CLS" Leak small 2>&1 | tail -3
|
|
say "Parallel, tiny objects"; J 25 -Xmx64m -XX:+UseParallelGC -cp "$CLS" Leak small 2>&1 | tail -3
|
|
} > "$OUT/10-out-of-memory.txt"; }
|
|
|
|
step_11() { { echo "# What one System.gc() costs (JDK 25, G1, 150 MB live)"
|
|
say "default"; J 25 -Xlog:gc -cp "$CLS" SysGc | grep -E 'Pause Full|System.gc|live chunks'
|
|
say "-XX:+DisableExplicitGC"; J 25 -XX:+DisableExplicitGC -Xlog:gc -cp "$CLS" SysGc | grep -E 'System.gc|live chunks'
|
|
say "-XX:+ExplicitGCInvokesConcurrent"; J 25 -XX:+ExplicitGCInvokesConcurrent -Xlog:gc -cp "$CLS" SysGc | grep -E '\(System.gc\(\)\)|System.gc\(\) #|live chunks'
|
|
say "ZGC"; J 25 -XX:+UseZGC -cp "$CLS" SysGc
|
|
} > "$OUT/11-system-gc.txt"; }
|
|
|
|
step_12() { { echo "# finalize() today"
|
|
say "what javac says (JDK 25, -Xlint:deprecation)"; cat "$OUT/00-javac-warnings.txt"
|
|
for v in 25 27 28; do say "JDK $v, default"; J $v -cp "$CLS" 'Finalize' 2>&1 | head -3; say "JDK $v, --finalization=disabled"; J $v --finalization=disabled -cp "$CLS" Finalize 2>&1 | head -3; done; } > "$OUT/12-finalize.txt"; }
|
|
|
|
step_14() { { echo "# The baseline: a FLAT live set (one list of 1 KB byte arrays, no pointers inside), JDK 25, -Xms512m -Xmx512m, 150 MB live, 8 s, one run each"
|
|
for gc in "-XX:+UseSerialGC" "-XX:+UseParallelGC" "-XX:+UseG1GC" "-XX:+UseZGC" "-XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational"; do
|
|
say "$gc"; J 25 -Xms512m -Xmx512m $gc -cp "$CLS" Churn 150 8 flat | grep -E 'requests|ticker' | sed 's/^/ /'; done; } > "$OUT/14-flat-live-set-baseline.txt"; }
|
|
|
|
step_15() { { echo "# Why is G1's worst case so uneven? Pause types and the three longest pauses in three G1 runs of the graph workload (JDK 25, -Xms1g -Xmx1g, 450 MB live)"
|
|
for r in 1 2 3; do say "run $r"; J 25 -Xms1g -Xmx1g -Xlog:gc -cp "$CLS" Churn 450 8 graph > /tmp/g1.log
|
|
echo "pause counts by type:"; grep -o 'Pause [A-Za-z]* ([^)]*)' /tmp/g1.log | sort | uniq -c | sort -rn
|
|
echo "three longest pauses:"; grep ' Pause ' /tmp/g1.log | awk '{print $NF "\t" $0}' | sort -rn | head -3 | cut -f2- | sed -E 's/^\[[^]]*\]\[[^]]*\]\[[^]]*\] //'; done; } > "$OUT/15-g1-pause-types.txt"; }
|
|
|
|
step_16() { { echo "# Heap is not the whole process: Native Memory Tracking on a live JVM (JDK 25, G1, -Xmx512m, 150 MB live)"
|
|
rm -f /tmp/churn.out; ( exec "$JDK25/bin/java" -Xms512m -Xmx512m -XX:NativeMemoryTracking=summary -cp "$CLS" Churn 150 3 flat wait > /tmp/churn.out 2>&1 ) &
|
|
pid=$!; for i in $(seq 1 60); do grep -q READY /tmp/churn.out 2>/dev/null && break; sleep 0.5; done
|
|
echo "\$ jcmd <pid> VM.native_memory summary (category totals only)"; "$JDK25/bin/jcmd" $pid VM.native_memory summary 2>&1 | grep -E '^-|^Total' | sed -E 's/^- +//' | cut -c1-110
|
|
echo; echo "resident set size of the process, from /proc: $(awk '/VmRSS/{print $2/1024 " MB"}' /proc/$pid/status)"; wait $pid; } > "$OUT/16-native-memory.txt"; }
|
|
|
|
step_17() { { echo "# A few defaults worth knowing (JDK 25)"
|
|
echo "\$ java -Xmx1g -XX:+UseG1GC -XX:+PrintFlagsFinal -version | grep ..."; J 25 -Xmx1g -XX:+UseG1GC -XX:+PrintFlagsFinal -version 2>/dev/null | grep -E ' MaxGCPauseMillis | G1HeapRegionSize | InitiatingHeapOccupancyPercent | ParallelGCThreads | ConcGCThreads ' | sed 's/ */ /g'
|
|
echo "\$ java -Xmx1g -XX:+UseSerialGC -XX:+PrintFlagsFinal -version | grep -E 'NewRatio|SurvivorRatio|MaxTenuringThreshold'"; J 25 -Xmx1g -XX:+UseSerialGC -XX:+PrintFlagsFinal -version 2>/dev/null | grep -E ' NewRatio | SurvivorRatio | MaxTenuringThreshold ' | sed 's/ */ /g'; } > "$OUT/17-flag-defaults.txt"; }
|
|
|
|
step_18() { { echo "# Shenandoah by JDK and mode, same graph workload as 07 (-Xms1g -Xmx1g, 450 MB live), one run each"
|
|
for v in 25 27 28; do for m in satb generational; do say "JDK $v, -XX:ShenandoahGCMode=$m"; J $v -Xms1g -Xmx1g -XX:+UseShenandoahGC -XX:ShenandoahGCMode=$m -cp "$CLS" Churn 450 8 graph | grep -E 'requests|ticker' | sed 's/^/ /'; done; done; } > "$OUT/18-shenandoah-by-jdk.txt"; }
|
|
|
|
step_19() { { echo "# Headroom: the graph workload again with a 2 GB heap instead of 1 GB (450 MB live is now 22 percent of the heap), JDK 25, one run each"
|
|
for gc in "-XX:+UseSerialGC" "-XX:+UseParallelGC" "-XX:+UseG1GC" "-XX:+UseZGC" "-XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational"; do
|
|
say "$gc"; J 25 -Xms2g -Xmx2g $gc -cp "$CLS" Churn 450 8 graph | grep -E 'requests|ticker' | sed 's/^/ /'; done; } > "$OUT/19-headroom-2g.txt"; }
|
|
|
|
step_20() { { echo "# What Shenandoah did on each JDK for the graph workload (-Xms1g -Xmx1g, 450 MB live, generational mode, one run each): pause types and the three longest pauses"
|
|
for v in 25 27 28; do say "JDK $v"; J $v -Xms1g -Xmx1g -XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational -Xlog:gc -cp "$CLS" Churn 450 8 graph > /tmp/sh.log
|
|
echo "pause counts by type:"; grep ' Pause ' /tmp/sh.log | grep -oE 'Pause (Init Mark|Final Mark|Degenerated GC|Full|Init Update Refs|Final Update Refs)' | sort | uniq -c | sort -rn
|
|
echo "three longest pauses:"; grep ' Pause ' /tmp/sh.log | awk '{print $NF "\t" $0}' | sort -rn | head -3 | cut -f2- | sed -E 's/^\[[^]]*\]\[[^]]*\]\[[^]]*\] //'; done; } > "$OUT/20-shenandoah-pause-types.txt"; }
|
|
|
|
step_21() { { echo "# A pause-free log is not a stall-free application: Shenandoah allocation stalls (generational mode, graph workload, -Xms1g -Xmx1g, 450 MB live, one run each)"
|
|
for v in 25 27 28; do say "JDK $v"; J $v -Xms1g -Xmx1g -XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational -Xlog:gc -cp "$CLS" Churn 450 8 graph > /tmp/sh.log
|
|
echo "allocation stalls logged : $(grep -c 'Allocation Stall' /tmp/sh.log)"
|
|
echo "longest allocation stalls :"; grep 'Allocation Stall' /tmp/sh.log | awk '{print $NF "\t" $0}' | sort -rn | head -2 | cut -f2- | sed -E 's/^\[[^]]*\]\[[^]]*\]\[[^]]*\] //; s/^/ /'
|
|
echo "longest stop-the-world pause: $(grep ' Pause ' /tmp/sh.log | awk '{print $NF}' | sort -rn | head -1)"; grep ticker /tmp/sh.log; done; } > "$OUT/21-shenandoah-allocation-stalls.txt"; }
|
|
|
|
step_22() { { echo "# The default collector inside real container limits (docker run --cpus --memory; needs Docker and the eclipse-temurin:25-jre and :27-jre images)"
|
|
for img in 25 27; do say "eclipse-temurin:$img-jre"
|
|
for lim in "--cpus=1 --memory=4g" "--cpus=2 --memory=1g" "--cpus=2 --memory=1500m" "--cpus=2 --memory=1791m" "--cpus=2 --memory=1792m" "--cpus=2 --memory=1800m" "--cpus=2 --memory=2g"; do
|
|
printf '%-28s -> ' "$lim"; docker run --rm $lim eclipse-temurin:$img-jre java -XX:+PrintFlagsFinal -version 2>/dev/null | grep -E ' Use(G1|Serial)GC ' | awk '$4=="true"{printf "%s", $2}'; echo
|
|
done; done; } > "$OUT/22-container-default-collector.txt"; }
|
|
|
|
step_13() { { echo "# the other two snippets in the article, run"; "$JDK25/bin/java" -cp "$CLS" StackAndHeap; "$JDK25/bin/java" -cp "$CLS" TryWithResources; } > "$OUT/13-small-demos.txt"; }
|
|
|
|
if [ $# -eq 0 ]; then set -- 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22; fi
|
|
for s in "$@"; do echo "step $s"; "step_$s"; done
|
|
echo "versions: $(ver 25) | $(ver 27) | $(ver 28)" > "$OUT/00-versions.txt"
|