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 java.lang.Object implements ClassInjector.UsingReflection.Dispatcher, ClassInjector.UsingReflection.Dispatcher.Initializable
A dispatcher implementation that usessun.misc.Unsafe#putBooleanto set theAccessibleObjectfield for making methods accessible.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classClassInjector.UsingReflection.Dispatcher.UsingUnsafeOverride.ForJava7CapableVmA resolved class dispatcher using unsafe field injection for a class injector on a VM running at least Java 7.protected static classClassInjector.UsingReflection.Dispatcher.UsingUnsafeOverride.ForLegacyVmA 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
Fields Modifier and Type Field Description protected java.lang.reflect.MethoddefineClassAn instance ofClassLoader.defineClass(String, byte[], int, int, ProtectionDomain).protected java.lang.reflect.MethoddefinePackageAn instance ofClassLoader.definePackage(String, String, String, String, String, String, String, URL).protected java.lang.reflect.MethodfindLoadedClassAn instance ofClassLoader.findLoadedClass(String).protected java.lang.reflect.MethodgetDefinedPackageAn instance ofjava.lang.ClassLoader#getDefinedPackage(String).protected java.lang.reflect.MethodgetPackageAn instance ofClassLoader.getPackage(String).-
Fields inherited from interface net.bytebuddy.dynamic.loading.ClassInjector.UsingReflection.Dispatcher
UNDEFINED
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedUsingUnsafeOverride(java.lang.reflect.Method findLoadedClass, java.lang.reflect.Method defineClass, java.lang.reflect.Method getDefinedPackage, java.lang.reflect.Method getPackage, java.lang.reflect.Method definePackage)Creates a new unsafe field injecting injection dispatcher.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Class<?>defineClass(java.lang.ClassLoader classLoader, java.lang.String name, byte[] binaryRepresentation, java.security.ProtectionDomain protectionDomain)Defines a class for the given class loader.java.lang.PackagedefinePackage(java.lang.ClassLoader classLoader, java.lang.String name, java.lang.String specificationTitle, java.lang.String specificationVersion, java.lang.String specificationVendor, java.lang.String implementationTitle, java.lang.String implementationVersion, java.lang.String implementationVendor, java.net.URL sealBase)Defines a package for the given class loader.java.lang.Class<?>findClass(java.lang.ClassLoader classLoader, java.lang.String name)Looks up a class from the given class loader.java.lang.PackagegetDefinedPackage(java.lang.ClassLoader classLoader, java.lang.String name)Looks up a package from a class loader.java.lang.PackagegetPackage(java.lang.ClassLoader classLoader, java.lang.String name)Looks up a package from a class loader or its ancestor.ClassInjector.UsingReflection.Dispatcherinitialize()Initializes this dispatcher.booleanisAvailable()Indicates if this dispatcher is available.protected static ClassInjector.UsingReflection.Dispatcher.Initializablemake()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 Detail
-
findLoadedClass
protected final java.lang.reflect.Method findLoadedClass
An instance ofClassLoader.findLoadedClass(String).
-
defineClass
protected final java.lang.reflect.Method defineClass
An instance ofClassLoader.defineClass(String, byte[], int, int, ProtectionDomain).
-
getDefinedPackage
@MaybeNull protected final java.lang.reflect.Method getDefinedPackage
An instance ofjava.lang.ClassLoader#getDefinedPackage(String). May benull.
-
getPackage
protected final java.lang.reflect.Method getPackage
An instance ofClassLoader.getPackage(String).
-
definePackage
protected final java.lang.reflect.Method definePackage
An instance ofClassLoader.definePackage(String, String, String, String, String, String, String, URL).
-
-
Constructor Detail
-
UsingUnsafeOverride
protected UsingUnsafeOverride(java.lang.reflect.Method findLoadedClass, java.lang.reflect.Method defineClass, @MaybeNull java.lang.reflect.Method getDefinedPackage, java.lang.reflect.Method getPackage, java.lang.reflect.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 Detail
-
make
protected static ClassInjector.UsingReflection.Dispatcher.Initializable make() throws java.lang.Exception
Creates a new initializable class injector using an unsafe field injection.- Returns:
- An appropriate initializable.
- Throws:
java.lang.Exception- If the injector cannot be created.
-
isAvailable
public boolean isAvailable()
Indicates if this dispatcher is available.- Specified by:
isAvailablein interfaceClassInjector.UsingReflection.Dispatcher.Initializable- Returns:
trueif this dispatcher is available.
-
initialize
public ClassInjector.UsingReflection.Dispatcher initialize()
Initializes this dispatcher.- Specified by:
initializein interfaceClassInjector.UsingReflection.Dispatcher.Initializable- Returns:
- The initialized dispatcher.
-
findClass
public java.lang.Class<?> findClass(java.lang.ClassLoader classLoader, java.lang.String name)Looks up a class from the given class loader.- Specified by:
findClassin 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
nullif no such class is defined for the provided class loader.
-
defineClass
public java.lang.Class<?> defineClass(java.lang.ClassLoader classLoader, java.lang.String name, byte[] binaryRepresentation, @MaybeNull java.security.ProtectionDomain protectionDomain)Defines a class for the given class loader.- Specified by:
defineClassin 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
@MaybeNull public java.lang.Package getDefinedPackage(java.lang.ClassLoader classLoader, java.lang.String name)
Looks up a package from a class loader. If the operation is not supported, falls back toClassInjector.UsingReflection.Dispatcher.getPackage(ClassLoader, String)- Specified by:
getDefinedPackagein 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
nullif no such package exists.
-
getPackage
public java.lang.Package getPackage(java.lang.ClassLoader classLoader, java.lang.String name)Looks up a package from a class loader or its ancestor.- Specified by:
getPackagein 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
nullif no such package exists.
-
definePackage
public java.lang.Package definePackage(java.lang.ClassLoader classLoader, java.lang.String name, @MaybeNull java.lang.String specificationTitle, @MaybeNull java.lang.String specificationVersion, @MaybeNull java.lang.String specificationVendor, @MaybeNull java.lang.String implementationTitle, @MaybeNull java.lang.String implementationVersion, @MaybeNull java.lang.String implementationVendor, @MaybeNull java.net.URL sealBase)Defines a package for the given class loader.- Specified by:
definePackagein 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 ornullif no specification title exists.specificationVersion- The specification version of the package ornullif no specification version exists.specificationVendor- The specification vendor of the package ornullif no specification vendor exists.implementationTitle- The implementation title of the package ornullif no implementation title exists.implementationVersion- The implementation version of the package ornullif no implementation version exists.implementationVendor- The implementation vendor of the package ornullif no implementation vendor exists.sealBase- The seal base URL ornullif the package should not be sealed.- Returns:
- The defined package.
-
-