Models GCs two phase abstraction Mark-sweep GC Defined First - - PowerPoint PPT Presentation

models gc s two phase abstraction mark sweep gc defined
SMART_READER_LITE
LIVE PREVIEW

Models GCs two phase abstraction Mark-sweep GC Defined First - - PowerPoint PPT Presentation

Models GCs two phase abstraction Mark-sweep GC Defined First algorithm for automated storage reclamation Is a stop-the-world collector Is an example of a tracing collector Has two phases Mark phase marks all objects


slide-1
SLIDE 1

Models GC’s two phase abstraction

slide-2
SLIDE 2

Mark-sweep GC Defined

 First algorithm for automated storage reclamation  Is a stop-the-world collector  Is an example of a tracing collector  Has two phases

 Mark phase

 marks all objects reachable from the root set of the currently

executing program  Sweep phase

 reclaims all objects not marked in the in the previous phase

2

slide-3
SLIDE 3

Implement 2-phase abstract GC alg.

 Distinguish live objects from garbage

 Done by tracing, the mark step  Starts at the root set  Traverse graph of pointer relationships

 Depth-first or breadth-first search

 Mark reached object in some way

 bitmap, bit in object, some other table

 Reclaim the garbage

 Done in sweep phase  Memory exhaustively examined to find garbage

 Linked to one or more free lists

3

slide-4
SLIDE 4

Mark-sweep operations

4

slide-5
SLIDE 5

Mark-sweep algorithm

// The mark-sweep collector mark_sweep() { for R in Roots mark(R) sweep() if free_pool is empty abort "Memory exhausted" } // Simple recursive marking mark(N) { if mark_bit(N) == unmarked mark_bit(N) = marked for M in Children(N) mark(*M) }

5

// The eager sweep of the heap sweep() { N = Heap_bottom while N < Heap_top if mark_bit(N) == unmarked free(N) else mark_bit(N) = unmarked N = N + size(N) }

slide-6
SLIDE 6

Graph of object relationships

6

Root set Before MS GC Runs

slide-7
SLIDE 7

Graph of object relationships

7

Root set Graph after mark phase

slide-8
SLIDE 8

Graph of object relationships

8

Root set Graph after sweep phase

slide-9
SLIDE 9

Graph of object relationships

9

Root set After MS GC Runs

slide-10
SLIDE 10

Advantages of mark-sweep GC

 Reclaims ‘all’ garbage

 Including cyclic data structures

 No overhead on manipulating pointers  Low space overhead

 Only a mark bit per object

10

slide-11
SLIDE 11

Disadvantages of mark-sweep GC

 Stop-the-world algorithm

 Computation suspended while GC runs  Pause time may be high

 Not practical for real-time, interactive applications, video

games

 High cost:

 proportional to size of heap (not just live objects)  Why?

 Active objects visited by mark phase  All of memory visited by sweep phase

11

slide-12
SLIDE 12

Disadvantages of mark-sweep GC

 Tending to fragment memory

 Programs may ‘thrash’

 High heap occupancy

 GC runs frequently

12

slide-13
SLIDE 13

How do we address these cons?

Subject of next class

13