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
@@ -0,0 +1,24 @@
|
||||
|
||||
== Class identity = name + defining loader ==
|
||||
same name: true
|
||||
same Class object: false
|
||||
c1 loader: 'plugin-v1' (com.ankurm.classloaders.PluginLoader)
|
||||
c2 loader: 'plugin-v2' (com.ankurm.classloaders.PluginLoader)
|
||||
both usable as Plugin (the interface is shared via the parent):
|
||||
p1.run() = Hello from GreeterPlugin v1
|
||||
p2.run() = Hello from GreeterPlugin v2
|
||||
c2.cast(p1): Cannot cast com.acme.GreeterPlugin to com.acme.GreeterPlugin
|
||||
|
||||
== The cast that fails even though the names match ==
|
||||
ClassCastException: class com.acme.GreeterPlugin cannot be cast to class com.ankurm.classloaders.api.Plugin (com.acme.GreeterPlugin is in unnamed module of loader 'plugin-bad' @<hash>; com.ankurm.classloaders.api.Plugin is in unnamed module of loader 'app')
|
||||
|
||||
== Hot reload: a fresh loader per version ==
|
||||
Hello from GreeterPlugin v1
|
||||
Hello from GreeterPlugin v2
|
||||
Hello from GreeterPlugin v1
|
||||
(the same class name, three times, three different Class objects)
|
||||
|
||||
== Unloading: a loader is collectable only when nothing reachable points into it ==
|
||||
plugin dropped, nothing else references it -> loader collected: true
|
||||
plugin instance stored in static Registry -> loader collected: false
|
||||
Registry cleared -> (new loader) collected: true
|
||||
Reference in New Issue
Block a user