multianewarray

Operation
Create new multidimensional array

multianewarray
indexbyte1
indexbyte2
dimensions

Forms
multianewarray = 197 (0xc5)

Stack
..., count1, [count2, ...] ..., arrayref

Description
The dimensions is an unsigned byte which must be greater than or equal to 1. It represents the number of dimensions of the array to be created. The operand stack must contain dimensions words, which must be of type int and nonnegative, each representing the number of components in a dimension of the array to be created. The count1 is the desired length in the first dimension, count2 in the second, etc.

All of the count values are popped off the operand stack. The unsigned indexbyte1 and indexbyte2 are used to construct an index into the constant pool of the current class (§3.6), where the value of the index is (indexbyte1 << 8) | indexbyte2. The item at that index in the constant pool must be a CONSTANT_Class (§4.4.1). The symbolic reference is resolved (§5.1.3). The resulting entry must be an array class type of dimensionality greater than or equal to dimensions.

A new multidimensional array of the array type is allocated from the garbage-collected heap. The components of the array of in the first dimension are initialized to subarrays of the type of the second dimension, and so on. The components of the first dimension of the array are initialized to the default initial value for the type of the components (§2.5.1). A reference arrayref to the new array is pushed onto the operand stack.

Linking Exceptions
During resolution of the CONSTANT_Class constant pool item, any of the exceptions documented in §5.1 can be thrown.

Otherwise, if the current class does not have permission to access the base class of the resolved array class, multianewarray throws an IllegalAccessError.

Runtime Exception
Otherwise, if any of the dimensions values on the operand stack is less than zero, the multianewarray instruction throws a NegativeArraySizeException.

Notes
It may be more efficient to use newarray or anewarray when creating an array of a single dimension.

The array class referenced via the constant pool instruction may have more dimensions than the dimensions operand of the multianewarray instruction. In that case, only the first dimensions of the dimensions of the array are created.