Class AgentBuilder.Default
- java.lang.Object
-
- net.bytebuddy.agent.builder.AgentBuilder.Default
-
- All Implemented Interfaces:
AgentBuilder
- Direct Known Subclasses:
AgentBuilder.Default.Redefining
- Enclosing interface:
- AgentBuilder
@Enhance public static class AgentBuilder.Default extends java.lang.Object implements AgentBuilder
The default implementation of an
AgentBuilder.By default, Byte Buddy ignores any types loaded by the bootstrap class loader and any synthetic type. Self-injection and rebasing is enabled. In order to avoid class format changes, set
AgentBuilder.disableClassFormatChanges(). All types are parsed without their debugging information (AgentBuilder.PoolStrategy.Default.FAST).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classAgentBuilder.Default.DelegatorAn abstract implementation of an agent builder that delegates all invocation to another instance.protected static interfaceAgentBuilder.Default.DispatcherA dispatcher for interacting with the instrumentation API.protected static classAgentBuilder.Default.ExecutingTransformerAClassFileTransformerthat implements the enclosing agent builder's configuration.protected classAgentBuilder.Default.IgnoringA delegator transformer for further precising what types to ignore.protected static interfaceAgentBuilder.Default.NativeMethodStrategyA strategy for determining if a native method name prefix should be used when rebasing methods.protected static classAgentBuilder.Default.RedefiningAn implementation of a default agent builder that allows for refinement of the redefinition strategy.protected static classAgentBuilder.Default.TransformationA transformation to apply.protected classAgentBuilder.Default.TransformingA helper class that describes aAgentBuilder.Defaultafter supplying aAgentBuilder.RawMatchersuch that one or severalAgentBuilder.Transformers can be supplied.protected static interfaceAgentBuilder.Default.WarmupStrategyA strategy to warm up aClassFileTransformerbefore using it to eagerly load classes and to avoid circularity errors when classes are loaded during actual transformation for the first time.-
Nested classes/interfaces inherited from interface net.bytebuddy.agent.builder.AgentBuilder
AgentBuilder.CircularityLock, AgentBuilder.ClassFileBufferStrategy, AgentBuilder.Default, AgentBuilder.DescriptionStrategy, AgentBuilder.FallbackStrategy, AgentBuilder.Identified, AgentBuilder.Ignored, AgentBuilder.InitializationStrategy, AgentBuilder.InjectionStrategy, AgentBuilder.InstallationListener, AgentBuilder.LambdaInstrumentationStrategy, AgentBuilder.Listener, AgentBuilder.LocationStrategy, AgentBuilder.Matchable<T extends AgentBuilder.Matchable<T>>, AgentBuilder.PatchMode, AgentBuilder.PoolStrategy, AgentBuilder.RawMatcher, AgentBuilder.RedefinitionListenable, AgentBuilder.RedefinitionStrategy, AgentBuilder.Transformer, AgentBuilder.TransformerDecorator, AgentBuilder.TypeStrategy
-
-
Field Summary
Fields Modifier and Type Field Description protected ByteBuddybyteBuddyTheByteBuddyinstance to be used.protected AgentBuilder.CircularityLockcircularityLockThe circularity lock to use.protected AgentBuilder.ClassFileBufferStrategyclassFileBufferStrategyThe class file buffer strategy to use.protected ClassFileLocatorclassFileLocatorA class file locator to be used for additional lookup of globally available types.private static AgentBuilder.CircularityLockDEFAULT_LOCKThe default circularity lock that assures that no agent created by any agent builder within this class loader causes a class loading circularity.protected AgentBuilder.DescriptionStrategydescriptionStrategyThe description strategy for resolving type descriptions for types.private static AgentBuilder.Default.DispatcherDISPATCHERA dipatcher to use for interacting with the instrumentation API.protected AgentBuilder.FallbackStrategyfallbackStrategyThe fallback strategy to apply.protected AgentBuilder.RawMatcherignoreMatcherIdentifies types that should not be instrumented.protected AgentBuilder.InitializationStrategyinitializationStrategyThe initialization strategy to use for creating classes.protected AgentBuilder.InjectionStrategyinjectionStrategyThe injection strategy for injecting classes into a class loader.protected AgentBuilder.InstallationListenerinstallationListenerThe installation listener to notify.private static java.lang.StringINSTALLER_GETTERThe name of the getter fornet.bytebuddy.agent.Installerto read theInstrumentation.private static java.lang.StringINSTALLER_TYPEThe name of the Byte Buddynet.bytebuddy.agent.Installerclass.protected AgentBuilder.LambdaInstrumentationStrategylambdaInstrumentationStrategyA strategy to determine of theLambdaMetafactoryshould be instrumented to allow for the instrumentation of classes that represent lambda expressions.protected AgentBuilder.ListenerlistenerThe listener to notify on transformations.protected AgentBuilder.LocationStrategylocationStrategyThe location strategy to use.protected AgentBuilder.Default.NativeMethodStrategynativeMethodStrategyThe native method strategy to use.private static byte[]NO_TRANSFORMATIONThe value that is to be returned from aClassFileTransformerto indicate that no class file transformation is to be applied.private static java.lang.Class<?>NOT_PREVIOUSLY_DEFINEDA type-safe constant to express that a class is not already loaded when applying a class file transformer.protected AgentBuilder.PoolStrategypoolStrategyThe pool strategy to use.protected AgentBuilder.RedefinitionStrategy.BatchAllocatorredefinitionBatchAllocatorThe batch allocator for the redefinition strategy to apply.protected AgentBuilder.RedefinitionStrategy.DiscoveryStrategyredefinitionDiscoveryStrategyThe discovery strategy for loaded types to be redefined.protected AgentBuilder.RedefinitionStrategy.ListenerredefinitionListenerThe redefinition listener for the redefinition strategy to apply.protected AgentBuilder.RedefinitionStrategy.ResubmissionStrategyredefinitionResubmissionStrategyThe resubmission strategy to apply.protected AgentBuilder.RedefinitionStrategyredefinitionStrategyThe redefinition strategy to apply.protected java.util.List<AgentBuilder.Default.Transformation>transformationsThe transformation object for handling type transformations.protected AgentBuilder.TransformerDecoratortransformerDecoratorA decorator to wrap the created class file transformer.protected AgentBuilder.TypeStrategytypeStrategyThe definition handler to use.protected AgentBuilder.Default.WarmupStrategywarmupStrategyThe warmup strategy to use.
-
Constructor Summary
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description AgentBuilderassureReadEdgeFromAndTo(java.lang.instrument.Instrumentation instrumentation, java.lang.Class<?>... type)Assures that all modules of the supplied types are read by the module of any instrumented type and vice versa.AgentBuilderassureReadEdgeFromAndTo(java.lang.instrument.Instrumentation instrumentation, java.util.Collection<? extends JavaModule> modules)Assures that all supplied modules are read by the module of any instrumented type and vice versa.AgentBuilderassureReadEdgeFromAndTo(java.lang.instrument.Instrumentation instrumentation, JavaModule... module)Assures that all supplied modules are read by the module of any instrumented type and vice versa.AgentBuilderassureReadEdgeTo(java.lang.instrument.Instrumentation instrumentation, java.lang.Class<?>... type)Assures that all modules of the supplied types are read by the module of any instrumented type.AgentBuilderassureReadEdgeTo(java.lang.instrument.Instrumentation instrumentation, java.util.Collection<? extends JavaModule> modules)Assures that all supplied modules are read by the module of any instrumented type.AgentBuilderassureReadEdgeTo(java.lang.instrument.Instrumentation instrumentation, JavaModule... module)Assures that all supplied modules are read by the module of any instrumented type.AgentBuilderdisableClassFormatChanges()Disables all implicit changes on a class file that Byte Buddy would apply for certain instrumentations.AgentBuilderdisableNativeMethodPrefix()Disables the use of a native method prefix for instrumented methods.private ResettableClassFileTransformerdoInstall(java.lang.instrument.Instrumentation instrumentation, AgentBuilder.RawMatcher matcher, AgentBuilder.PatchMode.Handler handler)Installs the class file transformer.private static <T> TdoPrivileged(java.security.PrivilegedAction<T> action)A proxy forjava.security.AccessController#doPrivilegedthat is activated if available.AgentBuilderenableNativeMethodPrefix(java.lang.String prefix)Enables the use of the given native method prefix for instrumented methods.AgentBuilder.Ignoredignore(AgentBuilder.RawMatcher rawMatcher)Excludes any type that is matched by the raw matcher provided to this method.AgentBuilder.Ignoredignore(ElementMatcher<? super TypeDescription> typeMatcher)Excludes any type that is matched by the provided matcher from instrumentation and considers types by allClassLoaders.AgentBuilder.Ignoredignore(ElementMatcher<? super TypeDescription> typeMatcher, ElementMatcher<? super java.lang.ClassLoader> classLoaderMatcher)Excludes any type that is matched by the provided matcher and is loaded by a class loader matching the second matcher.AgentBuilder.Ignoredignore(ElementMatcher<? super TypeDescription> typeMatcher, ElementMatcher<? super java.lang.ClassLoader> classLoaderMatcher, ElementMatcher<? super JavaModule> moduleMatcher)Excludes any type that is matched by the provided matcher and is loaded by a class loader matching the second matcher.ResettableClassFileTransformerinstallOn(java.lang.instrument.Instrumentation instrumentation)Creates and installs aResettableClassFileTransformerthat implements the configuration of this agent builder with a givenInstrumentation.ResettableClassFileTransformerinstallOnByteBuddyAgent()Creates and installs aResettableClassFileTransformerthat implements the configuration of this agent builder with the Byte Buddy-agent which must be installed prior to calling this method.ResettableClassFileTransformermakeRaw()Creates aResettableClassFileTransformerthat implements the configuration of this agent builder.private ResettableClassFileTransformermakeRaw(AgentBuilder.Listener listener, AgentBuilder.InstallationListener installationListener, AgentBuilder.RedefinitionStrategy.ResubmissionEnforcer resubmissionEnforcer)Creates a new class file transformer with a given listener.static AgentBuilderof(java.util.List<? extends Plugin> plugins)Creates anAgentBuilderthat realizes the provided build plugins.static AgentBuilderof(EntryPoint entryPoint, java.util.List<? extends Plugin> plugins)Creates anAgentBuilderthat realizes the provided build plugins.static AgentBuilderof(EntryPoint entryPoint, Plugin... plugin)Creates anAgentBuilderthat realizes the provided build plugins.static AgentBuilderof(EntryPoint entryPoint, ClassFileVersion classFileVersion, java.util.List<? extends Plugin> plugins)Creates anAgentBuilderthat realizes the provided build plugins.static AgentBuilderof(EntryPoint entryPoint, ClassFileVersion classFileVersion, Plugin... plugin)Creates anAgentBuilderthat realizes the provided build plugins.static AgentBuilderof(Plugin... plugin)Creates anAgentBuilderthat realizes the provided build plugins.static AgentBuilderof(ClassFileVersion classFileVersion, java.util.List<? extends Plugin> plugins)Creates anAgentBuilderthat realizes the provided build plugins.static AgentBuilderof(ClassFileVersion classFileVersion, Plugin... plugin)Creates anAgentBuilderthat realizes the provided build plugins.ResettableClassFileTransformerpatchOn(java.lang.instrument.Instrumentation instrumentation, ResettableClassFileTransformer classFileTransformer)Creates and installs aResettableClassFileTransformerthat implements the configuration of this agent builder with a givenInstrumentation.ResettableClassFileTransformerpatchOn(java.lang.instrument.Instrumentation instrumentation, ResettableClassFileTransformer classFileTransformer, AgentBuilder.PatchMode patchMode)Creates and installs aResettableClassFileTransformerthat implements the configuration of this agent builder with a givenInstrumentation.ResettableClassFileTransformerpatchOn(java.lang.instrument.Instrumentation instrumentation, ResettableClassFileTransformer classFileTransformer, AgentBuilder.RawMatcher differentialMatcher)Creates and installs aResettableClassFileTransformerthat implements the configuration of this agent builder with a givenInstrumentation.ResettableClassFileTransformerpatchOn(java.lang.instrument.Instrumentation instrumentation, ResettableClassFileTransformer classFileTransformer, AgentBuilder.RawMatcher differentialMatcher, AgentBuilder.PatchMode patchMode)Creates and installs aResettableClassFileTransformerthat implements the configuration of this agent builder with a givenInstrumentation.ResettableClassFileTransformerpatchOnByteBuddyAgent(ResettableClassFileTransformer classFileTransformer)Creates and installs aResettableClassFileTransformerthat implements the configuration of this agent builder with the Byte Buddy-agent which must be installed prior to calling this method.ResettableClassFileTransformerpatchOnByteBuddyAgent(ResettableClassFileTransformer classFileTransformer, AgentBuilder.PatchMode patchMode)Creates and installs aResettableClassFileTransformerthat implements the configuration of this agent builder with the Byte Buddy-agent which must be installed prior to calling this method.private static java.lang.instrument.InstrumentationresolveByteBuddyAgentInstrumentation()Resolves the instrumentation provided bynet.bytebuddy.agent.Installer.AgentBuilder.Identified.Narrowabletype(AgentBuilder.RawMatcher matcher)Matches a type being loaded in order to apply the suppliedAgentBuilder.Transformers before loading this type.AgentBuilder.Identified.Narrowabletype(ElementMatcher<? super TypeDescription> typeMatcher)Matches a type being loaded in order to apply the suppliedAgentBuilder.Transformers before loading this type.AgentBuilder.Identified.Narrowabletype(ElementMatcher<? super TypeDescription> typeMatcher, ElementMatcher<? super java.lang.ClassLoader> classLoaderMatcher)Matches a type being loaded in order to apply the suppliedAgentBuilder.Transformers before loading this type.AgentBuilder.Identified.Narrowabletype(ElementMatcher<? super TypeDescription> typeMatcher, ElementMatcher<? super java.lang.ClassLoader> classLoaderMatcher, ElementMatcher<? super JavaModule> moduleMatcher)Matches a type being loaded in order to apply the suppliedAgentBuilder.Transformers before loading this type.AgentBuilderwarmUp(java.lang.Class<?>... type)Warms up the generatedClassFileTransformerto trigger class loading of classes used by the transformer prior to its actual use.AgentBuilderwarmUp(java.util.Collection<java.lang.Class<?>> types)Warms up the generatedClassFileTransformerto trigger class loading of classes used by the transformer prior to its actual use.AgentBuilderwith(AgentBuilder.CircularityLock circularityLock)Defines a circularity lock that is acquired upon executing code that potentially loads new classes.AgentBuilderwith(AgentBuilder.ClassFileBufferStrategy classFileBufferStrategy)Specifies a class file buffer strategy that determines the use of the buffer supplied to a class file transformer.AgentBuilderwith(AgentBuilder.DescriptionStrategy descriptionStrategy)Specifies a strategy to be used for resolvingTypeDescriptionfor any type handled by the created transformer.AgentBuilderwith(AgentBuilder.FallbackStrategy fallbackStrategy)Specifies a fallback strategy to that this agent builder applies upon installing an agent and during class file transformation.AgentBuilderwith(AgentBuilder.InitializationStrategy initializationStrategy)Defines a given initialization strategy to be applied to generated types.AgentBuilderwith(AgentBuilder.InjectionStrategy injectionStrategy)Defines a strategy for injecting auxiliary types into the target class loader.AgentBuilderwith(AgentBuilder.InstallationListener installationListener)Adds an installation listener that is notified during installation events.AgentBuilderwith(AgentBuilder.LambdaInstrumentationStrategy lambdaInstrumentationStrategy)Enables or disables management of the JVM'sLambdaMetafactorywhich is responsible for creating classes that implement lambda expressions.AgentBuilderwith(AgentBuilder.Listener listener)Defines the givenAgentBuilder.Listenerto be notified by the created agent.AgentBuilderwith(AgentBuilder.LocationStrategy locationStrategy)Defines the use of the given location strategy for locating binary data to given class names.AgentBuilderwith(AgentBuilder.PoolStrategy poolStrategy)Defines the use of the given type locator for locating aTypeDescriptionfor an instrumented type.AgentBuilder.RedefinitionListenable.WithoutBatchStrategywith(AgentBuilder.RedefinitionStrategy redefinitionStrategy)Specifies a strategy for modifying types that were already loaded prior to the installation of this transformer.AgentBuilderwith(AgentBuilder.TransformerDecorator transformerDecorator)Adds a decorator for the created class file transformer.AgentBuilderwith(AgentBuilder.TypeStrategy typeStrategy)Defines how types should be transformed, e.g.AgentBuilderwith(ByteBuddy byteBuddy)Defines the givenByteBuddyinstance to be used by the created agent.AgentBuilderwith(ClassFileLocator classFileLocator)Registers an additional class file locator for types that are globally available but cannot be located otherwise.
-
-
-
Field Detail
-
INSTALLER_TYPE
private static final java.lang.String INSTALLER_TYPE
The name of the Byte Buddynet.bytebuddy.agent.Installerclass.- See Also:
- Constant Field Values
-
INSTALLER_GETTER
private static final java.lang.String INSTALLER_GETTER
The name of the getter fornet.bytebuddy.agent.Installerto read theInstrumentation.- See Also:
- Constant Field Values
-
NO_TRANSFORMATION
@AlwaysNull private static final byte[] NO_TRANSFORMATION
The value that is to be returned from aClassFileTransformerto indicate that no class file transformation is to be applied.
-
NOT_PREVIOUSLY_DEFINED
@AlwaysNull private static final java.lang.Class<?> NOT_PREVIOUSLY_DEFINED
A type-safe constant to express that a class is not already loaded when applying a class file transformer.
-
DISPATCHER
private static final AgentBuilder.Default.Dispatcher DISPATCHER
A dipatcher to use for interacting with the instrumentation API.
-
DEFAULT_LOCK
private static final AgentBuilder.CircularityLock DEFAULT_LOCK
The default circularity lock that assures that no agent created by any agent builder within this class loader causes a class loading circularity.
-
listener
protected final AgentBuilder.Listener listener
The listener to notify on transformations.
-
circularityLock
protected final AgentBuilder.CircularityLock circularityLock
The circularity lock to use.
-
poolStrategy
protected final AgentBuilder.PoolStrategy poolStrategy
The pool strategy to use.
-
typeStrategy
protected final AgentBuilder.TypeStrategy typeStrategy
The definition handler to use.
-
locationStrategy
protected final AgentBuilder.LocationStrategy locationStrategy
The location strategy to use.
-
classFileLocator
protected final ClassFileLocator classFileLocator
A class file locator to be used for additional lookup of globally available types.
-
nativeMethodStrategy
protected final AgentBuilder.Default.NativeMethodStrategy nativeMethodStrategy
The native method strategy to use.
-
warmupStrategy
protected final AgentBuilder.Default.WarmupStrategy warmupStrategy
The warmup strategy to use.
-
transformerDecorator
protected final AgentBuilder.TransformerDecorator transformerDecorator
A decorator to wrap the created class file transformer.
-
initializationStrategy
protected final AgentBuilder.InitializationStrategy initializationStrategy
The initialization strategy to use for creating classes.
-
redefinitionStrategy
protected final AgentBuilder.RedefinitionStrategy redefinitionStrategy
The redefinition strategy to apply.
-
redefinitionDiscoveryStrategy
protected final AgentBuilder.RedefinitionStrategy.DiscoveryStrategy redefinitionDiscoveryStrategy
The discovery strategy for loaded types to be redefined.
-
redefinitionBatchAllocator
protected final AgentBuilder.RedefinitionStrategy.BatchAllocator redefinitionBatchAllocator
The batch allocator for the redefinition strategy to apply.
-
redefinitionListener
protected final AgentBuilder.RedefinitionStrategy.Listener redefinitionListener
The redefinition listener for the redefinition strategy to apply.
-
redefinitionResubmissionStrategy
protected final AgentBuilder.RedefinitionStrategy.ResubmissionStrategy redefinitionResubmissionStrategy
The resubmission strategy to apply.
-
injectionStrategy
protected final AgentBuilder.InjectionStrategy injectionStrategy
The injection strategy for injecting classes into a class loader.
-
lambdaInstrumentationStrategy
protected final AgentBuilder.LambdaInstrumentationStrategy lambdaInstrumentationStrategy
A strategy to determine of theLambdaMetafactoryshould be instrumented to allow for the instrumentation of classes that represent lambda expressions.
-
descriptionStrategy
protected final AgentBuilder.DescriptionStrategy descriptionStrategy
The description strategy for resolving type descriptions for types.
-
fallbackStrategy
protected final AgentBuilder.FallbackStrategy fallbackStrategy
The fallback strategy to apply.
-
classFileBufferStrategy
protected final AgentBuilder.ClassFileBufferStrategy classFileBufferStrategy
The class file buffer strategy to use.
-
installationListener
protected final AgentBuilder.InstallationListener installationListener
The installation listener to notify.
-
ignoreMatcher
protected final AgentBuilder.RawMatcher ignoreMatcher
Identifies types that should not be instrumented.
-
transformations
protected final java.util.List<AgentBuilder.Default.Transformation> transformations
The transformation object for handling type transformations.
-
-
Constructor Detail
-
Default
public Default()
Creates a new default agent builder that uses a defaultByteBuddyinstance for creating classes.
-
Default
public Default(ByteBuddy byteBuddy)
Creates a new agent builder with default settings. By default, Byte Buddy ignores any types loaded by the bootstrap class loader, any type within anet.bytebuddypackage and any synthetic type. Self-injection and rebasing is enabled. In order to avoid class format changes, setAgentBuilder.disableClassFormatChanges(). All types are parsed without their debugging information (AgentBuilder.PoolStrategy.Default.FAST).- Parameters:
byteBuddy- The Byte Buddy instance to be used.
-
Default
protected Default(ByteBuddy byteBuddy, AgentBuilder.Listener listener, AgentBuilder.CircularityLock circularityLock, AgentBuilder.PoolStrategy poolStrategy, AgentBuilder.TypeStrategy typeStrategy, AgentBuilder.LocationStrategy locationStrategy, ClassFileLocator classFileLocator, AgentBuilder.Default.NativeMethodStrategy nativeMethodStrategy, AgentBuilder.Default.WarmupStrategy warmupStrategy, AgentBuilder.TransformerDecorator transformerDecorator, AgentBuilder.InitializationStrategy initializationStrategy, AgentBuilder.RedefinitionStrategy redefinitionStrategy, AgentBuilder.RedefinitionStrategy.DiscoveryStrategy redefinitionDiscoveryStrategy, AgentBuilder.RedefinitionStrategy.BatchAllocator redefinitionBatchAllocator, AgentBuilder.RedefinitionStrategy.Listener redefinitionListener, AgentBuilder.RedefinitionStrategy.ResubmissionStrategy redefinitionResubmissionStrategy, AgentBuilder.InjectionStrategy injectionStrategy, AgentBuilder.LambdaInstrumentationStrategy lambdaInstrumentationStrategy, AgentBuilder.DescriptionStrategy descriptionStrategy, AgentBuilder.FallbackStrategy fallbackStrategy, AgentBuilder.ClassFileBufferStrategy classFileBufferStrategy, AgentBuilder.InstallationListener installationListener, AgentBuilder.RawMatcher ignoreMatcher, java.util.List<AgentBuilder.Default.Transformation> transformations)
Creates a new default agent builder.- Parameters:
byteBuddy- The Byte Buddy instance to be used.listener- The listener to notify on transformations.circularityLock- The circularity lock to use.poolStrategy- The pool strategy to use.typeStrategy- The definition handler to use.locationStrategy- The location strategy to use.classFileLocator- A class file locator to be used for additional lookup of globally available types.nativeMethodStrategy- The native method strategy to apply.warmupStrategy- The warmup strategy to use.transformerDecorator- A decorator to wrap the created class file transformer.initializationStrategy- The initialization strategy to use for transformed types.redefinitionStrategy- The redefinition strategy to apply.redefinitionDiscoveryStrategy- The discovery strategy for loaded types to be redefined.redefinitionBatchAllocator- The batch allocator for the redefinition strategy to apply.redefinitionListener- The redefinition listener for the redefinition strategy to apply.redefinitionResubmissionStrategy- The resubmission strategy to apply.injectionStrategy- The injection strategy for injecting classes into a class loader.lambdaInstrumentationStrategy- A strategy to determine of theLambdaMetafactoryshould be instrumented to allow for the instrumentation of classes that represent lambda expressions.descriptionStrategy- The description strategy for resolving type descriptions for types.fallbackStrategy- The fallback strategy to apply.classFileBufferStrategy- The class file buffer strategy to use.installationListener- The installation listener to notify.ignoreMatcher- Identifies types that should not be instrumented.transformations- The transformations to apply for any non-ignored type.
-
-
Method Detail
-
doPrivileged
@Enhance private static <T> T doPrivileged(java.security.PrivilegedAction<T> action)
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.
-
of
public static AgentBuilder of(Plugin... plugin)
Creates anAgentBuilderthat realizes the provided build plugins. AsEntryPoint,EntryPoint.Default.REBASEis implied.- Parameters:
plugin- The build plugins to apply as a Java agent.- Returns:
- An appropriate agent builder.
-
of
public static AgentBuilder of(java.util.List<? extends Plugin> plugins)
Creates anAgentBuilderthat realizes the provided build plugins. AsEntryPoint,EntryPoint.Default.REBASEis implied.- Parameters:
plugins- The build plugins to apply as a Java agent.- Returns:
- An appropriate agent builder.
-
of
public static AgentBuilder of(EntryPoint entryPoint, Plugin... plugin)
Creates anAgentBuilderthat realizes the provided build plugins.- Parameters:
entryPoint- The build entry point to use.plugin- The build plugins to apply as a Java agent.- Returns:
- An appropriate agent builder.
-
of
public static AgentBuilder of(EntryPoint entryPoint, java.util.List<? extends Plugin> plugins)
Creates anAgentBuilderthat realizes the provided build plugins.- Parameters:
entryPoint- The build entry point to use.plugins- The build plugins to apply as a Java agent.- Returns:
- An appropriate agent builder.
-
of
public static AgentBuilder of(ClassFileVersion classFileVersion, Plugin... plugin)
Creates anAgentBuilderthat realizes the provided build plugins. AsEntryPoint,EntryPoint.Default.REBASEis implied.- Parameters:
classFileVersion- The class file version to use.plugin- The build plugins to apply as a Java agent.- Returns:
- An appropriate agent builder.
-
of
public static AgentBuilder of(ClassFileVersion classFileVersion, java.util.List<? extends Plugin> plugins)
Creates anAgentBuilderthat realizes the provided build plugins. AsEntryPoint,EntryPoint.Default.REBASEis implied.- Parameters:
classFileVersion- The class file version to use.plugins- The build plugins to apply as a Java agent.- Returns:
- An appropriate agent builder.
-
of
public static AgentBuilder of(EntryPoint entryPoint, ClassFileVersion classFileVersion, Plugin... plugin)
Creates anAgentBuilderthat realizes the provided build plugins.- Parameters:
entryPoint- The build entry point to use.classFileVersion- The class file version to use.plugin- The build plugins to apply as a Java agent.- Returns:
- An appropriate agent builder.
-
of
public static AgentBuilder of(EntryPoint entryPoint, ClassFileVersion classFileVersion, java.util.List<? extends Plugin> plugins)
Creates anAgentBuilderthat realizes the provided build plugins.- Parameters:
entryPoint- The build entry point to use.classFileVersion- The class file version to use.plugins- The build plugins to apply as a Java agent.- Returns:
- An appropriate agent builder.
-
with
public AgentBuilder with(ByteBuddy byteBuddy)
Defines the givenByteBuddyinstance to be used by the created agent.- Specified by:
within interfaceAgentBuilder- Parameters:
byteBuddy- The Byte Buddy instance to be used.- Returns:
- A new instance of this agent builder which makes use of the given
byteBuddyinstance.
-
with
public AgentBuilder with(AgentBuilder.Listener listener)
Defines the givenAgentBuilder.Listenerto be notified by the created agent. The given listener is notified after any other listener that is already registered. If a listener is registered twice, it is also notified twice.- Specified by:
within interfaceAgentBuilder- Parameters:
listener- The listener to be notified.- Returns:
- A new instance of this agent builder which creates an agent that informs the given listener about events.
-
with
public AgentBuilder with(AgentBuilder.CircularityLock circularityLock)
Defines a circularity lock that is acquired upon executing code that potentially loads new classes. While the lock is acquired, any class file transformer refrains from transforming any classes. By default, all created agents use a sharedAgentBuilder.CircularityLockto avoid that any classes that are required to execute an agent causes aClassCircularityError.- Specified by:
within interfaceAgentBuilder- Parameters:
circularityLock- The circularity lock to use.- Returns:
- A new instance of this agent builder which creates an agent that uses the supplied circularity lock.
-
with
public AgentBuilder with(AgentBuilder.TypeStrategy typeStrategy)
Defines how types should be transformed, e.g. if they should be rebased or redefined by the created agent.- Specified by:
within interfaceAgentBuilder- Parameters:
typeStrategy- The type strategy to use.- Returns:
- A new instance of this agent builder which uses the given type strategy.
-
with
public AgentBuilder with(AgentBuilder.PoolStrategy poolStrategy)
Defines the use of the given type locator for locating aTypeDescriptionfor an instrumented type.- Specified by:
within interfaceAgentBuilder- Parameters:
poolStrategy- The type locator to use.- Returns:
- A new instance of this agent builder which uses the given type locator for looking up class files.
-
with
public AgentBuilder with(AgentBuilder.LocationStrategy locationStrategy)
Defines the use of the given location strategy for locating binary data to given class names.- Specified by:
within interfaceAgentBuilder- Parameters:
locationStrategy- The location strategy to use.- Returns:
- A new instance of this agent builder which uses the given location strategy for looking up class files.
-
with
public AgentBuilder with(ClassFileLocator classFileLocator)
Registers an additional class file locator for types that are globally available but cannot be located otherwise. Typically, those types are injected classes into the boot loader.- Specified by:
within interfaceAgentBuilder- Parameters:
classFileLocator- The class file locator to add.- Returns:
- A new instance of this agent builder which uses the given class file locator for global type lookup.
-
enableNativeMethodPrefix
public AgentBuilder enableNativeMethodPrefix(java.lang.String prefix)
Enables the use of the given native method prefix for instrumented methods. Note that this prefix is also applied when preserving non-native methods. The use of this prefix is also registered when installing the final agent with anInstrumentation.- Specified by:
enableNativeMethodPrefixin interfaceAgentBuilder- Parameters:
prefix- The prefix to be used.- Returns:
- A new instance of this agent builder which uses the given native method prefix.
-
disableNativeMethodPrefix
public AgentBuilder disableNativeMethodPrefix()
Disables the use of a native method prefix for instrumented methods.- Specified by:
disableNativeMethodPrefixin interfaceAgentBuilder- Returns:
- A new instance of this agent builder which does not use a native method prefix.
-
warmUp
public AgentBuilder warmUp(java.lang.Class<?>... type)
Warms up the generated
ClassFileTransformerto trigger class loading of classes used by the transformer prior to its actual use. Ideally, warmup should include classes that cause a transformation and classes that are ignored. Warming up can be especially useful when transforming classes on the boot path, where circularity errors are more likely. At the same time, warming up might load classes that are expected to be unloaded when this agent is installed.Important: Warming up is applied just as a regular transformation and will also invoke the
AgentBuilder.Listener. This is done to avoid that listener classes can cause circularities. It is the users responsibility to suppress such log output, if necessary.- Specified by:
warmUpin interfaceAgentBuilder- Parameters:
type- The types to include in the warmup.- Returns:
- A new agent builder that considers the supplied classes in its warmup.
-
warmUp
public AgentBuilder warmUp(java.util.Collection<java.lang.Class<?>> types)
Warms up the generated
ClassFileTransformerto trigger class loading of classes used by the transformer prior to its actual use. Ideally, warmup should include classes that cause a transformation and classes that are ignored. Warming up can be especially useful when transforming classes on the boot path, where circularity errors are more likely. At the same time, warming up might load classes that are expected to be unloaded when this agent is installed.Important: Warming up is applied just as a regular transformation and will also invoke the
AgentBuilder.Listener. This is done to avoid that listener classes can cause circularities. It is the users responsibility to suppress such log output, if necessary.- Specified by:
warmUpin interfaceAgentBuilder- Parameters:
types- The types to include in the warmup.- Returns:
- A new agent builder that considers the supplied classes in its warmup.
-
with
public AgentBuilder with(AgentBuilder.TransformerDecorator transformerDecorator)
Adds a decorator for the created class file transformer.- Specified by:
within interfaceAgentBuilder- Parameters:
transformerDecorator- A decorator to wrap the created class file transformer.- Returns:
- A new agent builder that applies the supplied transformer decorator.
-
with
public AgentBuilder.RedefinitionListenable.WithoutBatchStrategy with(AgentBuilder.RedefinitionStrategy redefinitionStrategy)
Specifies a strategy for modifying types that were already loaded prior to the installation of this transformer.
Note: Defining a redefinition strategy resets any refinements of a previously set redefinition strategy.
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().- Specified by:
within interfaceAgentBuilder- Parameters:
redefinitionStrategy- The redefinition strategy to apply.- Returns:
- A new instance of this agent builder that applies the given redefinition strategy.
-
with
public AgentBuilder with(AgentBuilder.InitializationStrategy initializationStrategy)
Defines a given initialization strategy to be applied to generated types. An initialization strategy is responsible for setting up a type after it was loaded. This initialization must be performed after the transformation because a Java agent is only invoked before loading a type. By default, the initialization logic is added to a class's type initializer which queries a global object for any objects that are to be injected into the generated type.- Specified by:
within interfaceAgentBuilder- Parameters:
initializationStrategy- The initialization strategy to use.- Returns:
- A new instance of this agent builder that applies the given initialization strategy.
-
with
public AgentBuilder with(AgentBuilder.LambdaInstrumentationStrategy lambdaInstrumentationStrategy)
Enables or disables management of the JVM's
LambdaMetafactorywhich is responsible for creating classes that implement lambda expressions. Without this feature enabled, classes that are represented by lambda expressions are not instrumented by the JVM such that Java agents have no effect on them when a lambda expression's class is loaded for the first time.When activating this feature, Byte Buddy instruments the
LambdaMetafactoryand takes over the responsibility of creating classes that represent lambda expressions. In doing so, Byte Buddy has the opportunity to apply the built class file transformer. If the current VM does not support lambda expressions, activating this feature has no effect.Important: If this feature is active, it is important to release the built class file transformer when deactivating it. Normally, it is sufficient to call
Instrumentation.removeTransformer(ClassFileTransformer). When this feature is enabled, it is however also required to invokeAgentBuilder.LambdaInstrumentationStrategy.release(ClassFileTransformer, Instrumentation). Otherwise, the executing VMs class loader retains a reference to the class file transformer what can cause a memory leak.- Specified by:
within interfaceAgentBuilder- Parameters:
lambdaInstrumentationStrategy-trueif this feature should be enabled.- Returns:
- A new instance of this agent builder where this feature is explicitly enabled or disabled.
-
with
public AgentBuilder with(AgentBuilder.DescriptionStrategy descriptionStrategy)
Specifies a strategy to be used for resolvingTypeDescriptionfor any type handled by the created transformer.- Specified by:
within interfaceAgentBuilder- Parameters:
descriptionStrategy- The description strategy to use.- Returns:
- A new instance of this agent builder that applies the given description strategy.
-
with
public AgentBuilder with(AgentBuilder.FallbackStrategy fallbackStrategy)
Specifies a fallback strategy to that this agent builder applies upon installing an agent and during class file transformation.- Specified by:
within interfaceAgentBuilder- Parameters:
fallbackStrategy- The fallback strategy to be used.- Returns:
- A new agent builder that applies the supplied fallback strategy.
-
with
public AgentBuilder with(AgentBuilder.ClassFileBufferStrategy classFileBufferStrategy)
Specifies a class file buffer strategy that determines the use of the buffer supplied to a class file transformer.- Specified by:
within interfaceAgentBuilder- Parameters:
classFileBufferStrategy- The class file buffer strategy to use.- Returns:
- A new agent builder that applies the supplied class file buffer strategy.
-
with
public AgentBuilder with(AgentBuilder.InstallationListener installationListener)
Adds an installation listener that is notified during installation events. Installation listeners are only invoked if a class file transformer is installed using this agent builder's installation methods and uninstalled via the createdResettableClassFileTransformer'sresetmethods.- Specified by:
within interfaceAgentBuilder- Parameters:
installationListener- The installation listener to register.- Returns:
- A new agent builder that applies the supplied installation listener.
-
with
public AgentBuilder with(AgentBuilder.InjectionStrategy injectionStrategy)
Defines a strategy for injecting auxiliary types into the target class loader.- Specified by:
within interfaceAgentBuilder- Parameters:
injectionStrategy- The injection strategy to use.- Returns:
- A new agent builder with the supplied injection strategy configured.
-
disableClassFormatChanges
public AgentBuilder disableClassFormatChanges()
Disables all implicit changes on a class file that Byte Buddy would apply for certain instrumentations. When using this option, it is no longer possible to rebase a method, i.e. intercepted methods are fully replaced. Furthermore, it is no longer possible to implicitly apply loaded type initializers for explicitly initializing the generated type.
This is equivalent to setting
AgentBuilder.InitializationStrategy.NoOpandAgentBuilder.TypeStrategy.Default.REDEFINE_FROZEN(unless it is configured asAgentBuilder.TypeStrategy.Default.DECORATEwhere this strategy is retained) as well as configuring the underlyingByteBuddyinstance to use aImplementation.Context.Disabled. Using this strategy also configures Byte Buddy to create frozen instrumented types and discards any explicit configuration.- Specified by:
disableClassFormatChangesin interfaceAgentBuilder- Returns:
- A new instance of this agent builder that does not apply any implicit changes to the received class file.
-
assureReadEdgeTo
public AgentBuilder assureReadEdgeTo(java.lang.instrument.Instrumentation instrumentation, java.lang.Class<?>... type)
Assures that all modules of the supplied types are read by the module of any instrumented type. If the current VM does not support the Java module system, calling this method has no effect and this instance is returned.- Specified by:
assureReadEdgeToin interfaceAgentBuilder- Parameters:
instrumentation- The instrumentation instance that is used for adding a module read-dependency.type- The types for which to assure their module-visibility from any instrumented class.- Returns:
- A new instance of this agent builder that assures the supplied types module visibility.
- See Also:
AgentBuilder.Listener.ModuleReadEdgeCompleting
-
assureReadEdgeTo
public AgentBuilder assureReadEdgeTo(java.lang.instrument.Instrumentation instrumentation, JavaModule... module)
Assures that all supplied modules are read by the module of any instrumented type.- Specified by:
assureReadEdgeToin interfaceAgentBuilder- Parameters:
instrumentation- The instrumentation instance that is used for adding a module read-dependency.module- The modules for which to assure their module-visibility from any instrumented class.- Returns:
- A new instance of this agent builder that assures the supplied types module visibility.
- See Also:
AgentBuilder.Listener.ModuleReadEdgeCompleting
-
assureReadEdgeTo
public AgentBuilder assureReadEdgeTo(java.lang.instrument.Instrumentation instrumentation, java.util.Collection<? extends JavaModule> modules)
Assures that all supplied modules are read by the module of any instrumented type.- Specified by:
assureReadEdgeToin interfaceAgentBuilder- Parameters:
instrumentation- The instrumentation instance that is used for adding a module read-dependency.modules- The modules for which to assure their module-visibility from any instrumented class.- Returns:
- A new instance of this agent builder that assures the supplied types module visibility.
- See Also:
AgentBuilder.Listener.ModuleReadEdgeCompleting
-
assureReadEdgeFromAndTo
public AgentBuilder assureReadEdgeFromAndTo(java.lang.instrument.Instrumentation instrumentation, java.lang.Class<?>... type)
Assures that all modules of the supplied types are read by the module of any instrumented type and vice versa. If the current VM does not support the Java module system, calling this method has no effect and this instance is returned. Setting this option will also ensure that the instrumented type's package is opened to the target module, if applicable.- Specified by:
assureReadEdgeFromAndToin interfaceAgentBuilder- Parameters:
instrumentation- The instrumentation instance that is used for adding a module read-dependency.type- The types for which to assure their module-visibility from and to any instrumented class.- Returns:
- A new instance of this agent builder that assures the supplied types module visibility.
- See Also:
AgentBuilder.Listener.ModuleReadEdgeCompleting
-
assureReadEdgeFromAndTo
public AgentBuilder assureReadEdgeFromAndTo(java.lang.instrument.Instrumentation instrumentation, JavaModule... module)
Assures that all supplied modules are read by the module of any instrumented type and vice versa. Setting this option will also ensure that the instrumented type's package is opened to the target module.- Specified by:
assureReadEdgeFromAndToin interfaceAgentBuilder- Parameters:
instrumentation- The instrumentation instance that is used for adding a module read-dependency.module- The modules for which to assure their module-visibility from and to any instrumented class.- Returns:
- A new instance of this agent builder that assures the supplied types module visibility.
- See Also:
AgentBuilder.Listener.ModuleReadEdgeCompleting
-
assureReadEdgeFromAndTo
public AgentBuilder assureReadEdgeFromAndTo(java.lang.instrument.Instrumentation instrumentation, java.util.Collection<? extends JavaModule> modules)
Assures that all supplied modules are read by the module of any instrumented type and vice versa. Setting this option will also ensure that the instrumented type's package is opened to the target module.- Specified by:
assureReadEdgeFromAndToin interfaceAgentBuilder- Parameters:
instrumentation- The instrumentation instance that is used for adding a module read-dependency.modules- The modules for which to assure their module-visibility from and to any instrumented class.- Returns:
- A new instance of this agent builder that assures the supplied types module visibility.
- See Also:
AgentBuilder.Listener.ModuleReadEdgeCompleting
-
type
public AgentBuilder.Identified.Narrowable type(AgentBuilder.RawMatcher matcher)
Matches a type being loaded in order to apply the supplied
AgentBuilder.Transformers before loading this type. If several matchers positively match a type only the latest registered matcher is considered for transformation.If this matcher is chained with additional subsequent matchers, any matcher is executed in registration order with matchers that were registered first being executed first. Doing so, later transformations can override transformations that are applied by this matcher. To avoid this, it is possible to register this transformation as terminal via
AgentBuilder.Identified.Extendable.asTerminalTransformation()where no subsequent matchers are applied if this matcher matched a given type.Note: When applying a matcher, regard the performance implications by
AgentBuilder.ignore(ElementMatcher). The former matcher is applied first such that it makes sense to ignore name spaces that are irrelevant to instrumentation. If possible, it is also recommended, to exclude class loaders such as for example the bootstrap class loader.- Specified by:
typein interfaceAgentBuilder- Parameters:
matcher- A matcher that decides if the entailedAgentBuilder.Transformers should be applied for a type that is being loaded.- Returns:
- A definable that represents this agent builder which allows for the definition of one or several
AgentBuilder.Transformers to be applied when the givenmatcherindicates a match.
-
type
public AgentBuilder.Identified.Narrowable type(ElementMatcher<? super TypeDescription> typeMatcher)
Matches a type being loaded in order to apply the supplied
AgentBuilder.Transformers before loading this type. If several matchers positively match a type only the latest registered matcher is considered for transformation.If this matcher is chained with additional subsequent matchers, any matcher is executed in registration order with matchers that were registered first being executed first. Doing so, later transformations can override transformations that are applied by this matcher. To avoid this, it is possible to register this transformation as terminal via
AgentBuilder.Identified.Extendable.asTerminalTransformation()where no subsequent matchers are applied if this matcher matched a given type.Note: When applying a matcher, regard the performance implications by
AgentBuilder.ignore(ElementMatcher). The former matcher is applied first such that it makes sense to ignore name spaces that are irrelevant to instrumentation. If possible, it is also recommended, to exclude class loaders such as for example the bootstrap class loader by usingAgentBuilder.type(ElementMatcher, ElementMatcher)instead.- Specified by:
typein interfaceAgentBuilder- Parameters:
typeMatcher- AnElementMatcherthat is applied on the type being loaded that decides if the entailedAgentBuilder.Transformers should be applied for that type.- Returns:
- A definable that represents this agent builder which allows for the definition of one or several
AgentBuilder.Transformers to be applied when the giventypeMatcherindicates a match.
-
type
public AgentBuilder.Identified.Narrowable type(ElementMatcher<? super TypeDescription> typeMatcher, ElementMatcher<? super java.lang.ClassLoader> classLoaderMatcher)
Matches a type being loaded in order to apply the supplied
AgentBuilder.Transformers before loading this type. If several matchers positively match a type only the latest registered matcher is considered for transformation.If this matcher is chained with additional subsequent matchers, any matcher is executed in registration order with matchers that were registered first being executed first. Doing so, later transformations can override transformations that are applied by this matcher. To avoid this, it is possible to register this transformation as terminal via
AgentBuilder.Identified.Extendable.asTerminalTransformation()where no subsequent matchers are applied if this matcher matched a given type.Note: When applying a matcher, regard the performance implications by
AgentBuilder.ignore(ElementMatcher). The former matcher is applied first such that it makes sense to ignore name spaces that are irrelevant to instrumentation. If possible, it is also recommended, to exclude class loaders such as for example the bootstrap class loader.- Specified by:
typein interfaceAgentBuilder- Parameters:
typeMatcher- AnElementMatcherthat is applied on the type being loaded that decides if the entailedAgentBuilder.Transformers should be applied for that type.classLoaderMatcher- AnElementMatcherthat is applied to theClassLoaderthat is loading the type being loaded. This matcher is always applied first where the type matcher is not applied in case that this matcher does not indicate a match.- Returns:
- A definable that represents this agent builder which allows for the definition of one or several
AgentBuilder.Transformers to be applied when both the giventypeMatcherandclassLoaderMatcherindicate a match.
-
type
public AgentBuilder.Identified.Narrowable type(ElementMatcher<? super TypeDescription> typeMatcher, ElementMatcher<? super java.lang.ClassLoader> classLoaderMatcher, ElementMatcher<? super JavaModule> moduleMatcher)
Matches a type being loaded in order to apply the supplied
AgentBuilder.Transformers before loading this type. If several matchers positively match a type only the latest registered matcher is considered for transformation.If this matcher is chained with additional subsequent matchers, any matcher is executed in registration order with matchers that were registered first being executed first. Doing so, later transformations can override transformations that are applied by this matcher. To avoid this, it is possible to register this transformation as terminal via
AgentBuilder.Identified.Extendable.asTerminalTransformation()where no subsequent matchers are applied if this matcher matched a given type.Note: When applying a matcher, regard the performance implications by
AgentBuilder.ignore(ElementMatcher). The former matcher is applied first such that it makes sense to ignore name spaces that are irrelevant to instrumentation. If possible, it is also recommended, to exclude class loaders such as for example the bootstrap class loader.- Specified by:
typein interfaceAgentBuilder- Parameters:
typeMatcher- AnElementMatcherthat is applied on the type being loaded that decides if the entailedAgentBuilder.Transformers should be applied for that type.classLoaderMatcher- AnElementMatcherthat is applied to theClassLoaderthat is loading the type being loaded. This matcher is always applied second where the type matcher is not applied in case that this matcher does not indicate a match.moduleMatcher- AnElementMatcherthat is applied to theJavaModuleof the type being loaded. This matcher is always applied first where the class loader and type matchers are not applied in case that this matcher does not indicate a match. On a JVM that does not support the Java modules system, this matcher is not applied.- Returns:
- A definable that represents this agent builder which allows for the definition of one or several
AgentBuilder.Transformers to be applied when both the giventypeMatcherandclassLoaderMatcherindicate a match.
-
ignore
public AgentBuilder.Ignored ignore(ElementMatcher<? super TypeDescription> typeMatcher)
Excludes any type that is matched by the provided matcher from instrumentation and considers types by all
ClassLoaders. By default, Byte Buddy does not instrument synthetic types or types that are loaded by the bootstrap class loader.When ignoring a type, any subsequently chained matcher is applied after this matcher in the order of their registration. Also, if any matcher indicates that a type is to be ignored, none of the following chained matchers is executed.
Note: For performance reasons, it is recommended to always include a matcher that excludes as many namespaces as possible. Byte Buddy can determine a type's name without parsing its class file and can therefore discard such types with minimal overhead. When a different property of a type - such as for example its modifiers or its annotations is accessed - Byte Buddy parses the class file lazily in order to allow for such a matching. Therefore, any exclusion of a name should always be done as a first step and even if it does not influence the selection of what types are matched. Without changing this property, the class file of every type is being parsed!
Warning: If a type is loaded during the instrumentation of the same type, this causes the original call site that loads the type to remain unbound, causing a
LinkageError. It is therefore important to not instrument types that may be loaded during the application of aAgentBuilder.Transformer. For this reason, it is not recommended to instrument classes of the bootstrap class loader that Byte Buddy might require for instrumenting a class or to instrument any of Byte Buddy's classes. If such instrumentation is desired, it is important to assert for each class that they are not loaded during instrumentation.- Specified by:
ignorein interfaceAgentBuilder- Parameters:
typeMatcher- A matcher that identifies types that should not be instrumented.- Returns:
- A new instance of this agent builder that ignores all types that are matched by the provided matcher. All previous matchers for ignored types are discarded.
-
ignore
public AgentBuilder.Ignored ignore(ElementMatcher<? super TypeDescription> typeMatcher, ElementMatcher<? super java.lang.ClassLoader> classLoaderMatcher)
Excludes any type that is matched by the provided matcher and is loaded by a class loader matching the second matcher. By default, Byte Buddy does not instrument synthetic types, types within a
net.bytebuddy.*package or types that are loaded by the bootstrap class loader.When ignoring a type, any subsequently chained matcher is applied after this matcher in the order of their registration. Also, if any matcher indicates that a type is to be ignored, none of the following chained matchers is executed.
Note: For performance reasons, it is recommended to always include a matcher that excludes as many namespaces as possible. Byte Buddy can determine a type's name without parsing its class file and can therefore discard such types with minimal overhead. When a different property of a type - such as for example its modifiers or its annotations is accessed - Byte Buddy parses the class file lazily in order to allow for such a matching. Therefore, any exclusion of a name should always be done as a first step and even if it does not influence the selection of what types are matched. Without changing this property, the class file of every type is being parsed!
Warning: If a type is loaded during the instrumentation of the same type, this causes the original call site that loads the type to remain unbound, causing a
LinkageError. It is therefore important to not instrument types that may be loaded during the application of aAgentBuilder.Transformer. For this reason, it is not recommended to instrument classes of the bootstrap class loader that Byte Buddy might require for instrumenting a class or to instrument any of Byte Buddy's classes. If such instrumentation is desired, it is important to assert for each class that they are not loaded during instrumentation.- Specified by:
ignorein interfaceAgentBuilder- Parameters:
typeMatcher- A matcher that identifies types that should not be instrumented.classLoaderMatcher- A matcher that identifies a class loader that identifies classes that should not be instrumented.- Returns:
- A new instance of this agent builder that ignores all types that are matched by the provided matcher. All previous matchers for ignored types are discarded.
-
ignore
public AgentBuilder.Ignored ignore(ElementMatcher<? super TypeDescription> typeMatcher, ElementMatcher<? super java.lang.ClassLoader> classLoaderMatcher, ElementMatcher<? super JavaModule> moduleMatcher)
Excludes any type that is matched by the provided matcher and is loaded by a class loader matching the second matcher. By default, Byte Buddy does not instrument synthetic types, types within a
net.bytebuddy.*package or types that are loaded by the bootstrap class loader.When ignoring a type, any subsequently chained matcher is applied after this matcher in the order of their registration. Also, if any matcher indicates that a type is to be ignored, none of the following chained matchers is executed.
Note: For performance reasons, it is recommended to always include a matcher that excludes as many namespaces as possible. Byte Buddy can determine a type's name without parsing its class file and can therefore discard such types with minimal overhead. When a different property of a type - such as for example its modifiers or its annotations is accessed - Byte Buddy parses the class file lazily in order to allow for such a matching. Therefore, any exclusion of a name should always be done as a first step and even if it does not influence the selection of what types are matched. Without changing this property, the class file of every type is being parsed!
Warning: If a type is loaded during the instrumentation of the same type, this causes the original call site that loads the type to remain unbound, causing a
LinkageError. It is therefore important to not instrument types that may be loaded during the application of aAgentBuilder.Transformer. For this reason, it is not recommended to instrument classes of the bootstrap class loader that Byte Buddy might require for instrumenting a class or to instrument any of Byte Buddy's classes. If such instrumentation is desired, it is important to assert for each class that they are not loaded during instrumentation.- Specified by:
ignorein interfaceAgentBuilder- Parameters:
typeMatcher- A matcher that identifies types that should not be instrumented.classLoaderMatcher- A matcher that identifies a class loader that identifies classes that should not be instrumented.moduleMatcher- A matcher that identifies a module that identifies classes that should not be instrumented. On a JVM that does not support the Java modules system, this matcher is not applied.- Returns:
- A new instance of this agent builder that ignores all types that are matched by the provided matcher. All previous matchers for ignored types are discarded.
-
ignore
public AgentBuilder.Ignored ignore(AgentBuilder.RawMatcher rawMatcher)
Excludes any type that is matched by the raw matcher provided to this method. By default, Byte Buddy does not instrument synthetic types, types within a
net.bytebuddy.*package or types that are loaded by the bootstrap class loader.When ignoring a type, any subsequently chained matcher is applied after this matcher in the order of their registration. Also, if any matcher indicates that a type is to be ignored, none of the following chained matchers is executed.
Note: For performance reasons, it is recommended to always include a matcher that excludes as many namespaces as possible. Byte Buddy can determine a type's name without parsing its class file and can therefore discard such types with minimal overhead. When a different property of a type - such as for example its modifiers or its annotations is accessed - Byte Buddy parses the class file lazily in order to allow for such a matching. Therefore, any exclusion of a name should always be done as a first step and even if it does not influence the selection of what types are matched. Without changing this property, the class file of every type is being parsed!
Warning: If a type is loaded during the instrumentation of the same type, this causes the original call site that loads the type to remain unbound, causing a
LinkageError. It is therefore important to not instrument types that may be loaded during the application of aAgentBuilder.Transformer. For this reason, it is not recommended to instrument classes of the bootstrap class loader that Byte Buddy might require for instrumenting a class or to instrument any of Byte Buddy's classes. If such instrumentation is desired, it is important to assert for each class that they are not loaded during instrumentation.- Specified by:
ignorein interfaceAgentBuilder- Parameters:
rawMatcher- A raw matcher that identifies types that should not be instrumented.- Returns:
- A new instance of this agent builder that ignores all types that are matched by the provided matcher. All previous matchers for ignored types are discarded.
-
makeRaw
public ResettableClassFileTransformer makeRaw()
Creates aResettableClassFileTransformerthat implements the configuration of this agent builder. When using a raw class file transformer, theAgentBuilder.InstallationListenercallbacks are not invoked and the setAgentBuilder.RedefinitionStrategyis not applied onto currently loaded classes.- Specified by:
makeRawin interfaceAgentBuilder- Returns:
- A class file transformer that implements the configuration of this agent builder.
-
makeRaw
private ResettableClassFileTransformer makeRaw(AgentBuilder.Listener listener, AgentBuilder.InstallationListener installationListener, AgentBuilder.RedefinitionStrategy.ResubmissionEnforcer resubmissionEnforcer)
Creates a new class file transformer with a given listener.- Parameters:
listener- The listener to supply.installationListener- The installation listener to notify.resubmissionEnforcer- The resubmission enforcer to use.- Returns:
- The resettable class file transformer to use.
-
resolveByteBuddyAgentInstrumentation
private static java.lang.instrument.Instrumentation resolveByteBuddyAgentInstrumentation()
Resolves the instrumentation provided bynet.bytebuddy.agent.Installer.- Returns:
- The installed instrumentation instance.
-
installOn
public ResettableClassFileTransformer installOn(java.lang.instrument.Instrumentation instrumentation)
Creates and installs a
ResettableClassFileTransformerthat implements the configuration of this agent builder with a givenInstrumentation. If retransformation is enabled, the installation also causes all loaded types to be retransformed.In order to assure the correct handling of the
AgentBuilder.InstallationListener, an uninstallation should be applied via theResettableClassFileTransformer'sresetmethods.- Specified by:
installOnin interfaceAgentBuilder- Parameters:
instrumentation- The instrumentation on which this agent builder's configuration is to be installed.- Returns:
- The installed class file transformer.
-
installOnByteBuddyAgent
public ResettableClassFileTransformer installOnByteBuddyAgent()
Creates and installs a
ResettableClassFileTransformerthat implements the configuration of this agent builder with the Byte Buddy-agent which must be installed prior to calling this method. If retransformation is enabled, the installation also causes all loaded types to be retransformed.In order to assure the correct handling of the
AgentBuilder.InstallationListener, an uninstallation should be applied via theResettableClassFileTransformer'sresetmethods.- Specified by:
installOnByteBuddyAgentin interfaceAgentBuilder- Returns:
- The installed class file transformer.
- See Also:
AgentBuilder.installOn(Instrumentation)
-
patchOn
public ResettableClassFileTransformer patchOn(java.lang.instrument.Instrumentation instrumentation, ResettableClassFileTransformer classFileTransformer)
Creates and installs a
ResettableClassFileTransformerthat implements the configuration of this agent builder with a givenInstrumentation. If retransformation is enabled, the installation also causes all loaded types to be retransformed which have changed compared to the previous class file transformer that is provided as an argument. Without specification,AgentBuilder.PatchMode.OVERLAPis used.In order to assure the correct handling of the
AgentBuilder.InstallationListener, an uninstallation should be applied via theResettableClassFileTransformer'sresetmethods.- Specified by:
patchOnin interfaceAgentBuilder- Parameters:
instrumentation- The instrumentation on which this agent builder's configuration is to be installed.classFileTransformer- The class file transformer that is being patched.- Returns:
- The installed class file transformer.
-
patchOn
public ResettableClassFileTransformer patchOn(java.lang.instrument.Instrumentation instrumentation, ResettableClassFileTransformer classFileTransformer, AgentBuilder.RawMatcher differentialMatcher)
Creates and installs a
ResettableClassFileTransformerthat implements the configuration of this agent builder with a givenInstrumentation. If retransformation is enabled, the installation also causes all loaded types to be retransformed which have changed compared to the previous class file transformer that is provided as an argument. Without specification,AgentBuilder.PatchMode.OVERLAPis used.In order to assure the correct handling of the
AgentBuilder.InstallationListener, an uninstallation should be applied via theResettableClassFileTransformer'sresetmethods.- Specified by:
patchOnin interfaceAgentBuilder- Parameters:
instrumentation- The instrumentation on which this agent builder's configuration is to be installed.classFileTransformer- The class file transformer that is being patched.differentialMatcher- The differential matcher to decide what types need retransformation.- Returns:
- The installed class file transformer.
-
patchOn
public ResettableClassFileTransformer patchOn(java.lang.instrument.Instrumentation instrumentation, ResettableClassFileTransformer classFileTransformer, AgentBuilder.PatchMode patchMode)
Creates and installs a
ResettableClassFileTransformerthat implements the configuration of this agent builder with a givenInstrumentation. If retransformation is enabled, the installation also causes all loaded types to be retransformed which have changed compared to the previous class file transformer that is provided as an argument.In order to assure the correct handling of the
AgentBuilder.InstallationListener, an uninstallation should be applied via theResettableClassFileTransformer'sresetmethods.- Specified by:
patchOnin interfaceAgentBuilder- Parameters:
instrumentation- The instrumentation on which this agent builder's configuration is to be installed.classFileTransformer- The class file transformer that is being patched.patchMode- The patch mode to apply.- Returns:
- The installed class file transformer.
-
patchOn
public ResettableClassFileTransformer patchOn(java.lang.instrument.Instrumentation instrumentation, ResettableClassFileTransformer classFileTransformer, AgentBuilder.RawMatcher differentialMatcher, AgentBuilder.PatchMode patchMode)
Creates and installs a
ResettableClassFileTransformerthat implements the configuration of this agent builder with a givenInstrumentation. If retransformation is enabled, the installation also causes all loaded types to be retransformed which have changed compared to the previous class file transformer that is provided as an argument.In order to assure the correct handling of the
AgentBuilder.InstallationListener, an uninstallation should be applied via theResettableClassFileTransformer'sresetmethods.- Specified by:
patchOnin interfaceAgentBuilder- Parameters:
instrumentation- The instrumentation on which this agent builder's configuration is to be installed.classFileTransformer- The class file transformer that is being patched.differentialMatcher- The differential matcher to decide what types need retransformation.patchMode- The patch mode to apply.- Returns:
- The installed class file transformer.
-
patchOnByteBuddyAgent
public ResettableClassFileTransformer patchOnByteBuddyAgent(ResettableClassFileTransformer classFileTransformer)
Creates and installs a
ResettableClassFileTransformerthat implements the configuration of this agent builder with the Byte Buddy-agent which must be installed prior to calling this method. If retransformation is enabled, the installation also causes all loaded types to be retransformed which have changed compared to the previous class file transformer that is provided as an argument. Without specification,AgentBuilder.PatchMode.OVERLAPis used.In order to assure the correct handling of the
AgentBuilder.InstallationListener, an uninstallation should be applied via theResettableClassFileTransformer'sresetmethods.- Specified by:
patchOnByteBuddyAgentin interfaceAgentBuilder- Parameters:
classFileTransformer- The class file transformer that is being patched.- Returns:
- The installed class file transformer.
- See Also:
AgentBuilder.patchOn(Instrumentation, ResettableClassFileTransformer)
-
patchOnByteBuddyAgent
public ResettableClassFileTransformer patchOnByteBuddyAgent(ResettableClassFileTransformer classFileTransformer, AgentBuilder.PatchMode patchMode)
Creates and installs a
ResettableClassFileTransformerthat implements the configuration of this agent builder with the Byte Buddy-agent which must be installed prior to calling this method. If retransformation is enabled, the installation also causes all loaded types to be retransformed which have changed compared to the previous class file transformer that is provided as an argument.In order to assure the correct handling of the
AgentBuilder.InstallationListener, an uninstallation should be applied via theResettableClassFileTransformer'sresetmethods.- Specified by:
patchOnByteBuddyAgentin interfaceAgentBuilder- Parameters:
classFileTransformer- The class file transformer that is being patched.patchMode- The patch mode to apply.- Returns:
- The installed class file transformer.
- See Also:
AgentBuilder.patchOn(Instrumentation, ResettableClassFileTransformer, PatchMode)
-
doInstall
private ResettableClassFileTransformer doInstall(java.lang.instrument.Instrumentation instrumentation, AgentBuilder.RawMatcher matcher, AgentBuilder.PatchMode.Handler handler)
Installs the class file transformer.- Parameters:
instrumentation- The instrumentation to install the matcher on.matcher- The matcher to identify redefined types.handler- The handler to use for implementing a patch mode.- Returns:
- The created class file transformer.
-
-