deep

a Cross Development Platform for Java

User Tools

Site Tools


dev:crosscompiler:arrays

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
dev:crosscompiler:arrays [2015/03/29 09:46] – [Multidimensional Arrays] ursgrafdev:crosscompiler:arrays [2022/12/20 11:24] (current) ursgraf
Line 2: Line 2:
 The following figure demonstrates how arrays are implemented in the memory.  The following figure demonstrates how arrays are implemented in the memory. 
 [{{ .:array1.png?250&direct | //Implementation of an array//}}] [{{ .:array1.png?250&direct | //Implementation of an array//}}]
-An array extends //java/lang/object//. The field //Tag// points to the type descriptor of this array (//[ClassA// for this example). The single array elements themselves are of type //ClassA// and have a //Tag// which points to the type descriptor of //ClassA//. For this reason arrays of base types like ([B, [S ...) need a einen class descritor as well. \\+An array extends //java/lang/object//. The field //Tag// points to the type descriptor of this array (//[ClassA// for this example). The single array elements themselves are of type //ClassA// and have a //Tag// which points to the type descriptor of //ClassA//. For this reason arrays of base types like ([B, [S ...) need a class descritor as well. \\
 The field //length// denotes the number of elements of the array (16 bit). //heap// is used for the garbage collection ([[..:rts:heap|Heap Manager and Garbage Collection]]). In between there is a byte which contains an array bit. This is used for type checking. The //P// bit is for garbage collection. It is set for arrays of primitive types\\ The field //length// denotes the number of elements of the array (16 bit). //heap// is used for the garbage collection ([[..:rts:heap|Heap Manager and Garbage Collection]]). In between there is a byte which contains an array bit. This is used for type checking. The //P// bit is for garbage collection. It is set for arrays of primitive types\\
 When accessing array elements the code generator inserts code to check if the element index is in the range 0 to //length//.\\ When accessing array elements the code generator inserts code to check if the element index is in the range 0 to //length//.\\
-If the field //length// is used in Java the Bytecode instruktion //arraylength// is used. This instruktion has to be translated such as the //length// field is accessed.+If the field //length// is used in Java the Bytecode instruktion //arraylength// is used. This instruktion has to be translated so that the //length// field is accessed.
  
 ===== Generating Arrays ===== ===== Generating Arrays =====
Line 28: Line 28:
 <code> <code>
   0  iconst_4   0  iconst_4
-  1  anewarray ch/ntb/junitTarget/comp/objects/ClassA +  1  anewarray org/deepjava/junitTarget/comp/objects/ClassA 
-  4  putstatic ch/ntb/junitTarget/comp/objects/InheritanceTest.a1: Ljava/lang/Object[];+  4  putstatic org/deepjava/junitTarget/comp/objects/InheritanceTest.a1: Ljava/lang/Object[];
 </code> </code>
 Here, as well, the reference to //[ClassA// has to be fetched from the object directory when generating the SSA. There are cases when there is no entry for //[ClassA//. This is the case when there is never a type check for the type //[ClassA//. Then the SSA has a reference to null and the //Tag// can be 0 as well.  Here, as well, the reference to //[ClassA// has to be fetched from the object directory when generating the SSA. There are cases when there is no entry for //[ClassA//. This is the case when there is never a type check for the type //[ClassA//. Then the SSA has a reference to null and the //Tag// can be 0 as well. 
Line 47: Line 47:
   short[][] a = new short[2][3]   short[][] a = new short[2][3]
 </code> </code>
-gives a Bytecode+leads to the Bytecode
 <code> <code>
 0 iconst_2 0 iconst_2
 1 iconst_3 1 iconst_3
 2 multianewarray short[][] 2 multianewarray short[][]
-6 putstatic ch/ntb/inf/deep/runtime/mpc555/test/ArrayTest3.a1: short[][]+6 putstatic org/deepjava/runtime/mpc555/test/ArrayTest3.a1: short[][]
 </code> </code>
 If an array is immediately initialized  If an array is immediately initialized 
Line 81: Line 81:
 etc. etc.
 </code> </code>
-The problem with the first case is, that only the type descriptor //[[I// would be linked. However, //[I// must be created as well. Im Heapmanager muss die Methode //multianewarray// das Array allozieren und insbesondere auch die Referenzen auf [[I und [I setzenDie Referenz auf [[I wird als Parameter übergebenIm Typdescriptor von [[I steht die Referenz auf [I. Die muss dort geholt werden und am richtigen Ort im Object gespeichert werden. \\ +The problem with the first case is, that only the type descriptor //[[I// would be linked. However, //[I// must be created as well. In the method //multianewarray// of the heap manager the array must be allocated and the references to //[[I// and //[I// must be setThe reference to //[[I// is passed as a parameterIn //[[I// there is the reference to //[I//This reference must be fetched and inserted into the object at the appropriate position. \\ 
-Die gleichen Überlegungen gelten auch für Arrays mit höheren DimensionenAuch dort wird //multianewarray// nur in besonderen Situationen verwendet.+Similar thoughts are true for arrays with higher dimensionsAs well, the instruction //multianewarray// is used solely for special purposes.
 ==== Generating an Multidimensional Array of Objects ==== ==== Generating an Multidimensional Array of Objects ====
-Hier gelten grundsätzlich die gleichen Bedingungen wie oben +Here, the same conditions are true as described above
-Der folgende Javacode +
 <code java> <code java>
   ClassA[][][] a1 = new ClassA[3][2][2];   ClassA[][][] a1 = new ClassA[3][2][2];
 </code> </code>
-wird in den Bytecode+This leads to Bytecode
 <code> <code>
   0 iconst_3   0 iconst_3
Line 97: Line 96:
   7 astore_1 [a1]   7 astore_1 [a1]
 </code> </code>
-übersetzt. Hier wird also bereits also bereits die korrekte Referenz auf //[[[ClassA;// in die SSA aufgenommenDer Heapmanager muss wie bei den Basistypen aus dem Typdescriptor von //[[[ClassA;// die weiteren Typdescriptoren //[[ClassA;//, //[ClassA;// und //ClassA;// rekursiv holen. +The reference to //[[[ClassA;// can be found already in the SSA. The heap manager has to fetch the base types //[[ClassA;//, //[ClassA;// and //ClassA;// from the type descriptor recursively.
dev/crosscompiler/arrays.1427615196.txt.gz · Last modified: 2016/02/25 13:33 (external edit)