iinc 0x84

Adds a signed constant to an int local variable, without touching the stack.

Opcode
0x84 (132)
Family
Arithmetic and bitwise
Operands
  • 1 byte: local variable index
  • 1 byte: signed constant
Length
3 bytes
Operand stack
… → …
Can throw
nothing at run time (beyond linking errors)

What it does

Adds a signed byte constant to an int local variable, without touching the operand stack. javac uses it for i++, i--, ++i and i += c on int locals when the constant fits in a byte; wide iinc takes a two-byte constant, for i += 1000.

Whether i++ or ++i, the increment is the same iinc: the only difference is whether the iload that reads the value comes before or after it. It works only on locals; incrementing a field is a get, an add and a put.

How often javac uses it

In JDK 25.0.5's java.base module, iinc appears 7,076 times in 1,238 of its 7,391 classes: 0.36% of all instructions, the 53rd most common of 194 opcodes in use. Some of the methods that use it: java.io.BufferedReader.readLine, java.io.DataInputStream.readLine, java.io.DataOutputStream.writeBytes, java.io.File.normalizedList.

Examples

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

static void big(int i) in Increments, compiled by javac 25
26i += 1000;
0wide iinc 0, 1000// i
27System.out.println(i);
6getstatic #17// System.out : PrintStream
9iload_0 // i
10invokevirtual #23// PrintStream.println(int) : void
28}

Open in the viewer

static int doWhile(int n) in Loops, compiled by javac 25
21int digits = 0;
1istore_1 // digits
23n /= 10;
2iload_0 // n
3bipush 10
6istore_0 // n
24digits++;
7iinc 1, 1// digits
25} while (n != 0);
10iload_0 // n
26return digits;
14iload_1 // digits

Open in the viewer

Related instructions

iadd Adds two ints on top of the stack; pushes the result.wide Makes the next instruction take a two-byte local index (and a two-byte iinc constant).iload Pushes the int in local variable (operand).

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