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:
java.lang.instrument.ClassFileTransformer,ResettableClassFileTransformer
- Enclosing class:
- AgentBuilder.Default
protected static class AgentBuilder.Default.ExecutingTransformer extends ResettableClassFileTransformer.AbstractBase
AClassFileTransformerthat implements the enclosing agent builder's configuration.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static interfaceAgentBuilder.Default.ExecutingTransformer.FactoryA factory for creating aClassFileTransformerfor the current VM.protected classAgentBuilder.Default.ExecutingTransformer.Java9CapableVmDispatcherA privileged action for transforming a class on a JVM that supports modules.protected classAgentBuilder.Default.ExecutingTransformer.LegacyVmDispatcherA 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
Fields Modifier and Type Field Description private java.lang.ObjectaccessControlContextThe access control context to use for loading classes ornullif the access controller is not available on the current VM.private ByteBuddybyteBuddyThe Byte Buddy instance to be used.private AgentBuilder.CircularityLockcircularityLockA lock that prevents circular class transformations.private AgentBuilder.ClassFileBufferStrategyclassFileBufferStrategyThe class file buffer strategy to use.private ClassFileLocatorclassFileLocatorA class file locator for locating globally available types.private AgentBuilder.DescriptionStrategydescriptionStrategyThe description strategy for resolving type descriptions for types.protected static AgentBuilder.Default.ExecutingTransformer.FactoryFACTORYA factory for creating aClassFileTransformerthat supports the features of the current VM.private AgentBuilder.FallbackStrategyfallbackStrategyThe fallback strategy to use.private AgentBuilder.RawMatcherignoreMatcherIdentifies types that should not be instrumented.private AgentBuilder.InitializationStrategyinitializationStrategyThe initialization strategy to use for transformed types.private AgentBuilder.InjectionStrategyinjectionStrategyThe injection strategy to use.private AgentBuilder.InstallationListenerinstallationListenerThe installation listener to notify.private AgentBuilder.LambdaInstrumentationStrategylambdaInstrumentationStrategyThe lambda instrumentation strategy to use.private AgentBuilder.ListenerlistenerThe listener to notify on transformations.private AgentBuilder.LocationStrategylocationStrategyThe location strategy to use.private AgentBuilder.Default.NativeMethodStrategynativeMethodStrategyThe native method strategy to apply.private AgentBuilder.PoolStrategypoolStrategyThe pool strategy to use.private AgentBuilder.RedefinitionStrategy.ResubmissionEnforcerresubmissionEnforcerThe resubmission enforcer to use.private java.util.List<AgentBuilder.Default.Transformation>transformationsThe transformations to apply on non-ignored types.private AgentBuilder.TypeStrategytypeStrategyThe definition handler to use.
-
Constructor Summary
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static <T> TdoPrivileged(java.security.PrivilegedAction<T> action, java.lang.Object context)A proxy forjava.security.AccessController#doPrivilegedthat is activated if available.private byte[]doTransform(JavaModule module, java.lang.ClassLoader classLoader, java.lang.String name, java.lang.Class<?> classBeingRedefined, boolean loaded, java.security.ProtectionDomain protectionDomain, TypePool typePool, ClassFileLocator classFileLocator)Applies a transformation for a class that was captured by thisClassFileTransformer.private static java.lang.ObjectgetContext()A proxy forjava.security.AccessController#getContextthat is activated if available.java.util.Iterator<AgentBuilder.Transformer>iterator(TypeDescription typeDescription, java.lang.ClassLoader classLoader, JavaModule module, java.lang.Class<?> classBeingRedefined, java.security.ProtectionDomain protectionDomain)Creates an iterator over the transformers that are applied for a given type.booleanreset(java.lang.instrument.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(java.lang.ClassLoader classLoader, java.lang.String internalName, java.lang.Class<?> classBeingRedefined, java.security.ProtectionDomain protectionDomain, byte[] binaryRepresentation)protected byte[]transform(java.lang.Object rawModule, java.lang.ClassLoader classLoader, java.lang.String internalName, java.lang.Class<?> classBeingRedefined, java.security.ProtectionDomain protectionDomain, byte[] binaryRepresentation)Applies a transformation for a class that was captured by thisClassFileTransformer.private byte[]transform(JavaModule module, java.lang.ClassLoader classLoader, java.lang.String internalName, java.lang.Class<?> classBeingRedefined, java.security.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
-
-
-
-
Field Detail
-
FACTORY
protected static final AgentBuilder.Default.ExecutingTransformer.Factory FACTORY
A factory for creating aClassFileTransformerthat supports the features of the current VM.
-
byteBuddy
private final ByteBuddy byteBuddy
The Byte Buddy instance to be used.
-
poolStrategy
private final AgentBuilder.PoolStrategy poolStrategy
The pool strategy to use.
-
typeStrategy
private final AgentBuilder.TypeStrategy typeStrategy
The definition handler to use.
-
listener
private final AgentBuilder.Listener listener
The listener to notify on transformations.
-
nativeMethodStrategy
private final AgentBuilder.Default.NativeMethodStrategy nativeMethodStrategy
The native method strategy to apply.
-
initializationStrategy
private final AgentBuilder.InitializationStrategy initializationStrategy
The initialization strategy to use for transformed types.
-
injectionStrategy
private final AgentBuilder.InjectionStrategy injectionStrategy
The injection strategy to use.
-
lambdaInstrumentationStrategy
private final AgentBuilder.LambdaInstrumentationStrategy lambdaInstrumentationStrategy
The lambda instrumentation strategy to use.
-
descriptionStrategy
private final AgentBuilder.DescriptionStrategy descriptionStrategy
The description strategy for resolving type descriptions for types.
-
locationStrategy
private final AgentBuilder.LocationStrategy locationStrategy
The location strategy to use.
-
classFileLocator
private final ClassFileLocator classFileLocator
A class file locator for locating globally available types.
-
fallbackStrategy
private final AgentBuilder.FallbackStrategy fallbackStrategy
The fallback strategy to use.
-
classFileBufferStrategy
private final AgentBuilder.ClassFileBufferStrategy classFileBufferStrategy
The class file buffer strategy to use.
-
installationListener
private final AgentBuilder.InstallationListener installationListener
The installation listener to notify.
-
ignoreMatcher
private final AgentBuilder.RawMatcher ignoreMatcher
Identifies types that should not be instrumented.
-
resubmissionEnforcer
private final AgentBuilder.RedefinitionStrategy.ResubmissionEnforcer resubmissionEnforcer
The resubmission enforcer to use.
-
transformations
private final java.util.List<AgentBuilder.Default.Transformation> transformations
The transformations to apply on non-ignored types.
-
circularityLock
private final AgentBuilder.CircularityLock circularityLock
A lock that prevents circular class transformations.
-
accessControlContext
@MaybeNull private final java.lang.Object accessControlContext
The access control context to use for loading classes ornullif the access controller is not available on the current VM.
-
-
Constructor Detail
-
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, java.util.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.installationListener- The installation listener to notify.classFileBufferStrategy- The class file buffer strategy to use.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 Detail
-
getContext
@MaybeNull @Enhance private static java.lang.Object getContext()
A proxy forjava.security.AccessController#getContextthat is activated if available.- Returns:
- The current access control context or
nullif the current VM does not support it.
-
doPrivileged
@Enhance private static <T> T doPrivileged(java.security.PrivilegedAction<T> action, @MaybeNull java.lang.Object context)
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.context- The access control context ornullif the current VM does not support it.- Returns:
- The action's resolved value.
-
transform
@MaybeNull public byte[] transform(@MaybeNull java.lang.ClassLoader classLoader, @MaybeNull java.lang.String internalName, @MaybeNull java.lang.Class<?> classBeingRedefined, @MaybeNull java.security.ProtectionDomain protectionDomain, byte[] binaryRepresentation)
-
transform
@MaybeNull protected byte[] transform(java.lang.Object rawModule, @MaybeNull java.lang.ClassLoader classLoader, @MaybeNull java.lang.String internalName, @MaybeNull java.lang.Class<?> classBeingRedefined, @MaybeNull java.security.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 ornullif the type is loaded by the bootstrap loader.internalName- The internal name of the instrumented class.classBeingRedefined- The loadedClassbeing redefined ornullif no such class exists.protectionDomain- The instrumented type's protection domain ornullif 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 java.lang.ClassLoader classLoader, @MaybeNull java.lang.String internalName, @MaybeNull java.lang.Class<?> classBeingRedefined, @MaybeNull java.security.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 ornullif the current VM does not support modules.classLoader- The instrumented class's class loader.internalName- The internal name of the instrumented class.classBeingRedefined- The loadedClassbeing redefined ornullif no such class exists.protectionDomain- The instrumented type's protection domain ornullif 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 java.lang.ClassLoader classLoader, java.lang.String name, @MaybeNull java.lang.Class<?> classBeingRedefined, boolean loaded, @MaybeNull java.security.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 ornullif the current VM does not support modules.classLoader- The instrumented class's class loader.name- The binary name of the instrumented class.classBeingRedefined- The loadedClassbeing redefined ornullif no such class exists.loaded-trueif the instrumented type is loaded.protectionDomain- The instrumented type's protection domain ornullif 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 java.util.Iterator<AgentBuilder.Transformer> iterator(TypeDescription typeDescription, @MaybeNull java.lang.ClassLoader classLoader, @MaybeNull JavaModule module, @MaybeNull java.lang.Class<?> classBeingRedefined, @MaybeNull java.security.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 ornullif the boot loader.module- The type's module ornullif the module system is not supported by the current VM.classBeingRedefined- The class being redefined ornullif the type is not yet loaded.protectionDomain- The type's protection domain ornullif 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(java.lang.instrument.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.InstallationListeneris informed about the resetting without undoing any code changes.Note: A reset class file transformer should not be reinstalled. Instead, the
AgentBuilderwhich 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 bethisinstance 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:
trueif a reset was applied and this transformer was not previously removed.
-
-