Enum AgentBuilder.RedefinitionStrategy

java.lang.Object
java.lang.Enum<AgentBuilder.RedefinitionStrategy>
net.bytebuddy.agent.builder.AgentBuilder.RedefinitionStrategy
All Implemented Interfaces:
Serializable, Comparable<AgentBuilder.RedefinitionStrategy>, java.lang.constant.Constable
Enclosing interface:
AgentBuilder

public static enum AgentBuilder.RedefinitionStrategy extends Enum<AgentBuilder.RedefinitionStrategy>

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().

  • Enum Constant Details

    • DISABLED

      public static final AgentBuilder.RedefinitionStrategy DISABLED
      Disables redefinition such that already loaded classes are not affected by the agent.
    • REDEFINITION

      public static final AgentBuilder.RedefinitionStrategy 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 as AgentBuilder.TypeStrategy.Default.REDEFINE. Also, consider the constraints given by this type strategy.

    • RETRANSFORMATION

      public static final AgentBuilder.RedefinitionStrategy 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 as AgentBuilder.TypeStrategy.Default.REDEFINE. Also, consider the constraints given by this type strategy.

  • Field Details

    • DISPATCHER

      protected static final AgentBuilder.RedefinitionStrategy.Dispatcher DISPATCHER
      A dispatcher to use for interacting with the instrumentation API.
    • enabled

      private final boolean enabled
      Indicates that this redefinition strategy is enabled.
    • retransforming

      private final boolean retransforming
      true 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

      public static AgentBuilder.RedefinitionStrategy[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      Returns:
      an array containing the constants of this enum type, in the order they are declared
    • valueOf

      public static AgentBuilder.RedefinitionStrategy valueOf(String name)
      Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (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 type has no constant with the specified name
      NullPointerException - 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

      protected abstract void check(Instrumentation instrumentation)
      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

      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 the LambdaMetafactory 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.