invokeinterface 0xb9
Calls an interface method, chosen by the receiver's class.
- Opcode
0xb9(185)- Family
- Method calls
- Operands
- 2 bytes: InterfaceMethodref index
- 1 byte: argument slots + 1
- 1 byte: zero
- Length
- 5 bytes
- Operand stack
…, objectref, arg1, … → …, result- Can throw
NullPointerException,AbstractMethodError,IncompatibleClassChangeError
What it does
Calls a method declared on an interface, dispatched on the receiver's class. list.get(0) on a List variable compiles to it.
It carries two extra bytes: a count of argument slots (including the receiver), which the JVM could compute from the descriptor but the format kept from its earliest days, and a zero byte. If the method returns void, nothing is pushed. Long and double arguments take two stack slots each.
How often javac uses it
In JDK 25.0.5's java.base module, invokeinterface appears 25,892 times in 2,679 of its 7,391 classes: 1.3% of all instructions, the 23rd most common of 194 opcodes in use. Some of the methods that use it: java.io.CharArrayWriter.append, java.io.Console.instantiateConsole, java.io.DataInputStream.readUTF, java.io.DataOutputStream.writeUTF.
Examples
From the sample classes, compiled by javac 25 with -g. Each Java line is shown above the bytecode it compiled to; invokeinterface is highlighted.
static String first(List names) in Bridge, compiled by javac 25return names.get(0);public int compareTo(Numbers o) in Numbers, compiled by javac 25public int compareTo(Numbers<T> o) { return Integer.compare(items.size(), o.items.size()); }Related instructions
invokevirtual Calls an instance method, chosen by the receiver's class.checkcast Checks that the reference on top of the stack is of a type (throws ClassCastException if not).invokedynamic Calls through a call site that a bootstrap method links on first use (lambdas, string concatenation, records, pattern switches).
Specification: JVMS §6.5, invokeinterface (Java SE 25).