deep

a Cross Development Platform for Java

User Tools

Site Tools


dev:crosscompiler:objects

This is an old revision of the document!


Objects

Objects on the heap need a reference to their type descriptor (Tag) and information for the garbage collection.

Implementation of an object

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).

Allocation of objects

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.

Bytecode Instructions and Parameter Passing

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.

BytecodeUseHeap MethodParameterRegisterReturn ValueRegister
newObjectnewObjectReference to type descriptorR2Reference to ObjectR2
newarrayArray of base typenewPrimTypeArrayNofR2Reference to arrayR2
Java array typeR3
Reference to type descriptorR4
anewarrayArray of objectsnewRefArrayNofR2Reference to arrayR2
Reference to type descriptorR3
multianewarrayMultidimensional arraynewMultiDimArrayType or reference to TypeR2Reference to arrayR2
Nof dimensionsR3
Dimension 1R4
Dimension 2R5
etc.
StringnewstringReference to typeR2Reference to objectR2
LengthR3

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.

dev/crosscompiler/objects.1456403585.txt.gz · Last modified: 2016/02/25 13:33 by 127.0.0.1