Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| Beide Seiten der vorigen RevisionVorhergehende ÜberarbeitungNächste Überarbeitung | Vorhergehende Überarbeitung | ||
| software:deep:dev:rts:heap [2014-05-26 15:22] – graf | software:deep:dev:rts:heap [Unbekanntes Datum] (aktuell) – gelöscht - Externe Bearbeitung (Unbekanntes Datum) 127.0.0.1 | ||
|---|---|---|---|
| Zeile 1: | Zeile 1: | ||
| - | ====== Heap Manager and Garbage Collection ====== | ||
| - | ===== General Information ===== | ||
| - | Currently we support a simple mark & sweep algorithm. With this the mark phase must not be interrupted, | ||
| - | | ||
| - | ===== Initialization ===== | ||
| - | At startup the roots of all loaded classes are collected. Roots are static references to objects. An Integer array with this size is allocated and filled with the addresses of the roots. This array and also the array with the free lists are roots themselves. The array with the free lists will be marked in the mark phase which precludes sweeping but its entries will not be followed because it is an Integer array. Following would be wrong anyway.\\ | ||
| - | At the beginning the whole free heap will be entered as a single free block. | ||
| - | ===== Free Blocks, Allocation ===== | ||
| - | There are 8 lists with block sizes of (Bytes) 16, 32, 48, 64, 80, 96, 112 and >= 128. At the very beginning there is no array with theses lists. Therefore the allocation must be done "by hand". Only after the class constructor of the class //Heap// is executed the rest of the heap can be entered as a free block. \\ | ||
| - | To be able to follow the free blocks (when searching a new block or when sweeping) the structure below is used: | ||
| - | [{{ .: | ||
| - | The field //size// holds the size of the block, //next// gives the address of the next free block. There is no java class for these free blocks. The reason for this is that free and used blocks must be efficiently changed into each other. | ||
| - | [{{ .: | ||
| - | When allocating a new block a check is made for the free heap space. If this free space falls below a certain limit a garbage collection is started. | ||
| - | |||
| - | ===== Mark Phase ===== | ||
| - | Starting with the roots, all used blocks are marked. Objects may contain fields which are references. These references ,ust be followed as well. The type descriptors contain the information about which fields are references. | ||
| - | |||
| - | ===== Sweep Phase ===== | ||
| - | During the sweep phase the whole heap is traversed block by block. Each block, whether free, marked or no longer used) has to include information about its size. Free blocks and blocks which contain actual objects have this information at the start of the block. With arrays this information has te be retrieved with the aid of the type descriptor. | ||
| - | [{{ .: | ||
| - | |||
| - | The sweep phase could be easily made interruptible (using a task or doing only a part). Currently, this is not implemented. \\ | ||
| - | **Important** | ||
| - | Wird ein bestimmter Block frei (d.h. die letzte Referenz darauf geht verloren), dann wird dieser Block unter Umständen erst nach zweimaligem Mark/Sweep als freier Block markiert. Begründung: | ||
| - | |||
| - | ===== Strings ===== | ||
| - | Strings werden wie normale Objekte behandelt. In der Mark-Phase werden auch konstante Strings markiert, obwohl sich diese im Konstantenblock einer Klasse befinden. Das könnte zu einem Problem führen, wenn sich dieser Block in einem Flash befindet und dieses keinen Schreibzugriff erlaubt. Das ist aber normalerweise nicht so. Natürlich werden konstante Strings beim Sweepen nicht eingesammelt, | ||
| - | |||