Class LayeredClassLoader
- All Implemented Interfaces:
Cloneable
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.
- Since:
- 1.0
- Author:
- Alain Stalder, Made in Switzerland.
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedconstructor from builder, based on already compiled code layers.protectedLayeredClassLoader(LayeredClassLoader.Builder builder, boolean fromSourcesLayers) constructor from builder, based on sources to compile to code layers or on already compiled code layers. -
Method Summary
Modifier and TypeMethodDescriptionclone()creates a clone with the same code layers and with shared top code cache.creates a clone with the same code layers and a separate top code cache (initially with the same cached bytecode).tries to find the bytecode class loader that can load classes that were created by compiling the given source.gets the builder.gets the code layers.gets the load mode.gets the top code cache.Class<?>loads a class with the given name and from the given source.protected Class<?>Class<?>loadMainClass(Source source) loads the main class of the given source.voidreleaseClasses(ClassReleaser releaser) release metadata for all classed ever loaded by this class loader.Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findClass, findLibrary, findLoadedClass, findResource, findResource, findResources, findSystemClass, getClassLoadingLock, getDefinedPackage, getDefinedPackages, getName, getPackage, getPackages, getParent, getPlatformClassLoader, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, loadClass, registerAsParallelCapable, resolveClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
-
Constructor Details
-
LayeredClassLoader
constructor from builder, based on already compiled code layers.- Parameters:
builder- builder- Since:
- 1.0
-
LayeredClassLoader
constructor from builder, based on sources to compile to code layers or on already compiled code layers.- Parameters:
builder- builderfromSourcesLayers- if based on sources to compile to code layers or on already compiled code layers- Throws:
CompileException- if based on sources and compiling the sources layers failed- Since:
- 1.0
-
-
Method Details
-
loadClass
- Overrides:
loadClassin classClassLoader- Throws:
ClassNotFoundException
-
loadMainClass
loads the main class of the given 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 usingfindBytecodeClassLoaderBySource(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.- Specified by:
loadMainClassin classSourceClassLoader- Parameters:
source- source- Returns:
- main class
- Throws:
CompileException- if compilation was necessary to load the class and failedLoadException- if loading failed, including if the class was not found- Since:
- 1.0
-
loadClass
loads a class with the given name and from the given source.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 usingfindBytecodeClassLoaderBySource(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.- Specified by:
loadClassin classSourceClassLoader- Parameters:
source- sourcename- class name- Returns:
- class
- Throws:
CompileException- if compilation was necessary to load the class and failedLoadException- if loading failed, including if the class was not found- Since:
- 1.0
-
findBytecodeClassLoaderBySource
tries to find the bytecode class loader that can load classes that were created by compiling the given source.Specifically for
LayeredClassLoader, top code cache is not involved; the search is limited to static code layers and the parent class loader.- Specified by:
findBytecodeClassLoaderBySourcein classSourceClassLoader- Parameters:
source- source- Returns:
- bytecode class loader if found, null otherwise
- Since:
- 1.0
-
getLoadMode
Description copied from class:SourceClassLoadergets the load mode.- Specified by:
getLoadModein classSourceClassLoader- Returns:
- load mode
-
clone
creates a clone with the same code layers and with shared top code cache.- Specified by:
clonein classSourceClassLoader- Returns:
- clone
- Since:
- 1.0
-
releaseClasses
Description copied from class:SourceClassLoaderrelease metadata for all classed ever loaded by this class loader.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.
- Specified by:
releaseClassesin classSourceClassLoader- Parameters:
releaser- class releaser
-
cloneWithSeparateTopCodeCache
creates a clone with the same code layers and a separate top code cache (initially with the same cached bytecode).- Returns:
- clone
- Since:
- 1.0
-
getCodeLayers
gets the code layers.- Returns:
- code layers
- Since:
- 1.0
-
getBuilder
gets the builder.- Returns:
- builder
- Since:
- 1.0
-
getTopCodeCache
gets the top code cache.- Returns:
- top code cache
- Since:
- 1.0
-