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

Next revision
Previous revision
dev:crosscompiler:strings [2014/05/01 09:17] – external edit 127.0.0.1dev:crosscompiler:strings [2016/02/25 13:33] (current) – external edit 127.0.0.1
Line 14: Line 14:
  
 ===== Optimized String ===== ===== Optimized String =====
-Damit in Java wie gewohnt mit Strings gearbeitet werden kann, wird das Erzeugen und Verarbeiten von Strings vollständig in der Klasse //java/lang/String// gekapseltDiese Klasse ist eine Erweiterung von //BString// (steht für BaseString). //BString// hat als einziges Feld die Länge des Strings //count//. Damit wird sichergestelltdass //count// stets auf dem Index zu liegen kommt. //String// weist ein weiteres Feld auf //value// vom Typ //char[]//Aber statt einer Referenz auf ein Characterarray sollen nun in //value// direkt die Zeichen abgelegt werden+The creation and manipulation of strings is done solely in //java/lang/String//This class extends //BString// (this stands for //Base String//). //BString// has the single field //count//, which is the lenght of the string. This ensures that the field //count// will reside at index 0. //String// has another field //value// of type //char[]//Instead of containing a reference to a character array, this field contains the characters directly
  
-[{{ .strings2.png?300&direct | //Optimierter String// }}]+[{{ .strings2.png?300&direct | //Optimized String// }}]
  
-Das Feld //size// zeigt die Anzahl Bytes des ganzen Objektes an, analog zu anderen Objekten (siehe [[heap|Heap]]). Es dient der schnelleren 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 werdenweil die Grösse des Char-Arrays nicht aus dem Typdescriptor herausgelesen werden kannDa das Array ja fix ins Objekt zu liegen kommt, variiert die Grösse des Objektes von String zu StringIm Codegenerator wird nun geprüft, ob das new ein Objekt vom Typ String erzeugt und falls ja, wird nichts unternommenEinzig die Referenz auf den Typdescriptor von String muss in das Resultatregister von //new// geschrieben werden. \\ +//new// must not yet be executedbecause the size of the character array cannot be fetched from the type descriptorThe character array will be inserted directly into the object and this size varies from string to stringThe 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 aufHier darf nun nicht dieser Konstruktor aufgerufen werdenda ja das Objekt noch gar nicht existiertDurch 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 constructorbecause the object does not yet existThe 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 gemachtAuch 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 heapThe 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 aufgerufenDieser Aufruf muss direkt im Codegenerator eingefügt werden+  * call the constructor of the super classThis 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 sollmuss das im Codegenerator speziell berücksichtigt werdenEin solcher Zugriff hat in der SSA die Form+When accessing fields of a stringthe code generator has to modify the codeSuch 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 ReferenzAnschliessend wird über die Referenz und ein Index auf das Array zugegriffenIm Codegenerator muss bei einer Instruktion //sCloadFromField// geprüft werden, ob auf das Feld //String.value// zugegriffen wirdFalls jawird dieser Zugriff weggelassen und der Offset von //value// gemerktBei der darauffolgenden Instruktion //sCloadFromArray// muss dieser Offset zum Index dazuaddiert werdenEbenfalls darf als Arrayreferenz nicht das //value// dienen, sondern die Referenz auf den String. \\ +The field //value// is loaded. //value// is a referenceWith this reference and an index into the array the proper character can be accessedThe code generator has to check for the instruction //sCloadFromField// if the field is  //String.value//If truethe fetching is ommited and the offset of //value// is storedWith the subsequent instruction //sCloadFromArray//, the offset must be added to the indexAt 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 werdenHier gibt es aber noch eine Besonderheit. Weil Strings immutable sindwerden nur beim Initialisieren in den Fabrikmethoden die Arrayfelder geschriebenDarum kann die Prüfung auf Arrayüberschreitung weggelassen werden.+Similarly, writing to a string must be customizedHoweverstrings in java are immutable. Writing to strings happens only in the factory methods during initializationChecking 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.1398928638.txt.gz · Last modified: 2016/02/25 13:33 (external edit)