73
Comparison of Compacting Algorithms for Garbage Collection Ahmed Hussein Tuesday, February 7, 12

Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Comparison of Compacting Algorithms for Garbage Collection

Ahmed Hussein

Tuesday, February 7, 12

Page 2: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Agenda

• Compaction..What is that?

• Presenting four different algorithms

• Lisp2

• Table Compactors

• Morris

• Jonkers

Tuesday, February 7, 12

Page 3: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

OverviewMemory

O1 O2 O3 O4

O5 O6

O7 O8 O9

Tuesday, February 7, 12

Page 4: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Phase1..MarkingMemory

O1 O2 O3 O4

O5 O6

O7 O8 O9

Tuesday, February 7, 12

Page 5: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Phase2..CollectingMemory

O1 O3

O5 O6

O7 O9

Tuesday, February 7, 12

Page 6: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Phase2..CollectingMemory

O1 O3

O5 O6

O7 O9

O10

Tuesday, February 7, 12

Page 7: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Phase3..CompactionMemory

O1 O3

O5 O6

O7 O9

O10

Tuesday, February 7, 12

Page 8: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Phase3..CompactionMemory

O1 O3

O5 O6

O7 O9

O10

Tuesday, February 7, 12

Page 9: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Phase3..CompactionMemory

O1 O3 O5

O6

O7 O9

O10

Tuesday, February 7, 12

Page 10: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Phase3..CompactionMemory

O1 O3 O5

O6

O7

O9

O10

Tuesday, February 7, 12

Page 11: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Phase3..CompactionMemory

O1 O3 O5

O6

O7

O9

O10

Tuesday, February 7, 12

Page 12: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Phase3..CompactionMemory

O1 O3 O5

O6

O7

O9

O10

Tuesday, February 7, 12

Page 13: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Object Model

Size c

npc

Sizenpc

data

Tuesday, February 7, 12

Page 14: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Lisp2Memory

Size c1

npc

Size c2

npc

Size c1

npc

Tuesday, February 7, 12

Page 15: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Lisp2Memory

Size c1

npc

Size c2

npc

Compacting

Size c1

npc

Tuesday, February 7, 12

Page 16: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Lisp2Memory

Size c1

npc

Size c2

npc

Compacting

Size c1

npc

Tuesday, February 7, 12

Page 17: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Lisp2Memory

Size c1

npc

Size c2

npc

Compacting

Size c1

npc

Tuesday, February 7, 12

Page 18: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Lisp2

Size c1

npc

addressSize c

npc

Tuesday, February 7, 12

Page 19: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Lisp2

Size c1

npc

address

Tuesday, February 7, 12

Page 20: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Lisp2a2a1 a3 a4a0 a5

Pass1

Tuesday, February 7, 12

Page 21: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Lisp2a2a1 a3 a4a0 a5

Pass1

Tuesday, February 7, 12

Page 22: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Lisp2a2a1 a3 a4a0 a5

Pass1

Tuesday, February 7, 12

Page 23: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Lisp2a2a1 a3 a4a0 a5

Pass1

Tuesday, February 7, 12

Page 24: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Lisp2a2a1 a3 a4a0 a5

a1’

Pass1

Tuesday, February 7, 12

Page 25: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Lisp2a2a1 a3 a4a0 a5

a1’a2’=a1’+size

Pass1

Tuesday, February 7, 12

Page 26: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Lisp2a2a1 a3 a4a0 a5

a1’a2’=a1’+size

a4’=a2’+size

Pass1

Tuesday, February 7, 12

Page 27: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Lisp2a2a1 a4

Pass2

Tuesday, February 7, 12

Page 28: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Lisp2a2a1 a4

a1’

Pass2

Tuesday, February 7, 12

Page 29: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Lisp2a2a1 a4

a1’a2’=a1’+

size a1

Pass2

Tuesday, February 7, 12

Page 30: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Lisp2a2a1 a4

a1’a2’=a1’+

size a1

a4’=a2’+

size a2

Pass2

Tuesday, February 7, 12

Page 31: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Lisp2a2a1 a4

a1’a2’=a1’+

size a1

a4’=a2’+

size a2

Pass2

a1’

Tuesday, February 7, 12

Page 32: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Lisp2a2a1 a4

a1’a2’=a1’+

size a1

a4’=a2’+

size a2

Pass2

a1’ a2’

Tuesday, February 7, 12

Page 33: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Lisp2a2a1 a4

a1’a2’=a1’+

size a1

a4’=a2’+

size a2

Pass2

a1’ a2’ a4’

Tuesday, February 7, 12

Page 34: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Lisp2a4a1

a1’

a2a2’=a1’+size

a4’=a2’+size

Pass3

Tuesday, February 7, 12

Page 35: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Lisp2a4a1

a1’

a2a2’=a1’+size

a4’=a2’+size

Pass3

Tuesday, February 7, 12

Page 36: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Lisp2a4a1

a1’

a2a2’=a1’+size

a4’=a2’+size

Pass3

Tuesday, February 7, 12

Page 37: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Lisp2a4a1

a1’

a2a2’=a1’+size

a4’=a2’+size

Pass3

Tuesday, February 7, 12

Page 38: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Lisp2a4a1

a1’

a2a2’=a1’+size

a4’=a2’+size

Pass3

Tuesday, February 7, 12

Page 39: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Lisp2a4a1

a1’

a2a2’=a1’+size

a4’=a2’+size

Pass3

a1’

Tuesday, February 7, 12

Page 40: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Lisp2a4a1

a1’

a2a2’=a1’+size

a4’=a2’+size

Pass3

a1’ a2’

Tuesday, February 7, 12

Page 41: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Lisp2a4a1

a1’

a2a2’=a1’+size

a4’=a2’+size

Pass3

a1’ a2’ a4’

Tuesday, February 7, 12

Page 42: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Lisp2a4

a1

a1’

a2a2’=a1’+size

a4’=a2’+size

Pass3

a1’ a2’ a4’

Tuesday, February 7, 12

Page 43: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Lisp2a4

a1

a1’

a2a2’=a1’+size

a4’=a2’+size

Pass3

a1’ a2’ a4’

Tuesday, February 7, 12

Page 44: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Lisp2a4

a1

a1’

a2a2’=a1’+size

a4’=a2’+size

Pass3

a1’ a2’ a4’

Tuesday, February 7, 12

Page 45: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Lisp2..Finala2a1 a3

nil

Tuesday, February 7, 12

Page 46: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Lisp2..Finala2a1

nil

a3

nil

Tuesday, February 7, 12

Page 47: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Lisp2..Finala2a1

nil nil

a3

nil

Tuesday, February 7, 12

Page 48: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Lisp2 .. Summary

• Requires 1 extra word in each object for temp pointer. (even when the object is not live)

• Compaction is done in 3 phases:

1. Traverse the objects, sorted by address

• Compute new address of each live object

• free_ptr=0; free_ptr+=free_ptr+size of live object

2. Update Pointer fields.

3. Sliding CompactionTuesday, February 7, 12

Page 49: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Table Compactors

• We need to save the overhead due to temp pointers.

• Using inactive cells to store readjustments.

Tuesday, February 7, 12

Page 50: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Break Table

0 100 300 950 1200 1600 1999

Phase1

Tuesday, February 7, 12

Page 51: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Break Table

0 100 300 950 1200 1600 1999

(100,100)

0 100 300 950 1200 1600 1999

Phase1

Tuesday, February 7, 12

Page 52: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Break Table

0 100 300 950 1200 1600 1999

(100,100)

0 100 300 950 1200 1600 1999

(100,100)(950,750)

0 100 300 950 1200 1600 1999

Phase1

Tuesday, February 7, 12

Page 53: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Break Table

0 100 300 950 1200 1600 1999

(100,100)

0 100 300 950 1200 1600 1999

(100,100)(950,750)

0 100 300 950 1200 1600 1999(950,750)(100,100)

(1600, 1150)0 100 300 950 1200 1600 1999

Phase1

Tuesday, February 7, 12

Page 54: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Break Table

• Rolling back causes it to become unsorted.

• Need another phase just to sort the BT.

Tuesday, February 7, 12

Page 55: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Break Table

• Phase3 to fix the pointers.

1. Search through the BT table and determine the adjacent pairs(a, s) and (a’, s’) such that a <= p < a’

2. readjusted value should be p - s.

Tuesday, February 7, 12

Page 56: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Break Table ..Cost

• Phase1: linear

• Phase2: nlogn

• Phase3: nlogn

• we can enhance the last phase by constructing a hash if we have enough space.

• Other suggestions to keep a linked list in holes and update pointers before moving objects.

Tuesday, February 7, 12

Page 57: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Problem .. revisited

• It is clear from the previous 2 algorithms that updating pointers is bottleneck.

Tuesday, February 7, 12

Page 58: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Threading

A CB

PInfo

Tuesday, February 7, 12

Page 59: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Threading

A CB

PInfo

P

CBAInfo

Tuesday, February 7, 12

Page 60: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Threading

• After calculating the new address of P we can traverse the list and fix all the pointers to point to the new address of P.

Tuesday, February 7, 12

Page 61: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Jonker Algorithm

infoP

Tuesday, February 7, 12

Page 62: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Jonker Algorithm

info

First PathP

Tuesday, February 7, 12

Page 63: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Jonker Algorithm

info

First Path

Info

P

Tuesday, February 7, 12

Page 64: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Jonker Algorithm

info

First Path

Info

P

Info

p’=nextFree

Tuesday, February 7, 12

Page 65: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Jonker Algorithm

Tuesday, February 7, 12

Page 66: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Jonker AlgorithmSecond Path

Tuesday, February 7, 12

Page 67: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Jonker AlgorithmSecond Path

InfoP

p’

Tuesday, February 7, 12

Page 68: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Jonker AlgorithmSecond Path

InfoP

p’

info

Tuesday, February 7, 12

Page 69: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Analysis of Threaded

• Each object is touched three times.

• Space:

• Jonker, no space required but each node has a pointer-sized header.

• Morris

• 2 tag bits per field, 0 inactive, 1 pointer, 2 swapped pointer, 3 non pointer.

• Could be improved by merging marking phase with first phase.

Tuesday, February 7, 12

Page 70: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Threaded..Analysis

• Compact tables touch every object only twice.

Tuesday, February 7, 12

Page 71: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Compaction Summary

• Suits smaller physical memory. Semi-Space requires double the memory space.

• For long lived objects, the heap becomes similar to “generational collector”.

• Improve locality.

• Other algorithms have only one path.

Tuesday, February 7, 12

Page 72: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

How to Compare

• Variable sized objects?

• Directions?

• Have to tag pointer data?

• Time and Space Performance.

Tuesday, February 7, 12

Page 73: Comparison of Compacting Algorithms for Garbage Collection · Lisp2 .. Summary • Requires 1 extra word in each object for temp pointer. (even when the object is not live) • Compaction

Time Comparison

Tuesday, February 7, 12