APIdia Launch Partner
Top Description Inners Fields Constructors Methods
java.lang.invoke

pack-priv final Class GenerateJLIClassesHelper

extends Object
Class Inheritance
Imports
jdk.internal.vm.annotation.AOTSafeClassInitializer, sun.invoke.util.Wrapper, java.lang.classfile.Annotation, .ClassFile, java.lang.classfile.attribute.RuntimeVisibleAnnotationsAttribute, .SourceFileAttribute, java.lang.constant.ClassDesc, java.util.ArrayList, .HashSet, .Map, .Objects, .Set, .TreeMap, .TreeSet, java.util.stream.Stream

Generates bound method handle species classes, and classes with methods that hold compiled lambda form bytecode ahead of time, so certain lambda forms no longer need to spin classes because they can find existing bytecode. Bytecode pre-generation reduces static initialization costs, footprint costs, and circular dependencies that may arise if a class is generated per LambdaForm by InvokerBytecodeGenerator.

Since lambda forms and bound method handle species are closely tied to method types, which have many varieties, this generator needs traces to detect which method types are used, so generation matches the actual usage. See the main entrypoint generateHolderClasses(Stream) for more details about traces.

Note this pregeneration does not cover all lambda forms that can be created. For example, forms created by LambdaFormEditor are not captured.

Pregenerated species classes are resolved in ClassSpecializer.Factory#loadSpecies and behave identically to on-demand generated ones. Pregenerated lambda forms are resolved in InvokerBytecodeGenerator#lookupPregenerated, which looks up methods for code from the following 4 possibly-generated classes:

VarHandle linker forms, analogous to invoker forms in Invokers.Holder, have a similar pre-generation system except it is done at source generation; they reside in VarHandleGuards.

Usages of this generator

Currently, GenerateJLIClassesHelper is invoked when creating a modular JDK image or generating an AOT cache.

Modular Image

When creating a modular JDK image, jdk.tools.jlink.internal.plugins.GenerateJLIClassesPlugin passes the traces in the file jdk/tools/jlink/internal/plugins/default_jli_trace.txt in $JAVA_HOME/lib/modules to this generator. The traces are generated from the execution of build.tools.classlist.HelloClasslist in the build process of the JDK.

To list all the Species classes in a JDK image:

jimage list $JAVA_HOME/lib/modules | grep BoundMethodHandle.Species_
jimage list $JAVA_HOME/lib/modules | grep BoundMethodHandle.Species_

All these pregenerated classes can be examined by javap in the same image: (Note to escape $ in bash)

javap -c -p -v java.lang.invoke.LambdaForm\$Holder
javap -c -p -v java.lang.invoke.LambdaForm\$Holder
AOT Cache

When creating an AOT cache, traces generated from the training run are captured and stored inside the AOT configuration file, and are accessed with the C++ FinalImageRecipes class. Classes regenerated from these traces are linked in assembly phase; see regeneratedClasses.hpp.

See Also
generateHolderClasses(Stream), BoundMethodHandle.Specializer, DelegatingMethodHandle.Holder, DirectMethodHandle.Holder, Invokers.Holder, LambdaForm.Holder, VarHandleGuards

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class

Field Summary

Modifier and TypeField and Description
pack-priv static final Annotation
pack-priv static final String
pack-priv static final String
pack-priv static final String
pack-priv static final String
pack-priv static final Map<String, Integer>
pack-priv static final String
pack-priv static final String

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv static byte[]
generateBasicFormsClassBytes(String className)

Returns a byte[] representation of a class implementing the zero and identity forms of all LambdaForm.BasicTypes.

private static byte[]
generateCodeBytesForLFs(String className, String[] names, LambdaForm[] forms)

pack-priv static Map.Entry<String, byte[]>
generateConcreteBMHClassBytes(final String types)

Returns a byte[] representation of BoundMethodHandle species class implementing the signature defined by types.

pack-priv static byte[]
generateDelegatingMethodHandleHolderClassBytes(String className, MethodType[] methodTypes)

Returns a byte[] representation of a class implementing DelegatingMethodHandles of each MethodType kind in the methodTypes argument.

pack-priv static byte[]
generateDirectMethodHandleHolderClassBytes(String className, MethodType[] methodTypes, int[] types)

Returns a byte[] representation of a class implementing DirectMethodHandle of each pairwise combination of MethodType and an int representing method type.

pack-priv static Map<String, byte[]>
generateHolderClasses(Stream<String>
the traces to determine the lambda forms and species to generate
traces
)

Returns a map from class names in internal form to the corresponding class bytes.

pack-priv static byte[]
generateInvokersHolderClassBytes(String className, MethodType[] linkerMethodTypes, MethodType[] invokerMethodTypes, MethodType[] callSiteMethodTypes)

Returns a byte[] representation of a class implementing the invoker forms for the set of supplied linkerMethodTypes invokerMethodTypes, and callSiteMethodTypes.

private static LambdaForm
private static LambdaForm
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

AOT_SAFE_ANNOTATIONback to summary
pack-priv static final Annotation AOT_SAFE_ANNOTATION
BASIC_FORMS_HOLDERback to summary
pack-priv static final String BASIC_FORMS_HOLDER
BMH_SPECIES_PREFIXback to summary
pack-priv static final String BMH_SPECIES_PREFIX
DELEGATING_HOLDERback to summary
pack-priv static final String DELEGATING_HOLDER
DIRECT_HOLDERback to summary
pack-priv static final String DIRECT_HOLDER
DMH_METHOD_TYPE_MAPback to summary
pack-priv static final Map<String, Integer> DMH_METHOD_TYPE_MAP
INVOKERS_HOLDERback to summary
pack-priv static final String INVOKERS_HOLDER
INVOKERS_HOLDER_CLASS_NAMEback to summary
pack-priv static final String INVOKERS_HOLDER_CLASS_NAME

Constructor Detail

GenerateJLIClassesHelperback to summary
pack-priv GenerateJLIClassesHelper()

Method Detail

generateBasicFormsClassBytesback to summary
pack-priv static byte[] generateBasicFormsClassBytes(String className)

Returns a byte[] representation of a class implementing the zero and identity forms of all LambdaForm.BasicTypes.

generateCodeBytesForLFsback to summary
private static byte[] generateCodeBytesForLFs(String className, String[] names, LambdaForm[] forms)
generateConcreteBMHClassBytesback to summary
pack-priv static Map.Entry<String, byte[]> generateConcreteBMHClassBytes(final String types)

Returns a byte[] representation of BoundMethodHandle species class implementing the signature defined by types.

Annotations
@SuppressWarnings:rawtypes, unchecked
generateDelegatingMethodHandleHolderClassBytesback to summary
pack-priv static byte[] generateDelegatingMethodHandleHolderClassBytes(String className, MethodType[] methodTypes)

Returns a byte[] representation of a class implementing DelegatingMethodHandles of each MethodType kind in the methodTypes argument.

generateDirectMethodHandleHolderClassBytesback to summary
pack-priv static byte[] generateDirectMethodHandleHolderClassBytes(String className, MethodType[] methodTypes, int[] types)

Returns a byte[] representation of a class implementing DirectMethodHandle of each pairwise combination of MethodType and an int representing method type.

generateHolderClassesback to summary
pack-priv static Map<String, byte[]> generateHolderClasses(Stream<String> traces)

Returns a map from class names in internal form to the corresponding class bytes.

A few known lambda forms, such as field accessors, can be comprehensively generated. Most others lambda forms are associated with unique method types; thus they are generated per the given stream of SPECIES_RESOLVE and LF_RESOLVE trace logs, which are created according to MethodHandleStatics#TRACE_RESOLVE configuration.

The names of methods in the generated classes are internal tokens recognized by InvokerBytecodeGenerator#lookupPregenerated and are subject to change.

Parameters
traces:Stream<String>

the traces to determine the lambda forms and species to generate

See Also
MethodHandleStatics#traceLambdaForm, MethodHandleStatics#traceSpeciesType
generateInvokersHolderClassBytesback to summary
pack-priv static byte[] generateInvokersHolderClassBytes(String className, MethodType[] linkerMethodTypes, MethodType[] invokerMethodTypes, MethodType[] callSiteMethodTypes)

Returns a byte[] representation of a class implementing the invoker forms for the set of supplied linkerMethodTypes invokerMethodTypes, and callSiteMethodTypes.

makeDelegateForback to summary
private static LambdaForm makeDelegateFor(MethodType type)
makeReinvokerForback to summary
private static LambdaForm makeReinvokerFor(MethodType type)
java.lang.invoke back to summary

pack-priv Class GenerateJLIClassesHelper.HolderClassBuilder

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final TreeSet<String>
private final Map<String, Set<String>>
private final TreeSet<String>
private final TreeSet<String>
private final TreeSet<String>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv GenerateJLIClassesHelper.HolderClassBuilder
private void
addDMHMethodType(String dmh, String methodType)

pack-priv GenerateJLIClassesHelper.HolderClassBuilder
addInvokerType(String methodType)

pack-priv GenerateJLIClassesHelper.HolderClassBuilder
addLinkerType(String methodType)

pack-priv GenerateJLIClassesHelper.HolderClassBuilder
public static MethodType
asMethodType(String basicSignatureString)

pack-priv Map<String, byte[]>
public static boolean
public static boolean
private static String
private static void
private static Class<?>
simpleType(char c)

private static void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

callSiteTypesback to summary
private final TreeSet<String> callSiteTypes
dmhMethodsback to summary
private final Map<String, Set<String>> dmhMethods
invokerTypesback to summary
private final TreeSet<String> invokerTypes
linkerTypesback to summary
private final TreeSet<String> linkerTypes
speciesTypesback to summary
private final TreeSet<String> speciesTypes

Constructor Detail

HolderClassBuilderback to summary
pack-priv HolderClassBuilder()

Method Detail

addCallSiteTypeback to summary
pack-priv GenerateJLIClassesHelper.HolderClassBuilder addCallSiteType(String csType)
addDMHMethodTypeback to summary
private void addDMHMethodType(String dmh, String methodType)
addInvokerTypeback to summary
pack-priv GenerateJLIClassesHelper.HolderClassBuilder addInvokerType(String methodType)
addLinkerTypeback to summary
pack-priv GenerateJLIClassesHelper.HolderClassBuilder addLinkerType(String methodType)
addSpeciesTypeback to summary
pack-priv GenerateJLIClassesHelper.HolderClassBuilder addSpeciesType(String type)
asMethodTypeback to summary
public static MethodType asMethodType(String basicSignatureString)
buildback to summary
pack-priv Map<String, byte[]> build()
checkInvokerTypeParamsback to summary
public static boolean checkInvokerTypeParams(MethodType mt)
checkLinkerTypeParamsback to summary
public static boolean checkLinkerTypeParams(MethodType mt)
expandSignatureback to summary
private static String expandSignature(String signature)
requireBasicTypeback to summary
private static void requireBasicType(char c)
simpleTypeback to summary
private static Class<?> simpleType(char c)
validateMethodTypeback to summary
private static void validateMethodType(String type)