< prev index next >

src/java.base/share/classes/jdk/internal/loader/ClassLoaders.java

Print this page

@@ -34,10 +34,11 @@
 import java.util.jar.Manifest;
 
 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
  * loaders. It also creates the class loader that is used to locate resources
  * in modules defined to the boot class loader.

@@ -54,18 +55,26 @@
     private static final PlatformClassLoader PLATFORM_LOADER;
     private static final AppClassLoader APP_LOADER;
 
     // Creates the built-in class loaders.
     static {
+        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");
-        BOOT_LOADER =
-            new BootClassLoader((append != null && !append.isEmpty())
+            URLClassPath ucp = (append != null && !append.isEmpty())
                 ? new URLClassPath(append, true)
-                : null);
+                    : 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
         // contrary, we drop this historic interpretation of the empty
         // string and instead treat it as unspecified.

@@ -73,11 +82,19 @@
         if (cp == null || cp.isEmpty()) {
             String initialModuleName = System.getProperty("jdk.module.main");
             cp = (initialModuleName == null) ? "" : null;
         }
         URLClassPath ucp = new URLClassPath(cp, false);
+        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();
+        }
     }
 
     /**
      * Returns the class loader that is used to find resources in modules
      * defined to the boot class loader.

@@ -142,15 +159,12 @@
         static {
             if (!ClassLoader.registerAsParallelCapable())
                 throw new InternalError();
         }
 
-        final URLClassPath ucp;
-
-        AppClassLoader(PlatformClassLoader parent, URLClassPath ucp) {
+        AppClassLoader(BuiltinClassLoader parent, URLClassPath ucp) {
             super("app", parent, ucp);
-            this.ucp = ucp;
         }
 
         @Override
         protected Class<?> loadClass(String cn, boolean resolve)
             throws ClassNotFoundException

@@ -179,19 +193,26 @@
          * Called by the VM to support dynamic additions to the class path
          *
          * @see java.lang.instrument.Instrumentation#appendToSystemClassLoaderSearch
          */
         void appendToClassPathForInstrumentation(String path) {
-            ucp.addFile(path);
+            appendClassPath(path);
         }
 
         /**
          * Called by the VM to support define package for AppCDS
          */
         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);
+        }
     }
 
     /**
      * Attempts to convert the given string to a file URL.
      *
< prev index next >