Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01B38FGKKam5SCGgwgduVAh3
41 lines
2.4 KiB
Bash
Executable File
41 lines
2.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# JEP 534: object header size on JDK 26 (12 bytes) vs JDK 27 (8 bytes), measured with JOL 0.17.
|
|
# ./scripts/object-headers.sh -> docs/output/10-headers-jdk26.txt, 11-headers-jdk27.txt,
|
|
# 12-headers-jdk27-opt-out.txt, 13-jol-record-failure.txt,
|
|
# 14-jol-record-workaround.txt
|
|
set -euo pipefail
|
|
source "$(dirname "$0")/env.sh"
|
|
|
|
LIB="$ROOT/.lib"; mkdir -p "$LIB"
|
|
JOL="$LIB/jol-core-0.17.jar"
|
|
if [ ! -f "$JOL" ]; then
|
|
curl -sfL -o "$JOL" https://repo1.maven.org/maven2/org/openjdk/jol/jol-core/0.17/jol-core-0.17.jar
|
|
fi
|
|
echo "4c98e9e61b3f189241057cb21b4331d1093e5b85 $JOL" | sha1sum -c - >/dev/null # Maven Central's own .sha1
|
|
|
|
BUILD="$ROOT/build/headers"; rm -rf "$BUILD"; mkdir -p "$BUILD"
|
|
"$JDK27/bin/javac" --release 26 -cp "$JOL" -d "$BUILD" "$ROOT"/object-headers/src/*.java
|
|
|
|
# JOL wants to attach to itself (for Instrumentation) and calls sun.misc.Unsafe, which JDK 24+ warns about.
|
|
COMMON=(-Djdk.attach.allowAttachSelf=true -XX:+EnableDynamicAgentLoading --sun-misc-unsafe-memory-access=allow -cp "$BUILD:$JOL")
|
|
|
|
# The Serviceability Agent line JOL 0.17 prints on JDK 27 is JOL failing to read a flag that no longer exists
|
|
# (UseCompressedClassPointers is obsolete in 27); it is kept in the transcript because it is real.
|
|
"$JDK26/bin/java" "${COMMON[@]}" HeaderDemo > "$OUT/10-headers-jdk26.txt" 2>&1
|
|
"$JDK27/bin/java" "${COMMON[@]}" HeaderDemo > "$OUT/11-headers-jdk27.txt" 2>&1
|
|
"$JDK27/bin/java" -XX:-UseCompactObjectHeaders "${COMMON[@]}" HeaderDemo > "$OUT/12-headers-jdk27-opt-out.txt" 2>&1
|
|
|
|
# JOL 0.17 cannot lay out a record without a workaround. Capture the failure and the fix.
|
|
"$JDK27/bin/java" "${COMMON[@]}" RecordProbe > "$OUT/13-jol-record-failure.txt" 2>&1 || true
|
|
"$JDK27/bin/java" -Djol.magicFieldOffset=true "${COMMON[@]}" RecordProbe > "$OUT/14-jol-record-workaround.txt" 2>&1
|
|
|
|
# One compact table of instance sizes, extracted from the three transcripts (not retyped).
|
|
{
|
|
echo "# Instance sizes in bytes, extracted from 10-, 11- and 12- transcripts"
|
|
for f in 10-headers-jdk26 11-headers-jdk27 12-headers-jdk27-opt-out; do
|
|
echo "--- $f"
|
|
awk '/^=== /{t=$0} /^Instance size/{print t " -> " $0} /^1,000,000 /{print}' "$OUT/$f.txt"
|
|
done
|
|
} > "$OUT/15-headers-summary.txt"
|
|
cat "$OUT/15-headers-summary.txt"
|