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

# invokespecial

## Operation

Invoke instance method; direct invocation of instance initialization methods and methods of the current class and its supertypes

## Format

```
invokespecial
indexbyte1
indexbyte2
```

## Forms

*invokespecial* = 183 (0xb7)

## 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 entry at the index must be a symbolic reference to a method or an interface method ([§5.1](5.1.md)), which gives the name and descriptor ([§4.3.3](4.3.3.md)) of the method or interface method as well as a symbolic reference to the class or interface in which the method or interface method is to be found. The named method is resolved ([§5.4.3.3](5.4.3.3.md), [§5.4.3.4](5.4.3.4.md)).

If all of the following are true, let C be the direct superclass of the current class:

- The resolved method is not an instance initialization method ([§2.9.1](2.9.1.md)).
- The symbolic reference names a class (not an interface), and that class is a superclass of the current class.
- The `ACC_SUPER` flag is set for the `class` file ([§4.1](4.1.md)).

Otherwise, let C be the class or interface named by the symbolic reference.

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 is a class and 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 C is an interface and the class `Object` contains a declaration of a `public` instance method with the same name and descriptor as the resolved method, then it is the method to be invoked.
4. 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.

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 selected instance method.

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, the following take place:

- 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 method, any of the exceptions pertaining to method resolution ([§5.4.3.3](5.4.3.3.md)) can be thrown.

Otherwise, if the resolved method is an instance initialization method, and the class in which it is declared is not the class symbolically referenced by the instruction, a `NoSuchMethodError` is thrown.

Otherwise, if the resolved method is a class (`static`) method, the *invokespecial* instruction throws an `IncompatibleClassChangeError`.

## Run-time Exceptions

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

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

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

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

Otherwise, if step 4 of the lookup procedure determines there are no maximally-specific superinterface methods of C that match the resolved method's name and descriptor and are not `abstract`, *invokespecial* throws an `AbstractMethodError`.

## Notes

The difference between the *invokespecial* instruction and the *invokevirtual* instruction ([§*invokevirtual*](6.5.invokevirtual.md)) is that *invokevirtual* invokes a method based on the class of the object. The *invokespecial* instruction is used to directly invoke instance initialization methods ([§2.9.1](2.9.1.md)) as well as methods of the current class and its supertypes.

The *invokespecial* instruction was named `invokenonvirtual` prior to JDK release 1.0.2.

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 *invokespecial* instruction handles invocation of a non-`abstract` interface method, referenced either via a direct superinterface or via a superclass. In these cases, the rules for selection are essentially the same as those for *invokeinterface* (except that the search starts from a different class).
