Package net.bytebuddy.dynamic.loading
Class ClassInjector.UsingJna
- java.lang.Object
-
- net.bytebuddy.dynamic.loading.ClassInjector.AbstractBase
-
- net.bytebuddy.dynamic.loading.ClassInjector.UsingJna
-
- All Implemented Interfaces:
ClassInjector
- Enclosing interface:
- ClassInjector
@Enhance public static class ClassInjector.UsingJna extends ClassInjector.AbstractBase
A class injector using JNA to invoke JNI's define class utility for defining a class. This injector is only available if JNA is available on the class loader. Some JVM implementations might not support this injection method.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static interfaceClassInjector.UsingJna.DispatcherA dispatcher for JNA class injection.-
Nested classes/interfaces inherited from interface net.bytebuddy.dynamic.loading.ClassInjector
ClassInjector.AbstractBase, ClassInjector.UsingInstrumentation, ClassInjector.UsingJna, ClassInjector.UsingLookup, ClassInjector.UsingReflection, ClassInjector.UsingUnsafe
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.ObjectBOOTSTRAP_LOADER_LOCKA lock for the bootstrap loader when injecting.private java.lang.ClassLoaderclassLoaderThe class loader to inject classes into ornullfor the bootstrap loader.private static ClassInjector.UsingJna.DispatcherDISPATCHERThe dispatcher to use.private java.security.ProtectionDomainprotectionDomainThe protection domain to use ornullfor no protection domain.-
Fields inherited from class net.bytebuddy.dynamic.loading.ClassInjector.AbstractBase
SUPPRESS_ACCESS_CHECKS
-
Fields inherited from interface net.bytebuddy.dynamic.loading.ClassInjector
ALLOW_EXISTING_TYPES
-
-
Constructor Summary
Constructors Constructor Description UsingJna(java.lang.ClassLoader classLoader)Creates a new unsafe injector for the given class loader with a default protection domain.UsingJna(java.lang.ClassLoader classLoader, java.security.ProtectionDomain protectionDomain)Creates a new JNA injector for the given class loader with a default protection domain.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static <T> TdoPrivileged(java.security.PrivilegedAction<T> action)A proxy forjava.security.AccessController#doPrivilegedthat is activated if available.java.util.Map<java.lang.String,java.lang.Class<?>>injectRaw(java.util.Set<java.lang.String> names, ClassFileLocator classFileLocator)Injects the given types into the represented class loader.booleanisAlive()Indicates if this class injector is available on the current VM.static booleanisAvailable()Checks if JNA class injection is available on the current VM.static ClassInjectorofBootLoader()Returns an JNA class injector for the boot class loader.static ClassInjectorofPlatformLoader()Returns an JNA class injector for the platform class loader.static ClassInjectorofSystemLoader()Returns an JNA class injector for the system class loader.-
Methods inherited from class net.bytebuddy.dynamic.loading.ClassInjector.AbstractBase
inject, inject, injectRaw
-
-
-
-
Field Detail
-
DISPATCHER
private static final ClassInjector.UsingJna.Dispatcher DISPATCHER
The dispatcher to use.
-
BOOTSTRAP_LOADER_LOCK
private static final java.lang.Object BOOTSTRAP_LOADER_LOCK
A lock for the bootstrap loader when injecting.
-
classLoader
@MaybeNull @ValueHandling(REVERSE_NULLABILITY) private final java.lang.ClassLoader classLoader
The class loader to inject classes into ornullfor the bootstrap loader.
-
protectionDomain
@MaybeNull @ValueHandling(REVERSE_NULLABILITY) private final java.security.ProtectionDomain protectionDomain
The protection domain to use ornullfor no protection domain.
-
-
Constructor Detail
-
UsingJna
public UsingJna(@MaybeNull java.lang.ClassLoader classLoader)
Creates a new unsafe injector for the given class loader with a default protection domain.- Parameters:
classLoader- The class loader to inject classes into ornullfor the bootstrap loader.
-
UsingJna
public UsingJna(@MaybeNull java.lang.ClassLoader classLoader, @MaybeNull java.security.ProtectionDomain protectionDomain)
Creates a new JNA injector for the given class loader with a default protection domain.- Parameters:
classLoader- The class loader to inject classes into ornullfor the bootstrap loader.protectionDomain- The protection domain to use ornullfor no protection domain.
-
-
Method Detail
-
doPrivileged
@Enhance private static <T> T doPrivileged(java.security.PrivilegedAction<T> action)
A proxy forjava.security.AccessController#doPrivilegedthat is activated if available.- Type Parameters:
T- The type of the action's resolved value.- Parameters:
action- The action to execute from a privileged context.- Returns:
- The action's resolved value.
-
isAvailable
public static boolean isAvailable()
Checks if JNA class injection is available on the current VM.- Returns:
trueif JNA class injection is available on the current VM.
-
ofSystemLoader
public static ClassInjector ofSystemLoader()
Returns an JNA class injector for the system class loader.- Returns:
- A class injector for the system class loader.
-
ofPlatformLoader
public static ClassInjector ofPlatformLoader()
Returns an JNA class injector for the platform class loader. For VMs of version 8 or older, the extension class loader is represented instead.- Returns:
- A class injector for the platform class loader.
-
ofBootLoader
public static ClassInjector ofBootLoader()
Returns an JNA class injector for the boot class loader.- Returns:
- A class injector for the boot loader.
-
isAlive
public boolean isAlive()
Indicates if this class injector is available on the current VM.- Returns:
trueif this injector is available on the current VM.
-
injectRaw
public java.util.Map<java.lang.String,java.lang.Class<?>> injectRaw(java.util.Set<java.lang.String> names, ClassFileLocator classFileLocator)Injects the given types into the represented class loader.- Parameters:
names- The names of the types to load via injection.classFileLocator- The class file locator to use for resolving binary representations.- Returns:
- The loaded types that were passed as arguments.
-
-