< prev index next >

src/java.base/share/classes/jdk/internal/module/ModuleBootstrap.java

Print this page

        

@@ -52,10 +52,11 @@
 import jdk.internal.loader.BootLoader;
 import jdk.internal.loader.BuiltinClassLoader;
 import jdk.internal.misc.JavaLangAccess;
 import jdk.internal.misc.JavaLangModuleAccess;
 import jdk.internal.misc.SharedSecrets;
+import jdk.internal.misc.VM;
 import jdk.internal.perf.PerfCounter;
 
 /**
  * Initializes/boots the module system.
  *

@@ -170,14 +171,29 @@
         ModuleFinder systemModuleFinder;
 
         boolean haveModulePath = (appModulePath != null || upgradeModulePath != null);
         boolean needResolution = true;
 
+        // If the java heap was archived at CDS dump time and the environment
+        // at dump time matches the current environment then use the archived
+        // system modules and finder.
+        ArchivedModuleGraph archivedModuleGraph = ArchivedModuleGraph.get(mainModule);
+        if (archivedModuleGraph != null
+                && !haveModulePath
+                && addModules.isEmpty()
+                && limitModules.isEmpty()
+                && !isPatched) {
+            systemModules = archivedModuleGraph.systemModules();
+            systemModuleFinder = archivedModuleGraph.finder();
+            needResolution = (traceOutput != null);
+        } else {
+            boolean canArchive = false;
         if (!haveModulePath && addModules.isEmpty() && limitModules.isEmpty()) {
             systemModules = SystemModuleFinders.systemModules(mainModule);
-            if (systemModules != null && !isPatched && (traceOutput == null)) {
-                needResolution = false;
+                if (systemModules != null && !isPatched) {
+                    needResolution = (traceOutput != null);
+                    canArchive = true; 
             }
         }
         if (systemModules == null) {
             // all system modules are observable
             systemModules = SystemModuleFinders.allSystemModules();

@@ -189,10 +205,17 @@
             // exploded build or testing
             systemModules = new ExplodedSystemModules();
             systemModuleFinder = SystemModuleFinders.ofSystem();
         }
 
+            // Module graph can be archived at CDS dump time. Only allow the
+            // unnamed module case for now.
+            if (canArchive && (mainModule == null)) {
+                ArchivedModuleGraph.archive(mainModule, systemModules, systemModuleFinder);
+            }
+        }
+
         Counters.add("jdk.module.boot.1.systemModulesTime", t1);
 
 
         // Step 2: Define and load java.base. This patches all classes loaded
         // to date so that they are members of java.base. Once java.base is
< prev index next >