classloaders: Java class loaders module (three built-in loaders and which modules each owns, parent delegation traced across a two-loader chain, child-first PluginLoader, class identity and the failing (Plugin) cast, Class.forName vs loadClass initialisation, ClassNotFoundException vs NoClassDefFoundError incl. 'Could not initialize class', hot reload, unloading and a Registry leak, context class loader, jcmd VM.classloaders), 18 contract tests
Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b5pUjAyJuUaNEQqzGJ
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
74da9cd899
commit
cca173d104
Executable
+35
@@ -0,0 +1,35 @@
|
||||
#!/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
|
||||
Executable
+6
@@ -0,0 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
# Run one demo: scripts/run.sh HierarchyDemo
|
||||
set -euo pipefail
|
||||
cd "$(dirname "$0")/.."
|
||||
mvn -q -B compile
|
||||
java -Dstdout.encoding=UTF-8 -cp target/classes "com.ankurm.classloaders.${1:?demo class name}"
|
||||
Reference in New Issue
Block a user