This shows you the differences between two versions of the page.
Next revision | Previous revisionNext revisionBoth sides next revision | ||
dev:crosscompiler:class_initialization [2014/11/03 13:31] – external edit 127.0.0.1 | dev:crosscompiler:class_initialization [2015/04/06 13:37] – [Initialization of Objects] ursgraf | ||
---|---|---|---|
Line 32: | Line 32: | ||
} | } | ||
</ | </ | ||
- | Class A starts initializing, | + | Class A starts initializing, |
This error goes undetected. A user has to make sure that the initialization is done in a correct way. | This error goes undetected. A user has to make sure that the initialization is done in a correct way. | ||
==== Our Solution ==== | ==== Our Solution ==== | ||
- | Beim Linken sollen alle Top-Level Klassen als Parameter angegeben werden können. Diese Liste wird von links nach rechts geparst und die Imports | + | Before compilation all top-level classes (also called root classes) can be specified. This list will be parsed from left to right and the imports will be resolved |
- | In Java ist die Initialisierungsreihenfolge nicht klar definiert. Falls Test auf dem Host und dem Target stets das gleiche Resultat ergeben sollen, bietet sich folgende Lösung an: Im Klassenkonstruktor einer obersten Hauptklasse (die ansonsten vollständig leer ist) werden alle anderen Klassenkonstruktoren aufgerufen. Bei dieser Lösung entfällt auch die Notwendigkeit einer Systemtabelle. | + | It's important that the heap class and the kernel class are initialized first. For this they are put at the beginning of the list.\\ |
+ | Java does not define the order of initialization clearly. If tests on the host and the target should lead to the same result, the following solution would be appropriate: the class constructor of a otherwise empty helper class calls all the other class constructors. This solution would also allow to get rid of the system table. | ||
- | ===== Initialisierung von Objekten | + | ===== Initialization of Objects |
- | Die Initialisierung von Objekten wird in den Objektkonstruktoren zusammengefasst. | + | The initialization of objects is done in the object constructors. |
<code java> | <code java> | ||
int len = 4; // block 1 | int len = 4; // block 1 | ||
Line 49: | Line 50: | ||
} | } | ||
</ | </ | ||
- | Die Objektkonstruktoren heissen alle // | + | In the Bytecode these constructors carry the name // |
- | Beim Erzeugen eines Objektes wird stets zuerst mit Hilfe von // | + | When creating an object a call to // |
- | Klassen dürfen auch Instanzinitialisierer enthalten, z.B. | + | Classes might also have instance initializers, such as: |
<code java> | <code java> | ||
int[] data = new int[10]; | int[] data = new int[10]; | ||
{for (int i = 0; i < 10; i++) data[i] = i;} | {for (int i = 0; i < 10; i++) data[i] = i;} | ||
</ | </ | ||
- | Auch diese Instanzinitialisierer befinden sich im Bytecode in den Objektkonstruktoren. | + | These initializers go into the object constructors as well. |