Hi Ioi,

On 19/10/2019 3:36 am, Ioi Lam wrote:
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?

When you say "built-in" do you mean all of the boot/platform/app loaders?

Any non-trivial execution of Java code could potentially have a bad interaction if run after shutdown hooks have completed.

Cheers,
David

Thanks
- Ioi

Reply via email to