• No results found

The BootstrapMethods Attribute

In document The Java Virtual Machine Specification (Page 169-173)

4.4 The Constant Pool

4.7.23 The BootstrapMethods Attribute

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.

4.7 Attributes THE CLASS FILE 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_index item must be a valid index

into the constant_pool table. The constant_pool entry at that index

must be a CONSTANT_Utf8_info structure (§4.4.7) representing the string

"BootstrapMethods". attribute_length

The value of the attribute_length item indicates the length of the attribute,

excluding the initial six bytes.

The value of the attribute_length item is thus dependent on the number of

invokedynamic instructions in this ClassFile structure.

num_bootstrap_methods

The value of the num_bootstrap_methods item determines the number of

bootstrap method specifiers in the bootstrap_methods array. bootstrap_methods[]

Each entry in the bootstrap_methods table contains an index to a CONSTANT_MethodHandle_info structure (§4.4.8) which specifies a bootstrap

method, and a sequence (perhaps empty) of indexes to static arguments for the bootstrap method.

Each bootstrap_methods entry must contain the following three items: bootstrap_method_ref

The value of the bootstrap_method_ref item must be a valid index into

the constant_pool table. The constant_pool entry at that index must be

a CONSTANT_MethodHandle_info structure (§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 invoke

in java.lang.invoke.MethodHandle requires that the bootstrap method handle be adjustable to the actual arguments being passed, as if by a call to java.lang.invoke.MethodHandle.asType. Accordingly, the

THE CLASS FILE FORMAT Attributes 4.7

reference_kind item of the CONSTANT_MethodHandle_info structure should have the value 6 or 8 (§5.4.3.5), and the reference_index

item should specify a static method or constructor that takes three arguments of type java.lang.invoke.MethodHandles.Lookup, String, and

java.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_arguments item gives the number of

items in the bootstrap_arguments array. bootstrap_arguments[]

Each entry in the bootstrap_arguments array must be a valid

index into the constant_pool table. The constant_pool entry at

that index must be a CONSTANT_String_info, CONSTANT_Class_info,

CONSTANT_Integer_info, CONSTANT_Long_info,

CONSTANT_Float_info, CONSTANT_Double_info,

CONSTANT_MethodHandle_info, or CONSTANT_MethodType_info

structure (§4.4.3, §4.4.1, §4.4.4, §4.4.5, §4.4.8, §4.4.9). 4.7.24 The MethodParameters Attribute

The MethodParameters attribute is a variable-length attribute in the attributes

table of a method_info structure (§4.6). A MethodParameters attribute records

information about the formal parameters of a method, such as their names. There may be at most one MethodParameters attribute in the attributes table of

a method_info structure.

The MethodParameters attribute has the following format: MethodParameters_attribute { u2 attribute_name_index; u4 attribute_length; u1 parameters_count; { u2 name_index; u2 access_flags; } parameters[parameters_count]; }

The items of the MethodParameters_attribute structure are as follows: attribute_name_index

The value of the attribute_name_index item must be a valid index into the constant_pool table. The constant_pool entry at that index must be a CONSTANT_Utf8_info structure representing the string "MethodParameters".

4.7 Attributes THE CLASS FILE FORMAT

attribute_length

The value of the attribute_length item indicates the length of the attribute,

excluding the initial six bytes.

parameters_count

The value of the parameters_count item indicates the number of

parameter descriptors in the method descriptor (§4.3.3) referenced by the

descriptor_index of the attribute's enclosing method_info structure.

This is not a constraint which a Java Virtual Machine implementation must enforce during format checking (§4.8). The task of matching parameter descriptors in a method descriptor against the items in the parameters array below is done by the reflection libraries of the Java SE platform.

parameters[]

Each entry in the parameters array contains the following pair of items: name_index

The value of the name_index item must either be zero or a valid index into

the constant_pool table.

If the value of the name_index item is zero, then this parameters element

indicates a formal parameter with no name.

If the value of the name_index item is nonzero, the constant_pool entry

at that index must be a CONSTANT_Utf8_info structure representing a valid

unqualified name denoting a formal parameter (§4.2.2).

access_flags

The value of the access_flags item is as follows: 0x0010 (ACC_FINAL)

Indicates that the formal parameter was declared final. 0x1000 (ACC_SYNTHETIC)

Indicates that the formal parameter was not explicitly or implicitly declared in source code, according to the specification of the language in which the source code was written (JLS §13.1). (The formal parameter is an implementation artifact of the compiler which produced this class file.)

0x8000 (ACC_MANDATED)

Indicates that the formal parameter was implicitly declared in source code, according to the specification of the language in which the source

THE CLASS FILE FORMAT Format Checking 4.8

code was written (JLS §13.1). (The formal parameter is mandated by a language specification, so all compilers for the language must emit it.)

The i'th entry in the parameters array corresponds to the i'th parameter descriptor in the enclosing method's descriptor. (The parameters_count item is one byte because a method descriptor is limited to 255 parameters.) Effectively, this means the parameters

array stores information for all the parameters of the method. One could imagine other schemes, where entries in the parameters array specify their corresponding parameter descriptors, but it would unduly complicate the MethodParameters attribute.

The i'th entry in the parameters array may or may not correspond to the i'th type in the enclosing method's Signature attribute (if present), or to the i'th annotation in the enclosing method's parameter annotations.

In document The Java Virtual Machine Specification (Page 169-173)