This ClassLoader supports loading of classes and resources from modules.
Modules are defined to the ClassLoader by invoking the loadModule
method. Defining a module to this ClassLoader has the effect of making the
types in the module visible.
This ClassLoader also supports loading of classes and resources from a class path of URLs that are specified to the ClassLoader at construction time. The class path may expand at runtime (the Class-Path attribute in JAR files or via instrumentation agents).
The delegation model used by this ClassLoader differs to the regular delegation model. When requested to load a class then this ClassLoader first maps the class name to its package name. If there is a module defined to a BuiltinClassLoader containing this package then the class loader delegates directly to that class loader. If there isn't a module containing the package then it delegates the search to the parent class loader and if not found in the parent then it searches the class path. The main difference between this and the usual delegation model is that it allows the platform class loader to delegate to the application class loader, important with upgraded modules defined to the platform class loader.
Modifier and Type | Class and Description |
---|---|
private static class | BuiltinClassLoader.
A module defined/loaded by a built-in class loader. |
private static class | BuiltinClassLoader.
A ModuleReader that doesn't read any resources. |
Modifier and Type | Field and Description |
---|---|
private final Map | |
private final Map | |
private static final Map | |
private final BuiltinClassLoader | |
private volatile SoftReference | |
private URLClassPath |
Access | Constructor and Description |
---|---|
pack-priv |
Modifier and Type | Method and Description |
---|---|
pack-priv void | |
private static URL | |
private Class | Returns: the resulting Class ornull if an I/O error occursDefines the given binary class name to the VM, loading the class bytes from the given module. |
private Class | Returns: the resulting ClassDefines the given binary class name to the VM, loading the class bytes via the given Resource object. |
protected Package | |
private Package | |
protected Class | findClass(String
The binary name of the class cn)Overrides java. Finds the class with the specified binary name. |
protected Class | findClass(String
The module name; or mn, String null to find the class in the
unnamed module for this
class loaderThe binary name of the class cn)Overrides java. Finds the class with the specified binary name in a module. |
private Class | Returns: the resulting Class ornull if not foundFinds the class with the specified binary name if in a module defined to this ClassLoader. |
private Class | Returns: the resulting Class ornull if not foundFinds the class with the specified binary name on the class path. |
private BuiltinClassLoader. | |
private BuiltinClassLoader. | findLoadedModule(String mn, String cn)
Finds the candidate loaded module for the given class name in the named module. |
private List | findMiscResource(String name)
Returns the list of URLs to a "miscellaneous" resource in modules defined to this loader. |
protected ModuleReference | findModule(String
The name of the module to find name)Returns the |
public URL | findResource(String
The module name; or mn, String null to find a resource in the
unnamed module for this
class loaderThe resource name name)Overrides java. Returns a URL to a resource of the given name in a module defined to this class loader. |
public URL | findResource(String
The resource name name)Overrides java. Finds a resource with the given name in the modules defined to this class loader or its class path. |
private URL | findResource(ModuleReference mref, String name)
Returns the URL to a resource in a module or |
public InputStream | findResourceAsStream(String mn, String name)
Returns an input stream to a resource of the given name in a module defined to this class loader. |
private URL | |
private URL | |
public Enumeration | findResources(String
The resource name name)Overrides java. Returns an enumeration of URL objects to all the resources with the given name in modules defined to this class loader or on the class path of this loader. |
private Enumeration | findResourcesOnClassPath(String name)
Returns the URLs of all resources of the given name on the class path. |
private Package | getAndVerifyPackage(String pn, Manifest man, URL url)
Gets the Package with the specified package name. |
protected PermissionCollection | getPermissions(CodeSource
the codesource. cs)Overrides java. Returns the permissions for the given CodeSource. |
pack-priv boolean | |
private boolean | isOpen(ModuleReference mref, String pn)
Returns true if the given module opens the given package unconditionally. |
private boolean | |
protected Class | loadClass(String
The binary name of the class cn, boolean If resolve)true then resolve the classOverrides java. Loads the class with the specified binary name. |
protected Class | loadClassOrNull(String cn, boolean resolve)
A variation of |
protected final Class | |
public void | |
private ModuleReader | moduleReaderFor(ModuleReference mref)
Returns the ModuleReader for the given module, creating it if needed. |
pack-priv static Map | |
private void | resetArchivedStates()
Hides java. Called by the VM, during -Xshare:dump |
pack-priv void | setClassPath(URLClassPath ucp)
Sets the class path, called to reset the class path during -Xshare:dump |
moduleToReader | back to summary |
---|---|
private final Map<ModuleReference, ModuleReader> moduleToReader |
nameToModule | back to summary |
---|---|
private final Map<String, ModuleReference> nameToModule |
packageToModule | back to summary |
---|---|
private static final Map<String, BuiltinClassLoader. |
parent | back to summary |
---|---|
private final BuiltinClassLoader parent Hides java. |
resourceCache | back to summary |
---|---|
private volatile SoftReference<Map<String, List<URL>>> resourceCache |
ucp | back to summary |
---|---|
private URLClassPath ucp
|
BuiltinClassLoader | back to summary |
---|---|
pack-priv BuiltinClassLoader(String name, BuiltinClassLoader parent, URLClassPath ucp) Create a new instance. |
appendClassPath | back to summary |
---|---|
pack-priv void appendClassPath(String path) Appends to the given file path to the class path. |
checkURL | back to summary |
---|---|
private static URL checkURL(URL url) Checks access to the given URL. We use URLClassPath for consistent checking with java.net.URLClassLoader. |
defineClass | back to summary |
---|---|
private Class Defines the given binary class name to the VM, loading the class bytes from the given module.
|
defineClass | back to summary |
---|---|
private Class Defines the given binary class name to the VM, loading the class bytes via the given Resource object.
|
defineOrCheckPackage | back to summary |
---|---|
protected Package defineOrCheckPackage(String pn, Manifest man, URL url) Defines a package in this ClassLoader. If the package is already defined then its sealing needs to be checked if sealed by the legacy sealing mechanism.
|
definePackage | back to summary |
---|---|
private Package definePackage(String pn, Manifest man, URL url) Defines a new package in this ClassLoader. The attributes in the specified Manifest are used to get the package version and sealing information.
|
findClass | back to summary |
---|---|
protected Class Overrides java. Finds the class with the specified binary name.
|
findClass | back to summary |
---|---|
protected Class Overrides java. Finds the class with the specified binary name in a module.
This method returns
|
findClassInModuleOrNull | back to summary |
---|---|
private Class Finds the class with the specified binary name if in a module defined to this ClassLoader.
|
findClassOnClassPathOrNull | back to summary |
---|---|
private Class Finds the class with the specified binary name on the class path.
|
findLoadedModule | back to summary |
---|---|
private BuiltinClassLoader. Finds the candidate loaded module for the given class name.
Returns |
findLoadedModule | back to summary |
---|---|
private BuiltinClassLoader. Finds the candidate loaded module for the given class name
in the named module. Returns |
findMiscResource | back to summary |
---|---|
private List Returns the list of URLs to a "miscellaneous" resource in modules defined to this loader. A miscellaneous resource is not in a module package, e.g. META-INF/services/p.S. The cache used by this method avoids repeated searching of all modules.
|
findModule | back to summary |
---|---|
protected ModuleReference findModule(String name) Returns the
|
findResource | back to summary |
---|---|
public URL findResource(String mn, String name) throws IOException Overrides java. Returns a URL to a resource of the given name in a module defined to this class loader.
|
findResource | back to summary |
---|---|
public URL findResource(String name) Overrides java. Finds a resource with the given name in the modules defined to this class loader or its class path.
|
findResource | back to summary |
---|---|
private URL findResource(ModuleReference mref, String name) throws IOException Returns the URL to a resource in a module or
|
findResourceAsStream | back to summary |
---|---|
public InputStream findResourceAsStream(String mn, String name) throws IOException Returns an input stream to a resource of the given name in a module defined to this class loader.
|
findResourceOnClassPath | back to summary |
---|---|
private URL findResourceOnClassPath(String name) Returns a URL to a resource on the class path.
|
findResourceOrNull | back to summary |
---|---|
private URL findResourceOrNull(ModuleReference mref, String name) Returns the URL to a resource in a module. Returns |
findResources | back to summary |
---|---|
public Enumeration Overrides java. Returns an enumeration of URL objects to all the resources with the given name in modules defined to this class loader or on the class path of this loader.
|
findResourcesOnClassPath | back to summary |
---|---|
private Enumeration Returns the URLs of all resources of the given name on the class path.
|
getAndVerifyPackage | back to summary |
---|---|
private Package getAndVerifyPackage(String pn, Manifest man, URL url) Gets the Package with the specified package name. If defined then verifies it against the manifest and code source.
|
getPermissions | back to summary |
---|---|
protected PermissionCollection getPermissions(CodeSource cs) Overrides java. Returns the permissions for the given CodeSource.
|
hasClassPath | back to summary |
---|---|
pack-priv boolean hasClassPath() Returns |
isOpen | back to summary |
---|---|
private boolean isOpen(ModuleReference mref, String pn) Returns true if the given module opens the given package unconditionally. Implementation Note This method currently iterates over each of the open packages. This will be replaced once the ModuleDescriptor.Opens API is updated. |
isSealed | back to summary |
---|---|
private boolean isSealed(String pn, Manifest man) Returns
|
loadClass | back to summary |
---|---|
protected Class Overrides java. Loads the class with the specified binary name.
|
loadClassOrNull | back to summary |
---|---|
protected Class A variation of |
loadClassOrNull | back to summary |
---|---|
protected final Class A variation of |
loadModule | back to summary |
---|---|
public void loadModule(ModuleReference mref) Register a module this class loader. This has the effect of making the types in the module visible. |
moduleReaderFor | back to summary |
---|---|
private ModuleReader moduleReaderFor(ModuleReference mref) Returns the ModuleReader for the given module, creating it if needed. |
packageToModule | back to summary |
---|---|
pack-priv static Map Invoked by ArchivedClassLoaders to archive the package-to-module map. |
resetArchivedStates | back to summary |
---|---|
private void resetArchivedStates() Hides java. Doc from java. Called by the VM, during -Xshare:dump |
setClassPath | back to summary |
---|---|
pack-priv void setClassPath(URLClassPath ucp) Sets the class path, called to reset the class path during -Xshare:dump |
Modifier and Type | Field and Description |
---|---|
private URL | |
private final BuiltinClassLoader | |
private final ModuleReference | |
private final URI |
Access | Constructor and Description |
---|---|
pack-priv |
Modifier and Type | Method and Description |
---|---|
pack-priv URL | |
private URL | |
pack-priv BuiltinClassLoader | |
pack-priv ModuleReference | |
pack-priv String |
codeSourceURL | back to summary |
---|---|
private URL codeSourceURL
|
loader | back to summary |
---|---|
private final BuiltinClassLoader loader |
mref | back to summary |
---|---|
private final ModuleReference mref |
uri | back to summary |
---|---|
private final URI uri |
LoadedModule | back to summary |
---|---|
pack-priv LoadedModule(BuiltinClassLoader loader, ModuleReference mref) |
codeSourceURL | back to summary |
---|---|
pack-priv URL codeSourceURL() |
createURL | back to summary |
---|---|
private URL createURL(URI uri) |
loader | back to summary |
---|---|
pack-priv BuiltinClassLoader loader() |
mref | back to summary |
---|---|
pack-priv ModuleReference mref() |
name | back to summary |
---|---|
pack-priv String name() |
Access | Constructor and Description |
---|---|
private |
Modifier and Type | Method and Description |
---|---|
public void | |
public Optional | find(String
The name of the resource to open for reading name)Implements java. Finds a resource, returning a URI to the resource in the module. |
public Stream | list()
Implements java. Lists the contents of the module, returning a stream of elements that are the names of all resources in the module. |
NullModuleReader | back to summary |
---|---|
private NullModuleReader() |
close | back to summary |
---|---|
public void close() Implements java. Doc from java. Closes the module reader. Once closed then subsequent calls to locate or
read a resource will fail by throwing 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.
|
find | back to summary |
---|---|
public Optional Implements java. Doc from java. 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 ('/'). |
list | back to summary |
---|---|
public Stream Implements java. Doc from java. 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 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. |