aaload 0x32

Pops an array and an index; pushes the reference element.

Opcode
0x32 (50)
Family
Arrays
Operands
none
Length
1 byte
Operand stack
…, arrayref, index → …, value (reference)
Can throw
NullPointerException, ArrayIndexOutOfBoundsException

What it does

Pops an array (reference array) and an index; pushes the element at that index.

The element type is not known from the instruction; the verifier tracks it from the array's type. javac adds a checkcast after it when the source type needs one, for example with generic arrays.

How often javac uses it

In JDK 25.0.5's java.base module, aaload appears 8,966 times in 800 of its 7,391 classes: 0.46% of all instructions, the 45th most common of 194 opcodes in use. Some of the methods that use it: java.io.File.normalizedList, java.io.ObjectInputFilter$Config$Global.<init>, java.io.ObjectInputStream.resolveProxyClass, java.io.ObjectInputStream$FieldValues.<init>.

Examples

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

public static void main(String[] args) in Hello, compiled by javac 25
3String who = args.length > 0 ? args[0] : "world";
0aload_0 // args
5aload_0 // args
11ldc #7// "world"
13astore_1 // who
4System.out.println("Hello, " + who + "!");
14getstatic #9// System.out : PrintStream
17aload_1 // who
18invokedynamic #15// makeConcatWithConstants(String) : String ⇐ StringConcatFactory.makeConcatWithConstants "Hello, \1!"
23invokevirtual #19// PrintStream.println(String) : void
5}

Open in the viewer

static int arrays(int n) in Tour, compiled by javac 25
… 64 instructions before
68z[0] = true; b[0] = 1; c[0] = 'a'; s[0] = 2; i[0] = 3; l[0] = 4; f[0] = 5; d[0] = 6; str[0] = "x"; grid[0][0] = 7;
97ldc #25// "x"
100aload 10// grid
103aaload
105bipush 7
69return (z[0] ? 1 : 0) + b[0] + c[0] + s[0] + i[0] + (int) l[0] + (int) f[0] + (int) d[0] + str[0].length() + grid[0][0] + grid.length;
108aload_1 // z
110baload
… 50 instructions after

Open in the viewer

Related instructions

aastore Pops an array, an index and a reference value; stores the value in the array.arraylength Pops an array; pushes its length.anewarray Pops a length; pushes a new array of references.

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