Garbage CollectionGuido Wachsmuth       Delft                                    Course IN4303       University of       T...
Recapregister allocationHow can we assign registers to local variables and temporaries?  •   perform liveness analysis  • ...
Overviewtoday’s lecturegarbage collection                     Garbage Collection   3
Overviewtoday’s lecturegarbage collectionmark & sweep  •   mark reachable records  •   sweep unmarked records             ...
Overviewtoday’s lecturegarbage collectionmark & sweep  •   mark reachable records  •   sweep unmarked recordsreference cou...
Overviewtoday’s lecturegarbage collectionmark & sweep  •   mark reachable records  •   sweep unmarked recordsreference cou...
Igarbage collection                     Garbage Collection   4
the heap           Garbage Collection   5
Recap: Java Virtual Machinethe heap            method area                            stackpc: 00              constant po...
Recap: Java Virtual Machinethe heap            method area                            stackpc: 00    02              const...
Recap: Java Virtual Machinethe heap            method area                            stackpc: 00    04    02             ...
Recap: Java Virtual Machinethe heap            method area                            stackpc: 00    06    04    02       ...
Recap: Java Virtual Machinethe heap            method area                            stackpc: 00    07    06    04    02 ...
Heap  example12 ●   ●   15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9        20 ●     ●                              ...
IImark & sweep               Garbage Collection   8
Mark & sweepideamark  •     mark reachable records  •     start at variables (roots)  •     follow referencessweep  •     ...
Marking  example12 ●   ●   15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●                            ...
Marking  example12 ●   ●      15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●                         ...
Marking  example12 ●   ●      15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●                         ...
Marking  example12 ●   ●      15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●                         ...
Marking  example12 ●   ●      15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●                         ...
Marking  example12 ●   ●      15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●                         ...
Marking  example12 ●   ●      15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●                         ...
Marking  example12 ●   ●      15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●                         ...
Marking  example12 ●   ●      15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●                         ...
Marking  example12 ●   ●      15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●                         ...
Marking  example12 ●   ●      15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●                         ...
Marking  example12 ●   ●      15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●                         ...
Marking  example12 ●   ●      15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●                         ...
Marking  example12 ●   ●      15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●                         ...
Marking  example12 ●   ●      15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●                         ...
Marking  example12 ●   ●      15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●                         ...
Marking  example12 ●   ●      15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●                         ...
Marking  example12 ●   ●      15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●                         ...
Marking  example12 ●   ●      15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●                         ...
Marking  example12 ●   ●      15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●                         ...
Marking  example12 ●   ●      15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●                         ...
Marking  example12 ●   ●      15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●                         ...
Marking  example12 ●   ●      15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●                         ...
Marking  example12 ●   ●      15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●                         ...
Marking  example12 ●   ●      15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●                         ...
Marking  example12 ●   ●      15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●                         ...
Marking  example12 ●   ●      15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●                         ...
Marking  example12 ●   ●      15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●                         ...
Marking  example12 ●   ●      15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●                         ...
Marking  example12 ●   ●      15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●                         ...
Marking  example12 ●   ●      15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●                         ...
Sweeping  example12 ●   ●   15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●                           ...
Sweeping  example12 ●   ●     15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●                         ...
Sweeping  example12 ●   ●     15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●                         ...
Sweeping  example12 ●   ●     15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●                         ...
Sweeping  example12 ●   ●     15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●                         ...
Sweeping  example12 ●   ●     15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●                         ...
Sweeping  example12 ●   ●     15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●                         ...
Sweeping  example12 ●   ●     15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●                         ...
Sweeping  example12 ●   ●     15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●                         ...
Sweeping  example12 ●   ●     15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●                         ...
Sweeping  example12 ●   ●     15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●                         ...
Sweeping  example12 ●   ●     15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●                         ...
Markingalgorithmsfunction DFS(x)                function DFS(x)  if pointer(x) & !marked[x]     if pointer(x) & !marked[x]...
Recap: Marking  pointer reversals12 ●   ●   15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●           ...
Recap: Marking  pointer reversals12 ●   ●   15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●           ...
Recap: Marking  pointer reversals12 ●   ●   15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●           ...
Recap: Marking  pointer reversals12 ●   ●   15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●           ...
Recap: Marking  pointer reversals12 ●   ●   15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●           ...
Recap: Marking  pointer reversals12 ●   ●   15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●           ...
Recap: Marking  pointer reversals12 ●   ●   15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●           ...
Recap: Marking  pointer reversals12 ●   ●   15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●           ...
Recap: Marking  pointer reversals12 ●   ●   15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●           ...
Recap: Marking  pointer reversals12 ●   ●   15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●           ...
Recap: Marking  pointer reversals12 ●   ●   15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●           ...
Recap: Marking  pointer reversals12 ●   ●   15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●           ...
Recap: Marking  pointer reversals12 ●   ●   15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●           ...
Recap: Marking  pointer reversals12 ●   ●   15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●           ...
Recap: Marking  pointer reversals12 ●   ●   15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●           ...
Recap: Marking  pointer reversals12 ●   ●   15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●           ...
Recap: Marking  pointer reversals12 ●   ●   15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●           ...
Recap: Marking  pointer reversals12 ●   ●   15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●           ...
Recap: Marking  pointer reversals12 ●   ●   15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●           ...
Recap: Marking  pointer reversals12 ●   ●   15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●           ...
Recap: Marking  pointer reversals12 ●   ●   15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●           ...
Recap: Marking  pointer reversals12 ●   ●   15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●           ...
Recap: Marking  pointer reversals12 ●   ●   15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●           ...
Recap: Marking  pointer reversals12 ●   ●   15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●           ...
Recap: Marking  pointer reversals12 ●   ●   15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●           ...
Recap: Marking  pointer reversals12 ●   ●   15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●           ...
Recap: Marking  pointer reversals12 ●   ●   15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●           ...
Recap: Marking  pointer reversals12 ●   ●   15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●           ...
Recap: Marking  pointer reversals12 ●   ●   15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●           ...
Recap: Marking  pointer reversals12 ●   ●   15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●           ...
Mark & sweepnotessweeping  •   independent of marking algorithm  •   several freelists (per record size)  •   split free r...
IIIreference counts                   Garbage Collection 15
Reference countsideacounts  •      how many pointers point to each record?  •      store with each recordcounting  •      ...
Reference counts  example12 ●   ●   15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●                   ...
Reference counts  example12 1   ●   ●   15 1              ●   ●   ●17   37 2                               ●    ●   59 1  ...
Reference counts  example12 1   ●   ●   15 1              ●   ●   ●17   37 2                               ●    ●   59 1  ...
Reference countsnotescycles  •      memory leaks  •      break cycles explicitly  •      occasional mark & sweep collectio...
coffee break               Garbage Collection 19
IVcopy collections                   Garbage Collection 20
Copy collectionsideaspaces  •      fromspace & tospace  •      switch roles after copycopy  •      traverse reachability g...
Copy collection  example12 ●   ●   15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●                    ...
Copy collection  example12 ●   ●   15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●                    ...
Copy collection  example12 ●   ●   15 ●   ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●                    ...
Copy collection  example12 ●   ●   15 ●            ●     ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●     ...
Copy collection  example12 ●   ●   15 ●            ●     ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●     ...
Copy collection  example12 ●   ●   15 ●            ●     ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●     ...
Copy collection  example12 ●   ●   15 ●            ●     ●   ●   7   37 ●    ●   59 ●   ●    ●     9       20 ●     ●     ...
Copy collection  example12 ●   ●   15 ●            ●     ●   ●   7   37 ●                               ●      ●   59 ●   ...
Copy collection  example12 ●   ●   15 ●            ●     ●   ●   7   37 ●                               ●      ●   59 ●   ...
Copy collection  example12 ●   ●   15 ●            ●     ●   ●   7   37 ●                               ●      ●   59 ●   ...
Copy collection12 ●   ●   15 ●            ●     ●   ●   7   37 ●                               ●      ●   59 ●   ●    ●   ...
Copy collection12 ●   ●   15 ●            ●     ●   ●   7   37 ●                               ●      ●   59 ●   ●    ●   ...
Copy collection12 ●   ●   15 ●            ●     ●   ●   7   37 ●                               ●      ●   59 ●   ●    ●   ...
Copy collection12 ●   ●   15 ●            ●     ●   ●   7       37 ●                                   ●      ●   59 ●   ●...
Copy collection12 ● ●     ●   15 ●            ●     ●   ●   7       37 ●                                   ●      ●   59 ●...
Copy collection12 ● ●     ●   15 ●            ●     ●   ●   7       37 ●                                   ●      ●   59 ●...
Copy collection12 ● ●     ●   15 ●            ●     ●   ●   7       37 ●                                   ●      ●   59 ●...
Copy collection12 ● ●     ●   15 ●            ●     ●   ●   7       37 ●                                   ●      ●   59 ●...
Copy collection12 ● ●     ●   15 ●            ●     ●   ●   7       37 ●                                   ●      ●   59 ●...
Copy collection12 ● ●     ●   15 ●            ●     ●   ●   7       37 ●                                   ●      ●   59 ●...
Copy collection12 ● ●     ●   15 ●            ●     ●   ●   7       37 ●                                   ●      ●   59 ●...
Copy collection12 ● ●     ●   15 ●            ●     ●   ●   7       37 ●                                   ●      ●   59 ●...
Copy collection12 ● ●     ●   15 ●            ●     ●   ●   7       37 ●                                   ●      ●   59 ●...
Copy collection12 ● ●     ●   15 ●            ●     ●   ●   7       37 ●                                   ●      ●   59 ●...
Copy collection12 ● ●     ●   15 ●            ●     ●   ●   7       37 ●                                   ●      ●   59 ●...
Copy collection12 ● ●     ●   15 ●            ●     ●   ●   7       37 ●                                   ●      ●   59 ●...
Copy collection12 ● ●     ●   15 ●            ●     ●   ●   7       37 ●                                   ●      ●   59 ●...
Copy collection12 ● ●     ●   15 ●            ●     ●   ●   7       37 ●                                   ●      ●   59 ●...
Copy collection12 ● ●     ●   15 ●            ●     ●   ●   7       37 ●                                   ●      ●   59 ●...
Copy collection12 ● ●     ●   15 ●            ●     ●   ●   7       37 ●                                   ●      ●   59 ●...
Copy collection12 ● ●     ●   15 ●            ●     ●   ●   7       37 ●                                   ●      ●   59 ●...
Copy collection12 ● ●     ●   15 ●            ●     ●   ●   7       37 ●                                   ●      ●   59 ●...
Copy collection12 ● ●     ●   15 ●            ●     ●   ●   7       37 ●                                   ●      ●   59 ●...
Copy collection12 ● ●     ●   15 ●            ●     ●   ●   7       37 ●                                   ●      ●   59 ●...
Copy collection12 ● ●     ●   15 ●            ●     ●   ●   7       37 ●                                   ●      ●   59 ●...
Copy collection12 ● ●     ●   15 ●            ●     ●   ●   7       37 ●                                   ●      ●   59 ●...
Copy collection12 ● ●     ●   15 ●            ●     ●   ●   7       37 ●                                   ●      ●   59 ●...
Copy collection                                 ● 37 ●                                 p   q   r15 ●   ●   37 ●   ●   12 ●...
Copy collectionsalgorithmsfunction Forward(p)            function BFS()  if fromspace(p)               next = scan = start...
Copy collectionslocalityadjacent records  •   likely to be unrelatedpointers to records in records  •   likely to be acces...
Copy collectionsgenerational collectiongenerations   •   young data: likely to die soon   •   old data: likely to survive ...
Vsummary          Garbage Collection 27
Summarylessons learnedHow can we collect unreachable records on the heap?  •   reference counts  •   mark reachable record...
Literaturelearn moreAndrew W. Appel, Jens Palsberg: Modern CompilerImplementation in Java, 2nd edition. 2002              ...
Outlookcoming nextcompiler components and their generators  •   Lecture 11: Lexical Analysis  •   Lecture 12: Syntactical ...
questions            Garbage Collection 31
credits          Garbage Collection 32
PicturescopyrightsSlide 1:   Trash by Vladimer Shioshvili, some rights reservedSlide 5:   Gravel Pile by kenjonbro, some r...
Upcoming SlideShare
Loading in …5
×

Compiling Imperative and Object-Oriented Languages - Garbage Collection

1,773 views

Published on

Presentation slides for lecture 10 of course IN4303 on Compiler Construction at TU Delft.

Published in: Education
  • Be the first to comment

Compiling Imperative and Object-Oriented Languages - Garbage Collection

  1. 1. Garbage CollectionGuido Wachsmuth Delft Course IN4303 University of Technology Compiler Construction Challenge the future
  2. 2. Recapregister allocationHow can we assign registers to local variables and temporaries? • perform liveness analysis • build interference graph • colour interference graphWhat to do if the graph is not colourable? • keep local variables in memoryHow to handle move instructions efficiently? • coalesce nodes safely Garbage Collection 2
  3. 3. Overviewtoday’s lecturegarbage collection Garbage Collection 3
  4. 4. Overviewtoday’s lecturegarbage collectionmark & sweep • mark reachable records • sweep unmarked records Garbage Collection 3
  5. 5. Overviewtoday’s lecturegarbage collectionmark & sweep • mark reachable records • sweep unmarked recordsreference counting • deallocate records with count 0 Garbage Collection 3
  6. 6. Overviewtoday’s lecturegarbage collectionmark & sweep • mark reachable records • sweep unmarked recordsreference counting • deallocate records with count 0copy collection • copy reachable records • consider generations of records Garbage Collection 3
  7. 7. Igarbage collection Garbage Collection 4
  8. 8. the heap Garbage Collection 5
  9. 9. Recap: Java Virtual Machinethe heap method area stackpc: 00 constant pool optop: 00 local variables00 12 ldc 00 4303 4303 00 00 002A 002A01 00 00 01 0000 0004 01 0102 19 aload 02 02 0203 00 00 03 03 0304 12 ldc 04 04 0405 01 01 05 05 0506 2E iaload 06 06 06 heap4303 4303 "Compilers" 002A 002A [20,01,40,02,42] Garbage Collection 6
  10. 10. Recap: Java Virtual Machinethe heap method area stackpc: 00 02 constant pool optop: 00 01 local variables00 12 ldc 00 4303 4303 00 4303 4303 00 002A 002A01 00 00 01 0000 0004 01 0102 19 aload 02 02 0203 00 00 03 03 0304 12 ldc 04 04 0405 01 01 05 05 0506 2E iaload 06 06 06 heap4303 4303 "Compilers" 002A 002A [20,01,40,02,42] Garbage Collection 6
  11. 11. Recap: Java Virtual Machinethe heap method area stackpc: 00 04 02 constant pool optop: 00 02 01 local variables00 12 ldc 00 4303 4303 00 4303 4303 00 002A 002A01 00 00 01 0000 0004 01 002A 002A 0102 19 aload 02 02 0203 00 00 03 03 0304 12 ldc 04 04 0405 01 01 05 05 0506 2E iaload 06 06 06 heap4303 4303 "Compilers" 002A 002A [20,01,40,02,42] Garbage Collection 6
  12. 12. Recap: Java Virtual Machinethe heap method area stackpc: 00 06 04 02 constant pool optop: 00 03 02 01 local variables00 12 ldc 00 4303 4303 00 4303 4303 00 002A 002A01 00 00 01 0000 0004 01 002A 002A 0102 19 aload 02 02 0000 0004 0203 00 00 03 03 0304 12 ldc 04 04 0405 01 01 05 05 0506 2E iaload 06 06 06 heap4303 4303 "Compilers" 002A 002A [20,01,40,02,42] Garbage Collection 6
  13. 13. Recap: Java Virtual Machinethe heap method area stackpc: 00 07 06 04 02 constant pool optop: 00 02 01 local variables00 12 ldc 00 4303 4303 00 4303 4303 00 002A 002A01 00 00 01 0000 0004 01 002A 002A 0000 0042 0102 19 aload 02 02 0000 0004 0203 00 00 03 03 0304 12 ldc 04 04 0405 01 01 05 05 0506 2E iaload 06 06 06 heap4303 4303 "Compilers" 002A 002A [20,01,40,02,42] Garbage Collection 6
  14. 14. Heap example12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● p q r Garbage Collection 7
  15. 15. IImark & sweep Garbage Collection 8
  16. 16. Mark & sweepideamark • mark reachable records • start at variables (roots) • follow referencessweep • marked records: unmark • unmarked records: deallocate • linked list of free records Garbage Collection 9
  17. 17. Marking example12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● p q r Garbage Collection 10
  18. 18. Marking example12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● roots p q r Garbage Collection 10
  19. 19. Marking example12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● roots p q r Garbage Collection 10
  20. 20. Marking example12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● roots p q r Garbage Collection 10
  21. 21. Marking example12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● roots p q r Garbage Collection 10
  22. 22. Marking example12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● roots p q r Garbage Collection 10
  23. 23. Marking example12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● roots p q r Garbage Collection 10
  24. 24. Marking example12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● roots p q r Garbage Collection 10
  25. 25. Marking example12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● roots p q r Garbage Collection 10
  26. 26. Marking example12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● roots p q r Garbage Collection 10
  27. 27. Marking example12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● roots p q r Garbage Collection 10
  28. 28. Marking example12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● roots p q r Garbage Collection 10
  29. 29. Marking example12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● roots p q r Garbage Collection 10
  30. 30. Marking example12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● roots p q r Garbage Collection 10
  31. 31. Marking example12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● roots p q r Garbage Collection 10
  32. 32. Marking example12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● roots p q r Garbage Collection 10
  33. 33. Marking example12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● roots p q r Garbage Collection 10
  34. 34. Marking example12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● roots p q r Garbage Collection 10
  35. 35. Marking example12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● roots p q r Garbage Collection 10
  36. 36. Marking example12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● roots p q r Garbage Collection 10
  37. 37. Marking example12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● roots p q r Garbage Collection 10
  38. 38. Marking example12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● roots p q r Garbage Collection 10
  39. 39. Marking example12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● roots p q r Garbage Collection 10
  40. 40. Marking example12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● roots p q r Garbage Collection 10
  41. 41. Marking example12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● roots p q r Garbage Collection 10
  42. 42. Marking example12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● roots p q r Garbage Collection 10
  43. 43. Marking example12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● roots p q r Garbage Collection 10
  44. 44. Marking example12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● roots p q r Garbage Collection 10
  45. 45. Marking example12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● roots p q r Garbage Collection 10
  46. 46. Marking example12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● roots p q r Garbage Collection 10
  47. 47. Marking example12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● roots p q r Garbage Collection 10
  48. 48. Sweeping example12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● p q r Garbage Collection 11
  49. 49. Sweeping example12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● ● 37 ● freelist f p q r Garbage Collection 11
  50. 50. Sweeping example12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● ● 37 ● freelist f p q r Garbage Collection 11
  51. 51. Sweeping example12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● ● 37 ● freelist f p q r Garbage Collection 11
  52. 52. Sweeping example12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● ● 37 ● freelist f p q r Garbage Collection 11
  53. 53. Sweeping example12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● ● 37 ● freelist f p q r Garbage Collection 11
  54. 54. Sweeping example12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● ● 37 ● freelist f p q r Garbage Collection 11
  55. 55. Sweeping example12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● ● 37 ● freelist f p q r Garbage Collection 11
  56. 56. Sweeping example12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● ● 37 ● freelist f p q r Garbage Collection 11
  57. 57. Sweeping example12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● ● 37 ● freelist f p q r Garbage Collection 11
  58. 58. Sweeping example12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● ● 37 ● freelist f p q r Garbage Collection 11
  59. 59. Sweeping example12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● ● 37 ● freelist f p q r Garbage Collection 11
  60. 60. Markingalgorithmsfunction DFS(x) function DFS(x) if pointer(x) & !marked[x] if pointer(x) & !marked[x] marked[x] = true marked[x] = true t = 1 ; stack[t] = x foreach f in fields(x) while t > 0 DFS(f) x = stack[t] ; t = t - 1 foreach f in fields(x) if pointer(f) & !marked[f] marked[f] = true t = t + 1 ; stack[t] = f Garbage Collection 12
  61. 61. Recap: Marking pointer reversals12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● p q r Garbage Collection 13
  62. 62. Recap: Marking pointer reversals12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● p q r Garbage Collection 13
  63. 63. Recap: Marking pointer reversals12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● p q r Garbage Collection 13
  64. 64. Recap: Marking pointer reversals12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● p q r Garbage Collection 13
  65. 65. Recap: Marking pointer reversals12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● p q r Garbage Collection 13
  66. 66. Recap: Marking pointer reversals12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● p q r Garbage Collection 13
  67. 67. Recap: Marking pointer reversals12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● p q r Garbage Collection 13
  68. 68. Recap: Marking pointer reversals12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● p q r Garbage Collection 13
  69. 69. Recap: Marking pointer reversals12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● p q r Garbage Collection 13
  70. 70. Recap: Marking pointer reversals12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● p q r Garbage Collection 13
  71. 71. Recap: Marking pointer reversals12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● p q r Garbage Collection 13
  72. 72. Recap: Marking pointer reversals12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● p q r Garbage Collection 13
  73. 73. Recap: Marking pointer reversals12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● p q r Garbage Collection 13
  74. 74. Recap: Marking pointer reversals12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● p q r Garbage Collection 13
  75. 75. Recap: Marking pointer reversals12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● p q r Garbage Collection 13
  76. 76. Recap: Marking pointer reversals12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● p q r Garbage Collection 13
  77. 77. Recap: Marking pointer reversals12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● p q r Garbage Collection 13
  78. 78. Recap: Marking pointer reversals12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● p q r Garbage Collection 13
  79. 79. Recap: Marking pointer reversals12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● p q r Garbage Collection 13
  80. 80. Recap: Marking pointer reversals12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● p q r Garbage Collection 13
  81. 81. Recap: Marking pointer reversals12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● p q r Garbage Collection 13
  82. 82. Recap: Marking pointer reversals12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● p q r Garbage Collection 13
  83. 83. Recap: Marking pointer reversals12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● p q r Garbage Collection 13
  84. 84. Recap: Marking pointer reversals12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● p q r Garbage Collection 13
  85. 85. Recap: Marking pointer reversals12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● p q r Garbage Collection 13
  86. 86. Recap: Marking pointer reversals12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● p q r Garbage Collection 13
  87. 87. Recap: Marking pointer reversals12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● p q r Garbage Collection 13
  88. 88. Recap: Marking pointer reversals12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● p q r Garbage Collection 13
  89. 89. Recap: Marking pointer reversals12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● p q r Garbage Collection 13
  90. 90. Recap: Marking pointer reversals12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● p q r Garbage Collection 13
  91. 91. Mark & sweepnotessweeping • independent of marking algorithm • several freelists (per record size) • split free records for allocationfragmentation • external: many free records of small size • internal: too-large record with unused memory inside Garbage Collection 14
  92. 92. IIIreference counts Garbage Collection 15
  93. 93. Reference countsideacounts • how many pointers point to each record? • store with each recordcounting • extra instructionsdeallocate • put on freelist • recursive deallocation on allocation Garbage Collection 16
  94. 94. Reference counts example12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● p q r Garbage Collection 17
  95. 95. Reference counts example12 1 ● ● 15 1 ● ● ●17 37 2 ● ● 59 1 ● ● ●19 20 1 ● ● ● 37 ● p q r Garbage Collection 17
  96. 96. Reference counts example12 1 ● ● 15 1 ● ● ●17 37 2 ● ● 59 1 ● ● ●19 20 1 ● ● ● 37 ● p q r Garbage Collection 17
  97. 97. Reference countsnotescycles • memory leaks • break cycles explicitly • occasional mark & sweep collectionexpensive • fetch, decrease, store old reference counter • possible deallocation • fetch, increase, store new reference counter Garbage Collection 18
  98. 98. coffee break Garbage Collection 19
  99. 99. IVcopy collections Garbage Collection 20
  100. 100. Copy collectionsideaspaces • fromspace & tospace • switch roles after copycopy • traverse reachability graph • copy from fromspace to tospace • fromspace unreachable, free memory • tospace compact, no fragmentation Garbage Collection 21
  101. 101. Copy collection example12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● p q r Garbage Collection 22
  102. 102. Copy collection example12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● p q r Garbage Collection 22
  103. 103. Copy collection example12 ● ● 15 ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● p q r15 ● ● Garbage Collection 22
  104. 104. Copy collection example12 ● ● 15 ● ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● p q r15 ● ● Garbage Collection 22
  105. 105. Copy collection example12 ● ● 15 ● ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● p q r15 ● ● Garbage Collection 22
  106. 106. Copy collection example12 ● ● 15 ● ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● p q r15 ● ● Garbage Collection 22
  107. 107. Copy collection example12 ● ● 15 ● ● ● ● 7 37 ● ● 59 ● ● ● 9 20 ● ● ● 37 ● p q r15 ● ● 37 ● ● Garbage Collection 22
  108. 108. Copy collection example12 ● ● 15 ● ● ● ● 7 37 ● ● ● 59 ● ● ● 9 20 ● ● ● 37 ● p q r15 ● ● 37 ● ● Garbage Collection 22
  109. 109. Copy collection example12 ● ● 15 ● ● ● ● 7 37 ● ● ● 59 ● ● ● 9 20 ● ● ● 37 ● p q r15 ● ● 37 ● ● Garbage Collection 22
  110. 110. Copy collection example12 ● ● 15 ● ● ● ● 7 37 ● ● ● 59 ● ● ● 9 20 ● ● ● 37 ● p q r15 ● ● 37 ● ● Garbage Collection 22
  111. 111. Copy collection12 ● ● 15 ● ● ● ● 7 37 ● ● ● 59 ● ● ● 9 20 ● ● ● 37 ● p q r15 ● ● 37 ● ● Garbage Collection 23
  112. 112. Copy collection12 ● ● 15 ● ● ● ● 7 37 ● ● ● 59 ● ● ● 9 20 ● ● ● 37 ● p q r15 ● ● 37 ● ● Garbage Collection 23
  113. 113. Copy collection12 ● ● 15 ● ● ● ● 7 37 ● ● ● 59 ● ● ● 9 20 ● ● ● 37 ● p q r15 ● ● 37 ● ● Garbage Collection 23
  114. 114. Copy collection12 ● ● 15 ● ● ● ● 7 37 ● ● ● 59 ● ● ● 9 20 ● ● ● 37 ● p q r15 ● ● 37 ● ● 12 ● ● Garbage Collection 23
  115. 115. Copy collection12 ● ● ● 15 ● ● ● ● 7 37 ● ● ● 59 ● ● ● 9 20 ● ● ● 37 ● p q r15 ● ● 37 ● ● 12 ● ● Garbage Collection 23
  116. 116. Copy collection12 ● ● ● 15 ● ● ● ● 7 37 ● ● ● 59 ● ● ● 9 20 ● ● ● 37 ● p q r15 ● ● 37 ● ● 12 ● ● Garbage Collection 23
  117. 117. Copy collection12 ● ● ● 15 ● ● ● ● 7 37 ● ● ● 59 ● ● ● 9 20 ● ● ● 37 ● p q r15 ● ● 37 ● ● 12 ● ● Garbage Collection 23
  118. 118. Copy collection12 ● ● ● 15 ● ● ● ● 7 37 ● ● ● 59 ● ● ● 9 20 ● ● ● 37 ● p q r15 ● ● 37 ● ● 12 ● ● Garbage Collection 23
  119. 119. Copy collection12 ● ● ● 15 ● ● ● ● 7 37 ● ● ● 59 ● ● ● 9 20 ● ● ● 37 ● p q r15 ● ● 37 ● ● 12 ● ● Garbage Collection 23
  120. 120. Copy collection12 ● ● ● 15 ● ● ● ● 7 37 ● ● ● 59 ● ● ● 9 20 ● ● ● 37 ● p q r15 ● ● 37 ● ● 12 ● ● Garbage Collection 23
  121. 121. Copy collection12 ● ● ● 15 ● ● ● ● 7 37 ● ● ● 59 ● ● ● 9 20 ● ● ● 37 ● p q r15 ● ● 37 ● ● 12 ● ● 20 ● ● Garbage Collection 23
  122. 122. Copy collection12 ● ● ● 15 ● ● ● ● 7 37 ● ● ● 59 ● ● ● 9 20 ● ● ● ● 37 ● p q r15 ● ● 37 ● ● 12 ● ● 20 ● ● Garbage Collection 23
  123. 123. Copy collection12 ● ● ● 15 ● ● ● ● 7 37 ● ● ● 59 ● ● ● 9 20 ● ● ● ● 37 ● p q r15 ● ● 37 ● ● 12 ● ● 20 ● ● Garbage Collection 23
  124. 124. Copy collection12 ● ● ● 15 ● ● ● ● 7 37 ● ● ● 59 ● ● ● 9 20 ● ● ● ● 37 ● p q r15 ● ● 37 ● ● 12 ● ● 20 ● ● Garbage Collection 23
  125. 125. Copy collection12 ● ● ● 15 ● ● ● ● 7 37 ● ● ● 59 ● ● ● 9 20 ● ● ● ● 37 ● p q r15 ● ● 37 ● ● 12 ● ● 20 ● ● 59 ● ● Garbage Collection 23
  126. 126. Copy collection12 ● ● ● 15 ● ● ● ● 7 37 ● ● ● 59 ● ● ● ● 9 20 ● ● ● ● 37 ● p q r15 ● ● 37 ● ● 12 ● ● 20 ● ● 59 ● ● Garbage Collection 23
  127. 127. Copy collection12 ● ● ● 15 ● ● ● ● 7 37 ● ● ● 59 ● ● ● ● 9 20 ● ● ● ● 37 ● p q r15 ● ● 37 ● ● 12 ● ● 20 ● ● 59 ● ● Garbage Collection 23
  128. 128. Copy collection12 ● ● ● 15 ● ● ● ● 7 37 ● ● ● 59 ● ● ● ● 9 20 ● ● ● ● 37 ● p q r15 ● ● 37 ● ● 12 ● ● 20 ● ● 59 ● ● Garbage Collection 23
  129. 129. Copy collection12 ● ● ● 15 ● ● ● ● 7 37 ● ● ● 59 ● ● ● ● 9 20 ● ● ● ● 37 ● p q r15 ● ● 37 ● ● 12 ● ● 20 ● ● 59 ● ● Garbage Collection 23
  130. 130. Copy collection12 ● ● ● 15 ● ● ● ● 7 37 ● ● ● 59 ● ● ● ● 9 20 ● ● ● ● 37 ● p q r15 ● ● 37 ● ● 12 ● ● 20 ● ● 59 ● ● Garbage Collection 23
  131. 131. Copy collection12 ● ● ● 15 ● ● ● ● 7 37 ● ● ● 59 ● ● ● ● 9 20 ● ● ● ● 37 ● p q r15 ● ● 37 ● ● 12 ● ● 20 ● ● 59 ● ● Garbage Collection 23
  132. 132. Copy collection12 ● ● ● 15 ● ● ● ● 7 37 ● ● ● 59 ● ● ● ● 9 20 ● ● ● ● 37 ● p q r15 ● ● 37 ● ● 12 ● ● 20 ● ● 59 ● ● Garbage Collection 23
  133. 133. Copy collection12 ● ● ● 15 ● ● ● ● 7 37 ● ● ● 59 ● ● ● ● 9 20 ● ● ● ● 37 ● p q r15 ● ● 37 ● ● 12 ● ● 20 ● ● 59 ● ● Garbage Collection 23
  134. 134. Copy collection12 ● ● ● 15 ● ● ● ● 7 37 ● ● ● 59 ● ● ● ● 9 20 ● ● ● ● 37 ● p q r15 ● ● 37 ● ● 12 ● ● 20 ● ● 59 ● ● Garbage Collection 23
  135. 135. Copy collection12 ● ● ● 15 ● ● ● ● 7 37 ● ● ● 59 ● ● ● ● 9 20 ● ● ● ● 37 ● p q r15 ● ● 37 ● ● 12 ● ● 20 ● ● 59 ● ● Garbage Collection 23
  136. 136. Copy collection12 ● ● ● 15 ● ● ● ● 7 37 ● ● ● 59 ● ● ● ● 9 20 ● ● ● ● 37 ● p q r15 ● ● 37 ● ● 12 ● ● 20 ● ● 59 ● ● Garbage Collection 23
  137. 137. Copy collection12 ● ● ● 15 ● ● ● ● 7 37 ● ● ● 59 ● ● ● ● 9 20 ● ● ● ● 37 ● p q r15 ● ● 37 ● ● 12 ● ● 20 ● ● 59 ● ● Garbage Collection 23
  138. 138. Copy collection ● 37 ● p q r15 ● ● 37 ● ● 12 ● ● 20 ● ● 59 ● ● Garbage Collection 23
  139. 139. Copy collectionsalgorithmsfunction Forward(p) function BFS() if fromspace(p) next = scan = start(tospace) if tospace(fields(p)[1]) return fields(p)[1] foreach r in root() r = Forward(r) else while scan < next foreach f in fields(p) next.f = f foreach f in fields(scan) f = Forward(f) fields(p)[1] = next next = next + size(p) scan = scan + size(scan) return fields(p)[1] else return p Garbage Collection 24
  140. 140. Copy collectionslocalityadjacent records • likely to be unrelatedpointers to records in records • likely to be accessed • likely to be far apartsolution • depth-first copy: slow pointer reversals • hybrid copy algorithm Garbage Collection 25
  141. 141. Copy collectionsgenerational collectiongenerations • young data: likely to die soon • old data: likely to survive for more collections • divide heap, collect younger generations more frequentlycollection • roots: variables & pointers from older to younger generations • preserve pointers to old generations • promote objects to older generations Garbage Collection 26
  142. 142. Vsummary Garbage Collection 27
  143. 143. Summarylessons learnedHow can we collect unreachable records on the heap? • reference counts • mark reachable records, sweep unreachable records • copy reachable recordsHow can we reduce heap space needed for garbage collection? • pointer-reversal • breadth-first search • hybrid algorithms Garbage Collection 28
  144. 144. Literaturelearn moreAndrew W. Appel, Jens Palsberg: Modern CompilerImplementation in Java, 2nd edition. 2002 Garbage Collection 29
  145. 145. Outlookcoming nextcompiler components and their generators • Lecture 11: Lexical Analysis • Lecture 12: Syntactical Analysis • Lecture 13: SDF inside • Lecture 14: Static AnalysisLab Nov 19 & Nov 26 • test cases • finish Lab 2, do reference resolution next • finish Lab 3, do hover help next • content completion Garbage Collection 30
  146. 146. questions Garbage Collection 31
  147. 147. credits Garbage Collection 32
  148. 148. PicturescopyrightsSlide 1: Trash by Vladimer Shioshvili, some rights reservedSlide 5: Gravel Pile by kenjonbro, some rights reservedSlide 19: Typhoo by Dominica Williamson, some rights reservedSlide 30: Romantic Pigeon Date by Harald Hoyer, some rights reservedSlide 31: Questions by Oberazzi, some rights reservedSlide 32: Too Much Credit by Andres Rueda, some rights reserved Garbage Collection 33

×