istore_3 0x3e

Pops a int into local variable 3.

Opcode
0x3e (62)
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 3.

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_3 appears 4,445 times in 1,204 of its 7,391 classes: 0.23% of all instructions, the 64th most common of 194 opcodes in use. Some of the methods that use it: java.io.BufferedOutputStream.growIfNeeded, java.io.BufferedWriter.growIfNeeded, java.io.ByteArrayInputStream.read, java.io.ByteArrayOutputStream.ensureCapacity.

Examples

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

static String repeat(String s, int times) in Concat, compiled by javac 25
8String out = "";
0ldc #11// ""
2astore_2 // out
9for (int i = 0; i < times; i++) {
4istore_3 // i
5iload_3 // i
6iload_1 // times
10out += s;
10aload_2 // out
11aload_0 // s
12invokedynamic #13// makeConcatWithConstants(String, String) : String ⇐ StringConcatFactory.makeConcatWithConstants "\1\1"
17astore_2 // out
9for (int i = 0; i < times; i++) {
18iinc 3, 1// i
12return out;
24aload_2 // out

Open in the viewer

static int sum(int[] values) in ForEach, compiled by javac 25
… 1 instruction before
6int total = 0;
1istore_1 // total
7for (int v : values) {
2aload_0 // values
10iload 4
… 11 instructions after

Open in the viewer

Related instructions

iload_3 Pushes the int in local variable 3.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).