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.
|
||||
static ArchivableStaticFieldInfo open_archive_subgraph_entry_fields[] = {
|
||||
{"jdk/internal/module/ArchivedModuleGraph", "archivedSystemModules"},
|
||||
{"jdk/internal/module/ArchivedModuleGraph", "archivedModuleFinder"},
|
||||
{"jdk/internal/module/ArchivedModuleGraph", "archivedMainModule"},
|
||||
{"jdk/internal/module/ArchivedModuleGraph", "archivedConfiguration"},
|
||||
{"jdk/internal/module/ArchivedModuleGraph", "archivedModuleGraph"},
|
||||
{"java/util/ImmutableCollections$ListN", "EMPTY_LIST"},
|
||||
{"java/util/ImmutableCollections$MapN", "EMPTY_MAP"},
|
||||
{"java/util/ImmutableCollections$SetN", "EMPTY_SET"},
|
||||
|
|
|
@ -27,32 +27,40 @@ package jdk.internal.module;
|
|||
|
||||
import java.lang.module.Configuration;
|
||||
import java.lang.module.ModuleFinder;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import jdk.internal.misc.VM;
|
||||
|
||||
/**
|
||||
* Used by ModuleBootstrap to obtain the archived system modules and finder.
|
||||
*/
|
||||
final class ArchivedModuleGraph {
|
||||
private static String archivedMainModule;
|
||||
private static SystemModules archivedSystemModules;
|
||||
private static ModuleFinder archivedModuleFinder;
|
||||
private static Configuration archivedConfiguration;
|
||||
private static ArchivedModuleGraph archivedModuleGraph;
|
||||
|
||||
private final SystemModules systemModules;
|
||||
private final String mainModule;
|
||||
private final boolean hasSplitPackages;
|
||||
private final boolean hasIncubatorModules;
|
||||
private final ModuleFinder finder;
|
||||
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,
|
||||
Configuration configuration) {
|
||||
this.systemModules = modules;
|
||||
Configuration configuration,
|
||||
Map<String, Set<String>> concealedPackagesToOpen,
|
||||
Map<String, Set<String>> exportedPackagesToOpen) {
|
||||
this.mainModule = mainModule;
|
||||
this.hasSplitPackages = hasSplitPackages;
|
||||
this.hasIncubatorModules = hasIncubatorModules;
|
||||
this.finder = finder;
|
||||
this.configuration = configuration;
|
||||
}
|
||||
|
||||
SystemModules systemModules() {
|
||||
return systemModules;
|
||||
this.concealedPackagesToOpen = concealedPackagesToOpen;
|
||||
this.exportedPackagesToOpen = exportedPackagesToOpen;
|
||||
}
|
||||
|
||||
ModuleFinder finder() {
|
||||
|
@ -63,32 +71,54 @@ final class ArchivedModuleGraph {
|
|||
return configuration;
|
||||
}
|
||||
|
||||
// A factory method that ModuleBootstrap can use to obtain the
|
||||
// ArchivedModuleGraph.
|
||||
Map<String, Set<String>> concealedPackagesToOpen() {
|
||||
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) {
|
||||
if (Objects.equals(mainModule, archivedMainModule)
|
||||
&& archivedSystemModules != null
|
||||
&& archivedModuleFinder != null
|
||||
&& archivedConfiguration != null) {
|
||||
return new ArchivedModuleGraph(archivedSystemModules,
|
||||
archivedModuleFinder,
|
||||
archivedConfiguration);
|
||||
ArchivedModuleGraph graph = archivedModuleGraph;
|
||||
if (graph != null && Objects.equals(mainModule, graph.mainModule)) {
|
||||
return graph;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Used at CDS dump time
|
||||
/**
|
||||
* Archive the module graph for the given initial module.
|
||||
*/
|
||||
static void archive(String mainModule,
|
||||
SystemModules systemModules,
|
||||
boolean hasSplitPackages,
|
||||
boolean hasIncubatorModules,
|
||||
ModuleFinder finder,
|
||||
Configuration configuration) {
|
||||
if (archivedMainModule != null)
|
||||
Configuration configuration,
|
||||
Map<String, Set<String>> concealedPackagesToOpen,
|
||||
Map<String, Set<String>> exportedPackagesToOpen) {
|
||||
if (mainModule != null) {
|
||||
throw new UnsupportedOperationException();
|
||||
archivedMainModule = mainModule;
|
||||
archivedSystemModules = systemModules;
|
||||
archivedModuleFinder = finder;
|
||||
archivedConfiguration = configuration;
|
||||
}
|
||||
archivedModuleGraph = new ArchivedModuleGraph(mainModule,
|
||||
hasSplitPackages,
|
||||
hasIncubatorModules,
|
||||
finder,
|
||||
configuration,
|
||||
concealedPackagesToOpen,
|
||||
exportedPackagesToOpen);
|
||||
}
|
||||
|
||||
static {
|
||||
|
|
|
@ -172,6 +172,8 @@ public final class ModuleBootstrap {
|
|||
boolean haveModulePath = (appModulePath != null || upgradeModulePath != null);
|
||||
boolean needResolution = true;
|
||||
boolean canArchive = false;
|
||||
boolean hasSplitPackages;
|
||||
boolean hasIncubatorModules;
|
||||
|
||||
// If the java heap was archived at CDS dump time and the environment
|
||||
// at dump time matches the current environment then use the archived
|
||||
|
@ -182,8 +184,9 @@ public final class ModuleBootstrap {
|
|||
&& addModules.isEmpty()
|
||||
&& limitModules.isEmpty()
|
||||
&& !isPatched) {
|
||||
systemModules = archivedModuleGraph.systemModules();
|
||||
systemModuleFinder = archivedModuleGraph.finder();
|
||||
hasSplitPackages = archivedModuleGraph.hasSplitPackages();
|
||||
hasIncubatorModules = archivedModuleGraph.hasIncubatorModules();
|
||||
needResolution = (traceOutput != null);
|
||||
} else {
|
||||
if (!haveModulePath && addModules.isEmpty() && limitModules.isEmpty()) {
|
||||
|
@ -205,6 +208,11 @@ public final class ModuleBootstrap {
|
|||
systemModules = new ExplodedSystemModules();
|
||||
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);
|
||||
|
@ -395,7 +403,7 @@ public final class ModuleBootstrap {
|
|||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
@ -415,7 +423,7 @@ public final class ModuleBootstrap {
|
|||
// Step 7: Miscellaneous
|
||||
|
||||
// check incubating status
|
||||
if (systemModules.hasIncubatorModules() || haveModulePath) {
|
||||
if (hasIncubatorModules || haveModulePath) {
|
||||
checkIncubatingStatus(cf);
|
||||
}
|
||||
|
||||
|
@ -423,7 +431,21 @@ public final class ModuleBootstrap {
|
|||
long t7 = System.nanoTime();
|
||||
addExtraReads(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);
|
||||
|
||||
// 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
|
||||
// unnamed module case for now.
|
||||
if (canArchive && (mainModule == null)) {
|
||||
ArchivedModuleGraph.archive(mainModule, systemModules,
|
||||
systemModuleFinder, cf);
|
||||
ArchivedModuleGraph.archive(mainModule,
|
||||
hasSplitPackages,
|
||||
hasIncubatorModules,
|
||||
systemModuleFinder,
|
||||
cf,
|
||||
concealedPackagesToOpen,
|
||||
exportedPackagesToOpen);
|
||||
}
|
||||
|
||||
// total time to initialize
|
||||
|
@ -738,7 +765,8 @@ public final class ModuleBootstrap {
|
|||
* of system modules in the boot layer to code in unnamed modules.
|
||||
*/
|
||||
private static void addIllegalAccess(ModuleFinder upgradeModulePath,
|
||||
SystemModules systemModules,
|
||||
Map<String, Set<String>> concealedPackagesToOpen,
|
||||
Map<String, Set<String>> exportedPackagesToOpen,
|
||||
ModuleLayer bootLayer,
|
||||
boolean extraExportsOrOpens) {
|
||||
String value = getAndRemoveProperty("jdk.module.illegalAccess");
|
||||
|
@ -764,13 +792,11 @@ public final class ModuleBootstrap {
|
|||
IllegalAccessLogger.Builder builder
|
||||
= new IllegalAccessLogger.Builder(mode, System.err);
|
||||
|
||||
Map<String, Set<String>> map1 = systemModules.concealedPackagesToOpen();
|
||||
Map<String, Set<String>> map2 = systemModules.exportedPackagesToOpen();
|
||||
if (map1.isEmpty() && map2.isEmpty()) {
|
||||
if (concealedPackagesToOpen.isEmpty() && exportedPackagesToOpen.isEmpty()) {
|
||||
// need to generate (exploded build)
|
||||
IllegalAccessMaps maps = IllegalAccessMaps.generate(limitedFinder());
|
||||
map1 = maps.concealedPackagesToOpen();
|
||||
map2 = maps.exportedPackagesToOpen();
|
||||
concealedPackagesToOpen = maps.concealedPackagesToOpen();
|
||||
exportedPackagesToOpen = maps.exportedPackagesToOpen();
|
||||
}
|
||||
|
||||
// open specific packages in the system modules
|
||||
|
@ -789,8 +815,8 @@ public final class ModuleBootstrap {
|
|||
continue;
|
||||
}
|
||||
|
||||
Set<String> concealedPackages = map1.getOrDefault(name, Set.of());
|
||||
Set<String> exportedPackages = map2.getOrDefault(name, Set.of());
|
||||
Set<String> concealedPackages = concealedPackagesToOpen.getOrDefault(name, Set.of());
|
||||
Set<String> exportedPackages = exportedPackagesToOpen.getOrDefault(name, Set.of());
|
||||
|
||||
// refresh the set of concealed and exported packages if needed
|
||||
if (extraExportsOrOpens) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue