APIdia Launch Partner
Top Description Inners Fields Constructors Methods
jdk.internal.module

public final Class ModuleBootstrap

extends Object
Class Inheritance
Imports
java.io.File, .PrintStream, java.lang.module.Configuration, .ModuleDescriptor, .ModuleFinder, .ModuleReference, .ResolvedModule, java.net.URI, java.nio.file.Files, .Path, java.util.ArrayList, .Collections, .HashMap, .HashSet, .LinkedHashMap, .List, .Map, .Objects, .Optional, .Set, java.util.function.Function, java.util.stream.Collectors, jdk.internal.access.JavaLangAccess, .JavaLangModuleAccess, .SharedSecrets, jdk.internal.loader.BootLoader, .BuiltinClassLoader, .ClassLoaders, jdk.internal.misc.CDS, jdk.internal.perf.PerfCounter

Initializes/boots the module system. The boot method is called early in the startup to initialize the module system. In summary, the boot method creates a Configuration by resolving a set of module names specified via the launcher (or equivalent) -m and --add-modules options. The modules are located on a module path that is constructed from the upgrade module path, system modules, and application module path. The Configuration is instantiated as the boot layer with each module in the configuration defined to a class loader.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
ModuleBootstrap.Counters

Counters for startup performance analysis.

public static enum
public static enum
pack-priv static class
ModuleBootstrap.SafeModuleFinder

Wraps a (potentially not thread safe) ModuleFinder created during startup for use after startup.

Field Summary

Modifier and TypeField and Description
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final ModuleBootstrap.IllegalFinalFieldMutation
private static final ModuleBootstrap.IllegalNativeAccess
private static final String
private static final Set<String>
private static final JavaLangAccess
private static final JavaLangModuleAccess
private static volatile ModuleFinder
private static final String
private static final ModulePatcher
private static volatile ModuleFinder
private static final Set<String>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static void
addEnableFinalFieldMutation(ModuleLayer bootLayer)

Process the modules specified to --enable-final-field-mutation and grant the capability to mutate finals to specified named modules or all unnamed modules.

private static void
addEnableNativeAccess(ModuleLayer layer)

Grants native access to modules selected using the --enable-native-access command line option, and also to JDK modules that need the access.

private static void
addEnableNativeAccess(ModuleLayer layer, Set<String> moduleNames, boolean shouldWarn)

Grants native access for the given modules in the given layer.

private static void
addExtraExportsAndOpens(ModuleLayer bootLayer)

Process the --add-exports and --add-opens options to export/open additional packages specified on the command-line.

private static void
addExtraExportsOrOpens(ModuleLayer bootLayer, Map<String, List<String>> map, boolean opens)

private static void
addExtraReads(ModuleLayer bootLayer)

Process the --add-reads options to add any additional read edges that are specified on the command-line.

private static Set<String>
addModules()

Returns the set of module names specified by --add-module options.

private static boolean
allJrtOrModularJar(Configuration cf)

Returns true if all modules in the configuration are in the run-time image or modular JAR files.

public static ModuleLayer
boot()

Initialize the module system, returning the boot layer.

private static ModuleLayer
private static boolean
canUseArchivedBootLayer()

Returns true if the archived boot layer can be used.

private static void
checkIncubatingStatus(Configuration cf)

Checks incubating status of modules in the configuration

private static void
checkSplitPackages(Configuration cf, Function<String, ClassLoader> clf)

Checks for split packages between modules defined to the built-in class loaders.

private static boolean
containsIncubatorModule(Configuration cf)

Returns true if the configuration contains an incubator module.

private static boolean
containsSplitPackages(Configuration cf)

Returns true if the configuration contains modules with overlapping packages.

private static Map<String, List<String>>
decode(String
the system property prefix
prefix
,
String
the regex for splitting the RHS of the option value
regex
,
boolean allowDuplicates)

Decodes the values of --add-reads, -add-exports, --add-opens or --patch-modules options that are encoded in system properties.

private static Map<String, List<String>>
decode(String prefix)

Decodes the values of --add-reads, -add-exports or --add-opens which use the "," to separate the RHS of the option value.

private static Set<String>
decodeEnableFinalFieldMutation()

Returns the set of module names specified by --enable-final-field-mutation options.

private static Set<String>
decodeEnableNativeAccess()

Returns the set of module names specified by --enable-native-access options.

private static ModuleBootstrap.IllegalFinalFieldMutation
decodeIllegalFinalFieldMutation()

Process the --illegal-final-field-mutation option.

private static ModuleBootstrap.IllegalNativeAccess
decodeIllegalNativeAccess()

Process the --illegal-native-access option (and its default).

pack-priv static void
fail(String m)

Throws a RuntimeException with the given message

private static ModuleFinder
finderFor(String prop)

Creates a finder from the module path that is the value of the given system property and optionally patched by --patch-module

private static String
getAndRemoveProperty(String key)

Gets and remove the named system property

private static String
getProperty(String key)

Gets the named system property

public static ModuleBootstrap.IllegalFinalFieldMutation
public static ModuleBootstrap.IllegalNativeAccess
private static ModulePatcher
initModulePatcher()

Initialize the module patcher for the initial configuration passed on the value of the --patch-module options.

private static boolean
isJarFile(URI uri)

Returns true if the given URI locates a jar file on the file system.

public static ModuleFinder
limitedFinder()

Returns the ModuleFinder for the initial configuration.

private static ModuleFinder
limitFinder(ModuleFinder finder, Set<String> roots, Set<String> otherMods)

Returns a ModuleFinder that limits observability to the given root modules, their transitive dependences, plus a set of other modules.

private static Set<String>
limitModules()

Returns the set of module names specified by --limit-modules.

private static void
loadModules(Configuration cf, Function<String, ClassLoader> clf)

Load/register the modules to the built-in class loaders.

pack-priv static String
option(String prefix)

public static ModulePatcher
patcher()

Returns the ModulePatcher for the initial configuration.

pack-priv static String
unableToParse(String option, String text, String value)

public static ModuleFinder
unlimitedFinder()

Returns the ModuleFinder for the initial configuration before observability is limited by the --limit-modules command line option.

pack-priv static void
pack-priv static void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ADD_EXPORTSback to summary
private static final String ADD_EXPORTS
ADD_MODULESback to summary
private static final String ADD_MODULES
ADD_OPENSback to summary
private static final String ADD_OPENS
ADD_READSback to summary
private static final String ADD_READS
ALL_DEFAULTback to summary
private static final String ALL_DEFAULT
ALL_MODULE_PATHback to summary
private static final String ALL_MODULE_PATH
ALL_SYSTEMback to summary
private static final String ALL_SYSTEM
ALL_UNNAMEDback to summary
private static final String ALL_UNNAMED
ENABLE_NATIVE_ACCESSback to summary
private static final String ENABLE_NATIVE_ACCESS
ILLEGAL_FINAL_FIELD_MUTATIONback to summary
private static final ModuleBootstrap.IllegalFinalFieldMutation ILLEGAL_FINAL_FIELD_MUTATION
ILLEGAL_NATIVE_ACCESSback to summary
private static final ModuleBootstrap.IllegalNativeAccess ILLEGAL_NATIVE_ACCESS
JAVA_BASEback to summary
private static final String JAVA_BASE
JDK_NATIVE_ACCESS_MODULESback to summary
private static final Set<String> JDK_NATIVE_ACCESS_MODULES
JLAback to summary
private static final JavaLangAccess JLA
JLMAback to summary
private static final JavaLangModuleAccess JLMA
limitedFinderback to summary
private static volatile ModuleFinder limitedFinder
PATCH_MODULEback to summary
private static final String PATCH_MODULE
patcherback to summary
private static final ModulePatcher patcher
unlimitedFinderback to summary
private static volatile ModuleFinder unlimitedFinder
USER_NATIVE_ACCESS_MODULESback to summary
private static final Set<String> USER_NATIVE_ACCESS_MODULES

Constructor Detail

ModuleBootstrapback to summary
private ModuleBootstrap()

Method Detail

addEnableFinalFieldMutationback to summary
private static void addEnableFinalFieldMutation(ModuleLayer bootLayer)

Process the modules specified to --enable-final-field-mutation and grant the capability to mutate finals to specified named modules or all unnamed modules.

addEnableNativeAccessback to summary
private static void addEnableNativeAccess(ModuleLayer layer)

Grants native access to modules selected using the --enable-native-access command line option, and also to JDK modules that need the access.

In case of being in "source" launcher mode, warnings about unknown modules are deferred to the source launcher logic in the jdk.compiler module, as those modules might be not compiled, yet.

addEnableNativeAccessback to summary
private static void addEnableNativeAccess(ModuleLayer layer, Set<String> moduleNames, boolean shouldWarn)

Grants native access for the given modules in the given layer. Warns optionally about modules that were specified, but not present in the layer.

addExtraExportsAndOpensback to summary
private static void addExtraExportsAndOpens(ModuleLayer bootLayer)

Process the --add-exports and --add-opens options to export/open additional packages specified on the command-line.

addExtraExportsOrOpensback to summary
private static void addExtraExportsOrOpens(ModuleLayer bootLayer, Map<String, List<String>> map, boolean opens)
addExtraReadsback to summary
private static void addExtraReads(ModuleLayer bootLayer)

Process the --add-reads options to add any additional read edges that are specified on the command-line.

addModulesback to summary
private static Set<String> addModules()

Returns the set of module names specified by --add-module options.

allJrtOrModularJarback to summary
private static boolean allJrtOrModularJar(Configuration cf)

Returns true if all modules in the configuration are in the run-time image or modular JAR files.

bootback to summary
public static ModuleLayer boot()

Initialize the module system, returning the boot layer. The boot layer is obtained from the CDS archive if possible, otherwise it is generated from the module graph.

See Also
java.lang.System#initPhase2(boolean, boolean)
boot2back to summary
private static ModuleLayer boot2()
canUseArchivedBootLayerback to summary
private static boolean canUseArchivedBootLayer()

Returns true if the archived boot layer can be used. The system properties are checked in the order that they are used by boot2.

checkIncubatingStatusback to summary
private static void checkIncubatingStatus(Configuration cf)

Checks incubating status of modules in the configuration

checkSplitPackagesback to summary
private static void checkSplitPackages(Configuration cf, Function<String, ClassLoader> clf)

Checks for split packages between modules defined to the built-in class loaders.

containsIncubatorModuleback to summary
private static boolean containsIncubatorModule(Configuration cf)

Returns true if the configuration contains an incubator module.

containsSplitPackagesback to summary
private static boolean containsSplitPackages(Configuration cf)

Returns true if the configuration contains modules with overlapping packages.

decodeback to summary
private static Map<String, List<String>> decode(String prefix, String regex, boolean allowDuplicates)

Decodes the values of --add-reads, -add-exports, --add-opens or --patch-modules options that are encoded in system properties.

Parameters
prefix:String

the system property prefix

regex:String

the regex for splitting the RHS of the option value

decodeback to summary
private static Map<String, List<String>> decode(String prefix)

Decodes the values of --add-reads, -add-exports or --add-opens which use the "," to separate the RHS of the option value.

decodeEnableFinalFieldMutationback to summary
private static Set<String> decodeEnableFinalFieldMutation()

Returns the set of module names specified by --enable-final-field-mutation options.

decodeEnableNativeAccessback to summary
private static Set<String> decodeEnableNativeAccess()

Returns the set of module names specified by --enable-native-access options.

decodeIllegalFinalFieldMutationback to summary
private static ModuleBootstrap.IllegalFinalFieldMutation decodeIllegalFinalFieldMutation()

Process the --illegal-final-field-mutation option.

decodeIllegalNativeAccessback to summary
private static ModuleBootstrap.IllegalNativeAccess decodeIllegalNativeAccess()

Process the --illegal-native-access option (and its default).

failback to summary
pack-priv static void fail(String m)

Throws a RuntimeException with the given message

finderForback to summary
private static ModuleFinder finderFor(String prop)

Creates a finder from the module path that is the value of the given system property and optionally patched by --patch-module

getAndRemovePropertyback to summary
private static String getAndRemoveProperty(String key)

Gets and remove the named system property

getPropertyback to summary
private static String getProperty(String key)

Gets the named system property

illegalFinalFieldMutationback to summary
public static ModuleBootstrap.IllegalFinalFieldMutation illegalFinalFieldMutation()
illegalNativeAccessback to summary
public static ModuleBootstrap.IllegalNativeAccess illegalNativeAccess()
initModulePatcherback to summary
private static ModulePatcher initModulePatcher()

Initialize the module patcher for the initial configuration passed on the value of the --patch-module options.

isJarFileback to summary
private static boolean isJarFile(URI uri)

Returns true if the given URI locates a jar file on the file system.

limitedFinderback to summary
public static ModuleFinder limitedFinder()

Returns the ModuleFinder for the initial configuration.

API Note

Used to support "java --list-modules".

limitFinderback to summary
private static ModuleFinder limitFinder(ModuleFinder finder, Set<String> roots, Set<String> otherMods)

Returns a ModuleFinder that limits observability to the given root modules, their transitive dependences, plus a set of other modules.

limitModulesback to summary
private static Set<String> limitModules()

Returns the set of module names specified by --limit-modules.

loadModulesback to summary
private static void loadModules(Configuration cf, Function<String, ClassLoader> clf)

Load/register the modules to the built-in class loaders.

optionback to summary
pack-priv static String option(String prefix)
patcherback to summary
public static ModulePatcher patcher()

Returns the ModulePatcher for the initial configuration.

unableToParseback to summary
pack-priv static String unableToParse(String option, String text, String value)
unlimitedFinderback to summary
public static ModuleFinder unlimitedFinder()

Returns the ModuleFinder for the initial configuration before observability is limited by the --limit-modules command line option.

API Note

Used to support locating modules java.instrument and jdk.management.agent modules when they are loaded dynamically.

warnback to summary
pack-priv static void warn(String m)
warnUnknownModuleback to summary
pack-priv static void warnUnknownModule(String option, String mn)
jdk.internal.module back to summary

pack-priv Class ModuleBootstrap.Counters

extends Object
Class Inheritance

Counters for startup performance analysis.

Field Summary

Modifier and TypeField and Description
private static Map<String, Long>
private static long
private static final boolean
private static final boolean
private static long

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv static void
add(String name)

Add a counter - storing the time difference between now and the previous add or the start.

pack-priv static void
publish(String totalTimeName)

Publish the counters to the instrumentation buffer or stdout.

pack-priv static void
start()

Start counting time.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

countersback to summary
private static Map<String, Long> counters
previousTimeback to summary
private static long previousTime
PRINT_COUNTERSback to summary
private static final boolean PRINT_COUNTERS
PUBLISH_COUNTERSback to summary
private static final boolean PUBLISH_COUNTERS
startTimeback to summary
private static long startTime

Constructor Detail

Countersback to summary
pack-priv Counters()

Method Detail

addback to summary
pack-priv static void add(String name)

Add a counter - storing the time difference between now and the previous add or the start.

publishback to summary
pack-priv static void publish(String totalTimeName)

Publish the counters to the instrumentation buffer or stdout.

startback to summary
pack-priv static void start()

Start counting time.

jdk.internal.module back to summary

public final Enum ModuleBootstrap.IllegalFinalFieldMutation

extends Enum<ModuleBootstrap.IllegalFinalFieldMutation>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final ModuleBootstrap.IllegalFinalFieldMutation
public static final ModuleBootstrap.IllegalFinalFieldMutation
public static final ModuleBootstrap.IllegalFinalFieldMutation
public static final ModuleBootstrap.IllegalFinalFieldMutation

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static ModuleBootstrap.IllegalFinalFieldMutation
public static ModuleBootstrap.IllegalFinalFieldMutation[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

ALLOWback to summary
public static final ModuleBootstrap.IllegalFinalFieldMutation ALLOW
DEBUGback to summary
public static final ModuleBootstrap.IllegalFinalFieldMutation DEBUG
DENYback to summary
public static final ModuleBootstrap.IllegalFinalFieldMutation DENY
WARNback to summary
public static final ModuleBootstrap.IllegalFinalFieldMutation WARN

Constructor Detail

IllegalFinalFieldMutationback to summary
private IllegalFinalFieldMutation()

Method Detail

valueOfback to summary
public static ModuleBootstrap.IllegalFinalFieldMutation valueOf(String name)
valuesback to summary
public static ModuleBootstrap.IllegalFinalFieldMutation[] values()
jdk.internal.module back to summary

public final Enum ModuleBootstrap.IllegalNativeAccess

extends Enum<ModuleBootstrap.IllegalNativeAccess>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final ModuleBootstrap.IllegalNativeAccess
public static final ModuleBootstrap.IllegalNativeAccess
public static final ModuleBootstrap.IllegalNativeAccess

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static ModuleBootstrap.IllegalNativeAccess
public static ModuleBootstrap.IllegalNativeAccess[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

ALLOWback to summary
public static final ModuleBootstrap.IllegalNativeAccess ALLOW
DENYback to summary
public static final ModuleBootstrap.IllegalNativeAccess DENY
WARNback to summary
public static final ModuleBootstrap.IllegalNativeAccess WARN

Constructor Detail

IllegalNativeAccessback to summary
private IllegalNativeAccess()

Method Detail

valueOfback to summary
public static ModuleBootstrap.IllegalNativeAccess valueOf(String name)
valuesback to summary
public static ModuleBootstrap.IllegalNativeAccess[] values()
jdk.internal.module back to summary

pack-priv Class ModuleBootstrap.SafeModuleFinder

extends Object
implements ModuleFinder
Class Inheritance
All Implemented Interfaces
java.lang.module.ModuleFinder

Wraps a (potentially not thread safe) ModuleFinder created during startup for use after startup.

Field Summary

Modifier and TypeField and Description
private final Set<ModuleReference>
private volatile Map<String, ModuleReference>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public Optional<ModuleReference>
find(String name)

Implements java.lang.module.ModuleFinder.find.

Finds a reference to a module of a given name.

public Set<ModuleReference>
findAll()

Implements java.lang.module.ModuleFinder.findAll.

Returns the set of all module references that this finder can locate.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

mrefsback to summary
private final Set<ModuleReference> mrefs
nameToModuleback to summary
private volatile Map<String, ModuleReference> nameToModule

Constructor Detail

SafeModuleFinderback to summary
pack-priv SafeModuleFinder(ModuleFinder finder)

Method Detail

findback to summary
public Optional<ModuleReference> find(String name)

Implements java.lang.module.ModuleFinder.find.

Doc from java.lang.module.ModuleFinder.find.

Finds a reference to a module of a given name.

A ModuleFinder provides a consistent view of the modules that it locates. If find is invoked several times to locate the same module (by name) then it will return the same result each time. If a module is located then it is guaranteed to be a member of the set of modules returned by the findAll method.

Annotations
@Override
findAllback to summary
public Set<ModuleReference> findAll()

Implements java.lang.module.ModuleFinder.findAll.

Doc from java.lang.module.ModuleFinder.findAll.

Returns the set of all module references that this finder can locate.

A ModuleFinder provides a consistent view of the modules that it locates. If findAll is invoked several times then it will return the same (equals) result each time. For each ModuleReference element in the returned set then it is guaranteed that find will locate the ModuleReference if invoked to find that module.

Annotations
@Override