The BootstrapMethods attribute is a variable-length attribute in the attributes table of a ClassFile structure (§4.1). The BootstrapMethods attribute records bootstrap method specifiers referenced by invokedynamic instructions (§invokedynamic).
There must be exactly one BootstrapMethods attribute in the attributes table of a ClassFile structure if the constant_pool table of the ClassFile structure has at least one CONSTANT_InvokeDynamic_info entry (§4.4.10).
There may be at most one BootstrapMethods attribute in the attributes table of a ClassFile structure.
The BootstrapMethods attribute has the following format:
BootstrapMethods_attribute {
u2 attribute_name_index;
u4 attribute_length;
u2 num_bootstrap_methods;
{ u2 bootstrap_method_ref;
u2 num_bootstrap_arguments;
u2 bootstrap_arguments[num_bootstrap_arguments];
} bootstrap_methods[num_bootstrap_methods];
}
The items of the BootstrapMethods_attribute structure are as follows:
-
attribute_name_index
The value of the
attribute_name_indexitem must be a valid index into theconstant_pooltable. Theconstant_poolentry at that index must be aCONSTANT_Utf8_infostructure (§4.4.7) representing the string "BootstrapMethods". -
attribute_length
The value of the
attribute_lengthitem indicates the length of the attribute, excluding the initial six bytes.The value of the
attribute_lengthitem is thus dependent on the number of invokedynamic instructions in thisClassFilestructure. -
num_bootstrap_methods
The value of the
num_bootstrap_methodsitem determines the number of bootstrap method specifiers in thebootstrap_methodsarray. -
bootstrap_methods[]
Each entry in the
bootstrap_methodstable contains an index to aCONSTANT_MethodHandle_infostructure (§4.4.8) which specifies a bootstrap method, and a sequence (perhaps empty) of indexes to static arguments for the bootstrap method.Each
bootstrap_methodsentry must contain the following three items:-
bootstrap_method_ref
The value of the
bootstrap_method_refitem must be a valid index into theconstant_pooltable. Theconstant_poolentry at that index must be aCONSTANT_MethodHandle_infostructure (§4.4.8).The form of the method handle is driven by the continuing resolution of the call site specifier in §invokedynamic, where execution of
invokeinjava.lang.invoke.MethodHandlerequires that the bootstrap method handle be adjustable to the actual arguments being passed, as if by a call tojava.lang.invoke.MethodHandle.asType. Accordingly, thereference_kinditem of theCONSTANT_MethodHandle_infostructure should have the value 6 or 8 (§5.4.3.5), and thereference_indexitem should specify a static method or constructor that takes three arguments of typejava.lang.invoke.MethodHandles.Lookup,String, andjava.lang.invoke.MethodType, in that order. Otherwise, invocation of the bootstrap method handle during call site specifier resolution will complete abruptly. -
num_bootstrap_arguments
The value of the
num_bootstrap_argumentsitem gives the number of items in thebootstrap_argumentsarray. -
bootstrap_arguments[]
Each entry in the
bootstrap_argumentsarray must be a valid index into theconstant_pooltable. Theconstant_poolentry at that index must be aCONSTANT_String_info,CONSTANT_Class_info,CONSTANT_Integer_info,CONSTANT_Long_info,CONSTANT_Float_info,CONSTANT_Double_info,CONSTANT_MethodHandle_info, orCONSTANT_MethodType_infostructure (§4.4.3, §4.4.1, §4.4.4, §4.4.5, §4.4.8, §4.4.9).
-