Loading classes during VM shutdown
Ioi Lam
ioi.lam at oracle.com
Fri Oct 18 17:36:56 UTC 2019
For JDK-8232081 (Try to link all classes with ArchiveClassesAtExit),
when creating a dynamic CDS archive, I need to link all classes in the
"loaded" state. I am thinking of doing it at this point:
src/java.base/share/classes/java/lang/Shutdown.java:
private static void runHooks() {
synchronized (lock) {
/* Guard against the possibility of a daemon thread
invoking exit
* after DestroyJavaVM initiates the shutdown sequence
*/
if (VM.isShutdown()) return;
}
for (int i=0; i < MAX_SYSTEM_HOOKS; i++) {
try {
Runnable hook;
synchronized (lock) {
// acquire the lock to make sure the hook
registered during
// shutdown is visible here.
currentRunningHook = i;
hook = hooks[i];
}
if (hook != null) hook.run();
} catch (Throwable t) {
if (t instanceof ThreadDeath) {
ThreadDeath td = (ThreadDeath)t;
throw td;
}
}
}
+ VM.linkClassesIfDumpingDynamicArchive(); <<<<<<<<
// set shutdown state
VM.shutdown();
}
To be safe, I will only link classes loaded by the built-in loaders
(boot/platform/system). The reasons is linking classes may result in
more class loading, which would execute Java code in the class loaders.
I worry that arbitrary custom class loaders may not work well when
executed in this context, but the built-in loader should be OK. After
all, regular Shutdown hooks could (I think??) load classes ....
Does anyone see a problem with doing this?
Thanks
- Ioi
More information about the core-libs-dev
mailing list