Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Overview Assignment 6: hints  Living with a garbage collector Assignment 5: solution  Garbage collection.

Similar presentations


Presentation on theme: "1 Overview Assignment 6: hints  Living with a garbage collector Assignment 5: solution  Garbage collection."— Presentation transcript:

1 1 Overview Assignment 6: hints  Living with a garbage collector Assignment 5: solution  Garbage collection

2 2 Ex1– Memory Allocation in.NET Object B Object C NextObjPtr Object D Object E Object F Object A

3 3 Mark Phase Object A Object B Object C NextObjPtr Object D Object E Object F ROOTS globals locals registers

4 4 Copy Phase Object A Object B Object C NextObjPtr Object D Object E Object F ROOTS globals locals registers

5 5 Finalizers public class MyClass { public override void Finalize() { // Clean up the object }

6 6 Finalizers Freachable Queue Object A Object B Object C NextObjPtr Object D Object E Object F ROOTS globals locals registers Finalization Queue Object F Object A

7 7 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?

8 8 A6 Ex2 – Generations Object A Object B Object C NextObjPtr Object D Object E Object F Object G Object H Object I Object J Object L Gen 0 Gen 1

9 9 Generations / Write Barriers The compiler instruments the code to implement a write barrier. Think of a more efficient implementation of a write barrier.

10 10 A6 Ex3– Weak Pointers (.Net) Weak Pointer Tables Object A Object B Object C NextObjPtr Object D Object E Object F ROOTS globals locals registers Object F

11 11 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?

12 12 Overview Assignment 6: hints  Living with a garbage collector Assignment 5: solution  Garbage collection

13 13 A5 Ex1 - Barriers read write Read barrier: if pointer is forwarding follow the forwarding load pointer Write barrier: if p is black & q not black mark p gray write pointer p.next = q

14 14 A5 Ex1 - Barriers Which barrier to use for:  Incremental copying GC Read and write barriers  Mark & Sweep GC No barriers

15 15 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.

16 16 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


Download ppt "1 Overview Assignment 6: hints  Living with a garbage collector Assignment 5: solution  Garbage collection."

Similar presentations


Ads by Google