baload 0x33
Pops an array and an index; pushes the byte or boolean element.
- Opcode
0x33(51)- 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[]) and an index; pushes the element at that index, widened to int with sign extension.
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, baload appears 2,502 times in 314 of its 7,391 classes: 0.13% of all instructions, the 80th most common of 194 opcodes in use. Some of the methods that use it: java.io.BufferedInputStream.read, java.io.ByteArrayInputStream.read, java.io.DataInputStream.readUTF, java.io.FilterOutputStream.write.
Example
From the sample classes, compiled by javac 25 with -g. Each Java line is shown above the bytecode it compiled to; baload is highlighted.
static int arrays(int n) in Tour, compiled by javac 25z[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;return (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;Related instructions
bastore Pops an array, an index and a byte or boolean value; stores the value in the array.arraylength Pops an array; pushes its length.newarray Pops a length; pushes a new array of a primitive type.
Specification: JVMS §6.5, baload (Java SE 25).