Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b5pUjAyJuUaNEQqzGJ
36 lines
2.0 KiB
Bash
Executable File
36 lines
2.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Regenerates every file in output/. Module counts depend on the JDK build; the GC-based
|
|
# unloading demo asks the collector politely and can, in principle, vary (see the post).
|
|
set -euo pipefail
|
|
cd "$(dirname "$0")/.."
|
|
mvn -q -B compile
|
|
mkdir -p output
|
|
strip() { grep -v -e '^Picked up JAVA_TOOL_OPTIONS' -e '^Picked up _JAVA_OPTIONS'; }
|
|
run() { java -Dstdout.encoding=UTF-8 -cp target/classes "com.ankurm.classloaders.$1" 2>&1 | strip > "output/$2.txt"; }
|
|
|
|
run HierarchyDemo 01-hierarchy
|
|
run DelegationDemo 02-delegation
|
|
run ForNameDemo 03-forname-vs-loadclass
|
|
run ErrorsDemo 04-errors
|
|
run PluginDemo 05-plugins
|
|
run ContextLoaderDemo 06-context-loader
|
|
|
|
# 07: what the JVM itself logs about where each class came from (-Xlog:class+load, no decorators)
|
|
java -Dstdout.encoding=UTF-8 -Xlog:class+load=info:stdout:none -cp target/classes com.ankurm.classloaders.HierarchyDemo 2>&1 \
|
|
| strip | grep -E '^(java\.lang\.String|java\.util\.ArrayList|java\.sql\.Driver|javax\.tools\.JavaCompiler|com\.ankurm\.classloaders\.HierarchyDemo) source: ' \
|
|
| sed -E 's#file:/.*/target/classes/#file:<module>/target/classes/#' > output/07-class-load-log.txt
|
|
|
|
# 08: the JVM's own record of unloads (-Xlog:class+unload) while the unloading demo runs
|
|
java -Dstdout.encoding=UTF-8 -Xlog:class+unload=info:stdout:none -cp target/classes com.ankurm.classloaders.PluginDemo 2>&1 \
|
|
| strip | grep -E 'unloading class com\.acme' | sed -E 's/ 0x[0-9a-f]+//' | sort | uniq -c > output/08-class-unload-log.txt
|
|
|
|
# 09: jcmd VM.classloaders against a live JVM holding two named plugin loaders
|
|
java -cp target/classes com.ankurm.classloaders.HoldDemo > /tmp/hold.out 2>&1 &
|
|
HOLD=$!
|
|
for i in $(seq 1 60); do grep -q '^ready' /tmp/hold.out 2>/dev/null && break; sleep 0.5; done
|
|
jcmd "$HOLD" VM.classloaders 2>&1 | strip | sed -E "s/^$HOLD:/<pid>:/; s/0x[0-9a-f]+/0x<addr>/g" > output/09-jcmd-classloaders.txt
|
|
kill "$HOLD" 2>/dev/null || true
|
|
|
|
mvn -B test 2>&1 | grep -E 'Tests run|BUILD|ERROR|FAIL' | grep -v 'Picked up' > output/10-tests.txt
|
|
echo "regenerated:"; ls output
|