Package net.bytebuddy.dynamic.loading
Class ClassInjector.UsingReflection.Dispatcher.UsingUnsafeOverride
java.lang.Object
net.bytebuddy.dynamic.loading.ClassInjector.UsingReflection.Dispatcher.UsingUnsafeOverride
- All Implemented Interfaces:
ClassInjector.UsingReflection.Dispatcher
,ClassInjector.UsingReflection.Dispatcher.Initializable
- Direct Known Subclasses:
ClassInjector.UsingReflection.Dispatcher.UsingUnsafeOverride.ForJava7CapableVm
,ClassInjector.UsingReflection.Dispatcher.UsingUnsafeOverride.ForLegacyVm
- Enclosing interface:
- ClassInjector.UsingReflection.Dispatcher
public abstract static class ClassInjector.UsingReflection.Dispatcher.UsingUnsafeOverride
extends Object
implements ClassInjector.UsingReflection.Dispatcher, ClassInjector.UsingReflection.Dispatcher.Initializable
A dispatcher implementation that uses
sun.misc.Unsafe#putBoolean
to set the AccessibleObject
field
for making methods accessible.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static class
A resolved class dispatcher using unsafe field injection for a class injector on a VM running at least Java 7.protected static class
A resolved class dispatcher using unsafe field injection for a class injector prior to Java 7.Nested classes/interfaces inherited from interface net.bytebuddy.dynamic.loading.ClassInjector.UsingReflection.Dispatcher
ClassInjector.UsingReflection.Dispatcher.CreationAction, ClassInjector.UsingReflection.Dispatcher.Direct, ClassInjector.UsingReflection.Dispatcher.Initializable, ClassInjector.UsingReflection.Dispatcher.Unavailable, ClassInjector.UsingReflection.Dispatcher.UsingUnsafeInjection, ClassInjector.UsingReflection.Dispatcher.UsingUnsafeOverride
Nested classes/interfaces inherited from interface net.bytebuddy.dynamic.loading.ClassInjector.UsingReflection.Dispatcher.Initializable
ClassInjector.UsingReflection.Dispatcher.Initializable.Unavailable
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Method
protected final Method
protected final Method
An instance ofClassLoader.findLoadedClass(String)
.protected final Method
An instance ofjava.lang.ClassLoader#getDefinedPackage(String)
.protected final Method
An instance ofClassLoader.getPackage(String)
.Fields inherited from interface net.bytebuddy.dynamic.loading.ClassInjector.UsingReflection.Dispatcher
UNDEFINED
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionClass<?>
defineClass
(ClassLoader classLoader, String name, byte[] binaryRepresentation, ProtectionDomain protectionDomain) Defines a class for the given class loader.definePackage
(ClassLoader classLoader, String name, String specificationTitle, String specificationVersion, String specificationVendor, String implementationTitle, String implementationVersion, String implementationVendor, URL sealBase) Defines a package for the given class loader.Class<?>
findClass
(ClassLoader classLoader, String name) Looks up a class from the given class loader.getDefinedPackage
(ClassLoader classLoader, String name) Looks up a package from a class loader.getPackage
(ClassLoader classLoader, String name) Looks up a package from a class loader or its ancestor.Initializes this dispatcher.boolean
Indicates if this dispatcher is available.protected static ClassInjector.UsingReflection.Dispatcher.Initializable
make()
Creates a new initializable class injector using an unsafe field injection.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface net.bytebuddy.dynamic.loading.ClassInjector.UsingReflection.Dispatcher
getClassLoadingLock
-
Field Details
-
findLoadedClass
An instance ofClassLoader.findLoadedClass(String)
. -
defineClass
-
getDefinedPackage
An instance ofjava.lang.ClassLoader#getDefinedPackage(String)
. May benull
. -
getPackage
An instance ofClassLoader.getPackage(String)
. -
definePackage
-
-
Constructor Details
-
UsingUnsafeOverride
protected UsingUnsafeOverride(Method findLoadedClass, Method defineClass, @MaybeNull Method getDefinedPackage, Method getPackage, Method definePackage) Creates a new unsafe field injecting injection dispatcher.- Parameters:
findLoadedClass
- An instance ofClassLoader.findLoadedClass(String)
.defineClass
- An instance ofClassLoader.defineClass(String, byte[], int, int, ProtectionDomain)
.getDefinedPackage
- An instance ofjava.lang.ClassLoader#getDefinedPackage(String)
. May benull
.getPackage
- An instance ofClassLoader.getPackage(String)
.definePackage
- An instance ofClassLoader.definePackage(String, String, String, String, String, String, String, URL)
.
-
-
Method Details
-
make
Creates a new initializable class injector using an unsafe field injection.- Returns:
- An appropriate initializable.
- Throws:
Exception
- If the injector cannot be created.
-
isAvailable
public boolean isAvailable()Indicates if this dispatcher is available.- Specified by:
isAvailable
in interfaceClassInjector.UsingReflection.Dispatcher.Initializable
- Returns:
true
if this dispatcher is available.
-
initialize
Initializes this dispatcher.- Specified by:
initialize
in interfaceClassInjector.UsingReflection.Dispatcher.Initializable
- Returns:
- The initialized dispatcher.
-
findClass
Looks up a class from the given class loader.- Specified by:
findClass
in interfaceClassInjector.UsingReflection.Dispatcher
- Parameters:
classLoader
- The class loader for which a class should be located.name
- The binary name of the class that should be located.- Returns:
- The class for the binary name or
null
if no such class is defined for the provided class loader.
-
defineClass
public Class<?> defineClass(ClassLoader classLoader, String name, byte[] binaryRepresentation, @MaybeNull ProtectionDomain protectionDomain) Defines a class for the given class loader.- Specified by:
defineClass
in interfaceClassInjector.UsingReflection.Dispatcher
- Parameters:
classLoader
- The class loader for which a new class should be defined.name
- The binary name of the class that should be defined.binaryRepresentation
- The binary representation of the class.protectionDomain
- The protection domain for the defined class.- Returns:
- The defined, loaded class.
-
getDefinedPackage
Looks up a package from a class loader. If the operation is not supported, falls back toClassInjector.UsingReflection.Dispatcher.getPackage(ClassLoader, String)
- Specified by:
getDefinedPackage
in interfaceClassInjector.UsingReflection.Dispatcher
- Parameters:
classLoader
- The class loader to query.name
- The binary name of the package.- Returns:
- The package for the given name as defined by the provided class loader or
null
if no such package exists.
-
getPackage
Looks up a package from a class loader or its ancestor.- Specified by:
getPackage
in interfaceClassInjector.UsingReflection.Dispatcher
- Parameters:
classLoader
- The class loader to query.name
- The binary name of the package.- Returns:
- The package for the given name as defined by the provided class loader or its ancestor, or
null
if no such package exists.
-
definePackage
public Package definePackage(ClassLoader classLoader, String name, @MaybeNull String specificationTitle, @MaybeNull String specificationVersion, @MaybeNull String specificationVendor, @MaybeNull String implementationTitle, @MaybeNull String implementationVersion, @MaybeNull String implementationVendor, @MaybeNull URL sealBase) Defines a package for the given class loader.- Specified by:
definePackage
in interfaceClassInjector.UsingReflection.Dispatcher
- Parameters:
classLoader
- The class loader for which a package is to be defined.name
- The binary name of the package.specificationTitle
- The specification title of the package ornull
if no specification title exists.specificationVersion
- The specification version of the package ornull
if no specification version exists.specificationVendor
- The specification vendor of the package ornull
if no specification vendor exists.implementationTitle
- The implementation title of the package ornull
if no implementation title exists.implementationVersion
- The implementation version of the package ornull
if no implementation version exists.implementationVendor
- The implementation vendor of the package ornull
if no implementation vendor exists.sealBase
- The seal base URL ornull
if the package should not be sealed.- Returns:
- The defined package.
-