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 25static int doWhile(int n) in Loops, compiled by javac 25Related 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).