Add java21-to-25 module: compile-once probes on JDK 21 and 25, removed APIs, build matrix, pinning, compact headers and containers

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017ic4b7N4ZDbUtA3ofqAqRV
This commit is contained in:
Claude
2026-12-03 09:26:21 +05:30
parent d4b8552957
commit 3502fd7804
46 changed files with 1371 additions and 0 deletions
+50
View File
@@ -0,0 +1,50 @@
#!/usr/bin/env bash
# Build-tool and library matrix on JDK 25 with <release>25</release>. Needs Maven and Maven Central.
source "$(dirname "$0")/env.sh"
export JAVA_HOME=$J25 PATH=$J25/bin:$PATH MAVEN_OPTS=-Xmx1g
B=$W/matrix; rm -rf "$B"; mkdir -p "$B"; cp -r "$ROOT"/build-matrix/* "$B"/
mvnq() { mvn -B -ntp -q "$@" 2>&1 | clean | sed -e "s#$HOME#~#g"; return ${PIPESTATUS[0]}; }
# first line that says why it failed
why() { grep -E 'ERROR|Exception|error:|Unsupported|Mockito cannot|IllegalArgument' "$1" | grep -v -E '^\[ERROR\] *$|Help 1|-e switch|-X switch|re-run|For more|surefire-reports' | head -${2:-2} | cut -c1-260 | sed 's/^/ /'; }
run() { # label logfile dir mvn-args...
local label=$1 log=$2 dir=$3; shift 3
if (cd "$B/$dir" && mvnq clean "$@" >"$log" 2>&1); then echo " OK $label"; return 0; else echo " FAIL $label"; return 1; fi
}
echo "# 05-lombok: mvn compile on JDK 25, release 25. 'class path' = plain provided dependency; 'declared' = annotationProcessorPaths" > "$OUT/05-lombok.txt"
{ for v in 1.18.34 1.18.36 1.18.38 1.18.40 1.18.48; do
run "Lombok $v, declared processor" "$B/l.log" lombok compile -Pdeclared-processor -Dlombok.version=$v || why "$B/l.log"
done
run "Lombok 1.18.48, class path only" "$B/l.log" lombok compile -Dlombok.version=1.18.48 || why "$B/l.log" 3
} >> "$OUT/05-lombok.txt"
echo "# 06-mockito: mvn test on JDK 25, release 25, JUnit 6.1.3, mocking a concrete class" > "$OUT/06-mockito.txt"
{ for v in 5.14.2 5.15.2 5.17.0 5.18.0 5.25.0; do
run "Mockito $v" "$B/m.log" mockito test -Dmockito.version=$v || { why "$B/m.log" 2; grep -m1 "not supported by the current version of Byte Buddy" "$B/m.log" | cut -c1-300 | sed "s/^/ /"; }
done
echo; echo "--- Mockito 5.14.2 with -Dnet.bytebuddy.experimental=true (stop-gap, not a fix)"
run "Mockito 5.14.2 + experimental" "$B/m.log" mockito test -Dmockito.version=5.14.2 -Dextra.jvm.args=-Dnet.bytebuddy.experimental=true || why "$B/m.log" 3
echo; echo "--- Mockito 5.25.0, default: notices printed during the test run"
(cd "$B/mockito" && mvn -B -ntp clean test 2>&1 | clean | grep -E 'self-attaching|Java agent has been loaded|dynamic loading|PROBE|Sharing is only' | sed "s#$HOME#~#g" | cut -c1-200)
echo; echo "--- Mockito 5.25.0 with -Pmockito-agent (agent registered at startup)"
(cd "$B/mockito" && mvn -B -ntp clean test -Pmockito-agent 2>&1 | clean | grep -E 'self-attaching|Java agent has been loaded|dynamic loading|PROBE|Sharing is only|BUILD' | sed "s#$HOME#~#g" | cut -c1-200)
} >> "$OUT/06-mockito.txt"
echo "# 07-jacoco: mvn test -Pjacoco on JDK 25, release 25. 'agent errors' counts instrumentation failures in the log" > "$OUT/07-jacoco.txt"
{ for v in 0.8.11 0.8.12 0.8.13 0.8.14 0.8.15; do
(cd "$B/mockito" && mvn -B -ntp clean test -Pjacoco -Djacoco.version=$v 2>&1 | clean > "$B/j.log")
res=$(grep -q 'BUILD SUCCESS' "$B/j.log" && echo "BUILD SUCCESS" || echo "BUILD FAILURE")
echo " JaCoCo $v: $res, agent errors: $(grep -c 'Exception in thread\|IllegalClassFormatException\|Error while instrumenting\|Unsupported class file major' "$B/j.log")"
grep -m2 -E 'Unsupported class file major|Error while (instrumenting|analyzing)' "$B/j.log" | sed "s#$HOME#~#g" | cut -c1-220 | sed 's/^/ /'
done
} >> "$OUT/07-jacoco.txt"
echo "# 08-spring-boot: a component-scanning app compiled with release 25 and started on JDK 25" > "$OUT/08-spring-boot.txt"
{ for v in 3.2.12 3.3.0 3.3.13 3.4.0 3.4.3 3.4.4 3.4.5 3.4.13 3.5.16 4.0.0 4.2.0; do
d=$B/spring
(cd $d && mvnq clean compile dependency:build-classpath -Dboot.version=$v -Dmdep.outputFile=cp.txt >"$B/s.log" 2>&1) || { echo " FAIL(build) Boot $v"; why "$B/s.log"; continue; }
"$J25/bin/java" -cp "$d/target/classes:$(cat $d/cp.txt)" demo.App > "$B/s.log" 2>&1
if grep -q 'PROBE ok' "$B/s.log"; then echo " OK Boot $v"; else echo " FAIL Boot $v"; grep -m1 -E '^Caused by: .*Unsupported class file' "$B/s.log" | clean | cut -c1-220 | sed 's/^/ /'; fi
done
} >> "$OUT/08-spring-boot.txt"
tail -n +1 "$OUT"/0[5-8]-*.txt
+18
View File
@@ -0,0 +1,18 @@
#!/usr/bin/env bash
# The same checks inside eclipse-temurin images (pulled through mirror.gcr.io to avoid Docker Hub rate limits).
source "$(dirname "$0")/env.sh"
C=$W/c21; I21=${IMG21:-mirror.gcr.io/library/eclipse-temurin:21-jre}; I25=${IMG25:-mirror.gcr.io/library/eclipse-temurin:25-jre}
rm -rf "$C"; "$J21/bin/javac" --release 21 -nowarn -Xlint:-removal -d "$C" "$ROOT"/src/probes/DefaultsProbe.java 2>/dev/null; chmod -R a+rX "$W"
d() { docker run --rm -v "$C:/c:ro" "$@" 2>&1 | grep -v '^Picked up'; }
{ echo "# 14-containers: eclipse-temurin 21-jre and 25-jre, DefaultsProbe compiled once on 21"
for limits in "--cpus=2 --memory=2g" "--cpus=1 --memory=2g" "--cpus=2 --memory=512m"; do
for img in "$I21" "$I25"; do echo "=== ${img##*/} $limits"; d $limits "$img" java -cp /c DefaultsProbe | sed 's/^/ /'; done
done
for img in "$I21" "$I25"; do echo "=== ${img##*/} -XX:+UseZGC"; d --cpus=2 --memory=2g "$img" java -XX:+UseZGC -cp /c DefaultsProbe | grep -E 'collector|ZGen' | sed 's/^/ /'; done
echo "=== rollback: the 25 flag set through JDK_JAVA_OPTIONS, image rolled back to 21"
d -e JDK_JAVA_OPTIONS=-XX:+UseCompactObjectHeaders "$I21" java -version | grep -E 'Unrecognized|Error|NOTE' | sed 's/^/ /'
echo "=== same, with -XX:+IgnoreUnrecognizedVMOptions in front"
d -e "JDK_JAVA_OPTIONS=-XX:+IgnoreUnrecognizedVMOptions -XX:+UseCompactObjectHeaders" "$I21" java -version | grep -E 'Unrecognized|openjdk version|NOTE' | sed 's/^/ /'
echo "=== 25 image with the flag set through JDK_JAVA_OPTIONS"
d -e JDK_JAVA_OPTIONS=-XX:+UseCompactObjectHeaders --cpus=2 --memory=2g "$I25" java -cp /c DefaultsProbe | grep -E 'NOTE|Compact' | sed 's/^/ /'
} > "$OUT/14-containers.txt"
+8
View File
@@ -0,0 +1,8 @@
# Shared by every script. Set JDK21 and JDK25 to your installations.
export J21=${JDK21:-/usr/lib/jvm/java-21-openjdk-amd64} J25=${JDK25:?set JDK25 to a JDK 25 installation}
ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd); OUT=$ROOT/output; W=${WORK:-/tmp/java21-to-25-work}
mkdir -p "$OUT" "$W"
unset _JAVA_OPTIONS
# drops the banner a JVM prints for JAVA_TOOL_OPTIONS, and local paths
clean() { grep -v -E '^(\[[A-Z]+\] )?Picked up ' | sed -e "s#$W#<work>#g" -e "s#$ROOT/##g" -e "s#$HOME#~#g"; }
ver() { "$1/bin/java" -version 2>&1 | grep -v '^Picked up' | head -1 | sed -E 's/^openjdk version "([^"]+)".*/\1/'; }
+38
View File
@@ -0,0 +1,38 @@
#!/usr/bin/env bash
# Which JVM options that a Java 21 service might carry still start on Java 25, and the other way round (rollback).
source "$(dirname "$0")/env.sh"
echo "# 02-startup-flags: flag, then for each JDK the exit code and the first line the JVM printed (if any)"
for f in \
"-Djava.security.manager=allow" \
"-XX:+UseZGC -XX:+ZGenerational" \
"-XX:+UseZGC -XX:-ZGenerational" \
"-XX:+UseCompactObjectHeaders" \
"-XX:+UnlockExperimentalVMOptions -XX:+UseCompactObjectHeaders" \
"-XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational" \
"-XX:+UseStringDeduplication" \
"-XX:+UseLargePagesIndividualAllocation" \
"-XX:+UseNeon" \
"-XX:LockingMode=2" \
"-XX:+UseEmptySlotsInSupers" \
"-XX:+UseOprofile" \
"-XX:+DontYieldALot" \
"-Xnoagent" \
"-XX:+RegisterFinalizersAtInit" \
"-XX:+UseCompressedClassPointers" \
"-XX:-UseCompressedClassPointers" \
"-XX:+PreserveAllAnnotations" \
"-XX:+UseAdaptiveSizePolicyWithSystemGC" \
"-XX:+EnableDynamicAgentLoading" \
"--sun-misc-unsafe-memory-access=allow" \
"--enable-native-access=ALL-UNNAMED" \
"--illegal-native-access=deny" \
"-Djdk.tracePinnedThreads=full" \
; do
echo "--- $f"
for j in "$J21" "$J25"; do
out=$("$j/bin/java" $f -version 2>&1 | clean); code=$?
out=$("$j/bin/java" $f -version 2>&1 | clean | grep -v -E '^(openjdk |OpenJDK Runtime|OpenJDK 64-Bit Server VM (Temurin|\(build))' | head -1)
"$j/bin/java" $f -version >/dev/null 2>&1; code=$?
printf ' [%s] exit %s %s\n' "$(ver "$j")" "$code" "$out"
done
done
+11
View File
@@ -0,0 +1,11 @@
#!/usr/bin/env bash
# Runs the small Gradle project in ../lanes/upgrade (Java 25 toolchain) with two Gradle versions, Gradle itself on JDK 25.
# OLD_GRADLE=/path/to/gradle-8.14.3/bin/gradle NEW_GRADLE=/path/to/gradle-9.x/bin/gradle ./scripts/gradle.sh
source "$(dirname "$0")/env.sh"
{ echo "# 13-gradle: 'gradle run' with Gradle running on JDK $(ver "$J25")"
for g in "${OLD_GRADLE:?}" "${NEW_GRADLE:?}"; do
v=$("$g" --version 2>/dev/null | grep -E '^Gradle ' | head -1); echo "--- $v"
rm -rf "$W/gp"; cp -r "$ROOT/../lanes/upgrade" "$W/gp"
(cd "$W/gp" && JAVA_HOME=$J25 "$g" --no-daemon -q run 2>&1 | clean | grep -E -A1 'running on|What went wrong' | head -3 | sed 's/^/ /')
done
} > "$OUT/13-gradle.txt"
+69
View File
@@ -0,0 +1,69 @@
#!/usr/bin/env python3
"""Public types and methods present in the older javap dump and gone from the newer one.
usage: removed_api.py <old-dump> <new-dump> (dumps made by ../../api-diff/dump_api.py)
Modifier and 'throws' changes are ignored: a method counts as removed only if no method with the same
name and parameter types is declared on the class or on any supertype in the newer dump.
com.sun.source (compiler tree API) and jdk.jfr.snippets are skipped.
"""
import re, sys
def strip_generics(s):
prev = None
while prev != s:
prev, s = s, re.sub(r"<[^<>]*>", "", s)
return s
def parse(path):
out, cur = {}, None
for line in open(path):
line = line.rstrip("\n")
if line.startswith("#####") or line.startswith("Compiled from") or not line.strip() or line.strip() == "}":
continue
if not line.startswith(" "):
bare = strip_generics(line)
m = re.search(r"(?:class|interface)\s+([\w.$]+)", bare)
if not m:
cur = None
continue
cur = m.group(1)
supers = []
for kw in ("extends", "implements"):
k = re.search(kw + r"\s+(.*?)(?:\s+implements|\s*\{|$)", bare)
if k:
supers += [x.strip() for x in k.group(1).split(",")]
out[cur] = {"public": bare.startswith(("public ", "protected ")), "supers": supers, "methods": set()}
elif cur:
sig = strip_generics(line.strip())
m = re.search(r"([\w$]+)\(([^)]*)\)", sig)
if m and sig.startswith(("public", "protected")):
out[cur]["methods"].add(f"{m.group(1)}({m.group(2).replace(' ', '')})")
return out
old, new = parse(sys.argv[1]), parse(sys.argv[2])
def inherited(cls, sig, seen=None):
seen = seen or set()
if cls in seen:
return False
seen.add(cls)
info = new.get(cls)
if info is None:
return False
if sig in info["methods"]:
return True
return any(inherited(s, sig, seen) for s in info["supers"] + ["java.lang.Object"])
skip = ("com.sun.source.", "jdk.jfr.snippets")
print("## public types removed")
for c in sorted(set(old) - set(new)):
if old[c]["public"] and not c.startswith(skip):
print(" " + c)
print("## public methods removed (not inherited from a supertype either)")
for c in sorted(set(old) & set(new)):
if not old[c]["public"] or c.startswith(skip):
continue
for sig in sorted(old[c]["methods"] - new[c]["methods"]):
if not inherited(c, sig):
print(f" {c}.{sig}")
+74
View File
@@ -0,0 +1,74 @@
#!/usr/bin/env bash
# Regenerates output/. Needs JDK 21 and JDK 25 (set JDK21 / JDK25). The build matrix needs Maven and Maven Central;
# containers.sh needs Docker; gradle.sh needs two Gradle installations. See README.md.
source "$(dirname "$0")/env.sh"
cd "$ROOT"; rm -rf "$W/c21" "$W/p21" "$W/c25"; C=$W/c21
"$J21/bin/javac" --release 21 -nowarn -Xlint:-removal -d "$C" src/probes/*.java src/pinning/*.java 2>/dev/null
both() { for j in "$J21" "$J25"; do v=$(ver "$j"); "$j/bin/java" "$@" -cp "$C" "$CLS" 2>&1 | clean | grep -v '^$' | sed "s/^/ [$v] /"; done; }
one() { local j=$1; shift; "$j/bin/java" "$@" -cp "$C" "$CLS" 2>&1 | clean | grep -v '^$' | sed "s/^/ [$(ver "$j")] /"; }
{ echo "# 01-runtime-behaviour: classes compiled ONCE with JDK 21 (--release 21), run unchanged on JDK 21 and JDK 25"
for CLS in SecurityManagerProbe SubjectProbe ThreadControlProbe UnsafeProbe JniProbe FinalizerProbe DefaultsProbe; do echo "--- $CLS"; both; done
CLS=SecurityManagerProbe; echo "--- SecurityManagerProbe with -Djava.security.manager=allow"; both -Djava.security.manager=allow 2>/dev/null | grep -v -E 'WARNING|^\s+\[[0-9.]+\] \s+at '
CLS=UnsafeProbe; echo "--- UnsafeProbe on 25 with --sun-misc-unsafe-memory-access=deny"; one "$J25" --sun-misc-unsafe-memory-access=deny
echo "--- UnsafeProbe on 25 with --sun-misc-unsafe-memory-access=debug"; one "$J25" --sun-misc-unsafe-memory-access=debug
CLS=JniProbe; echo "--- JniProbe on 25 with --enable-native-access=ALL-UNNAMED"; one "$J25" --enable-native-access=ALL-UNNAMED
echo "--- JniProbe on 25 with --illegal-native-access=deny"; one "$J25" --illegal-native-access=deny
CLS=FinalizerProbe; echo "--- FinalizerProbe on 25 with --finalization=disabled"; one "$J25" --finalization=disabled
} > "$OUT/01-runtime-behaviour.txt"
./scripts/flags.sh > "$OUT/02-startup-flags.txt"
{ echo "--- JDK 25: compact object headers together with -XX:-UseCompressedClassPointers"
"$J25/bin/java" -XX:+UseCompactObjectHeaders -XX:-UseCompressedClassPointers -version 2>&1 | clean | grep 'Compact object headers' | sed 's/^/ /'
echo "--- JDK 25: CDS archive picked up with compact headers"
"$J25/bin/java" -XX:+UseCompactObjectHeaders -Xlog:cds -version 2>&1 | clean | grep 'trying to map' | head -1 | sed -E 's#^\[[^]]*\]\[info\]\[cds\] ##; s#[^ ]*/lib/server/#<jdk25>/lib/server/#' | sed 's/^/ /'
} >> "$OUT/02-startup-flags.txt"
jc() { local j=$1; shift; "$j/bin/javac" "$@" 2>&1 | clean | grep -v '^Note:'; }
{ echo "# 03-source-and-preview: preview code written for 21, and 25 APIs tried on 21"
for f in StringTemplateDemo StructuredTaskDemo; do
echo "=== $f: compile on 21 with --enable-preview, run on 21"
jc "$J21" --release 21 --enable-preview -d "$W/p21" src/preview21/$f.java; "$J21/bin/java" --enable-preview -cp "$W/p21" $f 2>&1 | clean
echo "=== $f: run the same class on 25 (with --enable-preview)"
"$J25/bin/java" --enable-preview -cp "$W/p21" $f 2>&1 | clean | head -2
echo "=== $f: recompile the source on 25 with --enable-preview"
jc "$J25" --release 25 --enable-preview -d "$W/p25" src/preview21/$f.java
done
echo "=== ThreadSuspendCall.java: javac on 21, then 25"
jc "$J21" -nowarn -d "$W/b21" src/broken/ThreadSuspendCall.java; echo " 21 exit $(("$J21/bin/javac" -nowarn -d "$W/b21" src/broken/ThreadSuspendCall.java >/dev/null 2>&1); echo $?)"
jc "$J25" -d "$W/b25" src/broken/ThreadSuspendCall.java
for f in ScopedValueDemo GathererDemo; do
echo "=== $f.java: javac on 21"; jc "$J21" -d "$W/n21" src/new25/$f.java | head -4
echo "=== $f.java: javac and java on 25, no flags"; jc "$J25" -d "$W/n25" src/new25/$f.java; "$J25/bin/java" -cp "$W/n25" $f 2>&1 | clean
done
} > "$OUT/03-source-and-preview.txt"
D=$W/apidiff; mkdir -p "$D"
[ -s "$D/api-21.txt" ] || python3 ../api-diff/dump_api.py "$J21" "$D/api-21.txt" >/dev/null
[ -s "$D/api-25.txt" ] || python3 ../api-diff/dump_api.py "$J25" "$D/api-25.txt" >/dev/null
{ echo "# 04-removed-api: public types and methods in JDK 21 that are gone in JDK 25 (javap -public over java.* and selected jdk.* modules)"
python3 scripts/removed_api.py "$D/api-21.txt" "$D/api-25.txt"; } > "$OUT/04-removed-api.txt"
"$J21/bin/jar" cf "$W/probes.jar" -C "$C" . 2>/dev/null
{ echo "# 09-scanners: JDK 25 tools pointed at a jar built by JDK 21"
echo "--- jdeps --jdk-internals probes.jar"; "$J25/bin/jdeps" --jdk-internals "$W/probes.jar" 2>&1 | clean | grep -E 'probes.jar|->' | head -3
echo "--- jdeprscan --release 25 --for-removal probes.jar"; "$J25/bin/jdeprscan" --release 25 --for-removal "$W/probes.jar" 2>&1 | clean | grep '^class' | sort
} > "$OUT/09-scanners.txt"
for j in "$J21" "$J25"; do "$j/bin/java" -cp "$C" LocaleProbe 2>&1 | clean > "$W/locale-$(ver "$j").txt"; done
{ echo "# 10-locale-diff: LocaleProbe (compiled once on 21) run on both JDKs; only the lines that differ. $(wc -l < "$W/locale-$(ver "$J21").txt") formats compared"
diff "$W/locale-$(ver "$J21").txt" "$W/locale-$(ver "$J25").txt" | grep -E '^[<>]' | sed "s/^</ [21]/; s/^>/ [25]/"
} > "$OUT/10-locale-diff.txt"
{ echo "# 11-pinning: compiled once on 21; run with -Djdk.virtualThreadScheduler.parallelism=2. Elapsed times are machine dependent"
for CLS in PinningProbe ClassInitPinningProbe; do echo "--- $CLS"; both -Djdk.virtualThreadScheduler.parallelism=2; done
CLS=PinningProbe; echo "--- PinningProbe with -Djdk.tracePinnedThreads=short (first lines)"
for j in "$J21" "$J25"; do one "$j" -Djdk.virtualThreadScheduler.parallelism=2 -Djdk.tracePinnedThreads=short | head -3; done
} > "$OUT/11-pinning.txt"
"$J25/bin/javac" -d "$W/c25" src/headers/HeaderProbe.java 2>/dev/null
{ echo "# 12-object-headers: bytes allocated per object on JDK $(ver "$J25"), 1,000,000 objects each"
echo "--- default (-XX:-UseCompactObjectHeaders)"; "$J25/bin/java" -cp "$W/c25" HeaderProbe 2>&1 | clean | sed 's/^/ /'
echo "--- -XX:+UseCompactObjectHeaders"; "$J25/bin/java" -XX:+UseCompactObjectHeaders -cp "$W/c25" HeaderProbe 2>&1 | clean | sed 's/^/ /'
} > "$OUT/12-object-headers.txt"
echo done