Class ClassLoaderForClassArtifacts
- Direct Known Subclasses:
CallSiteClassLoader
ClassLoader used to define per-class artifact
classes such as generated meta-method dispatchers.
Since Groovy 6.0 this loader first attempts to define each artifact as a
hidden nestmate of the target via
HiddenClassDefiner.tryDefineNestmate(Class, byte[], boolean). When
that soft-fails (unopened package, unsuitable host, …) it falls back to
ClassLoader.defineClass(byte[], int, int) with the protection domain captured at
construction. Module / nest-host policy is documented on
HiddenClassDefiner.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal SoftReference<Class>Soft reference to the class for which artifacts are generated. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new artifact class loader for the specified class. -
Method Summary
Modifier and TypeMethodDescriptioncreateClassName(Method method) Generates a unique class name for an artifact associated with the given method.createClassName(String methodName) Generates a unique class name for an artifact associated with the given method name.Defines a class from bytecode, preferring a hidden nestmate of the target.defineClassAndGetConstructor(String name, byte[] bytes, Class<?>... parameterTypes) Defines a class from bytecode and returns the public constructor matching the given parameter types, ornullif definition or lookup fails.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
-
Field Details
-
klazz
Soft reference to the class for which artifacts are generated.
-
-
Constructor Details
-
ClassLoaderForClassArtifacts
Creates a new artifact class loader for the specified class.- Parameters:
klazz- the class whose artifact classes are to be defined via this loader
-
-
Method Details
-
define
Defines a class from bytecode, preferring a hidden nestmate of the target.- Parameters:
name- the binary name used for the fallback (visible-class) pathbytes- the class-file bytes- Returns:
- the defined class
-
defineClassAndGetConstructor
public Constructor defineClassAndGetConstructor(String name, byte[] bytes, Class<?>... parameterTypes) Defines a class from bytecode and returns the public constructor matching the given parameter types, ornullif definition or lookup fails.Uses
Class.getConstructor(Class[])so the returned constructor is always publicly accessible (same contract as before hidden-class support).- Parameters:
name- the binary name (for fallback visible-class definition)bytes- the class-file bytesparameterTypes- the constructor parameter types to look up- Returns:
- the matching public constructor, or
null
-
loadClass
- Overrides:
loadClassin classClassLoader- Throws:
ClassNotFoundException
-
createClassName
Generates a unique class name for an artifact associated with the given method.- Parameters:
method- the method for which the artifact is generated- Returns:
- a unique class name
-
createClassName
Generates a unique class name for an artifact associated with the given method name.For classes in the
java.*package hierarchy the name is prefixed to avoid the restrictedjava.namespace. The counter suffix ensures uniqueness when multiple artifacts share the same logical name.- Parameters:
methodName- the method name component of the artifact class name- Returns:
- a unique class name
-