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.Unsafeto inject classes.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static interfaceClassInjector.UsingUnsafe.DispatcherA dispatcher for usingsun.misc.Unsafe.static classClassInjector.UsingUnsafe.FactoryA factory for creating aClassInjectorthat usessun.misc.Unsafeif available but attempts a fallback to usingjdk.internal.misc.Unsafeif thejdk.internalmodule is not resolved or unavailable.-
Nested classes/interfaces inherited from interface net.bytebuddy.dynamic.loading.ClassInjector
ClassInjector.AbstractBase, ClassInjector.UsingInstrumentation, 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 code.private java.lang.ClassLoaderclassLoaderThe class loader to inject classes into ornullfor the bootstrap loader.private ClassInjector.UsingUnsafe.Dispatcher.InitializabledispatcherThe dispatcher to use.private static ClassInjector.UsingUnsafe.Dispatcher.InitializableDISPATCHERThe dispatcher to use.private java.security.ProtectionDomainprotectionDomainThe protection domain to use ornullfor no protection domain.static java.lang.StringSAFE_PROPERTYIf this property is set, Byte Buddy does not make use of anyUnsafeclass.-
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.protectedUsingUnsafe(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 java.util.Map<java.lang.String,java.lang.Class<?>>injectRaw(java.util.Map<? extends java.lang.String,byte[]> types)Injects the given types into the represented class loader using a mapping from name to binary representation.booleanisAlive()Indicates if this class injector is available on the current VM.static booleanisAvailable()Checks if unsafe class injection is available on the current VM.static ClassInjectorofBootLoader()Returns an unsafe class injector for the boot class loader.static ClassInjectorofPlatformLoader()Returns an unsafe class injector for the platform class loader.static ClassInjectorofSystemLoader()Returns an unsafe class injector for the system class loader.-
Methods inherited from class net.bytebuddy.dynamic.loading.ClassInjector.AbstractBase
inject
-
-
-
-
Field Detail
-
SAFE_PROPERTY
public static final java.lang.String SAFE_PROPERTY
If this property is set, Byte Buddy does not make use of anyUnsafeclass.- See Also:
- Constant Field Values
-
DISPATCHER
private static final ClassInjector.UsingUnsafe.Dispatcher.Initializable 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 code.
-
classLoader
@ValueHandling(REVERSE_NULLABILITY) private final java.lang.ClassLoader classLoader
The class loader to inject classes into ornullfor the bootstrap loader.
-
protectionDomain
@ValueHandling(REVERSE_NULLABILITY) private final java.security.ProtectionDomain protectionDomain
The protection domain to use ornullfor no protection domain.
-
dispatcher
private final ClassInjector.UsingUnsafe.Dispatcher.Initializable dispatcher
The dispatcher to use.
-
-
Constructor Detail
-
UsingUnsafe
public UsingUnsafe(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.
-
UsingUnsafe
public UsingUnsafe(java.lang.ClassLoader classLoader, 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 ornullfor the bootstrap loader.protectionDomain- The protection domain to use ornullfor no protection domain.
-
UsingUnsafe
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.- 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 Detail
-
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.Map<? extends java.lang.String,byte[]> types)
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.
-
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
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.
-
-