Top Banner
Generational Generational Garbage Collection Garbage Collection Mirko Jerrentrup, [email protected]
42

Generational Garbage Collection - ps.uni-saarland.de€¦ · Generational garbage collection • objects partitioned intomultiple generations • old generation seldomly collected

May 31, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Generational Garbage Collection - ps.uni-saarland.de€¦ · Generational garbage collection • objects partitioned intomultiple generations • old generation seldomly collected

Generational Generational Garbage CollectionGarbage Collection

Mirko Jerrentrup, [email protected]

Page 2: Generational Garbage Collection - ps.uni-saarland.de€¦ · Generational garbage collection • objects partitioned intomultiple generations • old generation seldomly collected

OverviewOverview

• motivation

• at a glance

• issues

• problems and limitations

• conclusion

Page 3: Generational Garbage Collection - ps.uni-saarland.de€¦ · Generational garbage collection • objects partitioned intomultiple generations • old generation seldomly collected

MotivationMotivation

„classical“, e.g. copying GC:

• repeated handling of long-lived objects

• no improvement of locality

Page 4: Generational Garbage Collection - ps.uni-saarland.de€¦ · Generational garbage collection • objects partitioned intomultiple generations • old generation seldomly collected

The weak generational hypothesisThe weak generational hypothesis

• partition objects into generations

• special handling of young objects:

→ reduced pause times

→ better collection efficiency

• partition objects into generations

• special handling of young objects:

→ reduced pause times

→ better collection efficiency

„Most objects die young.“

[Ungar, 1984]

Page 5: Generational Garbage Collection - ps.uni-saarland.de€¦ · Generational garbage collection • objects partitioned intomultiple generations • old generation seldomly collected

Generational garbage collectionGenerational garbage collection

• objects partitioned into multiple generations

• old generation seldomly collected(major collection)

• surviving young objects promoted into old generation

• young generation frequently collected(minor collection)

Page 6: Generational Garbage Collection - ps.uni-saarland.de€¦ · Generational garbage collection • objects partitioned intomultiple generations • old generation seldomly collected

ExampleExample: : minorminor collectioncollection

old generation young generation

root set

root set

old generation young generation

root set for minor collection

root set for minor collection

live nodes

„garbage“ nodes

Inter-generational pointerInter-generational pointer

Page 7: Generational Garbage Collection - ps.uni-saarland.de€¦ · Generational garbage collection • objects partitioned intomultiple generations • old generation seldomly collected

IssuesIssues in in generational garbage collectiongenerational garbage collection

promotionpromotion

heap organizationheap organization

schedulingscheduling inter-generationalpointers

inter-generationalpointers

generational garbage collectiongenerational garbage collection

Page 8: Generational Garbage Collection - ps.uni-saarland.de€¦ · Generational garbage collection • objects partitioned intomultiple generations • old generation seldomly collected

promotionpromotion

heap organizationheap organization

schedulingscheduling inter-generationalpointers

inter-generationalpointers

generational garbage collectiongenerational garbage collection

Page 9: Generational Garbage Collection - ps.uni-saarland.de€¦ · Generational garbage collection • objects partitioned intomultiple generations • old generation seldomly collected

PromotionPromotion

late promotionearly promotion

long-living objectsbetter worse

short-living objects better worse

time

Page 10: Generational Garbage Collection - ps.uni-saarland.de€¦ · Generational garbage collection • objects partitioned intomultiple generations • old generation seldomly collected

Promotion Promotion policiespolicies

fixedfixed adaptiveadaptive

Promotion policiesPromotion policies

Appel‘s collector for SML/NJ demographic feedback-mediated tenuring

Page 11: Generational Garbage Collection - ps.uni-saarland.de€¦ · Generational garbage collection • objects partitioned intomultiple generations • old generation seldomly collected

AppelAppel‘s ‘s collector forcollector for SML/NJ (1)SML/NJ (1)

• two generations,very large young generation

• major collections only if old objectsoccupy half size of heap

[Appel, 1989]

Idea: manage promotion rates byfixing heap occupancy of young objects

• precondition: contigious heap

Page 12: Generational Garbage Collection - ps.uni-saarland.de€¦ · Generational garbage collection • objects partitioned intomultiple generations • old generation seldomly collected

AppelAppel‘s ‘s collector forcollector for SML/NJ (2)SML/NJ (2)

equal size

old freereserve

old newreserve

freereserveold svr

freeold´svrfree

reserveold free

equal size

freeold svr

half heap size

Page 13: Generational Garbage Collection - ps.uni-saarland.de€¦ · Generational garbage collection • objects partitioned intomultiple generations • old generation seldomly collected

DemographicDemographic feedbackfeedback--mediated tenuringmediated tenuring (1)(1)

• only promote if pause time will be acceptable

[Ungar, Jackson 1992]

Idea: promote only when necessaryto hold maximum pause time

• promote only as many objects to makepause time acceptable

• generate space-age table

Page 14: Generational Garbage Collection - ps.uni-saarland.de€¦ · Generational garbage collection • objects partitioned intomultiple generations • old generation seldomly collected

free

DemographicDemographic feedbackfeedback--mediated tenuringmediated tenuring (2)(2)

[Ungar, Jackson 1992]

free

No promotion at next collection

survivors survivors

promotion of 150 bytes„oldest“ objects

150 bytes

age size of age group

1

2

3

300 bytes

200 bytes

100 bytes

number ofsurvived

collections

number ofsurvived

collections

size of objectsin age group

size of objectsin age group

young generation

maximumacceptablepause time

Page 15: Generational Garbage Collection - ps.uni-saarland.de€¦ · Generational garbage collection • objects partitioned intomultiple generations • old generation seldomly collected

promotionpromotion

heap organizationheap organization

schedulingscheduling inter-generationalpointers

inter-generationalpointers

generational garbage collectiongenerational garbage collection

Page 16: Generational Garbage Collection - ps.uni-saarland.de€¦ · Generational garbage collection • objects partitioned intomultiple generations • old generation seldomly collected

Heap organizationHeap organization

Determination of object‘s generation

• copying collectors: subheaps for generation

contigious heaps → object adress

non-contigious heaps → header field or page-table

• non-copying collectors → header field

Page 17: Generational Garbage Collection - ps.uni-saarland.de€¦ · Generational garbage collection • objects partitioned intomultiple generations • old generation seldomly collected

Heap organization schemesHeap organization schemes

creation spacecreation space„high water mark“ bucket system„high water mark“ bucket system

heap organization schemesheap organization schemes

Page 18: Generational Garbage Collection - ps.uni-saarland.de€¦ · Generational garbage collection • objects partitioned intomultiple generations • old generation seldomly collected

Creation Creation spacespace (1)(1)

Organization of a generation:

• (small) aging area in two semi-spaces

• (large) new object area in one creation space

[Ungar, 1984]

Goals:• no large semi-spaces

• improve locality

Page 19: Generational Garbage Collection - ps.uni-saarland.de€¦ · Generational garbage collection • objects partitioned intomultiple generations • old generation seldomly collected

gc pause

Creation Creation spacespace (2)(2)

[Ungar, 1984]

time

generationoccupancy

creationspace

agingsemi-spaces

Page 20: Generational Garbage Collection - ps.uni-saarland.de€¦ · Generational garbage collection • objects partitioned intomultiple generations • old generation seldomly collected

„High „High water markwater mark“ “ bucketbucket system (1)system (1)

[Wilson, Moher 1989]

Goals:• avoid age field in object header

• adaptive promotion threshold

• two buckets per generation

• creation space partly holds first bucket

• high water mark seperates buckets

• creation and aging spaces per generation

Organization of generations:

Page 21: Generational Garbage Collection - ps.uni-saarland.de€¦ · Generational garbage collection • objects partitioned intomultiple generations • old generation seldomly collected

„High „High water markwater mark“ “ bucketbucket system (2)system (2)

[Wilson, Moher 1989]

time

heapoccupancy

youngergeneration

nextgeneration

bucket 1

bucket 2

highwatermark

Page 22: Generational Garbage Collection - ps.uni-saarland.de€¦ · Generational garbage collection • objects partitioned intomultiple generations • old generation seldomly collected

„High „High water markwater mark“ “ bucketbucket system (system (33))

[Wilson, Moher 1989]

• objects from bucket 1 are stored in bucket 2

• objects from bucket 2 are promoted into older generation

„high water mark” effect:

• „high water mark“ position determines promotion threshold

• promotion threshold between 1 and 2

Page 23: Generational Garbage Collection - ps.uni-saarland.de€¦ · Generational garbage collection • objects partitioned intomultiple generations • old generation seldomly collected

promotionpromotion

heap organizationheap organization

schedulingscheduling inter-generationalpointers

inter-generationalpointers

generational garbage collectiongenerational garbage collection

Page 24: Generational Garbage Collection - ps.uni-saarland.de€¦ · Generational garbage collection • objects partitioned intomultiple generations • old generation seldomly collected

Perform collection when :

• pause is not interruptive hide collection from userhide collection from user

efficent collectionefficent collection

Collection schedulingCollection scheduling

• large amount of garbage can be expected

Page 25: Generational Garbage Collection - ps.uni-saarland.de€¦ · Generational garbage collection • objects partitioned intomultiple generations • old generation seldomly collected

Efficient collectionsEfficient collections

• objects whose „death“ produces much garbage (root of a large tree etc.)

[Hayes 1991]

• exclude key objects from generational scheme

• store key objects „descendants“ inspecial large object area

• reclaiming of key objects trigger collection in key area

Key (large) objects :

Page 26: Generational Garbage Collection - ps.uni-saarland.de€¦ · Generational garbage collection • objects partitioned intomultiple generations • old generation seldomly collected

[Hayes 1991]

Efficient collectionsEfficient collections –– key objectskey objects (1)(1)

young generation

root set

key objectkey object

Page 27: Generational Garbage Collection - ps.uni-saarland.de€¦ · Generational garbage collection • objects partitioned intomultiple generations • old generation seldomly collected

[Hayes 1991]

Efficient collectionsEfficient collections –– key objectskey objects (2)(2)

young generation

root setkey objects

keyed area

Page 28: Generational Garbage Collection - ps.uni-saarland.de€¦ · Generational garbage collection • objects partitioned intomultiple generations • old generation seldomly collected

promotionpromotion

heap organizationheap organization

schedulingscheduling inter-generationalpointers

inter-generationalpointers

generational garbage collectiongenerational garbage collection

Page 29: Generational Garbage Collection - ps.uni-saarland.de€¦ · Generational garbage collection • objects partitioned intomultiple generations • old generation seldomly collected

InterInter--generational pointersgenerational pointers

Issues:

• detecting creation

• including into root set upon collection

• cost of detection / inclusion

old generation young generation

root set

root set for young generation

root set for young generation

Inter-generational pointerInter-generational pointer

Page 30: Generational Garbage Collection - ps.uni-saarland.de€¦ · Generational garbage collection • objects partitioned intomultiple generations • old generation seldomly collected

InterInter--generational pointer handlinggenerational pointer handling

detecting individualpointers

detecting individualpointers

marking pointer-containing areasmarking pointer-containing areas

• pointer indirection• remembered sets

page / word / card marking

detection / storing of inter-generational pointers

detection / storing of inter-generational pointers

inter-generational pointer handlinginter-generational pointer handling

Page 31: Generational Garbage Collection - ps.uni-saarland.de€¦ · Generational garbage collection • objects partitioned intomultiple generations • old generation seldomly collected

DetectionDetection

Detection of inter-generational pointers:

• trapping pointer stores

• only necessary to check objects in old generation(s)

• generally: only non-initializing stores

write-barrierwrite-barrier

Page 32: Generational Garbage Collection - ps.uni-saarland.de€¦ · Generational garbage collection • objects partitioned intomultiple generations • old generation seldomly collected

Individual pointersIndividual pointers –– entryentry tabletable

Idea: indirect pointers through an entry table

[Liebermann, Hewitt 1983]

generation 2 generation 1 generation 0

Page 33: Generational Garbage Collection - ps.uni-saarland.de€¦ · Generational garbage collection • objects partitioned intomultiple generations • old generation seldomly collected

Individual pointersIndividual pointers –– entryentry tabletable

Idea: indirect pointers through an entry table

[Liebermann, Hewitt 1983]

trapping stores (by mutator)

inter-generationalpointer-handling at collection time

small constantfor every store

O(#stores),small constant

O(#stores) N/A

time spaceall pointers in the entry tableare added to the root set

generation 2 generation 1 generation 0

entry table entry table

Page 34: Generational Garbage Collection - ps.uni-saarland.de€¦ · Generational garbage collection • objects partitioned intomultiple generations • old generation seldomly collected

Individual pointersIndividual pointers –– remembered setremembered set

Idea: remember objects with old-young pointers

[Ungar 1984]

trapping stores (by mutator)

inter-generationalpointer-handling at collection time

time space

small constantfor every store

N/Apointer-containersO(# )

pointer-containersO(# )

no duplicate entries in set dueto bit in object header

Objects are scanned for pointers:O(size of objects)

old generation young generation

Page 35: Generational Garbage Collection - ps.uni-saarland.de€¦ · Generational garbage collection • objects partitioned intomultiple generations • old generation seldomly collected

Pointer Pointer areasareas –– page markingpage marking

Idea: mark (virtual) memory pages containing objects with inter-generational pointers

• hardware / virtual memory management support

• only slight overhead for write barrier

• problems intercepting VM signals

• large pages → high collection cost

[Shaw 1988]

[Moon 1984]

trapping stores (by mutator)

inter-generationalpointer-handling at collection time

time space

N/A# i.g.p. •size of page

O( )

N/Asmall constantfor every store pages are scanned for pointers

Page 36: Generational Garbage Collection - ps.uni-saarland.de€¦ · Generational garbage collection • objects partitioned intomultiple generations • old generation seldomly collected

Pointer Pointer areasareas –– card markingcard marking

Idea: don´t mark to-large pagesor to-small words

[Wilson, Moher 1989]

• divide adress space into cards (∼128 bytes)

• lower collection cost if card size is near object size

• very low cost for write barrier: 2-3 instructions

[Sobalvarro 1988]

trapping stores (by mutator)

inter-generationalpointer-handling at collection time

time space

small constantfor every store

N/A

small portionof heap cards are scanned for pointers

# i.g.p. •size of card

O( )

Page 37: Generational Garbage Collection - ps.uni-saarland.de€¦ · Generational garbage collection • objects partitioned intomultiple generations • old generation seldomly collected

Remembered setsRemembered sets vs. vs. card markingcard marking

remembered sets (with sequential store buffers):

• small overhead for write barrier (2-3 instructions)

• no scanning upon collection

• duplicates in sequential store buffers

• collection overhead O(#pointer stores)

Page 38: Generational Garbage Collection - ps.uni-saarland.de€¦ · Generational garbage collection • objects partitioned intomultiple generations • old generation seldomly collected

Remembered setsRemembered sets vs. vs. card markingcard marking

card marking

• scanning upon collection

• collection overhead O(#inter-gen. pointers)

• long-lived object´s cards must be scanned repeatedly

• small overhead for write barrier (2-3 instructions)

Page 39: Generational Garbage Collection - ps.uni-saarland.de€¦ · Generational garbage collection • objects partitioned intomultiple generations • old generation seldomly collected

Remembered setsRemembered sets vs. vs. card markingcard marking

[Hosking, Hudson 1993]

hybrid card marking / remembered set GC

• write barrier like card-marking

• after collection, old-young-pointers

are added to remembered set

Page 40: Generational Garbage Collection - ps.uni-saarland.de€¦ · Generational garbage collection • objects partitioned intomultiple generations • old generation seldomly collected

Problems and limitationsProblems and limitations

heuristic failure:

• cluster of long-lived objects „pig in the snake“

• small heap-allocated objects

• large root sets

Page 41: Generational Garbage Collection - ps.uni-saarland.de€¦ · Generational garbage collection • objects partitioned intomultiple generations • old generation seldomly collected

ConclusionConclusion

• improvement, if assumptions hold

• highly variable

Page 42: Generational Garbage Collection - ps.uni-saarland.de€¦ · Generational garbage collection • objects partitioned intomultiple generations • old generation seldomly collected

Thank youThank you !!