Package net.bytebuddy.agent.builder
Enum AgentBuilder.LambdaInstrumentationStrategy
- java.lang.Object
-
- java.lang.Enum<AgentBuilder.LambdaInstrumentationStrategy>
-
- net.bytebuddy.agent.builder.AgentBuilder.LambdaInstrumentationStrategy
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Comparable<AgentBuilder.LambdaInstrumentationStrategy>
- Enclosing interface:
- AgentBuilder
public static enum AgentBuilder.LambdaInstrumentationStrategy extends java.lang.Enum<AgentBuilder.LambdaInstrumentationStrategy>
Implements the instrumentation of theLambdaMetafactory
if this feature is enabled.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
AgentBuilder.LambdaInstrumentationStrategy.AlternativeMetaFactoryRedirection
Implements the alternative lambda meta factory.protected static class
AgentBuilder.LambdaInstrumentationStrategy.LambdaInstanceFactory
A factory that creates instances that represent lambda expressions.protected static class
AgentBuilder.LambdaInstrumentationStrategy.MetaFactoryRedirection
Implements the regular lambda meta factory.
-
Field Summary
Fields Modifier and Type Field Description protected static org.objectweb.asm.MethodVisitor
IGNORE_ORIGINAL
Indicates that an original implementation can be ignored when redefining a method.private static java.lang.String
UNSAFE_CLASS
The name of the current VM'sUnsafe
class that is visible to the bootstrap loader.
-
Constructor Summary
Constructors Modifier Constructor Description private
LambdaInstrumentationStrategy()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract void
apply(ByteBuddy byteBuddy, java.lang.instrument.Instrumentation instrumentation, java.lang.instrument.ClassFileTransformer classFileTransformer)
Applies a transformation to lambda instances if applicable.boolean
isEnabled()
Indicates if this strategy enables instrumentation of theLambdaMetafactory
.protected abstract boolean
isInstrumented(java.lang.Class<?> type)
Validates if the supplied class is instrumented.static AgentBuilder.LambdaInstrumentationStrategy
of(boolean enabled)
Returns an enabled lambda instrumentation strategy fortrue
.static void
release(java.lang.instrument.ClassFileTransformer classFileTransformer, java.lang.instrument.Instrumentation instrumentation)
Releases the supplied class file transformer when it was built withAgentBuilder.with(LambdaInstrumentationStrategy)
enabled.static AgentBuilder.LambdaInstrumentationStrategy
valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name.static AgentBuilder.LambdaInstrumentationStrategy[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
Enum Constant Detail
-
ENABLED
public static final AgentBuilder.LambdaInstrumentationStrategy ENABLED
A strategy that enables instrumentation of theLambdaMetafactory
if such a factory exists on the current VM. Classes representing lambda expressions that are created by Byte Buddy are fully compatible to those created by the JVM and can be serialized or deserialized to one another. The classes do however show a few differences:- Byte Buddy's classes are public with a public executing transformer. Doing so, it is not necessary to instantiate a non-capturing lambda expression by reflection. This is done because Byte Buddy is not necessarily capable of using reflection due to an active security manager.
- Byte Buddy's classes are not marked as synthetic as an agent builder does not instrument synthetic classes by default.
-
DISABLED
public static final AgentBuilder.LambdaInstrumentationStrategy DISABLED
A strategy that does not instrument theLambdaMetafactory
.
-
-
Field Detail
-
UNSAFE_CLASS
private static final java.lang.String UNSAFE_CLASS
The name of the current VM'sUnsafe
class that is visible to the bootstrap loader.
-
IGNORE_ORIGINAL
protected static final org.objectweb.asm.MethodVisitor IGNORE_ORIGINAL
Indicates that an original implementation can be ignored when redefining a method.
-
-
Method Detail
-
values
public static AgentBuilder.LambdaInstrumentationStrategy[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (AgentBuilder.LambdaInstrumentationStrategy c : AgentBuilder.LambdaInstrumentationStrategy.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static AgentBuilder.LambdaInstrumentationStrategy valueOf(java.lang.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:
java.lang.IllegalArgumentException
- if this enum type has no constant with the specified namejava.lang.NullPointerException
- if the argument is null
-
release
public static void release(java.lang.instrument.ClassFileTransformer classFileTransformer, java.lang.instrument.Instrumentation instrumentation)
Releases the supplied class file transformer when it was built withAgentBuilder.with(LambdaInstrumentationStrategy)
enabled. Subsequently, the class file transformer is no longer applied when a class that represents a lambda expression is created.- Parameters:
classFileTransformer
- The class file transformer to release.instrumentation
- The instrumentation instance that is used to potentially rollback the instrumentation of theLambdaMetafactory
.
-
of
public static AgentBuilder.LambdaInstrumentationStrategy of(boolean enabled)
Returns an enabled lambda instrumentation strategy fortrue
.- Parameters:
enabled
- If lambda instrumentation should be enabled.- Returns:
true
if the returned strategy should be enabled.
-
apply
protected abstract void apply(ByteBuddy byteBuddy, java.lang.instrument.Instrumentation instrumentation, java.lang.instrument.ClassFileTransformer classFileTransformer)
Applies a transformation to lambda instances if applicable.- Parameters:
byteBuddy
- The Byte Buddy instance to use.instrumentation
- The instrumentation instance for applying a redefinition.classFileTransformer
- The class file transformer to apply.
-
isEnabled
public boolean isEnabled()
Indicates if this strategy enables instrumentation of theLambdaMetafactory
.- Returns:
true
if this strategy is enabled.
-
isInstrumented
protected abstract boolean isInstrumented(java.lang.Class<?> type)
Validates if the supplied class is instrumented. For lambda types (which are loaded by anonymous class loader), this method should return false if lambda instrumentation is disabled.- Parameters:
type
- The redefined type ornull
if no such type exists.- Returns:
true
if the supplied type should be instrumented according to this strategy.
-
-