160 likes | 309 Views
Overview. Assignment 6: hints Living with a garbage collector Assignment 5: solution Garbage collection. Ex1– Memory Allocation in .NET. Object F. Object E. Object D. NextObjPtr. Object C. Object B. Object A. Mark Phase. NextObjPtr. Object F. ROOTS globals locals registers.
E N D
Overview • Assignment 6: hints • Living with a garbage collector • Assignment 5: solution • Garbage collection
Ex1– Memory Allocation in .NET Object F Object E Object D NextObjPtr Object C Object B Object A
Mark Phase NextObjPtr Object F ROOTS globals locals registers Object E Object D Object C Object B Object A
Copy Phase NextObjPtr Object F ROOTS globals locals registers Object E Object D Object C Object B Object A
Finalizers public class MyClass { public override void Finalize() { // Clean up the object } }
Finalizers Finalization Queue Object A NextObjPtr Object F Object F ROOTS globals locals registers Object E Freachable Queue Object D Object C Object B Object A
Finalizers in the .Net system • Why finalize methods are not executed by the GC? • How to resuscitate objects in their finalizer method? • Does the execution order of the finalizers matter?
A6 Ex2 – Generations NextObjPtr Object J Object I Gen 0 Object H Object L Object G Object F Object E Gen 1 Object D Object C Object B Object A
Generations / Write Barriers The compiler instruments the code to implement a write barrier. • Think of a more efficient implementation of a write barrier.
A6 Ex3– Weak Pointers (.Net) NextObjPtr Object F ROOTS globals locals registers Object E Weak Pointer Tables Object D Object C Object B Object F Object A
A6 – Weak Pointers • Weak pointers in .NET: • users have to check if a weak pointer is still valid. • Weak pointers in Java and Python • users can be notified when a weak pointer is invalidated. • Advantages / disadvantages? • Examples?
Overview • Assignment 6: hints • Living with a garbage collector • Assignment 5: solution • Garbage collection
A5 Ex1 - Barriers p.next = q Read barrier: if pointer is forwarding follow the forwarding load pointer read write Write barrier: if p is black & q not black mark p gray write pointer
A5 Ex1 - Barriers • Which barrier to use for: • Incremental copying GC • Read and write barriers • Mark & Sweep GC • No barriers
A5 Ex2 – Copying collectors • How to solve the movement problem for the compacting and copying GC. • Copying GC: obj. moved to to-space, install forwarding pointer, update other pointers on forwarding pointer read. • Compacting GC: update pointers after mark, before the move operation.
A5 Ex2 – Copying collectors Mark & Sweep vs. Copying GCs: • Which collector has the fastest allocation? • M&S: traverse the list of free blocks • Copying: just allocate on top of the other objects (O(1)) • Give an estimate of the collection cycle cost (M = heap size, R = live objects) • M&S: R to mark, M to sweep R + M • Copying: move R objects R