aload_2 0x2c

Pushes the reference in local variable 2.

Opcode
0x2c (44)
Family
Loads
Operands
none
Length
1 byte
Operand stack
… → …, value (reference)
Can throw
nothing at run time (beyond linking errors)
Spec name
aload_<n>

What it does

Pushes the reference in local variable 2.

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

The reference may be null; nothing checks it until the reference is used.

How often javac uses it

In JDK 25.0.5's java.base module, aload_2 appears 34,470 times in 3,774 of its 7,391 classes: 1.8% of all instructions, the 18th most common of 194 opcodes in use. Some of the methods that use it: java.io.BufferedInputStream.getBufIfOpen, java.io.BufferedReader.read, java.io.BufferedWriter.flushBuffer, java.io.CharArrayReader.read.

Examples

From the sample classes, compiled by javac 25 with -g. Each Java line is shown above the bytecode it compiled to; aload_2 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(List values) in Boxing, compiled by javac 25
7int total = 0;
1istore_1 // total
8for (Integer v : values) {
2aload_0 // values
3invokeinterface #7, 1// List.iterator() : Iterator
10invokeinterface #13, 1// Iterator.hasNext() : boolean
15ifeq 38
19invokeinterface #19, 1// Iterator.next() : Object
24checkcast #23// Integer
27astore_3 // v
… 8 instructions after

Open in the viewer

Related instructions

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

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