Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Copyright (c) 2004 Borys Bradel Myths and Realities: The Performance Impact of Garbage Collection Paper: Stephen M. Blackburn, Perry Cheng, and Kathryn."— Presentation transcript:

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

2 2 Introduction Garbage collection makes life easier Additional level of abstraction No worries about memory management How to make it efficient? What are the tradeoffs?

3 3 Outline Terminology Garbage Collectors Benchmarks Results Conclusions

4 4 Runtime Components Mutator: the executing program includes time for object allocation and, if necessary, a write barrier Garbage collectors: allocate memory in a simple manner periodically identify unused memory and free it

5 5 Allocators Contiguous: append new objects Free-List: k size-segregated free-lists Example: a: allocate 8 bytes b: allocate 12 bytes c: allocate 16 bytes free b d: allocate 16 bytes

6 6 Contiguous a: 8 b: 12 c: 16 free b d: 16 a

7 7 Contiguous a: 8 b: 12 c: 16 free b d: 16 ab

8 8 Contiguous a: 8 b: 12 c: 16 free b d: 16 abc

9 9 Contiguous a: 8 b: 12 c: 16 free b d: 16 abc

10 10 Contiguous a: 8 b: 12 c: 16 free b d: 16 abcd Good spatial locality sequential allocation creates sequential memory location No reclamation quickly run out of space

11 11 Free-List a: 8 b: 12 c: 16 free b d: 16 a 8 byte 16 byte

12 12 Free-List a: 8 b: 12 c: 16 free b d: 16 a b 8 byte 16 byte

13 13 Free-List a: 8 b: 12 c: 16 free b d: 16 a b c 8 byte 16 byte

14 14 Free-List a: 8 b: 12 c: 16 free b d: 16 a c 8 byte 16 byte

15 15 Free-List a: 8 b: 12 c: 16 free b d: 16 a cd 8 byte 16 byte Bad spatial locality: different queues Reclamation Some fragmentation

16 16 Collectors Whole heap work on entire heap treats everything the same: slow Generational divide heap into old and new optimize for the common case: faster Tracing – compute transitive closure Reference Counting

17 17 Example a b c d e f g h

18 18 Tracing – Collection 1 a b c d e f g h Roots

19 19 Tracing – Collection 1 a b c d e f g h Roots Live

20 20 Tracing – Collection 1 a b c d e f g h Roots Live

21 21 Tracing - Change a b d e f g h Roots

22 22 Tracing – Collection 2 a b d e f g h Roots Live Dead

23 23 SemiSpace Contiguous allocator Divide space into two At collection time move live data over d e f g h defgh

24 24 d e f g h SemiSpace defgh

25 25 SemiSpace Waste of space Copies long lived objects many times Time proportional to survivors d f df

26 26 Mark and Sweep Free-list allocator Collect when heap is full Use bitmaps Copies long lived objects many times d ef g h d ef g h d f

27 27 Reference Counting a b c d: 2 e: 1 f: 1 g: 1 h: 2 Roots

28 28 Reference Counting a b d: 2 e: 0 f: 1 g: 1 h: 2 Roots

29 29 Reference Counting a b d: 2 f: 1 g: 0 h: 1 Roots

30 30 Reference Counting a b d: 2 f: 1 h: 0 Roots

31 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 32 Generational Collector “Weak generational hypothesis” the young die quickly, the old die slowly Put young objects in a nursery When nursery full, collect it and move survivors to old generation, a la SemiSpace When heap full, perform all out collection

33 33 Generational Example d e f g h NurseryMature

34 34 Generational Example d f NurseryMature i k m j l

35 35 Generational Example d f NurseryMature j l i m

36 36 Generational Example d f NurseryMature n o r p q j l i m

37 37 Generational Example d f NurseryMature o r q j l i m

38 38 Generational Collectors On writes, record pointers from mature to nursery objects Nursery is smaller than half of memory generally just contiguously allocated survivors copied over into mature space Mature space uses one of the three collectors – has their benefits/pitfalls

39 39 Benchmarks Low memory usage: 201, 222 Low nursery survival: 202, 228, 205, 227 High nursery survival: 213, 209, jbb focus: accesses/size Table 1 in [1]

40 40 Results Larger heap size decreases frequency of collection, up to a point Small difference in sizes cause different behaviours Generational are big win Less examined at each collection Fewer collections too, especially Mark and Sweep Figure 1 in [1]

41 41 More Results Write 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 42 Mutator Costs Whole heap SemiSpace 7-15% over Mark and Sweep Mainly due to cache effects Generational Locality 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 43 More Results For small heaps, collection overhead dominates – want generational Mark and Sweep For large heaps generational SemiSpace Reference counting too expensive

44 44 Infinite Heaps No garbage collection has small effect on mutator compared to when garbage collection is performed Most reference patterns exhibit temporal locality, not spatial locality When spatial locality is important, garbage collection results in better performance

45 45 Nursery Size Sweetspot well beyond size of L2 cache Larger size leads to fewer collections Eventually too big Figure 4 in [1]

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

47 47 References Figures 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.


Download ppt "Copyright (c) 2004 Borys Bradel Myths and Realities: The Performance Impact of Garbage Collection Paper: Stephen M. Blackburn, Perry Cheng, and Kathryn."

Similar presentations


Ads by Google