copyright (c) 2004 borys bradel myths and realities: the performance impact of garbage collection...

47
Copyright (c) 2004 Bory s Bradel Myths and Realities: The Performance Impact of Garbage Collection Paper: Stephen M. Blackburn, Perry Cheng, and Kathryn S. McKinley Presentation: Borys Bradel

Upload: prudence-daniels

Post on 03-Jan-2016

214 views

Category:

Documents


0 download

TRANSCRIPT

Copyright (c) 2004 Borys Bradel

Myths and Realities:The Performance Impact

of Garbage Collection

Paper: Stephen M. Blackburn, Perry Cheng, and Kathryn S.

McKinleyPresentation: Borys Bradel

2

IntroductionGarbage collection makes life easier

Additional level of abstractionNo worries about memory management

How to make it efficient?What are the tradeoffs?

3

OutlineTerminologyGarbage CollectorsBenchmarksResultsConclusions

4

Runtime ComponentsMutator:

the executing programincludes time for object allocation and, if necessary, a write barrier

Garbage collectors:allocate memory in a simple mannerperiodically identify unused memory and free it

5

AllocatorsContiguous: append new objectsFree-List: k size-segregated free-listsExample:

a: allocate 8 bytesb: allocate 12 bytesc: allocate 16 bytesfree bd: allocate 16 bytes

6

Contiguous

a: 8b: 12c: 16free bd: 16

a

7

Contiguous

a: 8b: 12c: 16free bd: 16

a b

8

Contiguous

a: 8b: 12c: 16free bd: 16

a b c

9

Contiguous

a: 8b: 12c: 16free bd: 16

a b c

10

Contiguous

a: 8b: 12c: 16free bd: 16

a b c d

Good spatial locality sequential allocation creates

sequential memory location

No reclamation quickly run out of space

11

Free-List

a: 8b: 12c: 16free bd: 16

a 8 byte

16 byte

12

Free-List

a: 8b: 12c: 16free bd: 16

a

b

8 byte

16 byte

13

Free-List

a: 8b: 12c: 16free bd: 16

a

b c

8 byte

16 byte

14

Free-List

a: 8b: 12c: 16free bd: 16

a

c

8 byte

16 byte

15

Free-List

a: 8b: 12c: 16free bd: 16

a

c d

8 byte

16 byte

Bad spatial locality: different queues

Reclamation Some fragmentation

16

CollectorsWhole heap

work on entire heaptreats everything the same: slow

Generationaldivide heap into old and newoptimize for the common case: faster

Tracing – compute transitive closureReference Counting

17

Example

a

b

c

d

ef

gh

18

Tracing – Collection 1

a

b

c

d

ef

gh

Roots

19

Tracing – Collection 1

a

b

c

d

ef

gh

Roots Live

20

Tracing – Collection 1

a

b

c

d

ef

gh

Roots Live

21

Tracing - Change

a

b

d

ef

gh

Roots

22

Tracing – Collection 2

a

b

d

ef

gh

Roots Live

Dead

23

SemiSpaceContiguous allocatorDivide space into twoAt collection time move live data overd

ef

gh

defgh

24

d

ef

gh

SemiSpace

defgh

25

SemiSpaceWaste of spaceCopies long lived objects many timesTime proportional to survivorsd

f

df

26

Mark and SweepFree-list allocatorCollect when heap is fullUse bitmapsCopies long lived objects many timesd

e f

g

h

d

e f

g

h

d

f

27

Reference Counting

a

b

c

d: 2

e: 1f: 1

g: 1h: 2

Roots

28

Reference Counting

a

b

d: 2

e: 0f: 1

g: 1h: 2

Roots

29

Reference Counting

a

b

d: 2

f: 1

g: 0h: 1

Roots

30

Reference Counting

a

b

d: 2

f: 1h: 0

Roots

31

Reference Counting

a

b

d: 2

f: 1

Roots Free-List

allocator Time

proportional to dead objects

Detects cycles Uses object

logging at writing

32

Generational Collector“Weak generational hypothesis”

the young die quickly, the old die slowly

Put young objects in a nurseryWhen nursery full, collect it and move survivors to old generation, a la SemiSpace

When heap full, perform all out collection

33

Generational Example

d

ef

gh

Nursery Mature

34

Generational Example

d

f

Nursery Maturei

km

jl

35

Generational Example

d

f

Nursery Mature

jl

i

m

36

Generational Example

d

f

Nursery Maturen

or

pq

jl

i

m

37

Generational Example

d

f

Nursery Mature

or

q

jl

i

m

38

Generational CollectorsOn writes, record pointers from mature to nursery objectsNursery

is smaller than half of memorygenerally just contiguously allocatedsurvivors copied over into mature space

Mature space uses one of the three collectors – has their benefits/pitfalls

39

BenchmarksLow memory usage: 201, 222Low nursery survival: 202, 228, 205, 227High nursery survival: 213, 209, jbbfocus: accesses/size

Table 1 in [1]

40

ResultsLarger heap size decreases frequency of collection, up to a pointSmall difference in sizes cause different behavioursGenerational are big win

Less examined at each collectionFewer collections too, especially Mark and Sweep

Figure 1 in [1]

41

More ResultsWrite Barrier

Up to 13.6% overhead, average of 3.2%Benefit from generations more than makes up for the overhead

Free-List versus contiguous allocation

Free-List 11% slower.

42

Mutator CostsWhole heap

SemiSpace 7-15% over Mark and Sweep Mainly due to cache effects

GenerationalLocality of mature objects not a factor (except when it is, like in jbb)So fewer collections for Mark and Sweep are a win

Figure 2 in [1]

43

More ResultsFor small heaps, collection overhead dominates – want generational Mark and SweepFor large heaps generational SemiSpaceReference counting too expensive

44

Infinite HeapsNo garbage collection has small effect on mutator compared to when garbage collection is performed

Most reference patterns exhibit temporal locality, not spatial localityWhen spatial locality is important, garbage collection results in better performance

45

Nursery SizeSweetspot well beyond size of L2 cache

Larger size leads to fewer collectionsEventually too big

Figure 4 in [1]

46

ConclusionsContiguous allocation yields better localityFree-lists are more space efficient, so less collectionCounters myth that collection frequency is first order effect on performance?Explicit allocation is bad because free list can’t capture locality???

47

ReferencesFigures and Tables are all from:[1] Stephen M. Blackburn, Perry Cheng, and Kathryn S. McKinley. Myths and Realities: The Performance of Garbage Collection. Sigmetrics – Performance, 2004.