invokespecial 0xb7

Calls a constructor, a private method or a superclass method directly.

Opcode
0xb7 (183)
Family
Method calls
Operands
  • 2 bytes: constant pool index
Length
3 bytes
Operand stack
…, objectref, arg1, … → …, result
Can throw
NullPointerException

What it does

Calls an instance method without virtual dispatch: exactly the method named. javac uses it for constructors (<init>), for super.m(), and for private methods of the same class.

Every constructor calls a superclass constructor with invokespecial before it may use this; new Foo() is new, dup, then invokespecial Foo.<init>. 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, invokespecial appears 43,732 times in 6,577 of its 7,391 classes: 2.2% of all instructions, the 13th most common of 194 opcodes in use. Some of the methods that use it: java.io.BufferedInputStream.getInIfOpen, java.io.BufferedOutputStream.<init>, java.io.BufferedReader.<init>, java.io.BufferedReader$1.<init>.

Examples

From the sample classes, compiled by javac 25 with -g. Each Java line is shown above the bytecode it compiled to; invokespecial is highlighted.

public Tour() in Tour, compiled by javac 25
3public class Tour {
0aload_0 // this
1invokespecial #1// new Object()

Open in the viewer

public Asserts() in Asserts, compiled by javac 25
2public class Asserts {
0aload_0 // this
1invokespecial #1// new Object()

Open in the viewer

Related instructions

new Allocates an object (uninitialised until its constructor runs).invokevirtual Calls an instance method, chosen by the receiver's class.invokestatic Calls a static method.

Specification: JVMS §6.5, invokespecial (Java SE 25).