Enum Class AgentBuilder.RedefinitionStrategy
- All Implemented Interfaces:
Serializable
,Comparable<AgentBuilder.RedefinitionStrategy>
,Constable
- Enclosing interface:
AgentBuilder
A redefinition strategy regulates how already loaded classes are modified by a built agent.
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()
.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
A batch allocator which is responsible for applying a redefinition in a batches.protected static class
A collector is responsible for collecting classes that are to be considered for modification.static interface
A strategy for discovering types to redefine.protected static interface
A dispatcher for interacting with the instrumentation API.static interface
A listener to be applied during a redefinition.protected static interface
A resubmission enforcer determines if a non-loaded class should be scheduled for resubmission or be treated upon first load.static interface
A resubmission scheduler is responsible for scheduling a job that is resubmitting unloaded types that failed during retransformation.protected static interface
A resubmission strategy is responsible for enabling resubmission of types that failed to resubmit.Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>>
-
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionDisables redefinition such that already loaded classes are not affected by the agent.Applies a redefinition to all classes that are already loaded and that would have been transformed if the built agent was registered before they were loaded.Applies a retransformation to all classes that are already loaded and that would have been transformed if the built agent was registered before they were loaded. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final AgentBuilder.RedefinitionStrategy.Dispatcher
A dispatcher to use for interacting with the instrumentation API.private final boolean
Indicates that this redefinition strategy is enabled.private final boolean
true
if this strategy applies retransformation. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
RedefinitionStrategy
(boolean enabled, boolean retransforming) Creates a new redefinition strategy. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
apply
(Instrumentation instrumentation, AgentBuilder.PoolStrategy poolStrategy, AgentBuilder.LocationStrategy locationStrategy, AgentBuilder.DescriptionStrategy descriptionStrategy, AgentBuilder.FallbackStrategy fallbackStrategy, AgentBuilder.RedefinitionStrategy.DiscoveryStrategy redefinitionDiscoveryStrategy, AgentBuilder.LambdaInstrumentationStrategy lambdaInstrumentationStrategy, AgentBuilder.Listener listener, AgentBuilder.RedefinitionStrategy.Listener redefinitionListener, AgentBuilder.RawMatcher matcher, AgentBuilder.RedefinitionStrategy.BatchAllocator redefinitionBatchAllocator, AgentBuilder.CircularityLock circularityLock) Applies this redefinition strategy by submitting all loaded types to redefinition.protected abstract void
check
(Instrumentation instrumentation) Checks if this strategy can be applied to the supplied instrumentation instance.protected boolean
Indicates that this redefinition strategy applies a modification of already loaded classes.protected boolean
Indicates if this strategy requires a class file transformer to be registered with a hint to apply the transformer for retransformation.protected abstract AgentBuilder.RedefinitionStrategy.Collector
make
(AgentBuilder.PoolStrategy poolStrategy, AgentBuilder.LocationStrategy locationStrategy, AgentBuilder.DescriptionStrategy descriptionStrategy, AgentBuilder.FallbackStrategy fallbackStrategy, AgentBuilder.Listener listener, AgentBuilder.RawMatcher matcher, AgentBuilder.CircularityLock circularityLock) Creates a collector instance that is responsible for collecting loaded classes for potential retransformation.Returns the enum constant of this class with the specified name.static AgentBuilder.RedefinitionStrategy[]
values()
Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
DISABLED
Disables redefinition such that already loaded classes are not affected by the agent. -
REDEFINITION
Applies a redefinition to all classes that are already loaded and that would have been transformed if the built agent was registered before they were loaded. The created
ClassFileTransformer
is not registered for applying retransformations.Using this strategy, a redefinition is applied as a single transformation request. This means that a single illegal redefinition of a class causes the entire redefinition attempt to fail.
Note: When applying a redefinition, it is normally required to use a
AgentBuilder.TypeStrategy
that applies a redefinition instead of rebasing classes such asAgentBuilder.TypeStrategy.Default.REDEFINE
. Also, consider the constraints given by this type strategy. -
RETRANSFORMATION
Applies a retransformation to all classes that are already loaded and that would have been transformed if the built agent was registered before they were loaded. The created
ClassFileTransformer
is registered for applying retransformations.Using this strategy, a retransformation is applied as a single transformation request. This means that a single illegal retransformation of a class causes the entire retransformation attempt to fail.
Note: When applying a retransformation, it is normally required to use a
AgentBuilder.TypeStrategy
that applies a redefinition instead of rebasing classes such asAgentBuilder.TypeStrategy.Default.REDEFINE
. Also, consider the constraints given by this type strategy.
-
-
Field Details
-
DISPATCHER
A dispatcher to use for interacting with the instrumentation API. -
enabled
private final boolean enabledIndicates that this redefinition strategy is enabled. -
retransforming
private final boolean retransformingtrue
if this strategy applies retransformation.
-
-
Constructor Details
-
RedefinitionStrategy
private RedefinitionStrategy(boolean enabled, boolean retransforming) Creates a new redefinition strategy.- Parameters:
enabled
-true
if this strategy is enabled.retransforming
-true
if this strategy applies retransformation.
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException
- if this enum class has no constant with the specified nameNullPointerException
- if the argument is null
-
isRetransforming
protected boolean isRetransforming()Indicates if this strategy requires a class file transformer to be registered with a hint to apply the transformer for retransformation.- Returns:
true
if a class file transformer must be registered with a hint for retransformation.
-
check
Checks if this strategy can be applied to the supplied instrumentation instance.- Parameters:
instrumentation
- The instrumentation instance to validate.
-
isEnabled
protected boolean isEnabled()Indicates that this redefinition strategy applies a modification of already loaded classes.- Returns:
true
if this redefinition strategy applies a modification of already loaded classes.
-
make
protected abstract AgentBuilder.RedefinitionStrategy.Collector make(AgentBuilder.PoolStrategy poolStrategy, AgentBuilder.LocationStrategy locationStrategy, AgentBuilder.DescriptionStrategy descriptionStrategy, AgentBuilder.FallbackStrategy fallbackStrategy, AgentBuilder.Listener listener, AgentBuilder.RawMatcher matcher, AgentBuilder.CircularityLock circularityLock) Creates a collector instance that is responsible for collecting loaded classes for potential retransformation.- Parameters:
poolStrategy
- The pool strategy to use.locationStrategy
- The location strategy to use.descriptionStrategy
- The description strategy for resolving type descriptions for types.fallbackStrategy
- The fallback strategy to apply.listener
- The listener to notify on transformations.matcher
- The matcher to identify what types to redefine.circularityLock
- The circularity lock to use.- Returns:
- A new collector for collecting already loaded classes for transformation.
-
apply
protected void apply(Instrumentation instrumentation, AgentBuilder.PoolStrategy poolStrategy, AgentBuilder.LocationStrategy locationStrategy, AgentBuilder.DescriptionStrategy descriptionStrategy, AgentBuilder.FallbackStrategy fallbackStrategy, AgentBuilder.RedefinitionStrategy.DiscoveryStrategy redefinitionDiscoveryStrategy, AgentBuilder.LambdaInstrumentationStrategy lambdaInstrumentationStrategy, AgentBuilder.Listener listener, AgentBuilder.RedefinitionStrategy.Listener redefinitionListener, AgentBuilder.RawMatcher matcher, AgentBuilder.RedefinitionStrategy.BatchAllocator redefinitionBatchAllocator, AgentBuilder.CircularityLock circularityLock) Applies this redefinition strategy by submitting all loaded types to redefinition. If this redefinition strategy is disabled, this method is non-operational.- Parameters:
instrumentation
- The instrumentation instance to use.poolStrategy
- The type locator to use.locationStrategy
- The location strategy to use.descriptionStrategy
- The description strategy for resolving type descriptions for types.fallbackStrategy
- The fallback strategy to apply.redefinitionDiscoveryStrategy
- The discovery strategy for loaded types to be redefined.lambdaInstrumentationStrategy
- A strategy to determine of theLambdaMetafactory
should be instrumented to allow for the instrumentation of classes that represent lambda expressions.listener
- The listener to notify on transformations.redefinitionListener
- The redefinition listener for the redefinition strategy to apply.matcher
- The matcher to identify what types to redefine.redefinitionBatchAllocator
- The batch allocator for the redefinition strategy to apply.circularityLock
- The circularity lock to use.
-