mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 23:34:52 +02:00
8207263: Store the Configuration for system modules into CDS archive
Archive boot layer Configuration. Reviewed-by: redestad, iklam, ccheung
This commit is contained in:
parent
5858a507f4
commit
a5d14313f5
13 changed files with 353 additions and 45 deletions
|
@ -41,8 +41,10 @@ import java.util.Set;
|
|||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import jdk.internal.misc.VM;
|
||||
import jdk.internal.module.ModuleReferenceImpl;
|
||||
import jdk.internal.module.ModuleTarget;
|
||||
import jdk.internal.vm.annotation.Stable;
|
||||
|
||||
/**
|
||||
* A configuration that is the result of <a href="package-summary.html#resolution">
|
||||
|
@ -103,7 +105,17 @@ import jdk.internal.module.ModuleTarget;
|
|||
public final class Configuration {
|
||||
|
||||
// @see Configuration#empty()
|
||||
private static final Configuration EMPTY_CONFIGURATION = new Configuration();
|
||||
// EMPTY_CONFIGURATION may be initialized from the CDS archive.
|
||||
private static @Stable Configuration EMPTY_CONFIGURATION;
|
||||
|
||||
static {
|
||||
// Initialize EMPTY_CONFIGURATION from the archive.
|
||||
VM.initializeFromArchive(Configuration.class);
|
||||
// Create a new empty Configuration if there is no archived version.
|
||||
if (EMPTY_CONFIGURATION == null) {
|
||||
EMPTY_CONFIGURATION = new Configuration();
|
||||
}
|
||||
}
|
||||
|
||||
// parent configurations, in search order
|
||||
private final List<Configuration> parents;
|
||||
|
|
|
@ -36,6 +36,7 @@ import java.util.function.Function;
|
|||
import java.util.function.Predicate;
|
||||
import java.util.function.UnaryOperator;
|
||||
import jdk.internal.misc.SharedSecrets;
|
||||
import jdk.internal.misc.VM;
|
||||
import jdk.internal.vm.annotation.Stable;
|
||||
|
||||
/**
|
||||
|
@ -409,7 +410,15 @@ class ImmutableCollections {
|
|||
static final class ListN<E> extends AbstractImmutableList<E>
|
||||
implements Serializable {
|
||||
|
||||
static final List<?> EMPTY_LIST = new ListN<>();
|
||||
// EMPTY_LIST may be initialized from the CDS archive.
|
||||
static @Stable List<?> EMPTY_LIST;
|
||||
|
||||
static {
|
||||
VM.initializeFromArchive(ListN.class);
|
||||
if (EMPTY_LIST == null) {
|
||||
EMPTY_LIST = new ListN<>();
|
||||
}
|
||||
}
|
||||
|
||||
@Stable
|
||||
private final E[] elements;
|
||||
|
@ -567,7 +576,15 @@ class ImmutableCollections {
|
|||
static final class SetN<E> extends AbstractImmutableSet<E>
|
||||
implements Serializable {
|
||||
|
||||
static final Set<?> EMPTY_SET = new SetN<>();
|
||||
// EMPTY_SET may be initialized from the CDS archive.
|
||||
static @Stable Set<?> EMPTY_SET;
|
||||
|
||||
static {
|
||||
VM.initializeFromArchive(SetN.class);
|
||||
if (EMPTY_SET == null) {
|
||||
EMPTY_SET = new SetN<>();
|
||||
}
|
||||
}
|
||||
|
||||
@Stable
|
||||
final E[] elements;
|
||||
|
@ -772,7 +789,15 @@ class ImmutableCollections {
|
|||
*/
|
||||
static final class MapN<K,V> extends AbstractImmutableMap<K,V> {
|
||||
|
||||
static final Map<?,?> EMPTY_MAP = new MapN<>();
|
||||
// EMPTY_MAP may be initialized from the CDS archive.
|
||||
static @Stable Map<?,?> EMPTY_MAP;
|
||||
|
||||
static {
|
||||
VM.initializeFromArchive(MapN.class);
|
||||
if (EMPTY_MAP == null) {
|
||||
EMPTY_MAP = new MapN<>();
|
||||
}
|
||||
}
|
||||
|
||||
@Stable
|
||||
final Object[] table; // pairs of key, value
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
|
||||
package jdk.internal.module;
|
||||
|
||||
import java.lang.module.Configuration;
|
||||
import java.lang.module.ModuleFinder;
|
||||
import java.util.Objects;
|
||||
import jdk.internal.misc.VM;
|
||||
|
@ -36,13 +37,18 @@ final class ArchivedModuleGraph {
|
|||
private static String archivedMainModule;
|
||||
private static SystemModules archivedSystemModules;
|
||||
private static ModuleFinder archivedModuleFinder;
|
||||
private static Configuration archivedConfiguration;
|
||||
|
||||
private final SystemModules systemModules;
|
||||
private final ModuleFinder finder;
|
||||
private final Configuration configuration;
|
||||
|
||||
private ArchivedModuleGraph(SystemModules modules, ModuleFinder finder) {
|
||||
private ArchivedModuleGraph(SystemModules modules,
|
||||
ModuleFinder finder,
|
||||
Configuration configuration) {
|
||||
this.systemModules = modules;
|
||||
this.finder = finder;
|
||||
this.configuration = configuration;
|
||||
}
|
||||
|
||||
SystemModules systemModules() {
|
||||
|
@ -53,27 +59,36 @@ final class ArchivedModuleGraph {
|
|||
return finder;
|
||||
}
|
||||
|
||||
Configuration configuration() {
|
||||
return configuration;
|
||||
}
|
||||
|
||||
// A factory method that ModuleBootstrap can use to obtain the
|
||||
// ArchivedModuleGraph.
|
||||
static ArchivedModuleGraph get(String mainModule) {
|
||||
if (Objects.equals(mainModule, archivedMainModule)
|
||||
&& archivedSystemModules != null
|
||||
&& archivedModuleFinder != null) {
|
||||
&& archivedModuleFinder != null
|
||||
&& archivedConfiguration != null) {
|
||||
return new ArchivedModuleGraph(archivedSystemModules,
|
||||
archivedModuleFinder);
|
||||
archivedModuleFinder,
|
||||
archivedConfiguration);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Used at CDS dump time
|
||||
static void archive(String mainModule, SystemModules systemModules,
|
||||
ModuleFinder finder) {
|
||||
static void archive(String mainModule,
|
||||
SystemModules systemModules,
|
||||
ModuleFinder finder,
|
||||
Configuration configuration) {
|
||||
if (archivedMainModule != null)
|
||||
throw new UnsupportedOperationException();
|
||||
archivedMainModule = mainModule;
|
||||
archivedSystemModules = systemModules;
|
||||
archivedModuleFinder = finder;
|
||||
archivedConfiguration = configuration;
|
||||
}
|
||||
|
||||
static {
|
||||
|
|
|
@ -172,6 +172,7 @@ public final class ModuleBootstrap {
|
|||
|
||||
boolean haveModulePath = (appModulePath != null || upgradeModulePath != null);
|
||||
boolean needResolution = true;
|
||||
boolean canArchive = false;
|
||||
|
||||
// If the java heap was archived at CDS dump time and the environment
|
||||
// at dump time matches the current environment then use the archived
|
||||
|
@ -186,7 +187,6 @@ public final class ModuleBootstrap {
|
|||
systemModuleFinder = archivedModuleGraph.finder();
|
||||
needResolution = (traceOutput != null);
|
||||
} else {
|
||||
boolean canArchive = false;
|
||||
if (!haveModulePath && addModules.isEmpty() && limitModules.isEmpty()) {
|
||||
systemModules = SystemModuleFinders.systemModules(mainModule);
|
||||
if (systemModules != null && !isPatched) {
|
||||
|
@ -206,12 +206,6 @@ public final class ModuleBootstrap {
|
|||
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);
|
||||
|
@ -353,8 +347,12 @@ public final class ModuleBootstrap {
|
|||
if (needResolution) {
|
||||
cf = JLMA.resolveAndBind(finder, roots, traceOutput);
|
||||
} else {
|
||||
Map<String, Set<String>> map = systemModules.moduleReads();
|
||||
cf = JLMA.newConfiguration(systemModuleFinder, map);
|
||||
if (archivedModuleGraph != null) {
|
||||
cf = archivedModuleGraph.configuration();
|
||||
} else {
|
||||
Map<String, Set<String>> map = systemModules.moduleReads();
|
||||
cf = JLMA.newConfiguration(systemModuleFinder, map);
|
||||
}
|
||||
}
|
||||
|
||||
// check that modules specified to --patch-module are resolved
|
||||
|
@ -436,6 +434,13 @@ public final class ModuleBootstrap {
|
|||
limitedFinder = new SafeModuleFinder(finder);
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
// total time to initialize
|
||||
Counters.add("jdk.module.boot.totalTime", t0);
|
||||
Counters.publish();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue