Slide 1

Slide 1 text

Managed Runtime Systems Lecture 04: Memory Management (Continued) Foivos Zakkak https://foivos.zakkak.net Except where otherwise noted, this presentation is licensed under the Creative Commons Attribution 4.0 International License. Third party marks and brands are the property of their respective holders.

Slide 2

Slide 2 text

Acknowledgments The following slides are based on the corresponding slides of Mario Walczko about Memory Management: Memory management part 1 Memory management part 2 Memory management debugging hints Managed Runtime Systems 1 of 13 https://foivos.zakkak.net

Slide 3

Slide 3 text

The Tri-color Abstraction Color each object depending on its current state Initially all objects are white (non processed) Each time an object gets traced it gets colored gray After an object has been scanned it gets colored black Managed Runtime Systems 2 of 13 https://foivos.zakkak.net

Slide 4

Slide 4 text

Tri-Color Tracing roots A B C D E F G H A H F A D G H F E D E G Managed Runtime Systems 3 of 13 https://foivos.zakkak.net

Slide 5

Slide 5 text

Tri-Color Tracing roots A B C D E F G H A H F A D G H F E D E G Managed Runtime Systems 3 of 13 https://foivos.zakkak.net

Slide 6

Slide 6 text

Tri-Color Tracing roots A B C D E F G H A H F A D G H F E D E G Managed Runtime Systems 3 of 13 https://foivos.zakkak.net

Slide 7

Slide 7 text

Tri-Color Tracing roots A B C D E F G H A H F A D G H F E D E G Managed Runtime Systems 3 of 13 https://foivos.zakkak.net

Slide 8

Slide 8 text

Tri-Color Tracing roots A B C D E F G H A H F A D G H F E D E G Managed Runtime Systems 3 of 13 https://foivos.zakkak.net

Slide 9

Slide 9 text

Tri-Color Tracing roots A B C D E F G H A H F A D G H F E D E G Managed Runtime Systems 3 of 13 https://foivos.zakkak.net

Slide 10

Slide 10 text

Tri-Color Tracing roots A B C D E F G H A H F A D G H F E D E G Managed Runtime Systems 3 of 13 https://foivos.zakkak.net

Slide 11

Slide 11 text

Tri-Color Tracing roots A B C D E F G H A H F A D G H F E D E G Managed Runtime Systems 3 of 13 https://foivos.zakkak.net

Slide 12

Slide 12 text

Tri-Color Tracing roots A B C D E F G H A H F A D G H F E D E G Managed Runtime Systems 3 of 13 https://foivos.zakkak.net

Slide 13

Slide 13 text

Tri-Color Tracing roots A B C D E F G H A H F A D G H F E D E G Managed Runtime Systems 3 of 13 https://foivos.zakkak.net

Slide 14

Slide 14 text

Tri-Color Tracing roots A B C D E F G H A H F A D G H F E D E G Managed Runtime Systems 3 of 13 https://foivos.zakkak.net

Slide 15

Slide 15 text

Tri-Color Tracing roots A B C D E F G H A H F A D G H F E D E G Managed Runtime Systems 3 of 13 https://foivos.zakkak.net

Slide 16

Slide 16 text

Tri-Color Tracing roots A B C D E F G H A H F A D G H F E D E G Managed Runtime Systems 3 of 13 https://foivos.zakkak.net

Slide 17

Slide 17 text

Tri-Color Tracing roots A B C D E F G H A H F A D G H F E D E G Managed Runtime Systems 3 of 13 https://foivos.zakkak.net

Slide 18

Slide 18 text

Tri-Color Tracing roots A B C D E F G H A H F A D G H F E D E G Managed Runtime Systems 3 of 13 https://foivos.zakkak.net

Slide 19

Slide 19 text

Copying Tri-color roots From To To From A B C D C B D C B D Managed Runtime Systems 4 of 13 https://foivos.zakkak.net

Slide 20

Slide 20 text

Copying Tri-color roots From To To From A B C D C B D C B D Managed Runtime Systems 4 of 13 https://foivos.zakkak.net

Slide 21

Slide 21 text

Copying Tri-color roots From To To From A B C D C B D C B D Managed Runtime Systems 4 of 13 https://foivos.zakkak.net

Slide 22

Slide 22 text

Copying Tri-color roots From To To From A B C D C B D C B D Managed Runtime Systems 4 of 13 https://foivos.zakkak.net

Slide 23

Slide 23 text

Copying Tri-color roots From To To From A B C D C B D C B D Managed Runtime Systems 4 of 13 https://foivos.zakkak.net

Slide 24

Slide 24 text

Copying Tri-color roots From To To From A B C D C B D C B D Managed Runtime Systems 4 of 13 https://foivos.zakkak.net

Slide 25

Slide 25 text

Copying Tri-color roots From To To From A B C D C B D C B D Managed Runtime Systems 4 of 13 https://foivos.zakkak.net

Slide 26

Slide 26 text

Copying Tri-color roots From To To From A B C D C B D C B D Managed Runtime Systems 4 of 13 https://foivos.zakkak.net

Slide 27

Slide 27 text

Copying Tri-color roots From To To From A B C D C B D C B D Managed Runtime Systems 4 of 13 https://foivos.zakkak.net

Slide 28

Slide 28 text

Copying Tri-color roots From To To From A B C D C B D C B D Managed Runtime Systems 4 of 13 https://foivos.zakkak.net

Slide 29

Slide 29 text

Main Advantage of the Tri-Color Abstraction Allows for incremental garbage collections Reduce the length of stop-the-world pauses Mutator threads and GC-scanning threads can run concurrently More on incremental and concurrent GCs on future lectures! Managed Runtime Systems 5 of 13 https://foivos.zakkak.net

Slide 30

Slide 30 text

Main Drawback of Semi-space Collectors They require twice the memory!!! Managed Runtime Systems 6 of 13 https://foivos.zakkak.net

Slide 31

Slide 31 text

Main Drawback of Semi-space Collectors They require twice the memory!!! and They copy long-lived data all the time!!! Managed Runtime Systems 6 of 13 https://foivos.zakkak.net

Slide 32

Slide 32 text

The Generatinal Hypothesis Most objects die young! Managed Runtime Systems 7 of 13 https://foivos.zakkak.net

Slide 33

Slide 33 text

The Generatinal Hypothesis Most objects die young! What if we could collect young objects separately? Managed Runtime Systems 7 of 13 https://foivos.zakkak.net

Slide 34

Slide 34 text

Generational Collectors Further slice the heap in generations (usually eden, young, and old) Move surviving objects to older generation (called tenuring) Occasionally perform a full mark-and-sweep collection Managed Runtime Systems 8 of 13 https://foivos.zakkak.net

Slide 35

Slide 35 text

Generational Collectors Eden Young Old A B C D E F G H D F I J K L M D K D K L Managed Runtime Systems 9 of 13 https://foivos.zakkak.net

Slide 36

Slide 36 text

Generational Collectors Eden Young Old A B C D E F G H D F I J K L M D K D K L Managed Runtime Systems 9 of 13 https://foivos.zakkak.net

Slide 37

Slide 37 text

Generational Collectors Eden Young Old A B C D E F G H D F I J K L M D K D K L Managed Runtime Systems 9 of 13 https://foivos.zakkak.net

Slide 38

Slide 38 text

Generational Collectors Eden Young Old A B C D E F G H D F I J K L M D K D K L Managed Runtime Systems 9 of 13 https://foivos.zakkak.net

Slide 39

Slide 39 text

Generational Collectors Eden Young Old A B C D E F G H D F I J K L M D K D K L Managed Runtime Systems 9 of 13 https://foivos.zakkak.net

Slide 40

Slide 40 text

Generational Collectors Eden Young Old A B C D E F G H D F I J K L M D K D K L Managed Runtime Systems 9 of 13 https://foivos.zakkak.net

Slide 41

Slide 41 text

Generational Collectors Eden Young Old A B C D E F G H D F I J K L M D K D K L Managed Runtime Systems 9 of 13 https://foivos.zakkak.net

Slide 42

Slide 42 text

Generational Collectors Eden Young Old A B C D E F G H D F I J K L M D K D K L Managed Runtime Systems 9 of 13 https://foivos.zakkak.net

Slide 43

Slide 43 text

Generational Collectors Eden Young Old A B C D E F G H D F I J K L M D K D K L Managed Runtime Systems 9 of 13 https://foivos.zakkak.net

Slide 44

Slide 44 text

Generational Collectors Eden Young Old A B C D E F G H D F I J K L M D K D K L Managed Runtime Systems 9 of 13 https://foivos.zakkak.net

Slide 45

Slide 45 text

Generational Collectors Eden Young Old A B C D E F G H D F I J K L M D K D K L Managed Runtime Systems 9 of 13 https://foivos.zakkak.net

Slide 46

Slide 46 text

Generational Collectors Eden Young Old A B C D E F G H D F I J K L M D K D K L Managed Runtime Systems 9 of 13 https://foivos.zakkak.net

Slide 47

Slide 47 text

Generational Collectors Eden Young Old A B C D E F G H D F I J K L M D K D K L Managed Runtime Systems 9 of 13 https://foivos.zakkak.net

Slide 48

Slide 48 text

Generational Collectors Eden Young Old A B C D E F G H D F I J K L M D K D K L Managed Runtime Systems 9 of 13 https://foivos.zakkak.net

Slide 49

Slide 49 text

Generational Collectors Eden Young Old A B C D E F G H D F I J K L M D K D K L Managed Runtime Systems 9 of 13 https://foivos.zakkak.net

Slide 50

Slide 50 text

Keeping Track of Old to Young References Avoid scanning old generation at young collections Keep a set of old-to-young references (called remembered set) Monitor writes to reference fields of old objects (called write-barrier) Managed Runtime Systems 10 of 13 https://foivos.zakkak.net

Slide 51

Slide 51 text

Card Marking write-barriers Keep a bit per memory block of old generation The bit indicates whether objects in the block reference young objects The card gets reset in every collection Managed Runtime Systems 11 of 13 https://foivos.zakkak.net

Slide 52

Slide 52 text

Generational Collection in Action 2 4 6 8 10 12 14 16 18 20 Perm Gen Old Gen New Gen Code Others VM Fig. 4: javac D- & E-cache contents, and heap usage 0 2 4 6 8 10 12 14 16 18 20 22 0 0.1 0.2 0.3 0.4 Cache 0 2 4 6 8 10 12 14 16 18 20 22 0 2 4 6 8 10 12 14 16 18 20 22 Cycles (billions) Heap Usage (MB) Fig. 7 Table 1 Fig. 8 E Figure Source: Introspection of a Java Virtual Machine under Simulation, Wright et al, Sun Labs TR-2006-159 Managed Runtime Systems 12 of 13 https://foivos.zakkak.net

Slide 53

Slide 53 text

Tuning Generational Garbage Collectors Tenuring threshold Allocating directly to old space Size of generations Old space collectors Managed Runtime Systems 13 of 13 https://foivos.zakkak.net