deep

a Cross Development Platform for Java

User Tools

Site Tools


dev:crosscompiler:objects

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 descriptor1st parameter registerReference to Objectreturn register
newarrayArray of base typenewPrimTypeArrayNof1st parameter registerReference to arrayreturn register
Java array type2nd parameter register
Reference to type descriptor3rd parameter register
anewarrayArray of objectsnewRefArrayNof1st parameter registerReference to arrayreturn register
Reference to type descriptor2nd parameter register
multianewarrayMultidimensional arraynewMultiDimArrayType or reference to Type1st parameter registerReference to arrayreturn register
Nof dimensions2nd parameter register
Dimension 13rd parameter register
Dimension 24th parameter register
etc.
StringnewstringReference to type1st parameter registerReference to objectreturn register
Length2nd parameter register

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.txt · Last modified: 2018/11/21 15:25 by ursgraf