---
spec: JVMS
title: "The Java Virtual Machine Specification"
edition: "Java SE 8 Edition"
java_version: 8
chapter: "Chapter 6. The Java Virtual Machine Instruction Set"
section: "6.5.invokeinterface"
heading: "invokeinterface"
parent: "6.5. Instructions"
source: https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-6.html#jvms-6.5.invokeinterface
id: "6.5.invokeinterface"
url: https://jvm.obfuscated.software/jvms/se8/6.5.invokeinterface.html
raw: https://jvm.obfuscated.software/jvms/se8/6.5.invokeinterface.md
---

# invokeinterface

## Operation

Invoke interface method

## Format

```
invokeinterface
indexbyte1
indexbyte2
count
0
```

## Forms

*invokeinterface* = 185 (0xb9)

## Operand Stack

..., *objectref*, [*arg1*, [*arg2* ...]] →

...

## Description

The unsigned *indexbyte1* and *indexbyte2* are used to construct an index into the run-time constant pool of the current class ([§2.6](2.6.md)), where the value of the index is (*indexbyte1* `<<` 8) | *indexbyte2*. The run-time constant pool item at that index must be a symbolic reference to an interface method ([§5.1](5.1.md)), which gives the name and descriptor ([§4.3.3](4.3.3.md)) of the interface method as well as a symbolic reference to the interface in which the interface method is to be found. The named interface method is resolved ([§5.4.3.4](5.4.3.4.md)).

The resolved interface method must not be an instance initialization method, or the class or interface initialization method ([§2.9](2.9.md)).

The *count* operand is an unsigned byte that must not be zero. The *objectref* must be of type `reference` and must be followed on the operand stack by *nargs* argument values, where the number, type, and order of the values must be consistent with the descriptor of the resolved interface method. The value of the fourth operand byte must always be zero.

Let C be the class of *objectref*. The actual method to be invoked is selected by the following lookup procedure:

1. If C contains a declaration for an instance method with the same name and descriptor as the resolved method, then it is the method to be invoked.
2. Otherwise, if C has a superclass, a search for a declaration of an instance method with the same name and descriptor as the resolved method is performed, starting with the direct superclass of C and continuing with the direct superclass of that class, and so forth, until a match is found or no further superclasses exist. If a match is found, then it is the method to be invoked.
3. Otherwise, if there is exactly one maximally-specific method ([§5.4.3.3](5.4.3.3.md)) in the superinterfaces of C that matches the resolved method's name and descriptor and is not `abstract`, then it is the method to be invoked.

If the method is `synchronized`, the monitor associated with *objectref* is entered or reentered as if by execution of a *monitorenter* instruction ([§*monitorenter*](6.5.monitorenter.md)) in the current thread.

If the method is not `native`, the *nargs* argument values and *objectref* are popped from the operand stack. A new frame is created on the Java Virtual Machine stack for the method being invoked. The *objectref* and the argument values are consecutively made the values of local variables of the new frame, with *objectref* in local variable 0, *arg1* in local variable 1 (or, if *arg1* is of type `long` or `double`, in local variables 1 and 2), and so on. Any argument value that is of a floating-point type undergoes value set conversion ([§2.8.3](2.8.3.md)) prior to being stored in a local variable. The new frame is then made current, and the Java Virtual Machine `pc` is set to the opcode of the first instruction of the method to be invoked. Execution continues with the first instruction of the method.

If the method is `native` and the platform-dependent code that implements it has not yet been bound ([§5.6](5.6.md)) into the Java Virtual Machine, that is done. The *nargs* argument values and *objectref* are popped from the operand stack and are passed as parameters to the code that implements the method. Any argument value that is of a floating-point type undergoes value set conversion ([§2.8.3](2.8.3.md)) prior to being passed as a parameter. The parameters are passed and the code is invoked in an implementation-dependent manner. When the platform-dependent code returns:

- If the `native` method is `synchronized`, the monitor associated with *objectref* is updated and possibly exited as if by execution of a *monitorexit* instruction ([§*monitorexit*](6.5.monitorexit.md)) in the current thread.
- If the `native` method returns a value, the return value of the platform-dependent code is converted in an implementation-dependent way to the return type of the `native` method and pushed onto the operand stack.

## Linking Exceptions

During resolution of the symbolic reference to the interface method, any of the exceptions pertaining to interface method resolution ([§5.4.3.4](5.4.3.4.md)) can be thrown.

Otherwise, if the resolved method is `static` or `private`, the *invokeinterface* instruction throws an `IncompatibleClassChangeError`.

## Run-time Exceptions

Otherwise, if *objectref* is `null`, the *invokeinterface* instruction throws a `NullPointerException`.

Otherwise, if the class of *objectref* does not implement the resolved interface, *invokeinterface* throws an `IncompatibleClassChangeError`.

Otherwise, if step 1 or step 2 of the lookup procedure selects a method that is not `public`, *invokeinterface* throws an `IllegalAccessError`.

Otherwise, if step 1 or step 2 of the lookup procedure selects an `abstract` method, *invokeinterface* throws an `AbstractMethodError`.

Otherwise, if step 1 or step 2 of the lookup procedure selects a `native` method and the code that implements the method cannot be bound, *invokeinterface* throws an `UnsatisfiedLinkError`.

Otherwise, if step 3 of the lookup procedure determines there are multiple maximally-specific methods in the superinterfaces of C that match the resolved method's name and descriptor and are not `abstract`, *invokeinterface* throws an `IncompatibleClassChangeError`

Otherwise, if step 3 of the lookup procedure determines there are zero maximally-specific methods in the superinterfaces of C that match the resolved method's name and descriptor and are not `abstract`, *invokeinterface* throws an `AbstractMethodError`.

## Notes

The *count* operand of the *invokeinterface* instruction records a measure of the number of argument values, where an argument value of type `long` or type `double` contributes two units to the *count* value and an argument of any other type contributes one unit. This information can also be derived from the descriptor of the selected method. The redundancy is historical.

The fourth operand byte exists to reserve space for an additional operand used in certain of Oracle's Java Virtual Machine implementations, which replace the *invokeinterface* instruction by a specialized pseudo-instruction at run time. It must be retained for backwards compatibility.

The *nargs* argument values and *objectref* are not one-to-one with the first *nargs*+1 local variables. Argument values of types `long` and `double` must be stored in two consecutive local variables, thus more than *nargs* local variables may be required to pass *nargs* argument values to the invoked method.

The selection logic allows a non-`abstract` method declared in a superinterface to be selected. Methods in interfaces are only considered if there is no matching method in the class hierarchy. In the event that there are two non-`abstract` methods in the superinterface hierarchy, with neither more specific than the other, an error occurs; there is no attempt to disambiguate (for example, one may be the referenced method and one may be unrelated, but we do not prefer the referenced method). On the other hand, if there are many `abstract` methods but only one non-`abstract` method, the non-`abstract` method is selected (unless an `abstract` method is more specific).
