BootstrapMethods attribute
The bootstrap methods that link invokedynamic call sites and compute Dynamic constants, each a MethodHandle with a list of static arguments from the constant pool..
- Appears on
- class
- Since
- class file 51.0 (Java 7)
- javac writes it
- whenever the class uses invokedynamic or a Dynamic constant
- Needed by the JVM
- yes: the JVM reads it to load, verify or run the class
Layout
| Type | Field | What it holds |
|---|---|---|
u2 | attribute_name_index | a Utf8: "BootstrapMethods" |
u4 | attribute_length | bytes after this field |
u2 | num_bootstrap_methods | |
{u2,u2,u2[]}[…] | bootstrap_methods | bootstrap_method_ref, num_bootstrap_arguments, bootstrap_arguments |
What it is for
The bootstrap methods that link invokedynamic call sites and compute Dynamic constants, each a MethodHandle with a list of static arguments from the constant pool.
A lambda's entry points at LambdaMetafactory.metafactory, with arguments for the interface method's type, the implementation method and the instantiated type. A string concatenation's points at StringConcatFactory.makeConcatWithConstants, with a recipe string in which \u0001 marks where each argument goes.
How common it is
JDK 25.0.5's java.base has 651 BootstrapMethods attributes, in 651 of its 7,391 classes (651 on classs).
A real one, byte by byte
From Hello.class (compiled by javac 25), on the class:
| Offset | Bytes | Field | Value |
|---|---|---|---|
| 1047 | 14 bytes | BootstrapMethods | |
| 1047 | 00 2b | attribute_name_index | #43 |
| 1049 | 00 00 00 08 | attribute_length | 8 |
| 1053 | 00 01 | num_bootstrap_methods | 1 |
| 1055 | 6 bytes | bootstrap method 0 | |
| 1055 | 00 2e | bootstrap_method_ref | #46 |
| 1057 | 00 01 | num_bootstrap_arguments | 1 |
| 1059 | 00 2c | bootstrap_argument | #44 |
Specification: JVMS §4.7, The BootstrapMethods Attribute (Java SE 25).