arraylength 0xbe
Pops an array; pushes its length.
- Opcode
0xbe(190)- Family
- Arrays
- Operands
- none
- Length
- 1 byte
- Operand stack
…, arrayref → …, length (int)- Can throw
NullPointerException
What it does
Pushes the length of an array: a.length in Java. Every array type shares this one instruction.
The enhanced for loop over an array reads the length once, before the loop starts, into a hidden local variable.
How often javac uses it
In JDK 25.0.5's java.base module, arraylength appears 6,694 times in 1,398 of its 7,391 classes: 0.34% of all instructions, the 54th most common of 194 opcodes in use. Some of the methods that use it: java.io.BufferedInputStream.fill, java.io.BufferedOutputStream.growIfNeeded, java.io.BufferedReader.fill, java.io.BufferedWriter.write.
Examples
From the sample classes, compiled by javac 25 with -g. Each Java line is shown above the bytecode it compiled to; arraylength is highlighted.
public static void main(String[] args) in Hello, compiled by javac 25String who = args.length > 0 ? args[0] : "world";System.out.println("Hello, " + who + "!");}static { … } in EnumSwitch.1, compiled by javac 25Related instructions
newarray Pops a length; pushes a new array of a primitive type.iaload Pops an array and an index; pushes the int element.
Specification: JVMS §6.5, arraylength (Java SE 25).