#!/usr/bin/env bash # JEP 523 in a real container: what does the JVM pick when nobody asks for a collector? # Runs GcReport in Docker with 1 CPU and 2 CPUs, on the JDK 26 and JDK 27 images. # ./scripts/g1-default.sh -> docs/output/01-g1-default-1cpu-vs-2cpu.txt # docs/output/02-g1-default-memory.txt set -euo pipefail source "$(dirname "$0")/env.sh" BUILD="$ROOT/build/g1"; rm -rf "$BUILD"; mkdir -p "$BUILD" "$JDK27/bin/javac" --release 26 -d "$BUILD" "$ROOT"/g1-container/src/*.java # one class file set runs on both JDKs run() { # image label docker-args... -- java-args... local img="$1" label="$2"; shift 2 echo "\$ docker run --rm $* $img java -cp /app GcReport" docker run --rm "$@" -v "$BUILD:/app:ro" "$img" java -cp /app GcReport echo } { echo "# JEP 523: which collector does the JVM pick when you do not choose one?" echo "# Same class files, same vendor (Amazon Corretto), same 2 GB memory limit. Only the JDK version and the CPU limit change." echo for cpus in 1 2; do for img in "$IMG26" "$IMG27"; do echo "=== $img --cpus=$cpus --memory=2g" run "$img" x --cpus=$cpus --memory=2g done done } > "$OUT/01-g1-default-1cpu-vs-2cpu.txt" 2>&1 { echo "# The other half of the old rule: memory. The old heuristic wanted at least 2 CPUs AND about 1792 MB." echo "# With 2 CPUs the CPU half of the rule is satisfied, so only the memory limit differs between these runs." echo for mem in 1g 2g; do for img in "$IMG26" "$IMG27"; do echo "=== $img --cpus=2 --memory=$mem" run "$img" x --cpus=2 --memory=$mem done done } > "$OUT/02-g1-default-memory.txt" 2>&1 { echo "# The opt-out still works on 27: an explicit choice always wins over the JVM's." echo echo "=== $IMG27 --cpus=1 --memory=2g -XX:+UseSerialGC" echo "\$ docker run --rm --cpus=1 --memory=2g $IMG27 java -XX:+UseSerialGC -cp /app GcReport" docker run --rm --cpus=1 --memory=2g -v "$BUILD:/app:ro" "$IMG27" java -XX:+UseSerialGC -cp /app GcReport } > "$OUT/03-g1-default-optout.txt" 2>&1 echo "wrote 01-, 02-, 03- transcripts to $OUT"