protected static enum AgentBuilder.LambdaInstrumentationStrategy.LambdaMetafactoryFactory extends Enum<AgentBuilder.LambdaInstrumentationStrategy.LambdaMetafactoryFactory> implements ByteCodeAppender
java.lang.invoke.LambdaMetafactory methods for use with Byte Buddy. The code that is
created by this factory is roughly equivalent to the following:
public static CallSite metafactory(MethodHandles.Lookup caller,
String interfaceMethodName,
MethodType factoryType,
MethodType interfaceMethodType,
MethodHandle implementation,
MethodType dynamicMethodType) throws Exception {
boolean serializable = false;
List<Class<?>> markerInterfaces = Collections.emptyList();
List<MethodType> additionalBridges = Collections.emptyList();
byte[] binaryRepresentation = (byte[]) ClassLoader.getSystemClassLoader().loadClass("net.bytebuddy.agent.builder.LambdaFactory").getDeclaredMethod("make",
Object.class,
String.class,
Object.class,
Object.class,
Object.class,
Object.class,
boolean.class,
List.class,
List.class).invoke(null,
caller,
interfaceMethodName,
factoryType,
interfaceMethodType,
implementation,
dynamicMethodType,
serializable,
markerInterfaces,
additionalBridges);
Class<?> lambdaClass = ... // loading code
return factoryType.parameterCount() == 0
? new ConstantCallSite(MethodHandles.constant(factoryType.returnType(), lambdaClass.getDeclaredConstructors()[0].newInstance()))
: new ConstantCallSite(Lookup.IMPL_LOOKUP.findStatic(lambdaClass, "get$Lambda", factoryType));
}
The code's preamble is adjusted for the alternative metafactory to ressemble the following:
public static CallSite altMetafactory(MethodHandles.Lookup caller,
String interfaceMethodName,
MethodType factoryType,
Object... argument) throws Exception {
int flags = (Integer) argument[3];
int index = 4;
Class<?>[] markerInterface;
if ((flags & 2) != 0) {
int count = (Integer) argument[index++];
markerInterface = new Class<?>[count];
System.arraycopy(argument, index, markerInterface, 0, count);
index += count;
} else {
markerInterface = new Class<?>[0];
}
MethodType[] additionalBridge;
if ((flags & 2) != 0) {
int count = (Integer) argument[index++];
additionalBridge = new MethodType[count];
System.arraycopy(argument, index, additionalBridge, 0, count);
} else {
additionalBridge = new MethodType[0];
}
MethodType interfaceMethodType = (MethodType) argument[0];
MethodHandle implementation = (MethodHandle) argument[1];
MethodType dynamicMethodType = (MethodType) argument[2];
boolean serializable = (flags & 1) != 0;
List<Class<?>> markerInterfaces = Arrays.asList(markerInterface);
List<MethodType> additionalBridges = Arrays.asList(additionalBridge);
// ... reminder of method as before
}
| Modifier and Type | Class and Description |
|---|---|
protected static interface |
AgentBuilder.LambdaInstrumentationStrategy.LambdaMetafactoryFactory.Loader
A loader is responsible for loading a generated class file in the current VM.
|
ByteCodeAppender.Compound, ByteCodeAppender.Simple, ByteCodeAppender.Size| Enum Constant and Description |
|---|
ALTERNATIVE
Implements the
java.lang.invoke.LambdaMetafactory#altMetafactory method. |
REGULAR
Implements the
java.lang.invoke.LambdaMetafactory#metafactory method. |
| Modifier and Type | Method and Description |
|---|---|
ByteCodeAppender.Size |
apply(MethodVisitor methodVisitor,
Implementation.Context implementationContext,
MethodDescription instrumentedMethod)
Applies this byte code appender to a type creation process.
|
protected abstract void |
onDispatch(MethodVisitor methodVisitor)
Invoked upon dispatch.
|
static AgentBuilder.LambdaInstrumentationStrategy.LambdaMetafactoryFactory |
valueOf(String name)
Returns the enum constant of this type with the specified name.
|
static AgentBuilder.LambdaInstrumentationStrategy.LambdaMetafactoryFactory[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
public static final AgentBuilder.LambdaInstrumentationStrategy.LambdaMetafactoryFactory REGULAR
java.lang.invoke.LambdaMetafactory#metafactory method.public static final AgentBuilder.LambdaInstrumentationStrategy.LambdaMetafactoryFactory ALTERNATIVE
java.lang.invoke.LambdaMetafactory#altMetafactory method.public static AgentBuilder.LambdaInstrumentationStrategy.LambdaMetafactoryFactory[] values()
for (AgentBuilder.LambdaInstrumentationStrategy.LambdaMetafactoryFactory c : AgentBuilder.LambdaInstrumentationStrategy.LambdaMetafactoryFactory.values()) System.out.println(c);
public static AgentBuilder.LambdaInstrumentationStrategy.LambdaMetafactoryFactory valueOf(String name)
name - the name of the enum constant to be returned.IllegalArgumentException - if this enum type has no constant with the specified nameNullPointerException - if the argument is nullpublic ByteCodeAppender.Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext, MethodDescription instrumentedMethod)
apply in interface ByteCodeAppendermethodVisitor - The method visitor to which the byte code appender writes its code to.implementationContext - The implementation context of the current type creation process.instrumentedMethod - The method that is the target of the instrumentation.protected abstract void onDispatch(MethodVisitor methodVisitor)
methodVisitor - The method visitor to use.Copyright © 2014–2025. All rights reserved.