bastore 0x54
Pops an array, an index and a byte or boolean value; stores the value in the array.
- Opcode
0x54(84)- Family
- Arrays
- Operands
- none
- Length
- 1 byte
- Operand stack
…, arrayref, index, value (int) → …- Can throw
NullPointerException,ArrayIndexOutOfBoundsException
What it does
Pops an array (byte[] or boolean[]), an index and a value; stores the value at that index, truncating the int to the element type.
The same instruction serves byte[] and boolean[]. The JVM may store a boolean array as bytes or as bits; for boolean[] the value is masked to its lowest bit.
How often javac uses it
In JDK 25.0.5's java.base module, bastore appears 22,081 times in 278 of its 7,391 classes: 1.1% of all instructions, the 26th most common of 194 opcodes in use. Some of the methods that use it: java.io.BufferedOutputStream.write, java.io.BufferedReader.readLine, java.io.ByteArrayOutputStream.write, java.io.FileInputStream.readAllBytes.
Example
From the sample classes, compiled by javac 25 with -g. Each Java line is shown above the bytecode it compiled to; bastore is highlighted.
static int arrays(int n) in Tour, compiled by javac 25Related instructions
baload Pops an array and an index; pushes the byte or boolean element.arraylength Pops an array; pushes its length.newarray Pops a length; pushes a new array of a primitive type.
Specification: JVMS §6.5, bastore (Java SE 25).