Package net.bytebuddy.dynamic.loading
Enum ClassReloadingStrategy.Strategy
java.lang.Object
java.lang.Enum<ClassReloadingStrategy.Strategy>
net.bytebuddy.dynamic.loading.ClassReloadingStrategy.Strategy
- All Implemented Interfaces:
Serializable
,Comparable<ClassReloadingStrategy.Strategy>
,java.lang.constant.Constable
- Enclosing class:
ClassReloadingStrategy
A strategy which performs the actual redefinition of a
Class
.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static class
A class file transformer that applies a givenClassDefinition
.protected static enum
A transformer that indicates that a class file should not be transformed.Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>>
-
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionRedefines a class usingInstrumentation.redefineClasses(java.lang.instrument.ClassDefinition...)
.Redefines a class usingInstrumentation.retransformClasses(Class[])
. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final byte[]
Indicates that a class is not redefined.private static final boolean
Instructs aClassFileTransformer
to redefine classes.private final boolean
true
if theREDEFINITION
strategy is used. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract void
apply
(Instrumentation instrumentation, Map<Class<?>, ClassDefinition> classDefinitions) Applies this strategy for the given arguments.boolean
Returnstrue
if this strategy representsREDEFINITION
.abstract void
reset
(Instrumentation instrumentation, ClassFileLocator classFileLocator, List<Class<?>> types) Resets the provided types to their original format.protected abstract ClassReloadingStrategy.Strategy
validate
(Instrumentation instrumentation) Validates that this strategy supports a given transformation type.Returns the enum constant of this type with the specified name.static ClassReloadingStrategy.Strategy[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.
-
Enum Constant Details
-
REDEFINITION
Redefines a class using
Instrumentation.redefineClasses(java.lang.instrument.ClassDefinition...)
.This strategy can be more efficient. However, the redefinition strategy does not allow to reset VM anonymous classes (e.g. classes that represent lambda expressions).
-
RETRANSFORMATION
Redefines a class using
Instrumentation.retransformClasses(Class[])
. This requires synchronization on theClassReloadingStrategy.instrumentation
object.This strategy can require more time to be applied but does not struggle to reset VM anonymous classes (e.g. classes that represent lambda expressions).
-
-
Field Details
-
NO_REDEFINITION
Indicates that a class is not redefined. -
REDEFINE_CLASSES
private static final boolean REDEFINE_CLASSESInstructs aClassFileTransformer
to redefine classes.- See Also:
-
redefinition
private final boolean redefinitiontrue
if theREDEFINITION
strategy is used.
-
-
Constructor Details
-
Strategy
private Strategy(boolean redefinition) Creates a new strategy.- Parameters:
redefinition
-true
if theREDEFINITION
strategy is used.
-
-
Method Details
-
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
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 nameNullPointerException
- if the argument is null
-
apply
protected abstract void apply(Instrumentation instrumentation, Map<Class<?>, ClassDefinition> classDefinitions) throws UnmodifiableClassException, ClassNotFoundExceptionApplies this strategy for the given arguments.- Parameters:
instrumentation
- The instrumentation to be used for applying the redefinition.classDefinitions
- A mapping of the classes to be redefined to their redefinition.- Throws:
UnmodifiableClassException
- If a class is not modifiable.ClassNotFoundException
- If a class was not found.
-
validate
Validates that this strategy supports a given transformation type.- Parameters:
instrumentation
- The instrumentation instance being used.- Returns:
- This strategy.
-
isRedefinition
public boolean isRedefinition()Returnstrue
if this strategy representsREDEFINITION
.- Returns:
true
if this strategy representsREDEFINITION
.
-
reset
public abstract void reset(Instrumentation instrumentation, ClassFileLocator classFileLocator, List<Class<?>> types) throws IOException, UnmodifiableClassException, ClassNotFoundException Resets the provided types to their original format.- Parameters:
instrumentation
- The instrumentation instance to use for class redefinition or retransformation.classFileLocator
- The class file locator to use.types
- The types to reset.- Throws:
IOException
- If an I/O exception occurs.UnmodifiableClassException
- If a class is not modifiable.ClassNotFoundException
- If a class could not be found.
-