iadd 0x60

Adds two ints on top of the stack; pushes the result.

Opcode
0x60 (96)
Family
Arithmetic and bitwise
Operands
none
Length
1 byte
Operand stack
…, value1 (int), value2 (int) → …, result (int)
Can throw
nothing at run time (beyond linking errors)

What it does

a + b on two ints: pops b, then a, and pushes the result.

Overflow wraps around silently, as in Java. Math.addExact is the version that throws.

Adding a small constant to a local variable uses iinc instead, which needs no stack at all.

byte, short and char values are ints on the stack, so their arithmetic uses iadd too; a result stored back into a smaller type is narrowed with i2b, i2s or i2c.

How often javac uses it

In JDK 25.0.5's java.base module, iadd appears 8,545 times in 1,339 of its 7,391 classes: 0.44% of all instructions, the 47th most common of 194 opcodes in use. Some of the methods that use it: java.io.BufferedInputStream.fill, java.io.BufferedOutputStream.growIfNeeded, java.io.BufferedReader.fill, java.io.BufferedWriter.growIfNeeded.

Examples

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

int field() in Increments, compiled by javac 25
14return field++;
0aload_0 // this
1dup
2getfield #7// Increments.field : int
8putfield #7// Increments.field : int

Open in the viewer

static int locals(int a, int b, int c, int d, long e, double f) in Tour, compiled by javac 25
123int g = a + b + c + d;
0iload_0 // a
1iload_1 // b
3iload_2 // c
5iload_3 // d
7istore 8// g
124return g + (int) e + (int) f;
9iload 8// g
11lload 4// e
13l2i
14iadd
15dload 6// f
17d2i
18iadd

Open in the viewer

Related instructions

ladd Adds two longs on top of the stack; pushes the result.fadd Adds two floats on top of the stack; pushes the result.dadd Adds two doubles on top of the stack; pushes the result.

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