Copying Garbage Collection Guido Tack 14. November 2001 - - PowerPoint PPT Presentation

copying garbage collection
SMART_READER_LITE
LIVE PREVIEW

Copying Garbage Collection Guido Tack 14. November 2001 - - PowerPoint PPT Presentation

Copying Garbage Collection Guido Tack 14. November 2001 tack@ps.uni-sb.de 1 The idea of Copying GC Two semi-spaces ( From -space and To -space) Only From-space active At GC time, copy the live nodes from From-Space to


slide-1
SLIDE 1

Copying Garbage Collection

Guido Tack

  • 14. November 2001

tack@ps.uni-sb.de

slide-2
SLIDE 2

1 The idea of Copying GC

  • Two “semi-spaces“ (From-space and To-space)
  • Only From-space “active“
  • At GC time, copy the live nodes from From-Space to To-Space
  • Then “flip“ the spaces
slide-3
SLIDE 3

1 The idea of Copying GC

  • Two “semi-spaces“ (From-space and To-space)
  • Only From-space “active“
  • At GC time, copy the live nodes from From-Space to To-Space
  • Then “flip“ the spaces
slide-4
SLIDE 4

1 The idea of Copying GC

  • Two “semi-spaces“ (From-space and To-space)
  • Only From-space “active“
  • At GC time, copy the live nodes from From-Space to To-Space
  • Then “flip“ the spaces
slide-5
SLIDE 5

1 The idea of Copying GC

  • Two “semi-spaces“ (From-space and To-space)
  • Only From-space “active“
  • At GC time, copy the live nodes from From-Space to To-Space
  • Then “flip“ the spaces
slide-6
SLIDE 6

1 The idea of Copying GC

  • Two “semi-spaces“ (From-space and To-space)
  • Only From-space “active“
  • At GC time, copy the live nodes from From-Space to To-Space
  • Then “flip“ the spaces
slide-7
SLIDE 7

2 Before GC

A D E F G C B

From To

slide-8
SLIDE 8

3 After GC

To

B’ C’ A’ D’ E’ F’ G’ A D E F G C B

From

slide-9
SLIDE 9

4 Cheney’s algorithm(1)

  • Iterative algorithm
  • Interleaves copying and scanning
  • Two pointers needed: scan / free
  • Forwarding pointers used to preserve sharing
slide-10
SLIDE 10

4 Cheney’s algorithm(1)

  • Iterative algorithm
  • Interleaves copying and scanning
  • Two pointers needed: scan / free
  • Forwarding pointers used to preserve sharing
slide-11
SLIDE 11

4 Cheney’s algorithm(1)

  • Iterative algorithm
  • Interleaves copying and scanning
  • Two pointers needed: scan / free
  • Forwarding pointers used to preserve sharing
slide-12
SLIDE 12

4 Cheney’s algorithm(1)

  • Iterative algorithm
  • Interleaves copying and scanning
  • Two pointers needed: scan / free
  • Forwarding pointers used to preserve sharing
slide-13
SLIDE 13

4 Cheney’s algorithm(1)

  • Iterative algorithm
  • Interleaves copying and scanning
  • Two pointers needed: scan / free
  • Forwarding pointers used to preserve sharing
slide-14
SLIDE 14

5 Cheney’s algorithm(2)

Tricolour abstraction:

  • Black nodes: GC finished, not to be considered again
  • Grey nodes: Visited but not completed
  • White nodes: Unvisited, considered garbage after tracing

GC terminates when all reachable nodes are black

slide-15
SLIDE 15

5 Cheney’s algorithm(2)

Tricolour abstraction:

  • Black nodes: GC finished, not to be considered again
  • Grey nodes: Visited but not completed
  • White nodes: Unvisited, considered garbage after tracing

GC terminates when all reachable nodes are black

slide-16
SLIDE 16

5 Cheney’s algorithm(2)

Tricolour abstraction:

  • Black nodes: GC finished, not to be considered again
  • Grey nodes: Visited but not completed
  • White nodes: Unvisited, considered garbage after tracing

GC terminates when all reachable nodes are black

slide-17
SLIDE 17

5 Cheney’s algorithm(2)

Tricolour abstraction:

  • Black nodes: GC finished, not to be considered again
  • Grey nodes: Visited but not completed
  • White nodes: Unvisited, considered garbage after tracing

GC terminates when all reachable nodes are black

slide-18
SLIDE 18

5 Cheney’s algorithm(2)

Tricolour abstraction:

  • Black nodes: GC finished, not to be considered again
  • Grey nodes: Visited but not completed
  • White nodes: Unvisited, considered garbage after tracing

GC terminates when all reachable nodes are black

slide-19
SLIDE 19

5 Cheney’s algorithm(2)

Tricolour abstraction:

  • Black nodes: GC finished, not to be considered again
  • Grey nodes: Visited but not completed
  • White nodes: Unvisited, considered garbage after tracing

GC terminates when all reachable nodes are black

slide-20
SLIDE 20

A D E F G C B

From To

scan free

slide-21
SLIDE 21

A D E F G C B

From To

scan free

slide-22
SLIDE 22

A D E F G C B

From To

scan free

slide-23
SLIDE 23

A D E F G C B

From To

scan free

slide-24
SLIDE 24

A D E F G C B

From To

scan free

slide-25
SLIDE 25

A D E F G C B

From To

scan free

slide-26
SLIDE 26

A D E F G C B

From To

scan free

slide-27
SLIDE 27

A D E F G C B

From To

scan free

slide-28
SLIDE 28

A D E F G C B

From To

A’ A’

scan free

slide-29
SLIDE 29

A D E F G C B

From To

A’ A’

scan free

slide-30
SLIDE 30

A D E F G C B

From To

A’ A’

scan free

slide-31
SLIDE 31

A D E F G C B

From To

A’ A’

scan free

slide-32
SLIDE 32

A D E F G C B

From To

A’ A’

scan free

slide-33
SLIDE 33

A D E F G C B

From To

A’ A’

scan free

slide-34
SLIDE 34

A D E F G C B

From To

A’ A’ B’ B’

free scan

slide-35
SLIDE 35

A D E F G C B

From To

A’ A’ B’ B’

free scan

slide-36
SLIDE 36

A D E F G C B

From To

A’ A’ B’ B’

free scan

slide-37
SLIDE 37

A D E F G C B

From To

A’ A’ B’ B’

free scan

slide-38
SLIDE 38

A D E F G C B

From To

A’ A’ B’ B’

free scan

slide-39
SLIDE 39

A D E F G C B

From To

A’ A’ B’ B’

free scan

slide-40
SLIDE 40

A D E F G C B

From To

A’ A’ B’ B’ C’ C’

free scan

slide-41
SLIDE 41

A D E F G C B

From To

A’ B’ B’ C’ C’ A’

free scan

slide-42
SLIDE 42

A D E F G C B

From To

A’ B’ B’ C’ C’ A’

free scan

slide-43
SLIDE 43

A D E F G C B

From To

A’ B’ B’ C’ C’ A’

free scan

slide-44
SLIDE 44

A D E F G C B

From To

A’ B’ B’ C’ C’ A’

free scan

slide-45
SLIDE 45

A D E F G C B

From To

A’ B’ B’ C’ C’ A’

free scan

slide-46
SLIDE 46

A D E F G C B

From To

A’ B’ B’ C’ C’ A’ D’ D’

scan free

slide-47
SLIDE 47

A D E F G C B

From To

A’ B’ B’ C’ C’ A’ D’ D’

scan free

slide-48
SLIDE 48

A D E F G C B

From To

A’ B’ B’ C’ C’ A’ D’ D’

scan free

slide-49
SLIDE 49

A D E F G C B

From To

A’ B’ B’ C’ C’ A’ D’ D’

scan free

slide-50
SLIDE 50

A D E F G C B

From To

A’ B’ B’ C’ C’ A’ D’ D’

scan free

slide-51
SLIDE 51

A D E F G C B

From To

A’ B’ B’ C’ C’ A’ D’ D’ E’ E’

scan free

slide-52
SLIDE 52

A D E F G C B

From To

A’ B’ B’ C’ C’ A’ D’ D’ E’ E’

scan free

slide-53
SLIDE 53

A D E F G C B

From To

A’ B’ B’ C’ C’ A’ D’ D’ E’ E’

scan free

slide-54
SLIDE 54

A D E F G C B

From To

A’ B’ B’ C’ C’ A’ D’ D’ E’ E’

scan free

slide-55
SLIDE 55

A D E F G C B

From To

A’ B’ B’ C’ C’ A’ D’ D’ E’ E’

scan free

slide-56
SLIDE 56

A D E F G C B

From To

A’ B’ B’ C’ C’ A’ D’ D’ E’ E’ F’ F’

scan free

slide-57
SLIDE 57

A D E F G C B

From To

A’ B’ B’ C’ C’ A’ D’ D’ E’ E’ F’ F’

scan free

slide-58
SLIDE 58

A D E F G C B

From To

A’ B’ B’ C’ C’ A’ D’ D’ E’ E’ F’ F’

scan free

slide-59
SLIDE 59

A D E F G C B

From To

A’ B’ B’ C’ C’ A’ D’ D’ E’ E’ F’ F’

scan free

slide-60
SLIDE 60

A D E F G C B

From To

A’ B’ B’ C’ C’ A’ D’ D’ E’ E’ F’ F’

scan free

slide-61
SLIDE 61

A D E F G C B

From To

A’ B’ B’ C’ C’ A’ D’ D’ E’ E’ F’ F’

scan free

slide-62
SLIDE 62

A D E F G C B

From To

A’ B’ B’ C’ C’ A’ D’ D’ E’ E’ F’ F’ G’ G’

scan free

slide-63
SLIDE 63

A D E F G C B

From To

A’ B’ B’ C’ C’ A’ D’ D’ E’ E’ F’ F’ G’ G’

scan free

slide-64
SLIDE 64

A D E F G C B

From To

A’ B’ B’ C’ C’ A’ D’ D’ E’ E’ F’ F’ G’ G’

free scan

slide-65
SLIDE 65

A D E F G C B

From To

A’ B’ B’ C’ C’ A’ D’ D’ E’ E’ F’ F’ G’ G’

free scan

slide-66
SLIDE 66

A D E F G C B

From To

A’ B’ B’ C’ C’ A’ D’ D’ E’ E’ F’ F’ G’ G’

free scan

slide-67
SLIDE 67

A D E F G C B

From To

A’ B’ B’ C’ C’ A’ D’ D’ E’ E’ F’ F’ G’ G’

free scan

slide-68
SLIDE 68

A D E F G C B

From To

A’ B’ B’ C’ C’ A’ D’ D’ E’ E’ F’ F’ G’ G’

free scan

slide-69
SLIDE 69

6 Assumptions

  • Size of nodes known
  • Child fields known
  • Two logically contiguous areas for the heap
  • Ability to mark nodes
slide-70
SLIDE 70

6 Assumptions

  • Size of nodes known
  • Child fields known
  • Two logically contiguous areas for the heap
  • Ability to mark nodes
slide-71
SLIDE 71

6 Assumptions

  • Size of nodes known
  • Child fields known
  • Two logically contiguous areas for the heap
  • Ability to mark nodes
slide-72
SLIDE 72

6 Assumptions

  • Size of nodes known
  • Child fields known
  • Two logically contiguous areas for the heap
  • Ability to mark nodes
slide-73
SLIDE 73

6 Assumptions

  • Size of nodes known
  • Child fields known
  • Two logically contiguous areas for the heap
  • Ability to mark nodes
slide-74
SLIDE 74

7 Properties

  • Constant stack required
  • Time depends only on no. of live nodes
  • Covers cycles / sharing
  • Heap is compacted
  • Stop/start collector
  • Nothing to do between GCs
slide-75
SLIDE 75

7 Properties

  • Constant stack required
  • Time depends only on no. of live nodes
  • Covers cycles / sharing
  • Heap is compacted
  • Stop/start collector
  • Nothing to do between GCs
slide-76
SLIDE 76

7 Properties

  • Constant stack required
  • Time depends only on no. of live nodes
  • Covers cycles / sharing
  • Heap is compacted
  • Stop/start collector
  • Nothing to do between GCs
slide-77
SLIDE 77

7 Properties

  • Constant stack required
  • Time depends only on no. of live nodes
  • Covers cycles / sharing
  • Heap is compacted
  • Stop/start collector
  • Nothing to do between GCs
slide-78
SLIDE 78

7 Properties

  • Constant stack required
  • Time depends only on no. of live nodes
  • Covers cycles / sharing
  • Heap is compacted
  • Stop/start collector
  • Nothing to do between GCs
slide-79
SLIDE 79

7 Properties

  • Constant stack required
  • Time depends only on no. of live nodes
  • Covers cycles / sharing
  • Heap is compacted
  • Stop/start collector
  • Nothing to do between GCs
slide-80
SLIDE 80

7 Properties

  • Constant stack required
  • Time depends only on no. of live nodes
  • Covers cycles / sharing
  • Heap is compacted
  • Stop/start collector
  • Nothing to do between GCs
slide-81
SLIDE 81

8 Disadvantages

High Level

  • Copying large objects is expensive
  • Twice the logical memory needed

Low Level

  • Breadth first ⇒ decreased locality
  • Paging issues
slide-82
SLIDE 82

8 Disadvantages

High Level

  • Copying large objects is expensive
  • Twice the logical memory needed

Low Level

  • Breadth first ⇒ decreased locality
  • Paging issues
slide-83
SLIDE 83

8 Disadvantages

High Level

  • Copying large objects is expensive
  • Twice the logical memory needed

Low Level

  • Breadth first ⇒ decreased locality
  • Paging issues
slide-84
SLIDE 84

8 Disadvantages

High Level

  • Copying large objects is expensive
  • Twice the logical memory needed

Low Level

  • Breadth first ⇒ decreased locality
  • Paging issues
slide-85
SLIDE 85

8 Disadvantages

High Level

  • Copying large objects is expensive
  • Twice the logical memory needed

Low Level

  • Breadth first ⇒ decreased locality
  • Paging issues
slide-86
SLIDE 86

9 Variations(1)

  • Large Object Areas

(possibly handled by different collector)

  • Areas for long living objects

(only scanned, not copied)

  • Maintain locality by using other exploration strategies

(but then stack becomes an issue)

slide-87
SLIDE 87

9 Variations(1)

  • Large Object Areas

(possibly handled by different collector)

  • Areas for long living objects

(only scanned, not copied)

  • Maintain locality by using other exploration strategies

(but then stack becomes an issue)

slide-88
SLIDE 88

9 Variations(1)

  • Large Object Areas

(possibly handled by different collector)

  • Areas for long living objects

(only scanned, not copied)

  • Maintain locality by using other exploration strategies

(but then stack becomes an issue)

slide-89
SLIDE 89

9 Variations(1)

  • Large Object Areas

(possibly handled by different collector)

  • Areas for long living objects

(only scanned, not copied)

  • Maintain locality by using other exploration strategies

(but then stack becomes an issue)

slide-90
SLIDE 90

9 Variations(1)

  • Large Object Areas

(possibly handled by different collector)

  • Areas for long living objects

(only scanned, not copied)

  • Maintain locality by using other exploration strategies

(but then stack becomes an issue)

slide-91
SLIDE 91

9 Variations(1)

  • Large Object Areas

(possibly handled by different collector)

  • Areas for long living objects

(only scanned, not copied)

  • Maintain locality by using other exploration strategies

(but then stack becomes an issue)

slide-92
SLIDE 92

9 Variations(1)

  • Large Object Areas

(possibly handled by different collector)

  • Areas for long living objects

(only scanned, not copied)

  • Maintain locality by using other exploration strategies

(but then stack becomes an issue)

slide-93
SLIDE 93

10 Variations(2)

Approximately depth-first copying(1) Modification of Cheney’s agorithm by Moon (1984)

  • Always start scanning on the last partially filled page in To-space
  • When that page is completed, continue with ordinary scan
  • As soon as an object is copied, start partial scan again

scan partial free

slide-94
SLIDE 94

10 Variations(2)

Approximately depth-first copying(1) Modification of Cheney’s agorithm by Moon (1984)

  • Always start scanning on the last partially filled page in To-space
  • When that page is completed, continue with ordinary scan
  • As soon as an object is copied, start partial scan again

scan partial free

slide-95
SLIDE 95

10 Variations(2)

Approximately depth-first copying(1) Modification of Cheney’s agorithm by Moon (1984)

  • Always start scanning on the last partially filled page in To-space
  • When that page is completed, continue with ordinary scan
  • As soon as an object is copied, start partial scan again

scan partial free

slide-96
SLIDE 96

10 Variations(2)

Approximately depth-first copying(1) Modification of Cheney’s agorithm by Moon (1984)

  • Always start scanning on the last partially filled page in To-space
  • When that page is completed, continue with ordinary scan
  • As soon as an object is copied, start partial scan again

scan partial free

slide-97
SLIDE 97

10 Variations(2)

Approximately depth-first copying(1) Modification of Cheney’s agorithm by Moon (1984)

  • Always start scanning on the last partially filled page in To-space
  • When that page is completed, continue with ordinary scan
  • As soon as an object is copied, start partial scan again

scan partial free

slide-98
SLIDE 98

11 Variations(3)

Approximately depth-first copying(2)

  • Drawback: Some nodes are scanned twice
  • Tests indicate a 15 percent improvement of locality
  • . . . and a 6 percent increased GC time
slide-99
SLIDE 99

11 Variations(3)

Approximately depth-first copying(2)

  • Drawback: Some nodes are scanned twice
  • Tests indicate a 15 percent improvement of locality
  • . . . and a 6 percent increased GC time
slide-100
SLIDE 100

11 Variations(3)

Approximately depth-first copying(2)

  • Drawback: Some nodes are scanned twice
  • Tests indicate a 15 percent improvement of locality
  • . . . and a 6 percent increased GC time
slide-101
SLIDE 101

11 Variations(3)

Approximately depth-first copying(2)

  • Drawback: Some nodes are scanned twice
  • Tests indicate a 15 percent improvement of locality
  • . . . and a 6 percent increased GC time
slide-102
SLIDE 102

12 Increasing efficiency

  • Making the semi-spaces bigger decreases frequency of GC
  • Less frequent GC means older objects

⇒ More garbage

slide-103
SLIDE 103

12 Increasing efficiency

  • Making the semi-spaces bigger decreases frequency of GC
  • Less frequent GC means older objects

⇒ More garbage

slide-104
SLIDE 104

12 Increasing efficiency

  • Making the semi-spaces bigger decreases frequency of GC
  • Less frequent GC means older objects

⇒ More garbage

slide-105
SLIDE 105

3 2 2 2 2 2

2x3 MB

slide-106
SLIDE 106

3 2 2 2 2 2

2x3 MB

6 5 2

2x6 MB

slide-107
SLIDE 107

13 When to use copying

  • Storage management dominated by allocation

(alloc. is cheap)

  • Many small, short-lived objects

(copying small objects not much more expensive than marking)

  • GC delay doesn’t matter (no real-time system)
slide-108
SLIDE 108

13 When to use copying

  • Storage management dominated by allocation

(alloc. is cheap)

  • Many small, short-lived objects

(copying small objects not much more expensive than marking)

  • GC delay doesn’t matter (no real-time system)
slide-109
SLIDE 109

13 When to use copying

  • Storage management dominated by allocation

(alloc. is cheap)

  • Many small, short-lived objects

(copying small objects not much more expensive than marking)

  • GC delay doesn’t matter (no real-time system)
slide-110
SLIDE 110

13 When to use copying

  • Storage management dominated by allocation

(alloc. is cheap)

  • Many small, short-lived objects

(copying small objects not much more expensive than marking)

  • GC delay doesn’t matter (no real-time system)
slide-111
SLIDE 111

14 Outlook

  • Hybrid systems can be used

(e.g. use copying only for small objects, mark-sweep for large

  • bjects)
  • Copying collection can be used as a foundation for

– incremental – generational GC algorithms.

slide-112
SLIDE 112

14 Outlook

  • Hybrid systems can be used

(e.g. use copying only for small objects, mark-sweep for large

  • bjects)
  • Copying collection can be used as a foundation for

– incremental – generational GC algorithms.

slide-113
SLIDE 113

14 Outlook

  • Hybrid systems can be used

(e.g. use copying only for small objects, mark-sweep for large

  • bjects)
  • Copying collection can be used as a foundation for

– incremental – generational GC algorithms.

slide-114
SLIDE 114

14 Outlook

  • Hybrid systems can be used

(e.g. use copying only for small objects, mark-sweep for large

  • bjects)
  • Copying collection can be used as a foundation for

– incremental – generational GC algorithms.

slide-115
SLIDE 115

14 Outlook

  • Hybrid systems can be used

(e.g. use copying only for small objects, mark-sweep for large

  • bjects)
  • Copying collection can be used as a foundation for

– incremental – generational GC algorithms.

slide-116
SLIDE 116

14 Outlook

  • Hybrid systems can be used

(e.g. use copying only for small objects, mark-sweep for large

  • bjects)
  • Copying collection can be used as a foundation for

– incremental – generational GC algorithms.