Most structures in the constant_pool table represent entities directly, by combining names, descriptors, and values recorded statically in the table. In contrast, the CONSTANT_Dynamic_info and CONSTANT_InvokeDynamic_info structures represent entities indirectly, by pointing to code which computes an entity dynamically. The code, called a bootstrap method, is invoked by the Java Virtual Machine during resolution of symbolic references derived from these structures (§5.1, §5.4.3.6). Each structure specifies a bootstrap method as well as an auxiliary name and type that characterize the entity to be computed. In more detail:
- The
CONSTANT_Dynamic_infostructure is used to represent a dynamically-computed constant, an arbitrary value that is produced by invocation of a bootstrap method in the course of an ldc instruction (§ldc), among others. The auxiliary type specified by the structure constrains the type of the dynamically-computed constant. - The
CONSTANT_InvokeDynamic_infostructure is used to represent a dynamically-computed call site, an instance ofjava.lang.invoke.CallSitethat is produced by invocation of a bootstrap method in the course of an invokedynamic instruction (§invokedynamic). The auxiliary type specified by the structure constrains the method type of the dynamically-computed call site.
CONSTANT_Dynamic_info {
u1 tag;
u2 bootstrap_method_attr_index;
u2 name_and_type_index;
}
CONSTANT_InvokeDynamic_info {
u1 tag;
u2 bootstrap_method_attr_index;
u2 name_and_type_index;
}
The items of these structures are as follows:
-
tag
The
tagitem of aCONSTANT_Dynamic_infostructure has the valueCONSTANT_Dynamic(17).The
tagitem of aCONSTANT_InvokeDynamic_infostructure has the valueCONSTANT_InvokeDynamic(18). -
bootstrap_method_attr_index
The value of the
bootstrap_method_attr_indexitem must be a valid index into thebootstrap_methodsarray of the bootstrap method table of thisclassfile (§4.7.23).CONSTANT_Dynamic_infostructures are unique in that they are syntactically allowed to refer to themselves via the bootstrap method table. Rather than mandating that such cycles are detected when classes are loaded (a potentially expensive check), we permit cycles initially but mandate a failure at resolution (§5.4.3.6). -
name_and_type_index
The value of the
name_and_type_indexitem must be a valid index into theconstant_pooltable. Theconstant_poolentry at that index must be aCONSTANT_NameAndType_infostructure (§4.4.6). Thisconstant_poolentry indicates a name and descriptor.In a
CONSTANT_Dynamic_infostructure, the indicated descriptor must be a field descriptor (§4.3.2).In a
CONSTANT_InvokeDynamic_infostructure, the indicated descriptor must be a method descriptor (§4.3.3).