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

public final Class SystemModuleFinders

extends Object
Class Inheritance
Imports
java.io.ByteArrayInputStream, .IOException, .InputStream, .UncheckedIOException, java.lang.module.ModuleDescriptor, .ModuleFinder, .ModuleReader, .ModuleReference, java.lang.reflect.Constructor, java.net.URI, java.nio.ByteBuffer, java.nio.file.Files, .Path, java.util.ArrayDeque, .Collections, .Deque, .HashMap, .HashSet, .Iterator, .Map, .Objects, .Optional, .Set, .Spliterator, java.util.function.Consumer, .Supplier, java.util.stream.Stream, .StreamSupport, jdk.internal.jimage.ImageReader, .SystemImageReader, jdk.internal.access.JavaNetUriAccess, .SharedSecrets, jdk.internal.util.StaticProperty, jdk.internal.module.ModuleHashes.HashSupplier

The factory for SystemModules objects and for creating ModuleFinder objects that find modules in the runtime image. This class supports initializing the module system when the runtime is an images build, an exploded build, or an images build with java.base patched by an exploded java.base. It also supports a testing mode that re-parses the module-info.class resources in the run-time image.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
SystemModuleFinders.ModuleContentSpliterator

A Spliterator for traversing the resources of a module linked into the run-time image.

private static class
SystemModuleFinders.SystemImage

Holder class for the ImageReader.

private static class
SystemModuleFinders.SystemModuleFinder

A ModuleFinder that finds module in an array or set of modules.

private static class
SystemModuleFinders.SystemModuleReader

A ModuleReader for reading resources from a module linked into the run-time image.

Field Summary

Modifier and TypeField and Description
private static volatile ModuleFinder
private static final JavaNetUriAccess
private static final boolean

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static Stream<ModuleInfo.Attributes>
allModuleAttributes()

Parses the module-info.class of all modules in the runtime image and returns a stream of Attributes for them.

pack-priv static SystemModules
allSystemModules()

Returns the SystemModules object to reconstitute all modules.

pack-priv static Map<String, byte[]>
generateNameToHash(ModuleHashes[] recordedHashes)

Generates a map of module name to hash value.

pack-priv static ModuleHashes.HashSupplier
hashSupplier(Map<String, byte[]> nameToHash, String name)

Returns a HashSupplier that returns the hash of the given module.

pack-priv static ModuleFinder
of(SystemModules systemModules)

Returns a ModuleFinder that is backed by the given SystemModules object.

private static ModuleFinder
ofModuleInfos()

Parses the module-info.class of all modules in the runtime image and returns a ModuleFinder to find the modules.

public static ModuleFinder
ofSystem()

Returns the ModuleFinder to find all system modules.

private static ModuleInfo.Attributes
readModuleAttributes(ImageReader reader, String moduleName)

Returns the module's "module-info", returning a holder for its class file attributes.

pack-priv static SystemModules
systemModules(String initialModule)

Returns a SystemModules object to reconstitute the modules for the given initial module.

pack-priv static ModuleReference
toModuleReference(ModuleDescriptor descriptor, ModuleTarget target, ModuleHashes recordedHashes, ModuleHashes.HashSupplier hasher, ModuleResolution mres)

Creates a ModuleReference to the system module.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cachedSystemModuleFinderback to summary
private static volatile ModuleFinder cachedSystemModuleFinder
JNUAback to summary
private static final JavaNetUriAccess JNUA
USE_FAST_PATHback to summary
private static final boolean USE_FAST_PATH

Constructor Detail

SystemModuleFindersback to summary
private SystemModuleFinders()

Method Detail

allModuleAttributesback to summary
private static Stream<ModuleInfo.Attributes> allModuleAttributes()

Parses the module-info.class of all modules in the runtime image and returns a stream of Attributes for them. The returned attributes are in no specific order.

allSystemModulesback to summary
pack-priv static SystemModules allSystemModules()

Returns the SystemModules object to reconstitute all modules. Returns null if this is an exploded build or java.base is patched by an exploded build.

generateNameToHashback to summary
pack-priv static Map<String, byte[]> generateNameToHash(ModuleHashes[] recordedHashes)

Generates a map of module name to hash value.

hashSupplierback to summary
pack-priv static ModuleHashes.HashSupplier hashSupplier(Map<String, byte[]> nameToHash, String name)

Returns a HashSupplier that returns the hash of the given module.

ofback to summary
pack-priv static ModuleFinder of(SystemModules systemModules)

Returns a ModuleFinder that is backed by the given SystemModules object.

API Note

The returned ModuleFinder is thread safe.

ofModuleInfosback to summary
private static ModuleFinder ofModuleInfos()

Parses the module-info.class of all modules in the runtime image and returns a ModuleFinder to find the modules.

API Note

The returned ModuleFinder is thread safe.

ofSystemback to summary
public static ModuleFinder ofSystem()

Returns the ModuleFinder to find all system modules. Supports both images and exploded builds.

API Note

Used by ModuleFinder.ofSystem()

readModuleAttributesback to summary
private static ModuleInfo.Attributes readModuleAttributes(ImageReader reader, String moduleName)

Returns the module's "module-info", returning a holder for its class file attributes. Every module is required to have a valid module-info.class.

systemModulesback to summary
pack-priv static SystemModules systemModules(String initialModule)

Returns a SystemModules object to reconstitute the modules for the given initial module. If the initial module is null then return the SystemModules object to reconstitute the default modules. Return null if there is no SystemModules class for the initial module, this is an exploded build, or java.base is patched by an exploded build.

toModuleReferenceback to summary
pack-priv static ModuleReference toModuleReference(ModuleDescriptor descriptor, ModuleTarget target, ModuleHashes recordedHashes, ModuleHashes.HashSupplier hasher, ModuleResolution mres)

Creates a ModuleReference to the system module.

jdk.internal.module back to summary

private Class SystemModuleFinders.ModuleContentSpliterator

extends Object
implements Spliterator<String>
Class Inheritance
  • java.lang.Object
  • jdk.internal.module.SystemModuleFinders.ModuleContentSpliterator
All Implemented Interfaces
java.util.Spliterator

A Spliterator for traversing the resources of a module linked into the run-time image.

Field Summary

Modifier and TypeField and Description
pack-priv Iterator<String>
pack-priv final String
pack-priv final Deque<ImageReader.Node>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public int
characteristics()

Implements java.util.Spliterator.characteristics.

Returns a set of characteristics of this Spliterator and its elements.

public long
estimateSize()

Implements java.util.Spliterator.estimateSize.

Returns an estimate of the number of elements that would be encountered by a forEachRemaining traversal, or returns Long#MAX_VALUE if infinite, unknown, or too expensive to compute.

private String
next()

Returns the name of the next non-directory node or null if there are no remaining nodes to visit.

public boolean
tryAdvance(Consumer<? super String> action)

Implements java.util.Spliterator.tryAdvance.

If a remaining element exists: performs the given action on it, returning true; else returns false.

public Spliterator<String>
trySplit()

Implements java.util.Spliterator.trySplit.

If this spliterator can be partitioned, returns a Spliterator covering elements, that will, upon return from this method, not be covered by this Spliterator.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

iteratorback to summary
pack-priv Iterator<String> iterator
moduleRootback to summary
pack-priv final String moduleRoot
stackback to summary
pack-priv final Deque<ImageReader.Node> stack

Constructor Detail

ModuleContentSpliteratorback to summary
pack-priv ModuleContentSpliterator(String module) throws IOException

Method Detail

characteristicsback to summary
public int characteristics()

Implements java.util.Spliterator.characteristics.

Doc from java.util.Spliterator.characteristics.

Returns a set of characteristics of this Spliterator and its elements. The result is represented as ORed values from ORDERED, DISTINCT, SORTED, SIZED, NONNULL, IMMUTABLE, CONCURRENT, SUBSIZED. Repeated calls to characteristics() on a given spliterator, prior to or in-between calls to trySplit, should always return the same result.

If a Spliterator reports an inconsistent set of characteristics (either those returned from a single invocation or across multiple invocations), no guarantees can be made about any computation using this Spliterator.

Annotations
@Override
estimateSizeback to summary
public long estimateSize()

Implements java.util.Spliterator.estimateSize.

Doc from java.util.Spliterator.estimateSize.

Returns an estimate of the number of elements that would be encountered by a forEachRemaining traversal, or returns Long#MAX_VALUE if infinite, unknown, or too expensive to compute.

If this Spliterator is SIZED and has not yet been partially traversed or split, or this Spliterator is SUBSIZED and has not yet been partially traversed, this estimate must be an accurate count of elements that would be encountered by a complete traversal. Otherwise, this estimate may be arbitrarily inaccurate, but must decrease as specified across invocations of trySplit.

Annotations
@Override
nextback to summary
private String next() throws IOException

Returns the name of the next non-directory node or null if there are no remaining nodes to visit.

tryAdvanceback to summary
public boolean tryAdvance(Consumer<? super String> action)

Implements java.util.Spliterator.tryAdvance.

Doc from java.util.Spliterator.tryAdvance.

If a remaining element exists: performs the given action on it, returning true; else returns false. If this Spliterator is ORDERED the action is performed on the next element in encounter order. Exceptions thrown by the action are relayed to the caller.

Subsequent behavior of a spliterator is unspecified if the action throws an exception.

Annotations
@Override
trySplitback to summary
public Spliterator<String> trySplit()

Implements java.util.Spliterator.trySplit.

Doc from java.util.Spliterator.trySplit.

If this spliterator can be partitioned, returns a Spliterator covering elements, that will, upon return from this method, not be covered by this Spliterator.

If this Spliterator is ORDERED, the returned Spliterator must cover a strict prefix of the elements.

Unless this Spliterator covers an infinite number of elements, repeated calls to trySplit() must eventually return null. Upon non-null return:

  • the value reported for estimateSize() before splitting, must, after splitting, be greater than or equal to estimateSize() for this and the returned Spliterator; and
  • if this Spliterator is SUBSIZED, then estimateSize() for this spliterator before splitting must be equal to the sum of estimateSize() for this and the returned Spliterator after splitting.

This method may return null for any reason, including emptiness, inability to split after traversal has commenced, data structure constraints, and efficiency considerations.

Annotations
@Override
jdk.internal.module back to summary

private Class SystemModuleFinders.SystemImage

extends Object
Class Inheritance

Holder class for the ImageReader.

Field Summary

Modifier and TypeField and Description
pack-priv static final ImageReader

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv static ImageReader
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

READERback to summary
pack-priv static final ImageReader READER

Constructor Detail

SystemImageback to summary
private SystemImage()

Method Detail

readerback to summary
pack-priv static ImageReader reader()
jdk.internal.module back to summary

private Class SystemModuleFinders.SystemModuleFinder

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

A ModuleFinder that finds module in an array or set of modules.

Field Summary

Modifier and TypeField and Description
pack-priv final Set<ModuleReference>
pack-priv final Map<String, ModuleReference>

Constructor Summary

AccessConstructor and Description
pack-priv
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
pack-priv final Set<ModuleReference> mrefs
nameToModuleback to summary
pack-priv final Map<String, ModuleReference> nameToModule

Constructor Detail

SystemModuleFinderback to summary
pack-priv SystemModuleFinder(ModuleReference[] array, Map.Entry<String, ModuleReference>[] map)
SystemModuleFinderback to summary
pack-priv SystemModuleFinder(Set<ModuleReference> mrefs, Map<String, ModuleReference> nameToModule)

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
jdk.internal.module back to summary

private Class SystemModuleFinders.SystemModuleReader

extends Object
implements ModuleReader
Class Inheritance
All Implemented Interfaces
java.lang.module.ModuleReader, java.io.Closeable, java.lang.AutoCloseable

A ModuleReader for reading resources from a module linked into the run-time image.

Field Summary

Modifier and TypeField and Description
private volatile boolean
private final String

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements java.lang.module.ModuleReader.close.

Closes the module reader.

private boolean
containsResource(String module, String name)

Returns true if the given resource exists, false if not found.

public Optional<URI>
find(String name)

Implements java.lang.module.ModuleReader.find.

Finds a resource, returning a URI to the resource in the module.

private ImageReader.Node
findResource(ImageReader reader, String name)

Returns the node for the given resource if found.

public Stream<String>
list()

Implements java.lang.module.ModuleReader.list.

Lists the contents of the module, returning a stream of elements that are the names of all resources in the module.

public Optional<InputStream>
open(String name)

Overrides default java.lang.module.ModuleReader.open.

Opens a resource, returning an input stream to read the resource in the module.

public Optional<ByteBuffer>
read(String name)

Overrides default java.lang.module.ModuleReader.read.

Reads a resource, returning a byte buffer with the contents of the resource.

private InputStream
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

closedback to summary
private volatile boolean closed
moduleback to summary
private final String module

Constructor Detail

SystemModuleReaderback to summary
pack-priv SystemModuleReader(String module)

Method Detail

closeback to summary
public void close()

Implements java.lang.module.ModuleReader.close.

Doc from java.lang.module.ModuleReader.close.

Closes the module reader. Once closed then subsequent calls to locate or read a resource will fail by throwing IOException.

A module reader is not required to be asynchronously closeable. If a thread is reading a resource and another thread invokes the close method, then the second thread may block until the read operation is complete.

Annotations
@Override
containsResourceback to summary
private boolean containsResource(String module, String name) throws IOException

Returns true if the given resource exists, false if not found.

findback to summary
public Optional<URI> find(String name) throws IOException

Implements java.lang.module.ModuleReader.find.

Doc from java.lang.module.ModuleReader.find.

Finds a resource, returning a URI to the resource in the module.

If the module reader can determine that the name locates a directory then the resulting URI will end with a slash ('/').

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs or the module reader is closed
findResourceback to summary
private ImageReader.Node findResource(ImageReader reader, String name) throws IOException

Returns the node for the given resource if found. If the name references a non-resource node, then null is returned.

listback to summary
public Stream<String> list() throws IOException

Implements java.lang.module.ModuleReader.list.

Doc from java.lang.module.ModuleReader.list.

Lists the contents of the module, returning a stream of elements that are the names of all resources in the module. Whether the stream of elements includes names corresponding to directories in the module is module reader specific.

In lazy implementations then an IOException may be thrown when using the stream to list the module contents. If this occurs then the IOException will be wrapped in an java.io.UncheckedIOException and thrown from the method that caused the access to be attempted.

The returned stream may contain references to one or more open directories in the module. The directories are closed by closing the stream.

The behavior of the stream when used after the module reader is closed is implementation specific and therefore not specified.

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs or the module reader is closed
openback to summary
public Optional<InputStream> open(String name) throws IOException

Overrides default java.lang.module.ModuleReader.open.

Doc from java.lang.module.ModuleReader.open.

Opens a resource, returning an input stream to read the resource in the module.

The behavior of the input stream when used after the module reader is closed is implementation specific and therefore not specified.

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs or the module reader is closed
readback to summary
public Optional<ByteBuffer> read(String name) throws IOException

Overrides default java.lang.module.ModuleReader.read.

Doc from java.lang.module.ModuleReader.read.

Reads a resource, returning a byte buffer with the contents of the resource. The element at the returned buffer's position is the first byte of the resource, the element at the buffer's limit is the last byte of the resource. Once consumed, the release method must be invoked. Failure to invoke the release method may result in a resource leak.

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs or the module reader is closed
toInputStreamback to summary
private InputStream toInputStream(ByteBuffer bb)