invokedynamic 0xba
Calls through a call site that a bootstrap method links on first use (lambdas, string concatenation, records, pattern switches).
- Opcode
0xba(186)- Family
- Method calls
- Operands
- 2 bytes: InvokeDynamic index
- 2 bytes: zero
- Length
- 5 bytes
- Operand stack
…, arg1, … → …, result- Can throw
BootstrapMethodError
What it does
Calls through a call site that is linked the first time it runs: the JVM calls a bootstrap method (listed in the BootstrapMethods attribute) which returns the code to run, and that link stays for later calls. Added in Java 7 for dynamic languages; javac began using it in Java 8.
javac uses it for lambdas and method references (LambdaMetafactory), string concatenation since Java 9 (StringConcatFactory), the toString, equals and hashCode of records (ObjectMethods), and pattern-matching switches (SwitchBootstraps). The two trailing operand bytes are always zero.
How often javac uses it
In JDK 25.0.5's java.base module, invokedynamic appears 2,330 times in 651 of its 7,391 classes: 0.12% of all instructions, the 82nd most common of 194 opcodes in use. Some of the methods that use it: java.io.FilePermission.initNb, java.io.FilePermissionCollection.add, java.io.ObjectInputFilter$Config.<clinit>, java.io.ObjectInputFilter$Config$Global.<init>.
Examples
From the sample classes, compiled by javac 25 with -g. Each Java line is shown above the bytecode it compiled to; invokedynamic is highlighted.
static Runnable hello() in Lambda, compiled by javac 25return () -> System.out.println("hello");public final String toString() in Point, compiled by javac 25public record Point(int x, int y) {Related instructions
invokestatic Calls a static method.invokevirtual Calls an instance method, chosen by the receiver's class.ldc Pushes a constant from the constant pool (index in one byte).
Specification: JVMS §6.5, invokedynamic (Java SE 25).