mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 15:24:43 +02:00
8214858: Improve module graph archiving
Reviewed-by: jiangli, alanb
This commit is contained in:
parent
c0099a8a0d
commit
c9c59d3155
3 changed files with 100 additions and 47 deletions
|
@ -71,10 +71,7 @@ static ArchivableStaticFieldInfo closed_archive_subgraph_entry_fields[] = {
|
||||||
};
|
};
|
||||||
// Entry fields for subgraphs archived in the open archive heap region.
|
// Entry fields for subgraphs archived in the open archive heap region.
|
||||||
static ArchivableStaticFieldInfo open_archive_subgraph_entry_fields[] = {
|
static ArchivableStaticFieldInfo open_archive_subgraph_entry_fields[] = {
|
||||||
{"jdk/internal/module/ArchivedModuleGraph", "archivedSystemModules"},
|
{"jdk/internal/module/ArchivedModuleGraph", "archivedModuleGraph"},
|
||||||
{"jdk/internal/module/ArchivedModuleGraph", "archivedModuleFinder"},
|
|
||||||
{"jdk/internal/module/ArchivedModuleGraph", "archivedMainModule"},
|
|
||||||
{"jdk/internal/module/ArchivedModuleGraph", "archivedConfiguration"},
|
|
||||||
{"java/util/ImmutableCollections$ListN", "EMPTY_LIST"},
|
{"java/util/ImmutableCollections$ListN", "EMPTY_LIST"},
|
||||||
{"java/util/ImmutableCollections$MapN", "EMPTY_MAP"},
|
{"java/util/ImmutableCollections$MapN", "EMPTY_MAP"},
|
||||||
{"java/util/ImmutableCollections$SetN", "EMPTY_SET"},
|
{"java/util/ImmutableCollections$SetN", "EMPTY_SET"},
|
||||||
|
|
|
@ -27,32 +27,40 @@ package jdk.internal.module;
|
||||||
|
|
||||||
import java.lang.module.Configuration;
|
import java.lang.module.Configuration;
|
||||||
import java.lang.module.ModuleFinder;
|
import java.lang.module.ModuleFinder;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import jdk.internal.misc.VM;
|
import jdk.internal.misc.VM;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used by ModuleBootstrap to obtain the archived system modules and finder.
|
* Used by ModuleBootstrap to obtain the archived system modules and finder.
|
||||||
*/
|
*/
|
||||||
final class ArchivedModuleGraph {
|
final class ArchivedModuleGraph {
|
||||||
private static String archivedMainModule;
|
private static ArchivedModuleGraph archivedModuleGraph;
|
||||||
private static SystemModules archivedSystemModules;
|
|
||||||
private static ModuleFinder archivedModuleFinder;
|
|
||||||
private static Configuration archivedConfiguration;
|
|
||||||
|
|
||||||
private final SystemModules systemModules;
|
private final String mainModule;
|
||||||
|
private final boolean hasSplitPackages;
|
||||||
|
private final boolean hasIncubatorModules;
|
||||||
private final ModuleFinder finder;
|
private final ModuleFinder finder;
|
||||||
private final Configuration configuration;
|
private final Configuration configuration;
|
||||||
|
private final Map<String, Set<String>> concealedPackagesToOpen;
|
||||||
|
private final Map<String, Set<String>> exportedPackagesToOpen;
|
||||||
|
|
||||||
private ArchivedModuleGraph(SystemModules modules,
|
private ArchivedModuleGraph(String mainModule,
|
||||||
|
boolean hasSplitPackages,
|
||||||
|
boolean hasIncubatorModules,
|
||||||
ModuleFinder finder,
|
ModuleFinder finder,
|
||||||
Configuration configuration) {
|
Configuration configuration,
|
||||||
this.systemModules = modules;
|
Map<String, Set<String>> concealedPackagesToOpen,
|
||||||
|
Map<String, Set<String>> exportedPackagesToOpen) {
|
||||||
|
this.mainModule = mainModule;
|
||||||
|
this.hasSplitPackages = hasSplitPackages;
|
||||||
|
this.hasIncubatorModules = hasIncubatorModules;
|
||||||
this.finder = finder;
|
this.finder = finder;
|
||||||
this.configuration = configuration;
|
this.configuration = configuration;
|
||||||
}
|
this.concealedPackagesToOpen = concealedPackagesToOpen;
|
||||||
|
this.exportedPackagesToOpen = exportedPackagesToOpen;
|
||||||
SystemModules systemModules() {
|
|
||||||
return systemModules;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ModuleFinder finder() {
|
ModuleFinder finder() {
|
||||||
|
@ -63,32 +71,54 @@ final class ArchivedModuleGraph {
|
||||||
return configuration;
|
return configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
// A factory method that ModuleBootstrap can use to obtain the
|
Map<String, Set<String>> concealedPackagesToOpen() {
|
||||||
// ArchivedModuleGraph.
|
return concealedPackagesToOpen;
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, Set<String>> exportedPackagesToOpen() {
|
||||||
|
return exportedPackagesToOpen;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean hasSplitPackages() {
|
||||||
|
return hasSplitPackages;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean hasIncubatorModules() {
|
||||||
|
return hasIncubatorModules;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the ArchivedModuleGraph for the given initial module.
|
||||||
|
*/
|
||||||
static ArchivedModuleGraph get(String mainModule) {
|
static ArchivedModuleGraph get(String mainModule) {
|
||||||
if (Objects.equals(mainModule, archivedMainModule)
|
ArchivedModuleGraph graph = archivedModuleGraph;
|
||||||
&& archivedSystemModules != null
|
if (graph != null && Objects.equals(mainModule, graph.mainModule)) {
|
||||||
&& archivedModuleFinder != null
|
return graph;
|
||||||
&& archivedConfiguration != null) {
|
|
||||||
return new ArchivedModuleGraph(archivedSystemModules,
|
|
||||||
archivedModuleFinder,
|
|
||||||
archivedConfiguration);
|
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Used at CDS dump time
|
/**
|
||||||
|
* Archive the module graph for the given initial module.
|
||||||
|
*/
|
||||||
static void archive(String mainModule,
|
static void archive(String mainModule,
|
||||||
SystemModules systemModules,
|
boolean hasSplitPackages,
|
||||||
|
boolean hasIncubatorModules,
|
||||||
ModuleFinder finder,
|
ModuleFinder finder,
|
||||||
Configuration configuration) {
|
Configuration configuration,
|
||||||
if (archivedMainModule != null)
|
Map<String, Set<String>> concealedPackagesToOpen,
|
||||||
|
Map<String, Set<String>> exportedPackagesToOpen) {
|
||||||
|
if (mainModule != null) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
archivedMainModule = mainModule;
|
}
|
||||||
archivedSystemModules = systemModules;
|
archivedModuleGraph = new ArchivedModuleGraph(mainModule,
|
||||||
archivedModuleFinder = finder;
|
hasSplitPackages,
|
||||||
archivedConfiguration = configuration;
|
hasIncubatorModules,
|
||||||
|
finder,
|
||||||
|
configuration,
|
||||||
|
concealedPackagesToOpen,
|
||||||
|
exportedPackagesToOpen);
|
||||||
}
|
}
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
|
|
@ -172,6 +172,8 @@ public final class ModuleBootstrap {
|
||||||
boolean haveModulePath = (appModulePath != null || upgradeModulePath != null);
|
boolean haveModulePath = (appModulePath != null || upgradeModulePath != null);
|
||||||
boolean needResolution = true;
|
boolean needResolution = true;
|
||||||
boolean canArchive = false;
|
boolean canArchive = false;
|
||||||
|
boolean hasSplitPackages;
|
||||||
|
boolean hasIncubatorModules;
|
||||||
|
|
||||||
// If the java heap was archived at CDS dump time and the environment
|
// If the java heap was archived at CDS dump time and the environment
|
||||||
// at dump time matches the current environment then use the archived
|
// at dump time matches the current environment then use the archived
|
||||||
|
@ -182,8 +184,9 @@ public final class ModuleBootstrap {
|
||||||
&& addModules.isEmpty()
|
&& addModules.isEmpty()
|
||||||
&& limitModules.isEmpty()
|
&& limitModules.isEmpty()
|
||||||
&& !isPatched) {
|
&& !isPatched) {
|
||||||
systemModules = archivedModuleGraph.systemModules();
|
|
||||||
systemModuleFinder = archivedModuleGraph.finder();
|
systemModuleFinder = archivedModuleGraph.finder();
|
||||||
|
hasSplitPackages = archivedModuleGraph.hasSplitPackages();
|
||||||
|
hasIncubatorModules = archivedModuleGraph.hasIncubatorModules();
|
||||||
needResolution = (traceOutput != null);
|
needResolution = (traceOutput != null);
|
||||||
} else {
|
} else {
|
||||||
if (!haveModulePath && addModules.isEmpty() && limitModules.isEmpty()) {
|
if (!haveModulePath && addModules.isEmpty() && limitModules.isEmpty()) {
|
||||||
|
@ -205,6 +208,11 @@ public final class ModuleBootstrap {
|
||||||
systemModules = new ExplodedSystemModules();
|
systemModules = new ExplodedSystemModules();
|
||||||
systemModuleFinder = SystemModuleFinders.ofSystem();
|
systemModuleFinder = SystemModuleFinders.ofSystem();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hasSplitPackages = systemModules.hasSplitPackages();
|
||||||
|
hasIncubatorModules = systemModules.hasIncubatorModules();
|
||||||
|
// not using the archived module graph - avoid accidental use
|
||||||
|
archivedModuleGraph = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Counters.add("jdk.module.boot.1.systemModulesTime", t1);
|
Counters.add("jdk.module.boot.1.systemModulesTime", t1);
|
||||||
|
@ -395,7 +403,7 @@ public final class ModuleBootstrap {
|
||||||
}
|
}
|
||||||
|
|
||||||
// check for split packages in the modules mapped to the built-in loaders
|
// check for split packages in the modules mapped to the built-in loaders
|
||||||
if (systemModules.hasSplitPackages() || isPatched || haveModulePath) {
|
if (hasSplitPackages || isPatched || haveModulePath) {
|
||||||
checkSplitPackages(cf, clf);
|
checkSplitPackages(cf, clf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -415,7 +423,7 @@ public final class ModuleBootstrap {
|
||||||
// Step 7: Miscellaneous
|
// Step 7: Miscellaneous
|
||||||
|
|
||||||
// check incubating status
|
// check incubating status
|
||||||
if (systemModules.hasIncubatorModules() || haveModulePath) {
|
if (hasIncubatorModules || haveModulePath) {
|
||||||
checkIncubatingStatus(cf);
|
checkIncubatingStatus(cf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -423,7 +431,21 @@ public final class ModuleBootstrap {
|
||||||
long t7 = System.nanoTime();
|
long t7 = System.nanoTime();
|
||||||
addExtraReads(bootLayer);
|
addExtraReads(bootLayer);
|
||||||
boolean extraExportsOrOpens = addExtraExportsAndOpens(bootLayer);
|
boolean extraExportsOrOpens = addExtraExportsAndOpens(bootLayer);
|
||||||
addIllegalAccess(upgradeModulePath, systemModules, bootLayer, extraExportsOrOpens);
|
|
||||||
|
Map<String, Set<String>> concealedPackagesToOpen;
|
||||||
|
Map<String, Set<String>> exportedPackagesToOpen;
|
||||||
|
if (archivedModuleGraph != null) {
|
||||||
|
concealedPackagesToOpen = archivedModuleGraph.concealedPackagesToOpen();
|
||||||
|
exportedPackagesToOpen = archivedModuleGraph.exportedPackagesToOpen();
|
||||||
|
} else {
|
||||||
|
concealedPackagesToOpen = systemModules.concealedPackagesToOpen();
|
||||||
|
exportedPackagesToOpen = systemModules.exportedPackagesToOpen();
|
||||||
|
}
|
||||||
|
addIllegalAccess(upgradeModulePath,
|
||||||
|
concealedPackagesToOpen,
|
||||||
|
exportedPackagesToOpen,
|
||||||
|
bootLayer,
|
||||||
|
extraExportsOrOpens);
|
||||||
Counters.add("jdk.module.boot.7.adjustModulesTime", t7);
|
Counters.add("jdk.module.boot.7.adjustModulesTime", t7);
|
||||||
|
|
||||||
// save module finders for later use
|
// save module finders for later use
|
||||||
|
@ -436,8 +458,13 @@ public final class ModuleBootstrap {
|
||||||
// Module graph can be archived at CDS dump time. Only allow the
|
// Module graph can be archived at CDS dump time. Only allow the
|
||||||
// unnamed module case for now.
|
// unnamed module case for now.
|
||||||
if (canArchive && (mainModule == null)) {
|
if (canArchive && (mainModule == null)) {
|
||||||
ArchivedModuleGraph.archive(mainModule, systemModules,
|
ArchivedModuleGraph.archive(mainModule,
|
||||||
systemModuleFinder, cf);
|
hasSplitPackages,
|
||||||
|
hasIncubatorModules,
|
||||||
|
systemModuleFinder,
|
||||||
|
cf,
|
||||||
|
concealedPackagesToOpen,
|
||||||
|
exportedPackagesToOpen);
|
||||||
}
|
}
|
||||||
|
|
||||||
// total time to initialize
|
// total time to initialize
|
||||||
|
@ -738,7 +765,8 @@ public final class ModuleBootstrap {
|
||||||
* of system modules in the boot layer to code in unnamed modules.
|
* of system modules in the boot layer to code in unnamed modules.
|
||||||
*/
|
*/
|
||||||
private static void addIllegalAccess(ModuleFinder upgradeModulePath,
|
private static void addIllegalAccess(ModuleFinder upgradeModulePath,
|
||||||
SystemModules systemModules,
|
Map<String, Set<String>> concealedPackagesToOpen,
|
||||||
|
Map<String, Set<String>> exportedPackagesToOpen,
|
||||||
ModuleLayer bootLayer,
|
ModuleLayer bootLayer,
|
||||||
boolean extraExportsOrOpens) {
|
boolean extraExportsOrOpens) {
|
||||||
String value = getAndRemoveProperty("jdk.module.illegalAccess");
|
String value = getAndRemoveProperty("jdk.module.illegalAccess");
|
||||||
|
@ -764,13 +792,11 @@ public final class ModuleBootstrap {
|
||||||
IllegalAccessLogger.Builder builder
|
IllegalAccessLogger.Builder builder
|
||||||
= new IllegalAccessLogger.Builder(mode, System.err);
|
= new IllegalAccessLogger.Builder(mode, System.err);
|
||||||
|
|
||||||
Map<String, Set<String>> map1 = systemModules.concealedPackagesToOpen();
|
if (concealedPackagesToOpen.isEmpty() && exportedPackagesToOpen.isEmpty()) {
|
||||||
Map<String, Set<String>> map2 = systemModules.exportedPackagesToOpen();
|
|
||||||
if (map1.isEmpty() && map2.isEmpty()) {
|
|
||||||
// need to generate (exploded build)
|
// need to generate (exploded build)
|
||||||
IllegalAccessMaps maps = IllegalAccessMaps.generate(limitedFinder());
|
IllegalAccessMaps maps = IllegalAccessMaps.generate(limitedFinder());
|
||||||
map1 = maps.concealedPackagesToOpen();
|
concealedPackagesToOpen = maps.concealedPackagesToOpen();
|
||||||
map2 = maps.exportedPackagesToOpen();
|
exportedPackagesToOpen = maps.exportedPackagesToOpen();
|
||||||
}
|
}
|
||||||
|
|
||||||
// open specific packages in the system modules
|
// open specific packages in the system modules
|
||||||
|
@ -789,8 +815,8 @@ public final class ModuleBootstrap {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Set<String> concealedPackages = map1.getOrDefault(name, Set.of());
|
Set<String> concealedPackages = concealedPackagesToOpen.getOrDefault(name, Set.of());
|
||||||
Set<String> exportedPackages = map2.getOrDefault(name, Set.of());
|
Set<String> exportedPackages = exportedPackagesToOpen.getOrDefault(name, Set.of());
|
||||||
|
|
||||||
// refresh the set of concealed and exported packages if needed
|
// refresh the set of concealed and exported packages if needed
|
||||||
if (extraExportsOrOpens) {
|
if (extraExportsOrOpens) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue