APIdia Launch Partner
Top Description Fields Constructors Methods
java.lang.module

pack-priv final Class Resolver

extends Object
Class Inheritance
Imports
java.io.PrintStream, java.lang.module.ModuleDescriptor.Provides, .ModuleDescriptor.Requires.Modifier, java.util.ArrayDeque, .ArrayList, .Arrays, .Collection, .Deque, .HashMap, .HashSet, .HexFormat, .LinkedHashSet, .List, .Map, .Optional, .Set, java.util.stream.Collectors, jdk.internal.module.ModuleHashes, .ModuleReferenceImpl, .ModuleResolution, .ModuleTarget

The resolver used by Configuration#resolve and Configuration#resolveAndBind.

Implementation Note

The resolver is used at VM startup and so deliberately avoids using lambda and stream usages in code paths used during startup.

Field Summary

Modifier and TypeField and Description
private final ModuleFinder
private final ModuleFinder
private boolean
private final Map<String, ModuleReference>
private final List<Configuration>
private String
private final PrintStream
private Set<ModuleDescriptor>
private Set<ModuleDescriptor>

Constructor Summary

AccessConstructor and Description
pack-priv
Resolver(ModuleFinder beforeFinder, List<Configuration> parents, ModuleFinder afterFinder, PrintStream traceOutput)

Method Summary

Modifier and TypeMethod and Description
private Set<ModuleReference>
addFoundAutomaticModules()

Add all automatic modules that have not already been found to the nameToReference map.

private void
addFoundModule(ModuleReference mref)

Add the module to the nameToReference map.

pack-priv Resolver
bind()

Augments the set of resolved modules with modules induced by the service-use relation.

pack-priv Resolver
bind(boolean
true if incubator modules are candidates to add to the module graph
bindIncubatorModules
)

Augments the set of resolved modules with modules induced by the service-use relation.

private void
checkExportSuppliers(Map<ResolvedModule, Set<ResolvedModule>> graph)

Checks the readability graph to ensure that

  1. A module does not read two or more modules with the same name. This includes the case where a module reads another module with the same name as itself.

  2. Two or more modules in the configuration don't export the same package to a module that reads both. This includes the case where a module M containing package p reads another module that exports p to M.

  3. A module M doesn't declare that it "uses p.S" or "provides p.S with ..." but package p is neither in module M nor exported to M by any module that M reads.

private void
checkHashes()

Checks the hashes in the module descriptor to ensure that they match any recorded hashes.

private void
checkTargetPlatform(String mn, ModuleTarget target)

Check that the module's constraints on the target platform does conflict with the constraint of other modules resolved so far.

private ResolvedModule
computeIfAbsent(Map<String, ResolvedModule> map, String name, Configuration cf, ModuleReference mref)

Equivalent to

map.computeIfAbsent(name, k -> new ResolvedModule(cf, mref))
</pre>
private String
cycleAsString(ModuleDescriptor descriptor)

Returns a String with a list of the modules in a detected cycle.

private void
detectCycles()

Checks the given module graph for cycles.

private void
failTwoSuppliers(ModuleDescriptor descriptor, String source, ModuleDescriptor supplier1, ModuleDescriptor supplier2)

Fail because a module in the configuration exports the same package to a module that reads both.

private Set<ModuleReference>
findAll()

Returns the set of all modules that are observable with the before and after ModuleFinders.

private static void
findFail(String fmt, Object... args)

Throw FindException with the given format string and arguments

private ResolvedModule
findInParent(String mn)

Find a module of the given name in the parent configurations

private ModuleReference
findWithAfterFinder(String mn)

Invokes the afterFinder to find method to find the given module.

private ModuleReference
findWithBeforeFinder(String mn)

Invokes the beforeFinder to find method to find the given module.

pack-priv Map<ResolvedModule, Set<ResolvedModule>>
finish(Configuration cf)

Execute post-resolution checks and returns the module graph of resolved modules as a map.

private boolean
isTracing()

Tracing support

private Map<ResolvedModule, Set<ResolvedModule>>
makeGraph(Configuration cf)

Computes the readability graph for the modules in the given Configuration.

private String
private static String
packageName(String cn)

Returns the package name

private boolean
requiresStaticMissingModule(ModuleDescriptor descriptor, Set<ResolvedModule> reads)

Returns true if a module 'requires static' a module that is not in the readability graph, or reads a module that 'requires static transitive' a module that is not in the readability graph.

pack-priv Resolver
resolve(Collection<String> roots)

Resolves the given named modules.

private Set<ModuleDescriptor>

Returns:

The set of module resolved by this invocation of resolve
resolve
(Deque<ModuleDescriptor> q)

Resolve all modules in the given queue.

private static void
resolveFail(String fmt, Object... args)

Throw ResolutionException with the given format string and arguments

pack-priv String
private void
trace(String fmt, Object... args)

private void
visit(ModuleDescriptor descriptor)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

afterFinderback to summary
private final ModuleFinder afterFinder
beforeFinderback to summary
private final ModuleFinder beforeFinder
haveAllAutomaticModulesback to summary
private boolean haveAllAutomaticModules
nameToReferenceback to summary
private final Map<String, ModuleReference> nameToReference
parentsback to summary
private final List<Configuration> parents
targetPlatformback to summary
private String targetPlatform
traceOutputback to summary
private final PrintStream traceOutput
visitedback to summary
private Set<ModuleDescriptor> visited
visitPathback to summary
private Set<ModuleDescriptor> visitPath

Constructor Detail

Resolverback to summary
pack-priv Resolver(ModuleFinder beforeFinder, List<Configuration> parents, ModuleFinder afterFinder, PrintStream traceOutput)
Exceptions
IllegalArgumentException:
if there are more than one parent and the constraints on the target platform conflict

Method Detail

addFoundAutomaticModulesback to summary
private Set<ModuleReference> addFoundAutomaticModules()

Add all automatic modules that have not already been found to the nameToReference map.

addFoundModuleback to summary
private void addFoundModule(ModuleReference mref)

Add the module to the nameToReference map. Also check any constraints on the target platform with the constraints of other modules.

bindback to summary
pack-priv Resolver bind()

Augments the set of resolved modules with modules induced by the service-use relation.

bindback to summary
pack-priv Resolver bind(boolean bindIncubatorModules)

Augments the set of resolved modules with modules induced by the service-use relation.

Parameters
bindIncubatorModules:boolean

true if incubator modules are candidates to add to the module graph

checkExportSuppliersback to summary
private void checkExportSuppliers(Map<ResolvedModule, Set<ResolvedModule>> graph)

Checks the readability graph to ensure that

  1. A module does not read two or more modules with the same name. This includes the case where a module reads another module with the same name as itself.

  2. Two or more modules in the configuration don't export the same package to a module that reads both. This includes the case where a module M containing package p reads another module that exports p to M.

  3. A module M doesn't declare that it "uses p.S" or "provides p.S with ..." but package p is neither in module M nor exported to M by any module that M reads.

checkHashesback to summary
private void checkHashes()

Checks the hashes in the module descriptor to ensure that they match any recorded hashes.

checkTargetPlatformback to summary
private void checkTargetPlatform(String mn, ModuleTarget target)

Check that the module's constraints on the target platform does conflict with the constraint of other modules resolved so far.

computeIfAbsentback to summary
private ResolvedModule computeIfAbsent(Map<String, ResolvedModule> map, String name, Configuration cf, ModuleReference mref)

Equivalent to

map.computeIfAbsent(name, k -> new ResolvedModule(cf, mref))
</pre>

cycleAsStringback to summary
private String cycleAsString(ModuleDescriptor descriptor)

Returns a String with a list of the modules in a detected cycle.

detectCyclesback to summary
private void detectCycles()

Checks the given module graph for cycles. For now the implementation is a simple depth first search on the dependency graph. We'll replace this later, maybe with Tarjan.

failTwoSuppliersback to summary
private void failTwoSuppliers(ModuleDescriptor descriptor, String source, ModuleDescriptor supplier1, ModuleDescriptor supplier2)

Fail because a module in the configuration exports the same package to a module that reads both. This includes the case where a module M containing a package p reads another module that exports p to at least module M.

findAllback to summary
private Set<ModuleReference> findAll()

Returns the set of all modules that are observable with the before and after ModuleFinders.

findFailback to summary
private static void findFail(String fmt, Object... args)

Throw FindException with the given format string and arguments

findInParentback to summary
private ResolvedModule findInParent(String mn)

Find a module of the given name in the parent configurations

findWithAfterFinderback to summary
private ModuleReference findWithAfterFinder(String mn)

Invokes the afterFinder to find method to find the given module.

findWithBeforeFinderback to summary
private ModuleReference findWithBeforeFinder(String mn)

Invokes the beforeFinder to find method to find the given module.

finishback to summary
pack-priv Map<ResolvedModule, Set<ResolvedModule>> finish(Configuration cf)

Execute post-resolution checks and returns the module graph of resolved modules as a map.

isTracingback to summary
private boolean isTracing()

Tracing support

makeGraphback to summary
private Map<ResolvedModule, Set<ResolvedModule>> makeGraph(Configuration cf)

Computes the readability graph for the modules in the given Configuration. The readability graph is created by propagating "requires" through the "requires transitive" edges of the module dependence graph. So if the module dependence graph has m1 requires m2 && m2 requires transitive m3 then the resulting readability graph will contain m1 reads m2, m1 reads m3, and m2 reads m3.

nameAndInfoback to summary
private String nameAndInfo(ModuleReference mref)
packageNameback to summary
private static String packageName(String cn)

Returns the package name

requiresStaticMissingModuleback to summary
private boolean requiresStaticMissingModule(ModuleDescriptor descriptor, Set<ResolvedModule> reads)

Returns true if a module 'requires static' a module that is not in the readability graph, or reads a module that 'requires static transitive' a module that is not in the readability graph.

resolveback to summary
pack-priv Resolver resolve(Collection<String> roots)

Resolves the given named modules.

resolveback to summary
private Set<ModuleDescriptor> resolve(Deque<ModuleDescriptor> q)

Resolve all modules in the given queue. On completion the queue will be empty and any resolved modules will be added to nameToReference.

Returns:Set<ModuleDescriptor>

The set of module resolved by this invocation of resolve

resolveFailback to summary
private static void resolveFail(String fmt, Object... args)

Throw ResolutionException with the given format string and arguments

targetPlatformback to summary
pack-priv String targetPlatform()
traceback to summary
private void trace(String fmt, Object... args)
visitback to summary
private void visit(ModuleDescriptor descriptor)