# new-instance

## Purpose

Construct a new instance of the indicated type, storing a reference to it in the destination. The type must refer to a non-array class.

## Details

Op & Format | Mnemonic / Syntax | Arguments
--- | --- | ---
22 21c | new-instance vAA, type@BBBB | `A:` destination register (8 bits) `B:` type index

## Constraints

- A must be a valid register index for the current stack frame.
- B must be a valid index into the type pool.
- Type constant pool entry B must contain a valid type descriptor for a non-array class.

## Behavior

- An attempt is made to get a reference to the class C the name of which is contained in type pool entry B.
- If C has not been loaded and resolved before, it is being loaded and resolved. All exceptions that are possible during class loading can occur at this point.
- An attempt is made to create a new instance I of C. All exceptions that are possible during instantiation can occur at this point.
- A reference to the new instance is stored in register vA, that is vA' = I.
- If v(A-1) is the lower part of a register pair, v(A-1)' becomes undefined.
- If v(A+1) is the upper part of a register pair, v(A+1)' becomes undefined.

## Exceptions

- All exceptions that are possible during class loading can occur.
- All exceptions that are possible during instantiation can occur.