![Page 1: Comparison of Compacting Algorithms for Garbage Collection](https://reader035.vdocuments.us/reader035/viewer/2022062323/568162a1550346895dd31963/html5/thumbnails/1.jpg)
1
Comparison of Compacting Algorithms for Garbage Collection
Mrinal DeoCS395T – Spring 2011
![Page 2: Comparison of Compacting Algorithms for Garbage Collection](https://reader035.vdocuments.us/reader035/viewer/2022062323/568162a1550346895dd31963/html5/thumbnails/2.jpg)
Mrinal Deo - CS 395T - Spring 2011 2
Recap • Mark Sweep– Pros• We use the entire
heap– Cons• The heap gets
fragmented over time
• Copying– Pros• Heap is rearranged by
copying into one large chunk.• Better locality• No fragmentation i.e.
speedier allocation.– Cons• We use only half of
the heap.
Introduce – Mark-Compact . Bring to benefits of Copying to Mark Sweep
![Page 3: Comparison of Compacting Algorithms for Garbage Collection](https://reader035.vdocuments.us/reader035/viewer/2022062323/568162a1550346895dd31963/html5/thumbnails/3.jpg)
Mrinal Deo - CS 395T - Spring 2011 3
Algorithms
Classical – Lisp 2
• D.E. Knuth, 1973
– Table Compactor• Modified algorithm based on Waite and Haddon, 1967
Modern (at the time)– Morris’ algorithm, 1978– Jonkers’ algorithm, 1979
![Page 4: Comparison of Compacting Algorithms for Garbage Collection](https://reader035.vdocuments.us/reader035/viewer/2022062323/568162a1550346895dd31963/html5/thumbnails/4.jpg)
Mrinal Deo - CS 395T - Spring 2011 4
Layout of a Cell
![Page 5: Comparison of Compacting Algorithms for Garbage Collection](https://reader035.vdocuments.us/reader035/viewer/2022062323/568162a1550346895dd31963/html5/thumbnails/5.jpg)
Mrinal Deo - CS 395T - Spring 2011 5
Lisp 2
• Requires additional space in each cell for a pointer
• Compaction phase is done in 3 passes:1. Start traversing the cells – sorted in terms of their
address• Compute new address of each active cell• @start free_ptr = 0; free_ptr += free_ptr + size of live cell
2. Update pointer fields of each active cell3. Sliding Compactor - Relocate active cells to one end
of the heap.
![Page 6: Comparison of Compacting Algorithms for Garbage Collection](https://reader035.vdocuments.us/reader035/viewer/2022062323/568162a1550346895dd31963/html5/thumbnails/6.jpg)
Mrinal Deo - CS 395T - Spring 2011 6
Lisp 2
![Page 7: Comparison of Compacting Algorithms for Garbage Collection](https://reader035.vdocuments.us/reader035/viewer/2022062323/568162a1550346895dd31963/html5/thumbnails/7.jpg)
Mrinal Deo - CS 395T - Spring 2011 7
Table Compactor
• Uses the same basic idea as the Lisp 2.• Differs in the place where we store the ‘new’
addresses of each cell.• Uses the ‘garbage cells’ to prepare the table of
relocated cells with destinations.
![Page 8: Comparison of Compacting Algorithms for Garbage Collection](https://reader035.vdocuments.us/reader035/viewer/2022062323/568162a1550346895dd31963/html5/thumbnails/8.jpg)
Mrinal Deo - CS 395T - Spring 2011 8
Table compactor Algorithm
![Page 9: Comparison of Compacting Algorithms for Garbage Collection](https://reader035.vdocuments.us/reader035/viewer/2022062323/568162a1550346895dd31963/html5/thumbnails/9.jpg)
Mrinal Deo - CS 395T - Spring 2011 9
Table Allocator Contd0 100 300 950 1200 1600
0 100 100,100 950 1200 1600
0 100 100,100950, 750
950 1200 1600
![Page 10: Comparison of Compacting Algorithms for Garbage Collection](https://reader035.vdocuments.us/reader035/viewer/2022062323/568162a1550346895dd31963/html5/thumbnails/10.jpg)
Mrinal Deo - CS 395T - Spring 2011 10
Threading
A B C
P (data)
A B Cdata
P
![Page 11: Comparison of Compacting Algorithms for Garbage Collection](https://reader035.vdocuments.us/reader035/viewer/2022062323/568162a1550346895dd31963/html5/thumbnails/11.jpg)
Mrinal Deo - CS 395T - Spring 2011 11
Morris Algorithm
• 3 passes – 1 forward 2 backward• 2 tag bits per field– 0 inactive– 1 pointer– Swapped pointer– Non pointer
![Page 12: Comparison of Compacting Algorithms for Garbage Collection](https://reader035.vdocuments.us/reader035/viewer/2022062323/568162a1550346895dd31963/html5/thumbnails/12.jpg)
Mrinal Deo - CS 395T - Spring 2011 12
Morris Algorithm
![Page 13: Comparison of Compacting Algorithms for Garbage Collection](https://reader035.vdocuments.us/reader035/viewer/2022062323/568162a1550346895dd31963/html5/thumbnails/13.jpg)
Mrinal Deo - CS 395T - Spring 2011 13
Jonker’s Algorithm
• Based on the same principle as Morris i.e threading.
• Require only 1 tag bit.• 2 passes – both in forward direction• Pointers can ONLY point to the head of a cell.
![Page 14: Comparison of Compacting Algorithms for Garbage Collection](https://reader035.vdocuments.us/reader035/viewer/2022062323/568162a1550346895dd31963/html5/thumbnails/14.jpg)
Mrinal Deo - CS 395T - Spring 2011 14
Jonker’s Algorithm
![Page 15: Comparison of Compacting Algorithms for Garbage Collection](https://reader035.vdocuments.us/reader035/viewer/2022062323/568162a1550346895dd31963/html5/thumbnails/15.jpg)
Mrinal Deo - CS 395T - Spring 2011 15
Time-Formulas
• Create optimized versions of each algorithm• Describe each procedure with a formula from
the type and number of operations performed • Replace unknowns in the formula with
machine specific constants, leaving the following variables:– α: Marked cell ratio (NMC/NC)– β: Live pointer ratio (NAP-1)/(NPC*NMC)
![Page 16: Comparison of Compacting Algorithms for Garbage Collection](https://reader035.vdocuments.us/reader035/viewer/2022062323/568162a1550346895dd31963/html5/thumbnails/16.jpg)
Mrinal Deo - CS 395T - Spring 2011 16
Results
![Page 17: Comparison of Compacting Algorithms for Garbage Collection](https://reader035.vdocuments.us/reader035/viewer/2022062323/568162a1550346895dd31963/html5/thumbnails/17.jpg)
Mrinal Deo - CS 395T - Spring 2011 17
Discussion• Applicability of these algorithms to current
Multicore Architectures.• Performance of these Algorithms on modern
workloads.• Traversing heap objects in increasing order of
their address – lower to higher. Does this put any kind of constraints on PL design?
![Page 18: Comparison of Compacting Algorithms for Garbage Collection](https://reader035.vdocuments.us/reader035/viewer/2022062323/568162a1550346895dd31963/html5/thumbnails/18.jpg)
Mrinal Deo - CS 395T - Spring 2011 18
Backup Slides.
![Page 19: Comparison of Compacting Algorithms for Garbage Collection](https://reader035.vdocuments.us/reader035/viewer/2022062323/568162a1550346895dd31963/html5/thumbnails/19.jpg)
Mrinal Deo - CS 395T - Spring 2011 19
Requirements of each Algorithm