public class LayeredClassLoader extends SourceClassLoader
SourceClassLoader
based on layers of BytecodeClassLoader
plus optionally a TopCodeCache
.
Depending on load modes, classes are first searched in the parent class loader, the individual layers or optionally created on-the-fly from source as part of the top code cache.
Modifier and Type | Class and Description |
---|---|
static class |
LayeredClassLoader.Builder
Builder for instances of
LayeredClassLoader . |
Modifier | Constructor and Description |
---|---|
protected |
LayeredClassLoader(LayeredClassLoader.Builder builder)
constructor from builder, based on already compiled code layers.
|
protected |
LayeredClassLoader(LayeredClassLoader.Builder builder,
boolean fromSourcesLayers)
constructor from builder, based on sources to compile to code layers
or on already compiled code layers.
|
Modifier and Type | Method and Description |
---|---|
LayeredClassLoader |
clone()
creates a clone with the same code layers
and with shared top code cache.
|
LayeredClassLoader |
cloneWithSeparateTopCodeCache()
creates a clone with the same code layers
and a separate top code cache
(initially with the same cached bytecode).
|
BytecodeClassLoader |
findBytecodeClassLoaderBySource(Source source)
tries to find the bytecode class loader that can load classes that were created
by compiling the given source.
|
LayeredClassLoader.Builder |
getBuilder()
gets the builder.
|
List<Code> |
getCodeLayers()
gets the code layers.
|
LoadMode |
getLoadMode()
gets the load mode.
|
TopCodeCache |
getTopCodeCache()
gets the top code cache.
|
Class<?> |
loadClass(Source source,
String name)
loads a class with the given name and from the given source.
|
protected Class<?> |
loadClass(String name,
boolean resolve) |
Class<?> |
loadMainClass(Source source)
loads the main class of the given source.
|
void |
releaseClasses(ClassReleaser releaser)
release metadata for all classed ever loaded by this class loader.
|
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findLibrary, findLoadedClass, findResource, findResources, findSystemClass, getClassLoadingLock, getPackage, getPackages, getParent, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, registerAsParallelCapable, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
protected LayeredClassLoader(LayeredClassLoader.Builder builder)
builder
- builderprotected LayeredClassLoader(LayeredClassLoader.Builder builder, boolean fromSourcesLayers)
builder
- builderfromSourcesLayers
- if based on sources to compile to code layers
or on already compiled code layersCompileException
- if based on sources and compiling the sources layers failedprotected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException
loadClass
in class ClassLoader
ClassNotFoundException
public Class<?> loadMainClass(Source source)
First searches for the source, then loads the main class that resulted from compiling the source.
Specifically for LayeredClassLoader
, the source is eventually
compiled on-the-fly from the given source if top code cache is on.
First, the class corresponding to the source is searched in static layers
using findBytecodeClassLoaderBySource(Source)
.
If not found, uses the source of the top code cache (compiling it, if necessary).
If found, uses the source of the top code cache (compiling it, if necessary)
if the source had changed since compiled in static layers (or top code cache)
and if top load mode is current first.
loadMainClass
in class SourceClassLoader
source
- sourceCompileException
- if compilation was necessary to load the class and failedLoadException
- if loading failed, including if the class was not foundpublic Class<?> loadClass(Source source, String name)
First searches for the source, only then for the class with given name as part of the classes that resulted from compiling the source.
Specifically for LayeredClassLoader
, the source is eventually
compiled on-the-fly from the given source if top code cache is on.
First, the class corresponding to the source is searched in static layers
using findBytecodeClassLoaderBySource(Source)
.
If not found, uses the source of the top code cache (compiling it, if necessary).
If found, uses the source of the top code cache (compiling it, if necessary)
if the source had changed since compiled in static layers (or top code cache)
and if top load mode is current first.
loadClass
in class SourceClassLoader
source
- sourcename
- class nameCompileException
- if compilation was necessary to load the class and failedLoadException
- if loading failed, including if the class was not foundpublic BytecodeClassLoader findBytecodeClassLoaderBySource(Source source)
Specifically for LayeredClassLoader
, top code cache is not involved;
the search is limited to static code layers and the parent class loader.
findBytecodeClassLoaderBySource
in class SourceClassLoader
source
- sourcepublic LoadMode getLoadMode()
SourceClassLoader
getLoadMode
in class SourceClassLoader
public LayeredClassLoader clone()
clone
in class SourceClassLoader
public void releaseClasses(ClassReleaser releaser)
SourceClassLoader
Allows to remove metadata associated by Groovy (or Java) with a class, which is often necessary to get on-the-fly garbage collection.
Generally call only when really done using this class loader and all loaded classes; subsequently trying to use this class loader or its classes results generally in undefined behavior.
releaseClasses
in class SourceClassLoader
releaser
- class releaserpublic LayeredClassLoader cloneWithSeparateTopCodeCache()
public List<Code> getCodeLayers()
public LayeredClassLoader.Builder getBuilder()
public TopCodeCache getTopCodeCache()