aastore 0x53

Pops an array, an index and a reference value; stores the value in the array.

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

What it does

Pops an array (reference array), an index and a value; stores the value at that index.

Java arrays are covariant: a variable of type Object[] can hold a String[]. So every aastore checks that the value is assignable to the array's actual element type, and throws ArrayStoreException if not. It is the only array store with that check, and also why array stores of references cost a little more.

How often javac uses it

In JDK 25.0.5's java.base module, aastore appears 67,452 times in 1,312 of its 7,391 classes: 3.5% of all instructions, the 6th most common of 194 opcodes in use. Some of the methods that use it: java.io.File.normalizedList, java.io.File$PathStatus.$values, java.io.FileInputStream.readAllBytes, java.io.FilePermission.hashCode.

Examples

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

private static EnumSwitch$Size[] $values() synthetic in EnumSwitch.Size, compiled by javac 25
6enum Size { SMALL, MEDIUM, LARGE }
1anewarray #1// EnumSwitch$Size
4dup
6getstatic #3// EnumSwitch$Size.SMALL : EnumSwitch$Size
10dup
12getstatic #7// EnumSwitch$Size.MEDIUM : EnumSwitch$Size
16dup
18getstatic #10// EnumSwitch$Size.LARGE : EnumSwitch$Size

Open in the viewer

private static Switches$Color[] $values() synthetic in Switches.Color, compiled by javac 25
6enum Color { RED, GREEN, BLUE }
1anewarray #1// Switches$Color
4dup
6getstatic #3// Switches$Color.RED : Switches$Color
10dup
12getstatic #7// Switches$Color.GREEN : Switches$Color
16dup
18getstatic #10// Switches$Color.BLUE : Switches$Color

Open in the viewer

Related instructions

aaload Pops an array and an index; pushes the reference element.arraylength Pops an array; pushes its length.anewarray Pops a length; pushes a new array of references.

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