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
A class injector that uses
sun.misc.Unsafe or jdk.internal.misc.Unsafe to inject classes.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static interfaceA dispatcher for usingsun.misc.Unsafeorjdk.internal.misc.Unsafe.static classA factory for creating aClassInjectorthat usessun.misc.Unsafeif available but attempts a fallback to usingjdk.internal.misc.Unsafeif thejdk.internalmodule is not resolved or unavailable.protected static interfaceA proxy ofjava.lang.System.Nested classes/interfaces inherited from interface ClassInjector
ClassInjector.AbstractBase, ClassInjector.UsingInstrumentation, ClassInjector.UsingJna, ClassInjector.UsingLookup, ClassInjector.UsingReflection, ClassInjector.UsingUnsafe -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final ObjectA lock for the bootstrap loader when injecting.private static final MethodThejava.lang.SecurityManager#checkPermissionmethod ornullif not available.private final ClassLoaderThe class loader to inject classes into ornullfor the bootstrap loader.private final ClassInjector.UsingUnsafe.Dispatcher.InitializableThe dispatcher to use.private static final ClassInjector.UsingUnsafe.Dispatcher.InitializableThe dispatcher to use.private final ProtectionDomainThe protection domain to use ornullfor no protection domain.static final StringIf this property is set, Byte Buddy does not make use of anyUnsafeclass.private static final ClassInjector.UsingUnsafe.SystemA proxy forjava.lang.Systemto access the security manager if available.Fields inherited from class ClassInjector.AbstractBase
SUPPRESS_ACCESS_CHECKSFields inherited from interface ClassInjector
ALLOW_EXISTING_TYPES -
Constructor Summary
ConstructorsModifierConstructorDescriptionUsingUnsafe(ClassLoader classLoader) Creates a new unsafe injector for the given class loader with a default protection domain.UsingUnsafe(ClassLoader classLoader, ProtectionDomain protectionDomain) Creates a new unsafe injector for the given class loader with a default protection domain.protectedUsingUnsafe(ClassLoader classLoader, ProtectionDomain protectionDomain, ClassInjector.UsingUnsafe.Dispatcher.Initializable dispatcher) Creates a new unsafe injector for the given class loader with a default protection domain. -
Method Summary
Modifier and TypeMethodDescriptionprivate static <T> TdoPrivileged(PrivilegedAction<T> action) A proxy forjava.security.AccessController#doPrivilegedthat is activated if available.injectRaw(Set<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 booleanChecks if unsafe class injection is available on the current VM.static ClassInjectorReturns an unsafe class injector for the boot class loader.static ClassInjectorReturns an unsafe class injector for the platform class loader.static ClassInjectorReturns an unsafe class injector for the system class loader.Methods inherited from class ClassInjector.AbstractBase
inject, inject, injectRaw
-
Field Details
-
SAFE_PROPERTY
If this property is set, Byte Buddy does not make use of anyUnsafeclass.- See Also:
-
DISPATCHER
The dispatcher to use. -
SYSTEM
A proxy forjava.lang.Systemto access the security manager if available. -
CHECK_PERMISSION
Thejava.lang.SecurityManager#checkPermissionmethod ornullif not available. -
BOOTSTRAP_LOADER_LOCK
A lock for the bootstrap loader when injecting. -
classLoader
The class loader to inject classes into ornullfor the bootstrap loader. -
protectionDomain
The protection domain to use ornullfor no protection domain. -
dispatcher
The dispatcher to use.
-
-
Constructor Details
-
UsingUnsafe
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.
-
UsingUnsafe
public UsingUnsafe(@MaybeNull ClassLoader classLoader, @MaybeNull 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 ornullfor the bootstrap loader.protectionDomain- The protection domain to use ornullfor no protection domain.
-
UsingUnsafe
protected UsingUnsafe(@MaybeNull ClassLoader classLoader, @MaybeNull 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 ornullfor the bootstrap loader.protectionDomain- The protection domain to use ornullfor no protection domain.dispatcher- The dispatcher to use.
-
-
Method Details
-
doPrivileged
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.
-
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
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:
trueif unsafe class injection is available on the current VM.
-
ofSystemLoader
Returns an unsafe class injector for the system class loader.- Returns:
- A class injector for the system class loader.
-
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
Returns an unsafe class injector for the boot class loader.- Returns:
- A class injector for the boot loader.
-