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
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 ClassesModifier and TypeClassDescriptionprotected static interface
A 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
FieldsModifier and TypeFieldDescriptionprivate static final Object
A lock for the bootstrap loader when injecting.private final ClassLoader
The class loader to inject classes into ornull
for the bootstrap loader.private static final ClassInjector.UsingJna.Dispatcher
The dispatcher to use.private final ProtectionDomain
The protection domain to use ornull
for no protection domain.Fields inherited from interface net.bytebuddy.dynamic.loading.ClassInjector
ALLOW_EXISTING_TYPES, SUPPRESS_ACCESS_CHECKS
-
Constructor Summary
ConstructorsConstructorDescriptionUsingJna
(ClassLoader classLoader) Creates a new unsafe injector for the given class loader with a default protection domain.UsingJna
(ClassLoader classLoader, ProtectionDomain protectionDomain) Creates a new JNA injector for the given class loader with a default protection domain. -
Method Summary
Modifier and TypeMethodDescriptionprivate static <T> T
doPrivileged
(PrivilegedAction<T> action) A proxy forjava.security.AccessController#doPrivileged
that is activated if available.Injects the given types into the represented class loader using a mapping from name to binary representation.boolean
isAlive()
Indicates if this class injector is available on the current VM.static boolean
Checks if JNA class injection is available on the current VM.static ClassInjector
Returns an JNA class injector for the boot class loader.static ClassInjector
Returns an JNA class injector for the platform class loader.static ClassInjector
Returns an JNA class injector for the system class loader.Methods inherited from class net.bytebuddy.dynamic.loading.ClassInjector.AbstractBase
inject
-
Field Details
-
DISPATCHER
The dispatcher to use. -
BOOTSTRAP_LOADER_LOCK
A lock for the bootstrap loader when injecting. -
classLoader
The class loader to inject classes into ornull
for the bootstrap loader. -
protectionDomain
The protection domain to use ornull
for no protection domain.
-
-
Constructor Details
-
UsingJna
Creates a new unsafe injector for the given class loader with a default protection domain.- Parameters:
classLoader
- The class loader to inject classes into ornull
for the bootstrap loader.
-
UsingJna
Creates a new JNA injector for the given class loader with a default protection domain.- Parameters:
classLoader
- The class loader to inject classes into ornull
for the bootstrap loader.protectionDomain
- The protection domain to use ornull
for no protection domain.
-
-
Method Details
-
doPrivileged
A proxy forjava.security.AccessController#doPrivileged
that 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:
true
if JNA class injection is available on the current VM.
-
ofSystemLoader
Returns an JNA class injector for the system class loader.- Returns:
- A class injector for the system class loader.
-
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
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:
true
if this injector is available on the current VM.
-
injectRaw
Injects the given types into the represented class loader using a mapping from name to binary representation.- Parameters:
types
- The types to load via injection.- Returns:
- The loaded types that were passed as arguments.
-