deep

a Cross Development Platform for Java

User Tools

Site Tools


dev:crosscompiler:strings

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:strings [2015/04/06 15:56] – [Optimized String] ursgrafdev:crosscompiler:strings [2016/02/25 13:33] (current) – external edit 127.0.0.1
Line 20: Line 20:
 The field //size// holds the number of bytes of the whole object. This is analogous to other objects (see [[dev:rts:heap|Heap Manager and Garbage Collection]]). It is used for an efficient sweep phase. The field //size// holds the number of bytes of the whole object. This is analogous to other objects (see [[dev:rts:heap|Heap Manager and Garbage Collection]]). It is used for an efficient sweep phase.
  
-===== Erzeugung ===== +===== Creation ===== 
-Beim Erzeugen eines String steht folgender Bytecode im Classfile+The Bytecode for the creation of a string is
 <code> <code>
 new java/lang/String new java/lang/String
 invokespecial constructor invokespecial constructor
 </code> </code>
-Das //new// darf noch nicht ausgeführt werden, weil die Grösse des Char-Arrays nicht aus dem Typdescriptor herausgelesen werden kann. Da das Array ja fix ins Objekt zu liegen kommt, variiert die Grösse des Objektes von String zu String. Im Codegenerator wird nun geprüft, ob das new ein Objekt vom Typ String erzeugt und falls ja, wird nichts unternommen. Einzig die Referenz auf den Typdescriptor von String muss in das Resultatregister von //new// geschrieben werden. \\ +//new// must not yet be executed, because the size of the character array cannot be fetched from the type descriptor. The character array will be inserted directly into the object and this size varies from string to string. The code generator has to check if //new// creates something of type //String//. If true, nothing will be done except putting the reference to the type descriptor of //String// into the result register of //new//. \\ 
-Die nächste Bytecode-Instruktion //invokespecial// ruft nun den passenden Objektkonstruktor auf. Hier darf nun nicht dieser Konstruktor aufgerufen werden, da ja das Objekt noch gar nicht existiert. Durch den Linker wird anstelle des Objektkonstruktors eine Fabrikmethode mit den gleichen Parametern gelinkt. +The next Bytecode instruction is //invokespecial//. In our case, it must not call the constructor, because the object does not yet exist. The linker will insert a call to a special factory method with similar parameters. 
 <code java> <code java>
 public static String allocateString(int ref, char value[]) { public static String allocateString(int ref, char value[]) {
Line 37: Line 37:
 } }
 </code> </code>
-Zuerst wird die Grösse des notwendigen Arrays bestimmt und dann die Allokation auf dem Heap gemacht. Auch hier muss der Linker statt des Hilfsstubs //newstring// die entsprechende Methode //newstring// in Heap.java einsetzen. //newstring// bewirkt folgende Aktionen:  +Foremost, the necessary size must be calculated and the object must be allocated on the heap. The linker must replace the method address of the stub //newstring// with the method //newstring// in the class //Heap//. //newstring// does:  
-  * setzt setzt den Tag  des Stringsobjektes auf den Typdescriptor von //String// (wie ein newobject) +  * set the tag of the string object to the type descriptor of //String// (similar to //newobject//). 
-  * erzeugt aber auch die notwendige Anzahl Arrayfelder (wie ein newarray) +  * create the necessary number of array fields (similar to //newarray//). 
-  * das Feld //count// wird gesetzt +  * set the field //count//. 
-  * der Konstruktor der Oberklasse wird aufgerufen. Dieser Aufruf muss direkt im Codegenerator eingefügt werden. +  * call the constructor of the super class. This call has to be inserted in the code generator. 
-  * Der String wird initialisiert +  * initialize the string. 
-Am Schluss muss die Referenz auf den durch die Fabrikmethode erzeugten String in das Resultatregister der //sCnew//-Instruktion geschrieben werden.   +Finally, the reference to the newly created string has to be put into the result register of the //sCnew// instruction.   
-===== Feldzugriffe ===== +===== Access to Fields ===== 
-Sobald auf Felder des Stringarrays zugegriffen werden soll, muss das im Codegenerator speziell berücksichtigt werden. Ein solcher Zugriff hat in der SSA die Form+When accessing fields of a string, the code generator has to modify the code. Such an access shows up in the SSA as follows
 <code> <code>
 1: MonadicRef[sCloadFromField] {0} <value([C)> (Char-Array) 1: MonadicRef[sCloadFromField] {0} <value([C)> (Char-Array)
Line 51: Line 51:
 3: Dyadic[sCloadFromArray] {1, 2} (Char) 3: Dyadic[sCloadFromArray] {1, 2} (Char)
 </code> </code>
-Zuerst wird also das Feld //value// geladen. //value// ist eine Referenz. Anschliessend wird über die Referenz und ein Index auf das Array zugegriffen. Im Codegenerator muss bei einer Instruktion //sCloadFromField// geprüft werden, ob auf das Feld //String.value// zugegriffen wird. Falls ja, wird dieser Zugriff weggelassen und der Offset von //value// gemerkt. Bei der darauffolgenden Instruktion //sCloadFromArray// muss dieser Offset zum Index dazuaddiert werden. Ebenfalls darf als Arrayreferenz nicht das //value// dienen, sondern die Referenz auf den String. \\ +The field //value// is loaded. //value// is a reference. With this reference and an index into the array the proper character can be accessed. The code generator has to check for the instruction //sCloadFromField// if the field is  //String.value//. If true, the fetching is ommited and the offset of //value// is stored. With the subsequent instruction //sCloadFromArray//, the offset must be added to the index. At the same time one cannot use //value// as the array reference but must use the reference to the string. \\ 
-Analog muss auch das Schreiben auf die Stringzeichen angepasst werden. Hier gibt es aber noch eine Besonderheit. Weil Strings immutable sind, werden nur beim Initialisieren in den Fabrikmethoden die Arrayfelder geschrieben. Darum kann die Prüfung auf Arrayüberschreitung weggelassen werden.+Similarly, writing to a string must be customized. However, strings in java are immutable. Writing to strings happens only in the factory methods during initialization. Checking for array index out of bounds may be ommited as well.
  
 ===== Constant String ===== ===== Constant String =====
-Constant strings are stored in the constant block of a class, see [[Linker32]]. The layout there must be identical to the layout on the heap as given above.+Constant strings are stored in the constant block of a class, see [[dev:crosscompiler:backend_ppc:linker32|Linker32]]. The layout there must be identical to the layout on the heap as given above.
  
 ===== Special Linking ===== ===== Special Linking =====
 The type descriptor of the class //String// must have its field //nofInstPtr// set to 0. Though there is a field //char[] values// we access this field in an omtimized way as decribed above. The garbage collector must not follow this field! The type descriptor of the class //String// must have its field //nofInstPtr// set to 0. Though there is a field //char[] values// we access this field in an omtimized way as decribed above. The garbage collector must not follow this field!
dev/crosscompiler/strings.1428328580.txt.gz · Last modified: 2016/02/25 13:33 (external edit)