multianewarray 0xc5
Pops several lengths; pushes a new multi-dimensional array.
- Opcode
0xc5(197)- Family
- Arrays
- Operands
- 2 bytes: class constant index
- 1 byte: dimensions
- Length
- 4 bytes
- Operand stack
…, count1, count2, … → …, arrayref- Can throw
NegativeArraySizeException
What it does
Creates a multi-dimensional array, popping one length for each dimension given. The first operand is the array type (such as [[I); the second is how many dimensions to create, which may be fewer than the type has.
javac uses it for new int[3][4]. When only the first length is given, as in new int[3][], it uses anewarray instead.
How often javac uses it
In JDK 25.0.5's java.base module, multianewarray appears 17 times in 13 of its 7,391 classes: <0.01% of all instructions, the 182nd most common of 194 opcodes in use. Some of the methods that use it: java.lang.invoke.LambdaForm.<clinit>, java.lang.invoke.StringConcatFactory.<clinit>, java.lang.reflect.Executable.sharedGetParameterAnnotations, java.util.zip.CRC32C.<clinit>.
Examples
From the sample classes, compiled by javac 25 with -g. Each Java line is shown above the bytecode it compiled to; multianewarray is highlighted.
static int arrays(int n) in Tour, compiled by javac 25static long mix(long a, int b, short c, byte d, double e, float f, char g, boolean h) in Numbers, compiled by javac 25Related instructions
anewarray Pops a length; pushes a new array of references.newarray Pops a length; pushes a new array of a primitive type.
Specification: JVMS §6.5, multianewarray (Java SE 25).