Package net.bytebuddy.agent.builder
Class AgentBuilder.Default.ExecutingTransformer
java.lang.Object
net.bytebuddy.agent.builder.ResettableClassFileTransformer.AbstractBase
net.bytebuddy.agent.builder.AgentBuilder.Default.ExecutingTransformer
- All Implemented Interfaces:
ClassFileTransformer
,ResettableClassFileTransformer
- Enclosing class:
AgentBuilder.Default
protected static class AgentBuilder.Default.ExecutingTransformer
extends ResettableClassFileTransformer.AbstractBase
A
ClassFileTransformer
that implements the enclosing agent builder's
configuration.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static interface
A factory for creating aClassFileTransformer
for the current VM.protected class
A privileged action for transforming a class on a JVM that supports modules.protected class
A privileged action for transforming a class on a JVM prior to Java 9.Nested classes/interfaces inherited from interface net.bytebuddy.agent.builder.ResettableClassFileTransformer
ResettableClassFileTransformer.AbstractBase, ResettableClassFileTransformer.Substitutable, ResettableClassFileTransformer.WithDelegation
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Object
The access control context to use for loading classes ornull
if the access controller is not available on the current VM.private final ByteBuddy
The Byte Buddy instance to be used.private final AgentBuilder.CircularityLock
A lock that prevents circular class transformations.private final AgentBuilder.ClassFileBufferStrategy
The class file buffer strategy to use.private final ClassFileLocator
A class file locator for locating globally available types.private final AgentBuilder.DescriptionStrategy
The description strategy for resolving type descriptions for types.protected static final AgentBuilder.Default.ExecutingTransformer.Factory
A factory for creating aClassFileTransformer
that supports the features of the current VM.private final AgentBuilder.FallbackStrategy
The fallback strategy to use.private final AgentBuilder.RawMatcher
Identifies types that should not be instrumented.private final AgentBuilder.InitializationStrategy
The initialization strategy to use for transformed types.private final AgentBuilder.InjectionStrategy
The injection strategy to use.private final AgentBuilder.InstallationListener
The installation listener to notify.private final AgentBuilder.LambdaInstrumentationStrategy
The lambda instrumentation strategy to use.private final AgentBuilder.Listener
The listener to notify on transformations.private final AgentBuilder.LocationStrategy
The location strategy to use.private final AgentBuilder.Default.NativeMethodStrategy
The native method strategy to apply.private final AgentBuilder.PoolStrategy
The pool strategy to use.private final AgentBuilder.RedefinitionStrategy.ResubmissionEnforcer
The resubmission enforcer to use.private final List
<AgentBuilder.Default.Transformation> The transformations to apply on non-ignored types.private final AgentBuilder.TypeStrategy
The definition handler to use. -
Constructor Summary
ConstructorsConstructorDescriptionExecutingTransformer
(ByteBuddy byteBuddy, AgentBuilder.Listener listener, AgentBuilder.PoolStrategy poolStrategy, AgentBuilder.TypeStrategy typeStrategy, AgentBuilder.LocationStrategy locationStrategy, ClassFileLocator classFileLocator, AgentBuilder.Default.NativeMethodStrategy nativeMethodStrategy, AgentBuilder.InitializationStrategy initializationStrategy, AgentBuilder.InjectionStrategy injectionStrategy, AgentBuilder.LambdaInstrumentationStrategy lambdaInstrumentationStrategy, AgentBuilder.DescriptionStrategy descriptionStrategy, AgentBuilder.FallbackStrategy fallbackStrategy, AgentBuilder.ClassFileBufferStrategy classFileBufferStrategy, AgentBuilder.InstallationListener installationListener, AgentBuilder.RawMatcher ignoreMatcher, AgentBuilder.RedefinitionStrategy.ResubmissionEnforcer resubmissionEnforcer, List<AgentBuilder.Default.Transformation> transformations, AgentBuilder.CircularityLock circularityLock) Creates a new class file transformer. -
Method Summary
Modifier and TypeMethodDescriptionprivate static <T> T
doPrivileged
(PrivilegedAction<T> action, Object context) A proxy forjava.security.AccessController#doPrivileged
that is activated if available.private byte[]
doTransform
(JavaModule module, ClassLoader classLoader, String name, Class<?> classBeingRedefined, boolean loaded, ProtectionDomain protectionDomain, TypePool typePool, ClassFileLocator classFileLocator) Applies a transformation for a class that was captured by thisClassFileTransformer
.private static Object
A proxy forjava.security.AccessController#getContext
that is activated if available.iterator
(TypeDescription typeDescription, ClassLoader classLoader, JavaModule module, Class<?> classBeingRedefined, ProtectionDomain protectionDomain) Creates an iterator over the transformers that are applied for a given type.boolean
reset
(Instrumentation instrumentation, ResettableClassFileTransformer classFileTransformer, AgentBuilder.RedefinitionStrategy redefinitionStrategy, AgentBuilder.RedefinitionStrategy.DiscoveryStrategy redefinitionDiscoveryStrategy, AgentBuilder.RedefinitionStrategy.BatchAllocator redefinitionBatchAllocator, AgentBuilder.RedefinitionStrategy.Listener redefinitionListener) Deregisters this class file transformer and redefines any transformed class to its state without this class file transformer applied, if the supplied redefinition strategy is enabled.byte[]
transform
(ClassLoader classLoader, String internalTypeName, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] binaryRepresentation) protected byte[]
transform
(Object rawModule, ClassLoader classLoader, String internalTypeName, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] binaryRepresentation) Applies a transformation for a class that was captured by thisClassFileTransformer
.private byte[]
transform
(JavaModule module, ClassLoader classLoader, String internalTypeName, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] binaryRepresentation) Applies a transformation for a class that was captured by thisClassFileTransformer
.Methods inherited from class net.bytebuddy.agent.builder.ResettableClassFileTransformer.AbstractBase
reset, reset, reset, reset, reset, reset, reset
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.instrument.ClassFileTransformer
transform
-
Field Details
-
FACTORY
A factory for creating aClassFileTransformer
that supports the features of the current VM. -
byteBuddy
The Byte Buddy instance to be used. -
poolStrategy
The pool strategy to use. -
typeStrategy
The definition handler to use. -
listener
The listener to notify on transformations. -
nativeMethodStrategy
The native method strategy to apply. -
initializationStrategy
The initialization strategy to use for transformed types. -
injectionStrategy
The injection strategy to use. -
lambdaInstrumentationStrategy
The lambda instrumentation strategy to use. -
descriptionStrategy
The description strategy for resolving type descriptions for types. -
locationStrategy
The location strategy to use. -
classFileLocator
A class file locator for locating globally available types. -
fallbackStrategy
The fallback strategy to use. -
classFileBufferStrategy
The class file buffer strategy to use. -
installationListener
The installation listener to notify. -
ignoreMatcher
Identifies types that should not be instrumented. -
resubmissionEnforcer
The resubmission enforcer to use. -
transformations
The transformations to apply on non-ignored types. -
circularityLock
A lock that prevents circular class transformations. -
accessControlContext
The access control context to use for loading classes ornull
if the access controller is not available on the current VM.
-
-
Constructor Details
-
ExecutingTransformer
public ExecutingTransformer(ByteBuddy byteBuddy, AgentBuilder.Listener listener, AgentBuilder.PoolStrategy poolStrategy, AgentBuilder.TypeStrategy typeStrategy, AgentBuilder.LocationStrategy locationStrategy, ClassFileLocator classFileLocator, AgentBuilder.Default.NativeMethodStrategy nativeMethodStrategy, AgentBuilder.InitializationStrategy initializationStrategy, AgentBuilder.InjectionStrategy injectionStrategy, AgentBuilder.LambdaInstrumentationStrategy lambdaInstrumentationStrategy, AgentBuilder.DescriptionStrategy descriptionStrategy, AgentBuilder.FallbackStrategy fallbackStrategy, AgentBuilder.ClassFileBufferStrategy classFileBufferStrategy, AgentBuilder.InstallationListener installationListener, AgentBuilder.RawMatcher ignoreMatcher, AgentBuilder.RedefinitionStrategy.ResubmissionEnforcer resubmissionEnforcer, List<AgentBuilder.Default.Transformation> transformations, AgentBuilder.CircularityLock circularityLock) Creates a new class file transformer.- Parameters:
byteBuddy
- The Byte Buddy instance to be used.listener
- The listener to notify on transformations.poolStrategy
- The pool strategy to use.typeStrategy
- The definition handler to use.locationStrategy
- The location strategy to use.classFileLocator
- A class file locator for locating globally available types.nativeMethodStrategy
- The native method strategy to apply.initializationStrategy
- The initialization strategy to use for transformed types.injectionStrategy
- The injection strategy to use.lambdaInstrumentationStrategy
- The lambda instrumentation strategy to use.descriptionStrategy
- The description strategy for resolving type descriptions for types.fallbackStrategy
- The fallback strategy to use.classFileBufferStrategy
- The class file buffer strategy to use.installationListener
- The installation listener to notify.ignoreMatcher
- Identifies types that should not be instrumented.resubmissionEnforcer
- The resubmission enforcer to use.transformations
- The transformations to apply on non-ignored types.circularityLock
- The circularity lock to use.
-
-
Method Details
-
getContext
A proxy forjava.security.AccessController#getContext
that is activated if available.- Returns:
- The current access control context or
null
if the current VM does not support it.
-
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.context
- The access control context ornull
if the current VM does not support it.- Returns:
- The action's resolved value.
-
transform
@MaybeNull public byte[] transform(@MaybeNull ClassLoader classLoader, @MaybeNull String internalTypeName, @MaybeNull Class<?> classBeingRedefined, @MaybeNull ProtectionDomain protectionDomain, byte[] binaryRepresentation) -
transform
@MaybeNull protected byte[] transform(Object rawModule, @MaybeNull ClassLoader classLoader, @MaybeNull String internalTypeName, @MaybeNull Class<?> classBeingRedefined, @MaybeNull ProtectionDomain protectionDomain, byte[] binaryRepresentation) Applies a transformation for a class that was captured by thisClassFileTransformer
. Invoking this method allows to process module information which is available since Java 9.- Parameters:
rawModule
- The instrumented class's Javajava.lang.Module
.classLoader
- The type's class loader ornull
if the type is loaded by the bootstrap loader.internalTypeName
- The internal name of the instrumented class.classBeingRedefined
- The loadedClass
being redefined ornull
if no such class exists.protectionDomain
- The instrumented type's protection domain ornull
if not available.binaryRepresentation
- The class file of the instrumented class in its current state.- Returns:
- The transformed class file or an empty byte array if this transformer does not apply an instrumentation.
-
transform
@MaybeNull private byte[] transform(@MaybeNull JavaModule module, @MaybeNull ClassLoader classLoader, @MaybeNull String internalTypeName, @MaybeNull Class<?> classBeingRedefined, @MaybeNull ProtectionDomain protectionDomain, byte[] binaryRepresentation) Applies a transformation for a class that was captured by thisClassFileTransformer
.- Parameters:
module
- The instrumented class's Java module in its wrapped form ornull
if the current VM does not support modules.classLoader
- The instrumented class's class loader.internalTypeName
- The internal name of the instrumented class.classBeingRedefined
- The loadedClass
being redefined ornull
if no such class exists.protectionDomain
- The instrumented type's protection domain ornull
if not available.binaryRepresentation
- The class file of the instrumented class in its current state.- Returns:
- The transformed class file or an empty byte array if this transformer does not apply an instrumentation.
-
doTransform
@MaybeNull private byte[] doTransform(@MaybeNull JavaModule module, @MaybeNull ClassLoader classLoader, String name, @MaybeNull Class<?> classBeingRedefined, boolean loaded, @MaybeNull ProtectionDomain protectionDomain, TypePool typePool, ClassFileLocator classFileLocator) Applies a transformation for a class that was captured by thisClassFileTransformer
.- Parameters:
module
- The instrumented class's Java module in its wrapped form ornull
if the current VM does not support modules.classLoader
- The instrumented class's class loader.name
- The binary name of the instrumented class.classBeingRedefined
- The loadedClass
being redefined ornull
if no such class exists.loaded
-true
if the instrumented type is loaded.protectionDomain
- The instrumented type's protection domain ornull
if not available.typePool
- The type pool to use.classFileLocator
- The class file locator to use.- Returns:
- The transformed class file or an empty byte array if this transformer does not apply an instrumentation.
-
iterator
public Iterator<AgentBuilder.Transformer> iterator(TypeDescription typeDescription, @MaybeNull ClassLoader classLoader, @MaybeNull JavaModule module, @MaybeNull Class<?> classBeingRedefined, @MaybeNull ProtectionDomain protectionDomain) Creates an iterator over the transformers that are applied for a given type.- Parameters:
typeDescription
- A description of a type.classLoader
- The type's class loader ornull
if the boot loader.module
- The type's module ornull
if the module system is not supported by the current VM.classBeingRedefined
- The class being redefined ornull
if the type is not yet loaded.protectionDomain
- The type's protection domain ornull
if not available.- Returns:
- An iterator over the transformers that are applied by this class file transformer if the given type is discovered.
-
reset
public boolean reset(Instrumentation instrumentation, ResettableClassFileTransformer classFileTransformer, AgentBuilder.RedefinitionStrategy redefinitionStrategy, AgentBuilder.RedefinitionStrategy.DiscoveryStrategy redefinitionDiscoveryStrategy, AgentBuilder.RedefinitionStrategy.BatchAllocator redefinitionBatchAllocator, AgentBuilder.RedefinitionStrategy.Listener redefinitionListener) Deregisters this class file transformer and redefines any transformed class to its state without this class file transformer applied, if the supplied redefinition strategy is enabled. If it is not enabled, only the
AgentBuilder.InstallationListener
is informed about the resetting without undoing any code changes.Note: A reset class file transformer should not be reinstalled. Instead, the
AgentBuilder
which built the transformer should be asked to install a new transformer.Important: Most JVMs do not support changes of a class's structure after a class was already loaded. Therefore, it is typically required that this class file transformer was built while enabling
AgentBuilder.disableClassFormatChanges()
.- Parameters:
instrumentation
- The instrumentation instance from which to deregister the transformer.classFileTransformer
- The actual class file transformer to deregister which might bethis
instance or any wrapper.redefinitionStrategy
- The redefinition to apply.redefinitionDiscoveryStrategy
- The discovery strategy for the types to reset.redefinitionBatchAllocator
- The batch allocator to use.redefinitionListener
- The redefinition listener to apply.- Returns:
true
if a reset was applied and this transformer was not previously removed.
-