Top Description Fields Constructors Methods
net.bytebuddy.agent.builder

public Class LambdaFactory

extends Object
Class Inheritance
Annotations
@Enhance
Imports
edu.umd.cs.findbugs.annotations.SuppressFBWarnings, net.bytebuddy.build.HashCodeAndEqualsPlugin, net.bytebuddy.description.type.TypeDescription, net.bytebuddy.dynamic.ClassFileLocator, net.bytebuddy.dynamic.loading.ClassInjector, java.lang.instrument.ClassFileTransformer, java.lang.reflect.Method, java.util.Collection, .Collections, .List, .Map, java.util.concurrent.ConcurrentHashMap

This class serves as a dispatcher for creating lambda expression objects when Byte Buddy is configured to instrument the java.lang.invoke.LambdaMetafactory. For this purpose, this class is injected into the class path to serve as a VM-global singleton and for becoming reachable from the JVM's meta factory. This class keeps a reference to all registered transformers which need to be explicitly deregistered in order to avoid a memory leak.

Field Summary

Modifier and TypeField and Description
public static final Map<ClassFileTransformer, LambdaFactory>
CLASS_FILE_TRANSFORMERS

A mapping of all registered class file transformers and their lambda factories, linked in their application order.

private final Method
dispatcher

The dispatcher method to invoke for creating a new lambda instance.

private static final String
FIELD_NAME

The name of the field to access.

private final Object
target

The target instance that is a factory for creating lambdas.

Constructor Summary

AccessConstructor and Description
public
LambdaFactory(Object
The target instance that is a factory for creating lambdas.
target
,
Method
The dispatcher method to invoke for creating a new lambda instance.
dispatcher
)

Creates a new lambda factory.

Method Summary

Modifier and TypeMethod and Description
private byte[]

Returns:

A binary representation of the transformed class file.
invoke
(Object
A lookup context representing the creating class of this lambda expression.
caller
,
String
The name of the lambda expression's represented method.
invokedName
,
Object
The type of the lambda expression's factory method.
invokedType
,
Object
The type of the lambda expression's represented method.
samMethodType
,
Object
A handle representing the target of the lambda expression's method.
implMethod
,
Object
A specialization of the type of the lambda expression's represented method.
instantiatedMethodType
,
boolean
true if the lambda expression should be serializable.
serializable
,
List<Class<?>>
A list of interfaces for the lambda expression to represent.
markerInterfaces
,
List<?>
A list of additional bridge methods to be implemented by the lambda expression.
additionalBridges
,
Collection<ClassFileTransformer>
A collection of class file transformers to apply when creating the class.
classFileTransformers
)

Applies this lambda meta factory.

public static byte[]

Returns:

A binary representation of the transformed class file.
make
(Object
A lookup context representing the creating class of this lambda expression.
caller
,
String
The name of the lambda expression's represented method.
invokedName
,
Object
The type of the lambda expression's factory method.
invokedType
,
Object
The type of the lambda expression's represented method.
samMethodType
,
Object
A handle representing the target of the lambda expression's method.
implMethod
,
Object
A specialization of the type of the lambda expression's represented method.
instantiatedMethodType
,
boolean
true if the lambda expression should be serializable.
serializable
,
List<Class<?>>
A list of interfaces for the lambda expression to represent.
markerInterfaces
,
List<?>
A list of additional bridge methods to be implemented by the lambda expression.
additionalBridges
)

Dispatches the creation of a new class representing a class file.

public static boolean

Returns:

true if this is the first registered transformer. This indicates that the LambdaMetafactory must be instrumented to delegate to this alternative factory.
register
(ClassFileTransformer
The class file transformer to register.
classFileTransformer
,
Object
The lambda class file factory to use. This factory must define a visible instance method with the signature byte[] make(Object, String, Object, Object, Object, Object, boolean, List, List, Collection. The arguments provided are the invokedynamic call site's lookup object, the lambda method's name, the factory method's type, the lambda method's type, the target method's handle, the specialized method type of the lambda expression, a boolean to indicate serializability, a list of marker interfaces, a list of additional bridges and a collection of class file transformers to apply.
classFileFactory
)

Registers a class file transformer together with a factory for creating a lambda expression.

public static boolean

Returns:

true if the removed transformer was the last class file transformer registered. This indicates that the LambdaMetafactory must be instrumented to no longer delegate to this alternative factory.
release
(ClassFileTransformer
The class file transformer to release.
classFileTransformer
)

Releases a class file transformer.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CLASS_FILE_TRANSFORMERSback to summary
public static final Map<ClassFileTransformer, LambdaFactory> CLASS_FILE_TRANSFORMERS

A mapping of all registered class file transformers and their lambda factories, linked in their application order. This field must not be accessed directly but only by reading this class from the system class loader.

Annotations
@SuppressFBWarnings:MS_MUTABLE_COLLECTION_PKGPROTECT
justification:The field must be accessible by different class loader instances.
dispatcherback to summary
private final Method dispatcher

The dispatcher method to invoke for creating a new lambda instance.

FIELD_NAMEback to summary
private static final String FIELD_NAME

The name of the field to access.

targetback to summary
private final Object target

The target instance that is a factory for creating lambdas.

Constructor Detail

LambdaFactoryback to summary
public LambdaFactory(Object target, Method dispatcher)

Creates a new lambda factory.

Parameters
target:Object

The target instance that is a factory for creating lambdas.

dispatcher:Method

The dispatcher method to invoke for creating a new lambda instance.

Method Detail

invokeback to summary
private byte[] invoke(Object caller, String invokedName, Object invokedType, Object samMethodType, Object implMethod, Object instantiatedMethodType, boolean serializable, List<Class<?>> markerInterfaces, List<?> additionalBridges, Collection<ClassFileTransformer> classFileTransformers)

Applies this lambda meta factory.

Parameters
caller:Object

A lookup context representing the creating class of this lambda expression.

invokedName:String

The name of the lambda expression's represented method.

invokedType:Object

The type of the lambda expression's factory method.

samMethodType:Object

The type of the lambda expression's represented method.

implMethod:Object

A handle representing the target of the lambda expression's method.

instantiatedMethodType:Object

A specialization of the type of the lambda expression's represented method.

serializable:boolean

true if the lambda expression should be serializable.

markerInterfaces:List<Class<?>>

A list of interfaces for the lambda expression to represent.

additionalBridges:List<?>

A list of additional bridge methods to be implemented by the lambda expression.

classFileTransformers:Collection<ClassFileTransformer>

A collection of class file transformers to apply when creating the class.

Returns:byte[]

A binary representation of the transformed class file.

makeback to summary
public static byte[] make(Object caller, String invokedName, Object invokedType, Object samMethodType, Object implMethod, Object instantiatedMethodType, boolean serializable, List<Class<?>> markerInterfaces, List<?> additionalBridges)

Dispatches the creation of a new class representing a class file.

Parameters
caller:Object

A lookup context representing the creating class of this lambda expression.

invokedName:String

The name of the lambda expression's represented method.

invokedType:Object

The type of the lambda expression's factory method.

samMethodType:Object

The type of the lambda expression's represented method.

implMethod:Object

A handle representing the target of the lambda expression's method.

instantiatedMethodType:Object

A specialization of the type of the lambda expression's represented method.

serializable:boolean

true if the lambda expression should be serializable.

markerInterfaces:List<Class<?>>

A list of interfaces for the lambda expression to represent.

additionalBridges:List<?>

A list of additional bridge methods to be implemented by the lambda expression.

Returns:byte[]

A binary representation of the transformed class file.

registerback to summary
public static boolean register(ClassFileTransformer classFileTransformer, Object classFileFactory)

Registers a class file transformer together with a factory for creating a lambda expression. It is possible to call this method independently of the class loader's context as the supplied injector makes sure that the manipulated collection is the one that is held by the system class loader.

Parameters
classFileTransformer:ClassFileTransformer

The class file transformer to register.

classFileFactory:Object

The lambda class file factory to use. This factory must define a visible instance method with the signature byte[] make(Object, String, Object, Object, Object, Object, boolean, List, List, Collection. The arguments provided are the invokedynamic call site's lookup object, the lambda method's name, the factory method's type, the lambda method's type, the target method's handle, the specialized method type of the lambda expression, a boolean to indicate serializability, a list of marker interfaces, a list of additional bridges and a collection of class file transformers to apply.

Returns:boolean

true if this is the first registered transformer. This indicates that the LambdaMetafactory must be instrumented to delegate to this alternative factory.

Annotations
@SuppressWarnings:all
releaseback to summary
public static boolean release(ClassFileTransformer classFileTransformer)

Releases a class file transformer.

Parameters
classFileTransformer:ClassFileTransformer

The class file transformer to release.

Returns:boolean

true if the removed transformer was the last class file transformer registered. This indicates that the LambdaMetafactory must be instrumented to no longer delegate to this alternative factory.

Annotations
@SuppressWarnings:all