Contents | Prev | Next | IndexThe JavaTM Virtual Machine Specification


new

Operation Create new object

new
indexbyte1
indexbyte2


Forms new = 187 (0xbb)

Stack ... ..., objectref

Description 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) and must result in a class type (it must not result in an array or interface type). Memory for a new instance of that class is allocated from the garbage-collected heap, and the instance variables of the new object are initialized to their default initial values (§2.5.1). The objectref, a reference to the instance, 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 CONSTANT_Class constant pool item re-solves to an interface or is an abstract class, new throws an InstantiationError.

Otherwise, if the current class does not have permission to access the resolved class (§2.7.8), new throws an IllegalAccessError.

Note The new instruction does not completely create a new instance; instance creation is not completed until an instance initialization method has been invoked on the uninitialized instance.


newarray

Operation Create new array

newarray
atype


Forms newarray = 188 (0xbc)

Stack ..., count ..., arrayref

Description The count must be of type int. It is popped off the operand stack. The count represents the number of elements in the array to be created.

The atype is a code that indicates the type of array to create. It must take one of the following values:

Array Type atype
T_BOOLEAN 4
T_CHAR 5
T_FLOAT 6
T_DOUBLE 7
T_BYTE 8
T_SHORT 9
T_INT 10
T_LONG 11


A new array whose components are of type atype, of length count, is allocated from the garbage-collected heap. A reference arrayref to this new array object is pushed into the operand stack. All of the elements of the new array are initialized to the default initial values for its type (§2.5.1).

Runtime Exception If count is less than zero, newarray throws a NegativeArraySizeException.

Notes In Sun's implementation of the Java Virtual Machine, arrays of type boolean (atype is T_BOOLEAN) are stored as arrays of 8-bit values and are manipulated using the baload and bastore instructions, instructions that also access arrays of type byte. Other implementations may implement packed boolean arrays; the baload and bastore instructions must still be used to access those arrays.


nop

Operation Do nothing

nop


Forms nop = 0 (0x0)

Stack No change

Description Do nothing.


Contents | Prev | Next | Index

Java Virtual Machine Specification

Copyright © 1996, 1997 Sun Microsystems, Inc. All rights reserved
Please send any comments or corrections to jvm@java.sun.com