JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

135
© 2013 IBM Corporation Ryan A. Sciampacone – Managed Run4me Architect 24 September 2013 Garbage Collec4on Unleashed Demys4fying the Wizardry

description

Garbage Collection Unleashed: Demystifying the Wizardry JavaOne 2013 CON3948 Ryan A. Sciampacone, Senior Software Developer, IBM JTC Abstract: Problems with garbage collection? Pauses too long? Maybe too frequent? Other than telling you to give your application more memory, does staring at the logs yield little to no information? Ready to throw your hands up in frustration? Many application developers struggle with understanding where they may have gone wrong from either a deployment or a development perspective when garbage collection becomes a suspect. This presentation aims to demystify some of the mechanics of garbage collection technologies by looking at a series of problems, mapping them back to the implementation in simple terms, and understanding what this means about the collection and your application and how to address the issue.

Transcript of JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

Page 1: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Ryan  A.  Sciampacone  –  Managed  Run4me  Architect  24  September  2013  

Garbage  Collec4on  Unleashed  Demys4fying  the  Wizardry  

Page 2: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Important  Disclaimers  THE  INFORMATION  CONTAINED  IN  THIS  PRESENTATION  IS  PROVIDED  FOR  INFORMATIONAL  PURPOSES  ONLY.    

WHILST  EFFORTS  WERE  MADE  TO  VERIFY  THE  COMPLETENESS  AND  ACCURACY  OF  THE  INFORMATION  CONTAINED  IN  THIS  PRESENTATION,  IT  IS  PROVIDED  “AS  IS”,  WITHOUT  WARRANTY  OF  ANY  KIND,  EXPRESS  OR  IMPLIED.    

ALL  PERFORMANCE  DATA  INCLUDED  IN  THIS  PRESENTATION  HAVE  BEEN  GATHERED  IN  A  CONTROLLED  ENVIRONMENT.    YOUR  OWN  TEST  RESULTS  MAY  VARY  BASED  ON  HARDWARE,  SOFTWARE  OR  INFRASTRUCTURE  DIFFERENCES.  

ALL  DATA  INCLUDED  IN  THIS  PRESENTATION  ARE  MEANT  TO  BE  USED  ONLY  AS  A  GUIDE.  

IN  ADDITION,  THE  INFORMATION  CONTAINED  IN  THIS  PRESENTATION  IS  BASED  ON  IBM’S  CURRENT  PRODUCT  PLANS  AND  STRATEGY,  WHICH  ARE  SUBJECT  TO  CHANGE  BY  IBM,  WITHOUT  NOTICE.    

IBM  AND  ITS  AFFILIATED  COMPANIES  SHALL  NOT  BE  RESPONSIBLE  FOR  ANY  DAMAGES  ARISING  OUT  OF  THE  USE  OF,  OR  OTHERWISE  RELATED  TO,  THIS  PRESENTATION  OR  ANY  OTHER  DOCUMENTATION.    

NOTHING  CONTAINED  IN  THIS  PRESENTATION  IS  INTENDED  TO,  OR  SHALL  HAVE  THE  EFFECT  OF:    

-­‐  CREATING  ANY  WARRANT  OR  REPRESENTATION  FROM  IBM,  ITS  AFFILIATED  COMPANIES  OR  ITS  OR  THEIR  SUPPLIERS  AND/OR  LICENSORS  

2

Page 3: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Your  Speaker:  Ryan  A.  Sciampacone  

• Run4me  Architect  @  IBM  (JTC)  •  Interpreters  • Garbage  Collec4on  • Plaaorm  interfacing  /  op4miza4on  • Hardware  exploita4on  

(E)  [email protected]  (T)  @rsciampacone  

• Visit  the  IBM  Booth  #5112  to  meet  other  IBM  Developers  

3

Page 4: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

What  should  you  take  away  from  all  this?  

• Not  a  tuning  talk  • Explore  some  (possibly)  unexpected  behavior  in  Java  

• Your  plaaorm  changes  performance  in  strange  ways  

• Add  to  your  “deep  knowledge”  toolkit  • Most  importantly:  To  be  entertained  

4

Page 5: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

UP  TO  SPEED  Let’s  get  everyone…  

5

Page 6: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Compac4on  

6

Thread Graphic: Wikimedia Commons http://en.m.wikipedia.org/wiki/File:Process_vs._thread.svg

?  Allocate

Heap  

Object  

Thread  

Page 7: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Compac4on  

7

Thread Graphic: Wikimedia Commons http://en.m.wikipedia.org/wiki/File:Process_vs._thread.svg

?  Allocate

Heap  

Object  

Thread  

Page 8: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Compac4on  

8

Thread Graphic: Wikimedia Commons http://en.m.wikipedia.org/wiki/File:Process_vs._thread.svg

?  Allocate

Heap  

Object  

Thread  

Page 9: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Compac4on  

9

Thread Graphic: Wikimedia Commons http://en.m.wikipedia.org/wiki/File:Process_vs._thread.svg

Allocate

Heap  

Object  

Thread  

Page 10: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Genera4onal  

10

Heap  

Object  

Thread  

New Old

Thread Graphic: Wikimedia Commons http://en.m.wikipedia.org/wiki/File:Process_vs._thread.svg

Page 11: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Genera4onal  

11

Heap  

Object  

Thread  

New Old

Allocate

Thread Graphic: Wikimedia Commons http://en.m.wikipedia.org/wiki/File:Process_vs._thread.svg

Page 12: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Genera4onal  

12

Heap  

Object  

Thread  

New Old

Allocate

Thread Graphic: Wikimedia Commons http://en.m.wikipedia.org/wiki/File:Process_vs._thread.svg

Page 13: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Genera4onal  

13

Heap  

Object  

Thread  

New Old

GC  Thread Graphic: Wikimedia Commons http://en.m.wikipedia.org/wiki/File:Process_vs._thread.svg

Page 14: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Genera4onal  

14

Heap  

Object  

Thread  

New Old

GC  Thread Graphic: Wikimedia Commons http://en.m.wikipedia.org/wiki/File:Process_vs._thread.svg

Page 15: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Genera4onal  

15

Heap  

Object  

Thread  

New Old

Allocate

Thread Graphic: Wikimedia Commons http://en.m.wikipedia.org/wiki/File:Process_vs._thread.svg

Page 16: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Genera4onal  

16

Heap  

Object  

Thread  

New Old

Allocate

Thread Graphic: Wikimedia Commons http://en.m.wikipedia.org/wiki/File:Process_vs._thread.svg

Page 17: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Genera4onal  

17

Heap  

Object  

Thread  

New Old

GC  Thread Graphic: Wikimedia Commons http://en.m.wikipedia.org/wiki/File:Process_vs._thread.svg

Page 18: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Genera4onal  

18

Heap  

Object  

Thread  

New Old

GC  

Tenure

Thread Graphic: Wikimedia Commons http://en.m.wikipedia.org/wiki/File:Process_vs._thread.svg

Page 19: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Genera4onal  

19

Heap  

Object  

Thread  

New Old

Global  GC  Thread Graphic: Wikimedia Commons http://en.m.wikipedia.org/wiki/File:Process_vs._thread.svg

Page 20: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Stop  the  World  

20

Duke Logo: © Oracle Recycle Symbol: Creative Commons http://commons.wikimedia.org/wiki/File:Recycle.jpg

Page 21: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Concurrent  

21

Duke Logo: © Oracle Recycle Symbol: Creative Commons http://commons.wikimedia.org/wiki/File:Recycle.jpg

Java  Ac4vity    

GC  Ac4vity    

Page 22: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Parallel  

22

Duke Logo: © Oracle Recycle Symbol: Creative Commons http://commons.wikimedia.org/wiki/File:Recycle.jpg

Java  Ac4vity    

GC  Ac4vity    

…  

Page 23: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

ALLOCATION  Quick  look  at  the  mechanics  of…  

23

Page 24: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Alloca4on  

24

Padlock: Public domain http://en.wikipedia.org/wiki/File:Viking_Age_lock.png

Heap  

Object  

Thread  A

lloca

te

Page 25: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Alloca4on  

25

Padlock: Public domain http://en.wikipedia.org/wiki/File:Viking_Age_lock.png

Heap  

Object  

Thread  A

lloca

te

Page 26: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Alloca4on  

26

Padlock: Public domain http://openclipart.org/detail/22179/lock-by-nicubunu

Heap  

Object  

Thread  A

lloca

te

Private  Buffer  

Page 27: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Alloca4on  

27

Padlock: Public domain http://openclipart.org/detail/22179/lock-by-nicubunu

Heap  

Object  

Thread  A

lloca

te

Page 28: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Alloca4on  

28

Padlock: Public domain http://openclipart.org/detail/22179/lock-by-nicubunu

Heap  

Object  

Thread  A

lloca

te

Page 29: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

FINALIZATION  Gekng  around  to  eventually  talking  about  something  you  inevitably  have  to…  

29

Page 30: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

The  meaning  of  “in  scope”  

30

Page 31: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

The  meaning  of  “in  scope”  

31

Simple  Finalizer  

Page 32: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

The  meaning  of  “in  scope”  

32

Create  instance  of  finalizable  object  

Page 33: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

The  meaning  of  “in  scope”  

33

No  references  to  the  finalizable  object  at  this  point  

Page 34: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

The  meaning  of  “in  scope”  

34

Will  obj  be  finalized?  

Page 35: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Example  

35

Page 36: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Perhaps  a  bit  more  dangerous…  

36

Page 37: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

THE  ORDER  OF  THINGS  Finaliza4on  

37

Page 38: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

What  can  we  expect  as  output?  

38

Page 39: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Example  

39

Page 40: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

So  what  happened?  

40

New Old

FinalizableObject(2)  

FinalizableObject(1)  

Page 41: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

So  what  happened?  

41

New Old

FinalizableObject(2)  

FinalizableObject(1)  

Page 42: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

So  what  happened?  

42

New Old

FinalizableObject(2)  

FinalizableObject(1)  

GC  

Page 43: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

So  what  happened?  

43

New Old

FinalizableObject(2)  

FinalizableObject(1)  

GC  

Tenure

Page 44: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

So  what  happened?  

44

New Old

FinalizableObject(2)  

FinalizableObject(1)  

Page 45: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

So  what  happened?  

45

New Old

FinalizableObject(2)  

FinalizableObject(1)  

Page 46: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

So  what  happened?  

46

New Old

FinalizableObject(2)  

FinalizableObject(1)  

Page 47: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

So  what  happened?  

47

New Old

FinalizableObject(2)  

FinalizableObject(1)  

GC  

Page 48: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

So  what  happened?  

48

New Old

FinalizableObject(2)  

FinalizableObject(1)  

GC  

Finalized!

Page 49: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

ANCHOR  POINTS  AND  GC  Finaliza4on  

49

Page 50: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

What  about  anchor  points?  

50

finalize() finalize()

Page 51: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

What  about  anchor  points?  

51

Page 52: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Example  

52

Page 53: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Why  only  one?  

53

finalize() finalize()

Page 54: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Why  only  one?  

54

finalize() finalize()

Page 55: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Why  only  one?  

55

New Old

Page 56: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Why  only  one?  

56

New Old

Allocate?  

Page 57: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Why  only  one?  

57

New Old

Allocate?  

Page 58: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Why  only  one?  

58

New Old

Allocate?   Allocate?  

Page 59: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Why  only  one?  

59

New Old

Allocate?   Allocate?  

GC  

Page 60: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

ICEBERGS  What  lies  beneath  the  surface…  

60

Page 61: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation 61

Iceberg: Jesus Diaz, Gizmodo

Page 62: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Out  of  Memory  (as  we  know  and  love  it)  

62

Heap  

Object  

Thread  

New Old

Thread Graphic: Wikimedia Commons http://en.m.wikipedia.org/wiki/File:Process_vs._thread.svg

Allocate

Page 63: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation 63

Page 64: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation 64

Page 65: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Not  all  memory  is  “heap”  memory  

65

Heap  

Object  

Na4ve  Resource  

Page 66: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Not  all  memory  is  “heap”  memory  

66

Heap  

Object  

Na4ve  Resource  

Page 67: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Not  all  memory  is  “heap”  memory  

67

Heap  

Object  

Na4ve  Resource  

Page 68: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation 68

Page 69: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation 69

Page 70: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation 70

Page 71: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation 71

Page 72: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Keep  track  /  Use  facili4es  available  

• Plenty  of  process  monitoring  somware  out  there  

• Consider  resource  limi4ng  /  thronling  facili4es  

72

Page 73: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

SHARING  MEMORY  Two  for  me  and  one  for  you…  

73

Page 74: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Two  threads  and  one  field  

74

Object  

Thread  field1

field2

field<N>

“Same”  

Page 75: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Two  threads  and  one  field  

75

Object  

Thread  field1

field2

field<N>

field1

field2

field<N>

“Different”  

Page 76: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Example  

76

Page 77: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

The  CPU  Cache  (High  level)  

77

CPU: Wikipedia Commons https://en.wikipedia.org/wiki/Central_processing_unit

(0x1F89DB04)  

Memory  

CPU  

Page 78: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

The  CPU  Cache  (High  level)  

78

CPU: Wikipedia Commons https://en.wikipedia.org/wiki/Central_processing_unit

(0x1F89DB04)  

Memory  

CPU  

Cache  

Page 79: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

The  CPU  Cache  (High  level)  

79

CPU: Wikipedia Commons https://en.wikipedia.org/wiki/Central_processing_unit

(0x1F89DB04)  

Memory  

CPU  

Cache  

Page 80: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

The  CPU  Cache  (High  level)  

80

CPU: Wikipedia Commons https://en.wikipedia.org/wiki/Central_processing_unit

(0x1F89DB04)  

Memory  

CPU  

Cache   Cache  CPU  

Page 81: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

The  CPU  Cache  (High  level)  

81

CPU: Wikipedia Commons https://en.wikipedia.org/wiki/Central_processing_unit

(0x1F89DB04)  

Memory  

CPU  

Cache   Cache  CPU  

Page 82: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

The  CPU  Cache  (High  level)  

82

CPU: Wikipedia Commons https://en.wikipedia.org/wiki/Central_processing_unit

(0x1F89DB04)  

Memory  

CPU  

Cache   Cache  CPU  

Page 83: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Two  threads  and  two  fields  

83

Object  

Thread  field1

field2

field<N>

“Same”  

Page 84: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Two  threads  and  two  fields  

84

Object  

Thread  field1

field2

field<N>

field1

field2

field<N>

“Different”  

Page 85: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Example  

85

Page 86: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

The  CPU  Cache  Pt.  2  (High  level)  

86

CPU: Wikipedia Commons https://en.wikipedia.org/wiki/Central_processing_unit

Memory  

CPU  

Cache  

Page 87: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

The  CPU  Cache  Pt.  2  (High  level)  

87

CPU: Wikipedia Commons https://en.wikipedia.org/wiki/Central_processing_unit

Memory  

CPU  

Cache  

Cache  Line  

Page 88: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

The  CPU  Cache  Pt.  2  (High  level)  

88

CPU: Wikipedia Commons https://en.wikipedia.org/wiki/Central_processing_unit

Memory  

CPU  

Cache  

Cache  Line  

Page 89: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

The  CPU  Cache  Pt.  2  (High  level)  

89

CPU: Wikipedia Commons https://en.wikipedia.org/wiki/Central_processing_unit

Memory  

CPU  

Cache   Cache  CPU  

Cache  Line  

Page 90: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

The  CPU  Cache  Pt.  2  (High  level)  

90

CPU: Wikipedia Commons https://en.wikipedia.org/wiki/Central_processing_unit

Memory  

CPU  

Cache   Cache  CPU  

Cache  Line  

Page 91: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

The  CPU  Cache  Pt.  2  (High  level)  

91

CPU: Wikipedia Commons https://en.wikipedia.org/wiki/Central_processing_unit

Memory  

CPU  

Cache   Cache  CPU  

Cache  Line  

Page 92: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

FIELD  ORDERING  When  ordering  pizza  you  expect  the  crust  on  the  bonom…  

92

Page 93: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Subclass  with  fields  “far  apart”  

93

Page 94: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Subclass  with  fields  “far  apart”  

94

Page 95: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Two  threads  and  two  fields  and  one  subclass  

95

Object  

Thread  

field1

field2

pad001

pad0NN

pad100 “Second”  

pad1NN

field3

Page 96: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Two  threads  and  two  fields  and  one  subclass  

96

Object  

Thread  

field1

field2

pad001

pad0NN

pad100

pad1NN

… “Third”  

field3

Page 97: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Example  

97

Page 98: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

So  what  happened?  

98

Page 99: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

So  what  happened?  

99

field1

field2

pad001

pad0NN

pad100

pad1NN

field3

Page 100: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

So  what  happened?  

100

field1

field2

pad001

pad0NN

pad100

pad1NN

field3

Page 101: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

So  what  happened?  

101

field1 field2

pad001

pad0NN

pad100

pad1NN

field3

Page 102: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

So  what  happened?  

102

field1 field2

pad001

pad0NN

pad100

pad1NN

field3

Page 103: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

So  what  happened?  

103

field1 field2

pad001

pad0NN

pad100

pad1NN

field3

Cache  Line  

Page 104: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

So  what  happened?  (Alternate  version)  

104

field1

pad001

pad0NN

pad100

pad1NN

field2 field3

Page 105: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

CACHE  CAPACITY  Spreading  things  out  doesn’t  always  reduce  collisions…  

105

Page 106: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Small  data,  Big  problems  

106

byte[]  

Page 107: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Small  data,  Big  problems  

107

Cache  Line  (64  Bytes)  

byte[]  

Page 108: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Small  data,  Big  problems  

108

Cache  Line  (64  Bytes)  

byte[]  

Page 109: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Small  data,  Big  problems  

109

4KB   4KB  

Cache  Line  (64  Bytes)  

byte[]  

Page 110: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Small  data,  Big  problems  

110

4KB   4KB  

Cache  Line  (64  Bytes)  

byte[]  

Page 111: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Small  data,  Big  problems  

111

4KB   4KB  

Cache  Line  (64  Bytes)  

byte[]  

Page 112: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Small  data,  Big  problems  

112

4KB   4KB  

Cache  Line  (64  Bytes)  

byte[]  

Page 113: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Small  data,  Big  problems  

113

4KB   4KB  

Cache  Line  (64  Bytes)  

byte[]  

Page 114: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Small  data,  Big  problems  

•  Access  the  same  index  from  each  line  •  Move  to  the  next  index  •  Repeat  

114

4KB   4KB  

Cache  Line  (64  Bytes)  

byte[]  

Page 115: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Example  

115

Page 116: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Cache  “capacity”  is  less  than  you  think  

116

CPU: Wikipedia Commons https://en.wikipedia.org/wiki/Central_processing_unit

Cache  

Page 117: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Cache  “capacity”  is  less  than  you  think  

117

CPU: Wikipedia Commons https://en.wikipedia.org/wiki/Central_processing_unit

Cache  

Page 118: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Cache  “capacity”  is  less  than  you  think  

118

CPU: Wikipedia Commons https://en.wikipedia.org/wiki/Central_processing_unit

Cache  

Page 119: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Cache  “capacity”  is  less  than  you  think  

119

CPU: Wikipedia Commons https://en.wikipedia.org/wiki/Central_processing_unit

Cache  

Page 120: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Cache  “capacity”  is  less  than  you  think  

120

CPU: Wikipedia Commons https://en.wikipedia.org/wiki/Central_processing_unit

Cache  

Page 121: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Cache  “capacity”  is  less  than  you  think  

121

CPU: Wikipedia Commons https://en.wikipedia.org/wiki/Central_processing_unit

Cache  

Page 122: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Cache  “capacity”  is  less  than  you  think  

122

CPU: Wikipedia Commons https://en.wikipedia.org/wiki/Central_processing_unit

Cache  8  Entries  

Page 123: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

HOW  MEMORY  WORKS  Before  I  forget,  a  few  more  things  about…  

123

Page 124: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Non  Uniform  Memory  Architecture  (NUMA)  

124

CPU: Wikipedia Commons https://en.wikipedia.org/wiki/Central_processing_unit DRAM: Wikipedia Commons http://en.wikipedia.org/wiki/Dynamic_random-access_memory

Page 125: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Non  Uniform  Memory  Architecture  (NUMA)  

125

CPU: Wikipedia Commons https://en.wikipedia.org/wiki/Central_processing_unit DRAM: Wikipedia Commons http://en.wikipedia.org/wiki/Dynamic_random-access_memory

Page 126: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Non  Uniform  Memory  Architecture  (NUMA)  

126

CPU: Wikipedia Commons https://en.wikipedia.org/wiki/Central_processing_unit DRAM: Wikipedia Commons http://en.wikipedia.org/wiki/Dynamic_random-access_memory

Page 127: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Non  Uniform  Memory  Architecture  (NUMA)  

127

CPU: Wikipedia Commons https://en.wikipedia.org/wiki/Central_processing_unit DRAM: Wikipedia Commons http://en.wikipedia.org/wiki/Dynamic_random-access_memory

Page 128: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Non  Uniform  Memory  Architecture  (NUMA)  

128

CPU: Wikipedia Commons https://en.wikipedia.org/wiki/Central_processing_unit DRAM: Wikipedia Commons http://en.wikipedia.org/wiki/Dynamic_random-access_memory

Page 129: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Non  Uniform  Memory  Architecture  (NUMA)  

129

CPU: Wikipedia Commons https://en.wikipedia.org/wiki/Central_processing_unit DRAM: Wikipedia Commons http://en.wikipedia.org/wiki/Dynamic_random-access_memory

Page 130: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Non  Uniform  Memory  Architecture  (NUMA)  

130

CPU: Wikipedia Commons https://en.wikipedia.org/wiki/Central_processing_unit DRAM: Wikipedia Commons http://en.wikipedia.org/wiki/Dynamic_random-access_memory

Page 131: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Non  Uniform  Memory  Architecture  

• JVMs  do  have  support  • Balanced  GC  policy  •  -­‐Xnuma  

• Plaaorm  commands  for  thronling  /  afini4zing  •  Taskset  • Numactl  

• Virtualiza4on  

131

Page 132: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Resource  on  Memory  

132

Page 133: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

PARTING  REMARKS  And  finally…  

133

Page 134: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

?  134

Page 135: JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry

© 2013 IBM Corporation

Copyright  and  Trademarks  

©  IBM  Corpora4on  2013.  All  Rights  Reserved.      IBM,  the  IBM  logo,  and  ibm.com  are  trademarks  or  registered  trademarks  of  Interna4onal  Business  Machines  Corp.,  and  registered  in  many  jurisdic4ons  worldwide.    

 Other  product  and  service  names  might  be  trademarks  of  IBM  or  other  companies.      A  current  list  of  IBM  trademarks  is  available  on  the  Web  –  see  the  IBM  “Copyright  and  trademark  informa4on”  page  at  URL:    www.ibm.com/legal/copytrade.shtml  

135