mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-26 22:34:27 +02:00
8319343: Improve CDS module graph support for --add-modules option
Reviewed-by: alanb, iklam
This commit is contained in:
parent
568b07a09b
commit
d4eb2d924e
12 changed files with 381 additions and 21 deletions
|
@ -25,6 +25,7 @@
|
|||
package jdk.internal.module;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.lang.module.Configuration;
|
||||
import java.lang.module.ModuleFinder;
|
||||
|
@ -43,19 +44,22 @@ class ArchivedModuleGraph {
|
|||
private final Configuration configuration;
|
||||
private final Function<String, ClassLoader> classLoaderFunction;
|
||||
private final String mainModule;
|
||||
private final Set<String> addModules;
|
||||
|
||||
private ArchivedModuleGraph(boolean hasSplitPackages,
|
||||
boolean hasIncubatorModules,
|
||||
ModuleFinder finder,
|
||||
Configuration configuration,
|
||||
Function<String, ClassLoader> classLoaderFunction,
|
||||
String mainModule) {
|
||||
String mainModule,
|
||||
Set<String> addModules) {
|
||||
this.hasSplitPackages = hasSplitPackages;
|
||||
this.hasIncubatorModules = hasIncubatorModules;
|
||||
this.finder = finder;
|
||||
this.configuration = configuration;
|
||||
this.classLoaderFunction = classLoaderFunction;
|
||||
this.mainModule = mainModule;
|
||||
this.addModules = addModules;
|
||||
}
|
||||
|
||||
ModuleFinder finder() {
|
||||
|
@ -78,12 +82,24 @@ class ArchivedModuleGraph {
|
|||
return hasIncubatorModules;
|
||||
}
|
||||
|
||||
static boolean sameAddModules(Set<String> addModules) {
|
||||
if (archivedModuleGraph.addModules == null || addModules == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (archivedModuleGraph.addModules.size() != addModules.size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return archivedModuleGraph.addModules.containsAll(addModules);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ArchivedModuleGraph for the given initial module.
|
||||
*/
|
||||
static ArchivedModuleGraph get(String mainModule) {
|
||||
static ArchivedModuleGraph get(String mainModule, Set<String> addModules) {
|
||||
ArchivedModuleGraph graph = archivedModuleGraph;
|
||||
if ((graph != null) && Objects.equals(graph.mainModule, mainModule)) {
|
||||
if ((graph != null) && Objects.equals(graph.mainModule, mainModule) && sameAddModules(addModules)) {
|
||||
return graph;
|
||||
} else {
|
||||
return null;
|
||||
|
@ -98,13 +114,15 @@ class ArchivedModuleGraph {
|
|||
ModuleFinder finder,
|
||||
Configuration configuration,
|
||||
Function<String, ClassLoader> classLoaderFunction,
|
||||
String mainModule) {
|
||||
String mainModule,
|
||||
Set<String> addModules) {
|
||||
archivedModuleGraph = new ArchivedModuleGraph(hasSplitPackages,
|
||||
hasIncubatorModules,
|
||||
finder,
|
||||
configuration,
|
||||
classLoaderFunction,
|
||||
mainModule);
|
||||
mainModule,
|
||||
addModules);
|
||||
}
|
||||
|
||||
static {
|
||||
|
|
|
@ -141,7 +141,6 @@ public final class ModuleBootstrap {
|
|||
private static boolean canUseArchivedBootLayer() {
|
||||
return getProperty("jdk.module.upgrade.path") == null &&
|
||||
getProperty("jdk.module.patch.0") == null && // --patch-module
|
||||
getProperty("jdk.module.addmods.0") == null && // --add-modules
|
||||
getProperty("jdk.module.limitmods") == null && // --limit-modules
|
||||
getProperty("jdk.module.addreads.0") == null && // --add-reads
|
||||
getProperty("jdk.module.addexports.0") == null && // --add-exports
|
||||
|
@ -212,10 +211,9 @@ public final class ModuleBootstrap {
|
|||
// 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);
|
||||
ArchivedModuleGraph archivedModuleGraph = ArchivedModuleGraph.get(mainModule, addModules);
|
||||
if (archivedModuleGraph != null
|
||||
&& !haveModulePath
|
||||
&& addModules.isEmpty()
|
||||
&& limitModules.isEmpty()
|
||||
&& !isPatched) {
|
||||
systemModuleFinder = archivedModuleGraph.finder();
|
||||
|
@ -466,7 +464,6 @@ public final class ModuleBootstrap {
|
|||
|
||||
if (CDS.isDumpingStaticArchive()
|
||||
&& !haveUpgradeModulePath
|
||||
&& addModules.isEmpty()
|
||||
&& allJrtOrModularJar(cf)) {
|
||||
assert !isPatched;
|
||||
|
||||
|
@ -478,7 +475,8 @@ public final class ModuleBootstrap {
|
|||
systemModuleFinder,
|
||||
cf,
|
||||
clf,
|
||||
mainModule);
|
||||
mainModule,
|
||||
addModules);
|
||||
if (!hasSplitPackages && !hasIncubatorModules) {
|
||||
ArchivedBootLayer.archive(bootLayer);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue