This is an old revision of the document!
Objects on the heap need a reference to their type descriptor (Tag) and information for the garbage collection.
The field size allows for a faster sweep phase during garbage collection. size includes the size of the object plus heap field and Tag.
If the object is an array the field size contains the length of the array (see Arrays).
When a new object is created there is a call to the method newObject of the class Heap. After this follows the call of the constructor of the super class. For the class java/lang/Object this call is missing in the Bytecode.
If an array is to be created things run differently. Each array is an extension of java/lang/Object. In the Bytecode the call to this constructor is missing. If java/lang/Object has fields which need to be initialized this would have to be done when allocating the array in the heap.
There are 4 different Bytecode instructions to create objects on the heap. The following table shows this instructions together with register usage. This usage is platform specific and must be fixed between the code generator and the Heap class of the runtime system.
Bytecode | Use | Heap Method | Parameter | Register | Return Value | Register |
---|---|---|---|---|---|---|
new | Object | newObject | Reference to type descriptor | R2 | Reference to Object | R2 |
newarray | Array of base type | newPrimTypeArray | Nof | R2 | Reference to array | R2 |
Java array type | R3 | |||||
Reference to type descriptor | R4 | |||||
anewarray | Array of objects | newRefArray | Nof | R2 | Reference to array | R2 |
Reference to type descriptor | R3 | |||||
multianewarray | Multidimensional array | newMultiDimArray | Type or reference to Type | R2 | Reference to array | R2 |
Nof dimensions | R3 | |||||
Dimension 1 | R4 | |||||
Dimension 2 | R5 | |||||
etc. | ||||||
String | newstring | Reference to type | R2 | Reference to object | R2 | |
Length | R3 |
The class Heap is a system class. Its methods will be linked to the appropriate Bytecode instructions as indicated above.
The instruction newstring is used to create strings, see Strings.