Operation
Invoke a dynamically-computed call site
Format
invokedynamic
indexbyte1
indexbyte2
0
0
Forms
invokedynamic = 186 (0xba)
Operand Stack
..., [arg1, [arg2 ...]] →
...
Description
First, the unsigned indexbyte1 and indexbyte2 are used to construct an index into the run-time constant pool of the current class (§2.6), where the value of the index is (indexbyte1 << 8) | indexbyte2. The run-time constant pool entry at the index must be a symbolic reference to a dynamically-computed call site (§5.1). The values of the third and fourth operand bytes must always be zero.
The symbolic reference is resolved (§5.4.3.6) for this specific invokedynamic instruction to obtain a reference to an instance of java.lang.invoke.CallSite. The instance of java.lang.invoke.CallSite is considered "bound" to this specific invokedynamic instruction.
The instance of java.lang.invoke.CallSite indicates a target method handle. The nargs argument values are popped from the operand stack, and the target method handle is invoked. The invocation occurs as if by execution of an invokevirtual instruction that indicates a run-time constant pool index to a symbolic reference R where:
- R is a symbolic reference to a method of a class;
- for the symbolic reference to the class in which the method is to be found, R specifies
java.lang.invoke.MethodHandle; - for the name of the method, R specifies
invokeExact; - for the descriptor of the method, R specifies the method descriptor in the dynamically-computed call site.
and where it is as if the following items were pushed, in order, onto the operand stack:
- a
referenceto the target method handle; - the nargs argument values, where the number, type, and order of the values must be consistent with the method descriptor in the dynamically-computed call site.
Linking Exceptions
During resolution of the symbolic reference to a dynamically-computed call site, any of the exceptions pertaining to dynamically-computed call site resolution can be thrown.
Notes
If the symbolic reference to the dynamically-computed call site can be resolved, it implies that a non-null reference to an instance of java.lang.invoke.CallSite is bound to the invokedynamic instruction. Therefore, the target method handle, indicated by the instance of java.lang.invoke.CallSite, is non-null.
Similarly, successful resolution implies that the method descriptor in the symbolic reference is semantically equal to the type descriptor of the target method handle.
Together, these invariants mean that an invokedynamic instruction which is bound to an instance of java.lang.invoke.CallSite never throws a NullPointerException or a java.lang.invoke.WrongMethodTypeException.