istore_2 0x3d

Pops a int into local variable 2.

Opcode
0x3d (61)
Family
Stores
Operands
none
Length
1 byte
Operand stack
…, value (int) → …
Can throw
nothing at run time (beyond linking errors)
Spec name
istore_<n>

What it does

Pops an int into local variable 2.

Slots 0 to 3 each have a one-byte instruction; the general istore takes a one-byte slot number, and wide extends that to two bytes.

int locals also hold booleans, bytes, chars and shorts: the JVM has no smaller local variable types.

How often javac uses it

In JDK 25.0.5's java.base module, istore_2 appears 4,586 times in 1,130 of its 7,391 classes: 0.24% of all instructions, the 63rd 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; istore_2 is highlighted.

static int local(int i) in Increments, compiled by javac 25
7i++;
0iinc 0, 1// i
8int a = i++;
3iload_0 // i
4iinc 0, 1// i
7istore_1 // a
9int b = ++i;
8iinc 0, 1// i
11iload_0 // i
12istore_2 // b
10return a + b;
13iload_1 // a
14iload_2 // b
15iadd

Open in the viewer

static int forLoop(int n) in Loops, compiled by javac 25
4int sum = 0;
1istore_1 // sum
5for (int i = 0; i < n; i++) {
3istore_2 // i
4iload_2 // i
5iload_0 // n
6sum += i;
9iload_1 // sum
10iload_2 // i
11iadd
12istore_1 // sum
5for (int i = 0; i < n; i++) {
13iinc 2, 1// i
8return sum;
19iload_1 // sum

Open in the viewer

Related instructions

iload_2 Pushes the int in local variable 2.istore Pops a int into local variable (operand).wide Makes the next instruction take a two-byte local index (and a two-byte iinc constant).

Specification: JVMS §6.5, istore_<n> (Java SE 25).