Package net.bytebuddy.dynamic.loading
Class ClassInjector.UsingUnsafe
- java.lang.Object
-
- net.bytebuddy.dynamic.loading.ClassInjector.AbstractBase
-
- net.bytebuddy.dynamic.loading.ClassInjector.UsingUnsafe
-
- All Implemented Interfaces:
ClassInjector
- Enclosing interface:
- ClassInjector
@Enhance public static class ClassInjector.UsingUnsafe extends ClassInjector.AbstractBase
A class injector that usessun.misc.Unsafe
orjdk.internal.misc.Unsafe
to inject classes.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static interface
ClassInjector.UsingUnsafe.Dispatcher
A dispatcher for usingsun.misc.Unsafe
orjdk.internal.misc.Unsafe
.static class
ClassInjector.UsingUnsafe.Factory
A factory for creating aClassInjector
that usessun.misc.Unsafe
if available but attempts a fallback to usingjdk.internal.misc.Unsafe
if thejdk.internal
module is not resolved or unavailable.protected static interface
ClassInjector.UsingUnsafe.System
A proxy ofjava.lang.System
.-
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.Object
BOOTSTRAP_LOADER_LOCK
A lock for the bootstrap loader when injecting.private static java.lang.reflect.Method
CHECK_PERMISSION
Thejava.lang.SecurityManager#checkPermission
method ornull
if not available.private java.lang.ClassLoader
classLoader
The class loader to inject classes into ornull
for the bootstrap loader.private ClassInjector.UsingUnsafe.Dispatcher.Initializable
dispatcher
The dispatcher to use.private static ClassInjector.UsingUnsafe.Dispatcher.Initializable
DISPATCHER
The dispatcher to use.private java.security.ProtectionDomain
protectionDomain
The protection domain to use ornull
for no protection domain.static java.lang.String
SAFE_PROPERTY
If this property is set, Byte Buddy does not make use of anyUnsafe
class.private static ClassInjector.UsingUnsafe.System
SYSTEM
A proxy forjava.lang.System
to access the security manager if available.-
Fields inherited from interface net.bytebuddy.dynamic.loading.ClassInjector
ALLOW_EXISTING_TYPES, SUPPRESS_ACCESS_CHECKS
-
-
Constructor Summary
Constructors Modifier Constructor Description UsingUnsafe(java.lang.ClassLoader classLoader)
Creates a new unsafe injector for the given class loader with a default protection domain.UsingUnsafe(java.lang.ClassLoader classLoader, java.security.ProtectionDomain protectionDomain)
Creates a new unsafe injector for the given class loader with a default protection domain.protected
UsingUnsafe(java.lang.ClassLoader classLoader, java.security.ProtectionDomain protectionDomain, ClassInjector.UsingUnsafe.Dispatcher.Initializable dispatcher)
Creates a new unsafe 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> T
doPrivileged(java.security.PrivilegedAction<T> action)
A proxy forjava.security.AccessController#doPrivileged
that 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.boolean
isAlive()
Indicates if this class injector is available on the current VM.static boolean
isAvailable()
Checks if unsafe class injection is available on the current VM.static ClassInjector
ofBootLoader()
Returns an unsafe class injector for the boot class loader.static ClassInjector
ofPlatformLoader()
Returns an unsafe class injector for the platform class loader.static ClassInjector
ofSystemLoader()
Returns an unsafe class injector for the system class loader.-
Methods inherited from class net.bytebuddy.dynamic.loading.ClassInjector.AbstractBase
inject, inject, injectRaw
-
-
-
-
Field Detail
-
SAFE_PROPERTY
public static final java.lang.String SAFE_PROPERTY
If this property is set, Byte Buddy does not make use of anyUnsafe
class.- See Also:
- Constant Field Values
-
DISPATCHER
private static final ClassInjector.UsingUnsafe.Dispatcher.Initializable DISPATCHER
The dispatcher to use.
-
SYSTEM
private static final ClassInjector.UsingUnsafe.System SYSTEM
A proxy forjava.lang.System
to access the security manager if available.
-
CHECK_PERMISSION
private static final java.lang.reflect.Method CHECK_PERMISSION
Thejava.lang.SecurityManager#checkPermission
method ornull
if not available.
-
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 ornull
for the bootstrap loader.
-
protectionDomain
@MaybeNull @ValueHandling(REVERSE_NULLABILITY) private final java.security.ProtectionDomain protectionDomain
The protection domain to use ornull
for no protection domain.
-
dispatcher
private final ClassInjector.UsingUnsafe.Dispatcher.Initializable dispatcher
The dispatcher to use.
-
-
Constructor Detail
-
UsingUnsafe
public UsingUnsafe(@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 ornull
for the bootstrap loader.
-
UsingUnsafe
public UsingUnsafe(@MaybeNull java.lang.ClassLoader classLoader, @MaybeNull java.security.ProtectionDomain protectionDomain)
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.protectionDomain
- The protection domain to use ornull
for no protection domain.
-
UsingUnsafe
protected UsingUnsafe(@MaybeNull java.lang.ClassLoader classLoader, @MaybeNull java.security.ProtectionDomain protectionDomain, ClassInjector.UsingUnsafe.Dispatcher.Initializable dispatcher)
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.protectionDomain
- The protection domain to use ornull
for no protection domain.dispatcher
- The dispatcher to use.
-
-
Method Detail
-
doPrivileged
@Enhance private static <T> T doPrivileged(java.security.PrivilegedAction<T> action)
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.
-
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
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.
-
isAvailable
public static boolean isAvailable()
Checks if unsafe class injection is available on the current VM.- Returns:
true
if unsafe class injection is available on the current VM.
-
ofSystemLoader
public static ClassInjector ofSystemLoader()
Returns an unsafe class injector for the system class loader.- Returns:
- A class injector for the system class loader.
-
ofPlatformLoader
public static ClassInjector ofPlatformLoader()
Returns an unsafe 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 unsafe class injector for the boot class loader.- Returns:
- A class injector for the boot loader.
-
-