--- old/src/java.base/share/classes/jdk/internal/loader/ClassLoaders.java 2020-08-12 15:01:19.693389125 -0700 +++ new/src/java.base/share/classes/jdk/internal/loader/ClassLoaders.java 2020-08-12 15:01:19.029364130 -0700 @@ -36,6 +36,7 @@ import jdk.internal.access.JavaLangAccess; import jdk.internal.access.SharedSecrets; import jdk.internal.misc.VM; +import jdk.internal.module.ServicesCatalog; /** * Creates and provides access to the built-in platform and application class @@ -56,14 +57,22 @@ // Creates the built-in class loaders. static { - // -Xbootclasspath/a or -javaagent with Boot-Class-Path attribute - String append = VM.getSavedProperty("jdk.boot.class.path.append"); - BOOT_LOADER = - new BootClassLoader((append != null && !append.isEmpty()) - ? new URLClassPath(append, true) - : null); - PLATFORM_LOADER = new PlatformClassLoader(BOOT_LOADER); - + ArchivedClassLoaders archivedClassLoaders = ArchivedClassLoaders.get(); + if (archivedClassLoaders != null) { + // assert VM.getSavedProperty("jdk.boot.class.path.append") == null + BOOT_LOADER = (BootClassLoader) archivedClassLoaders.bootLoader(); + PLATFORM_LOADER = (PlatformClassLoader) archivedClassLoaders.platformLoader(); + ServicesCatalog catalog = archivedClassLoaders.servicesCatalog(PLATFORM_LOADER); + ServicesCatalog.putServicesCatalog(PLATFORM_LOADER, catalog); + } else { + // -Xbootclasspath/a or -javaagent with Boot-Class-Path attribute + String append = VM.getSavedProperty("jdk.boot.class.path.append"); + URLClassPath ucp = (append != null && !append.isEmpty()) + ? new URLClassPath(append, true) + : null; + BOOT_LOADER = new BootClassLoader(ucp); + PLATFORM_LOADER = new PlatformClassLoader(BOOT_LOADER); + } // A class path is required when no initial module is specified. // In this case the class path defaults to "", meaning the current // working directory. When an initial module is specified, on the @@ -75,7 +84,15 @@ cp = (initialModuleName == null) ? "" : null; } URLClassPath ucp = new URLClassPath(cp, false); - APP_LOADER = new AppClassLoader(PLATFORM_LOADER, ucp); + if (archivedClassLoaders != null) { + APP_LOADER = (AppClassLoader) archivedClassLoaders.appLoader(); + ServicesCatalog catalog = archivedClassLoaders.servicesCatalog(APP_LOADER); + ServicesCatalog.putServicesCatalog(APP_LOADER, catalog); + APP_LOADER.setClassPath(ucp); + } else { + APP_LOADER = new AppClassLoader(PLATFORM_LOADER, ucp); + ArchivedClassLoaders.archive(); + } } /** @@ -144,11 +161,8 @@ throw new InternalError(); } - final URLClassPath ucp; - - AppClassLoader(PlatformClassLoader parent, URLClassPath ucp) { + AppClassLoader(BuiltinClassLoader parent, URLClassPath ucp) { super("app", parent, ucp); - this.ucp = ucp; } @Override @@ -181,7 +195,7 @@ * @see java.lang.instrument.Instrumentation#appendToSystemClassLoaderSearch */ void appendToClassPathForInstrumentation(String path) { - ucp.addFile(path); + appendClassPath(path); } /** @@ -190,6 +204,13 @@ protected Package defineOrCheckPackage(String pn, Manifest man, URL url) { return super.defineOrCheckPackage(pn, man, url); } + + /** + * Called by the VM, during -Xshare:dump + */ + private void resetArchivedStates() { + setClassPath(null); + } } /**