JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry
-
Upload
rsciampacone -
Category
Technology
-
view
861 -
download
0
description
Transcript of 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
© 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
© 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
© 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
© 2013 IBM Corporation
UP TO SPEED Let’s get everyone…
5
© 2013 IBM Corporation
Compac4on
6
Thread Graphic: Wikimedia Commons http://en.m.wikipedia.org/wiki/File:Process_vs._thread.svg
? Allocate
Heap
Object
Thread
© 2013 IBM Corporation
Compac4on
7
Thread Graphic: Wikimedia Commons http://en.m.wikipedia.org/wiki/File:Process_vs._thread.svg
? Allocate
Heap
Object
Thread
© 2013 IBM Corporation
Compac4on
8
Thread Graphic: Wikimedia Commons http://en.m.wikipedia.org/wiki/File:Process_vs._thread.svg
? Allocate
Heap
Object
Thread
© 2013 IBM Corporation
Compac4on
9
Thread Graphic: Wikimedia Commons http://en.m.wikipedia.org/wiki/File:Process_vs._thread.svg
Allocate
Heap
Object
Thread
© 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
© 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
© 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
© 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
© 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
© 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
© 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
© 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
© 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
© 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
© 2013 IBM Corporation
Stop the World
20
Duke Logo: © Oracle Recycle Symbol: Creative Commons http://commons.wikimedia.org/wiki/File:Recycle.jpg
© 2013 IBM Corporation
Concurrent
21
Duke Logo: © Oracle Recycle Symbol: Creative Commons http://commons.wikimedia.org/wiki/File:Recycle.jpg
Java Ac4vity
GC Ac4vity
© 2013 IBM Corporation
Parallel
22
Duke Logo: © Oracle Recycle Symbol: Creative Commons http://commons.wikimedia.org/wiki/File:Recycle.jpg
Java Ac4vity
GC Ac4vity
…
© 2013 IBM Corporation
ALLOCATION Quick look at the mechanics of…
23
© 2013 IBM Corporation
Alloca4on
24
Padlock: Public domain http://en.wikipedia.org/wiki/File:Viking_Age_lock.png
Heap
Object
Thread A
lloca
te
© 2013 IBM Corporation
Alloca4on
25
Padlock: Public domain http://en.wikipedia.org/wiki/File:Viking_Age_lock.png
Heap
Object
Thread A
lloca
te
© 2013 IBM Corporation
Alloca4on
26
Padlock: Public domain http://openclipart.org/detail/22179/lock-by-nicubunu
Heap
Object
Thread A
lloca
te
Private Buffer
© 2013 IBM Corporation
Alloca4on
27
Padlock: Public domain http://openclipart.org/detail/22179/lock-by-nicubunu
Heap
Object
Thread A
lloca
te
© 2013 IBM Corporation
Alloca4on
28
Padlock: Public domain http://openclipart.org/detail/22179/lock-by-nicubunu
Heap
Object
Thread A
lloca
te
© 2013 IBM Corporation
FINALIZATION Gekng around to eventually talking about something you inevitably have to…
29
© 2013 IBM Corporation
The meaning of “in scope”
30
© 2013 IBM Corporation
The meaning of “in scope”
31
Simple Finalizer
© 2013 IBM Corporation
The meaning of “in scope”
32
Create instance of finalizable object
© 2013 IBM Corporation
The meaning of “in scope”
33
No references to the finalizable object at this point
© 2013 IBM Corporation
The meaning of “in scope”
34
Will obj be finalized?
© 2013 IBM Corporation
Example
35
© 2013 IBM Corporation
Perhaps a bit more dangerous…
36
© 2013 IBM Corporation
THE ORDER OF THINGS Finaliza4on
37
© 2013 IBM Corporation
What can we expect as output?
38
© 2013 IBM Corporation
Example
39
© 2013 IBM Corporation
So what happened?
40
New Old
FinalizableObject(2)
FinalizableObject(1)
© 2013 IBM Corporation
So what happened?
41
New Old
FinalizableObject(2)
FinalizableObject(1)
© 2013 IBM Corporation
So what happened?
42
New Old
FinalizableObject(2)
FinalizableObject(1)
GC
© 2013 IBM Corporation
So what happened?
43
New Old
FinalizableObject(2)
FinalizableObject(1)
GC
Tenure
© 2013 IBM Corporation
So what happened?
44
New Old
FinalizableObject(2)
FinalizableObject(1)
© 2013 IBM Corporation
So what happened?
45
New Old
FinalizableObject(2)
FinalizableObject(1)
© 2013 IBM Corporation
So what happened?
46
New Old
FinalizableObject(2)
FinalizableObject(1)
© 2013 IBM Corporation
So what happened?
47
New Old
FinalizableObject(2)
FinalizableObject(1)
GC
© 2013 IBM Corporation
So what happened?
48
New Old
FinalizableObject(2)
FinalizableObject(1)
GC
Finalized!
© 2013 IBM Corporation
ANCHOR POINTS AND GC Finaliza4on
49
© 2013 IBM Corporation
What about anchor points?
50
finalize() finalize()
© 2013 IBM Corporation
What about anchor points?
51
© 2013 IBM Corporation
Example
52
© 2013 IBM Corporation
Why only one?
53
finalize() finalize()
© 2013 IBM Corporation
Why only one?
54
finalize() finalize()
© 2013 IBM Corporation
Why only one?
55
New Old
© 2013 IBM Corporation
Why only one?
56
New Old
Allocate?
© 2013 IBM Corporation
Why only one?
57
New Old
Allocate?
© 2013 IBM Corporation
Why only one?
58
New Old
Allocate? Allocate?
© 2013 IBM Corporation
Why only one?
59
New Old
Allocate? Allocate?
GC
© 2013 IBM Corporation
ICEBERGS What lies beneath the surface…
60
© 2013 IBM Corporation 61
Iceberg: Jesus Diaz, Gizmodo
© 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
© 2013 IBM Corporation 63
© 2013 IBM Corporation 64
© 2013 IBM Corporation
Not all memory is “heap” memory
65
Heap
Object
Na4ve Resource
© 2013 IBM Corporation
Not all memory is “heap” memory
66
Heap
Object
Na4ve Resource
© 2013 IBM Corporation
Not all memory is “heap” memory
67
Heap
Object
Na4ve Resource
© 2013 IBM Corporation 68
© 2013 IBM Corporation 69
© 2013 IBM Corporation 70
© 2013 IBM Corporation 71
© 2013 IBM Corporation
Keep track / Use facili4es available
• Plenty of process monitoring somware out there
• Consider resource limi4ng / thronling facili4es
72
© 2013 IBM Corporation
SHARING MEMORY Two for me and one for you…
73
© 2013 IBM Corporation
Two threads and one field
74
Object
Thread field1
field2
field<N>
…
“Same”
© 2013 IBM Corporation
Two threads and one field
75
Object
Thread field1
field2
field<N>
…
field1
field2
field<N>
…
“Different”
© 2013 IBM Corporation
Example
76
© 2013 IBM Corporation
The CPU Cache (High level)
77
CPU: Wikipedia Commons https://en.wikipedia.org/wiki/Central_processing_unit
(0x1F89DB04)
Memory
CPU
© 2013 IBM Corporation
The CPU Cache (High level)
78
CPU: Wikipedia Commons https://en.wikipedia.org/wiki/Central_processing_unit
(0x1F89DB04)
Memory
CPU
Cache
© 2013 IBM Corporation
The CPU Cache (High level)
79
CPU: Wikipedia Commons https://en.wikipedia.org/wiki/Central_processing_unit
(0x1F89DB04)
Memory
CPU
Cache
© 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
© 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
© 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
© 2013 IBM Corporation
Two threads and two fields
83
Object
Thread field1
field2
field<N>
…
“Same”
© 2013 IBM Corporation
Two threads and two fields
84
Object
Thread field1
field2
field<N>
…
field1
field2
field<N>
…
“Different”
© 2013 IBM Corporation
Example
85
© 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
© 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
© 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
© 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
© 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
© 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
© 2013 IBM Corporation
FIELD ORDERING When ordering pizza you expect the crust on the bonom…
92
© 2013 IBM Corporation
Subclass with fields “far apart”
93
© 2013 IBM Corporation
Subclass with fields “far apart”
94
© 2013 IBM Corporation
Two threads and two fields and one subclass
95
Object
Thread
field1
field2
…
pad001
pad0NN
pad100 “Second”
pad1NN
…
field3
© 2013 IBM Corporation
Two threads and two fields and one subclass
96
Object
Thread
field1
field2
…
pad001
pad0NN
pad100
pad1NN
… “Third”
field3
© 2013 IBM Corporation
Example
97
© 2013 IBM Corporation
So what happened?
98
© 2013 IBM Corporation
So what happened?
99
field1
field2
…
pad001
pad0NN
pad100
pad1NN
…
field3
© 2013 IBM Corporation
So what happened?
100
field1
field2
…
pad001
pad0NN
pad100
pad1NN
…
field3
© 2013 IBM Corporation
So what happened?
101
field1 field2
…
pad001
pad0NN
pad100
pad1NN
…
field3
© 2013 IBM Corporation
So what happened?
102
field1 field2
…
pad001
pad0NN
pad100
pad1NN
…
field3
© 2013 IBM Corporation
So what happened?
103
field1 field2
…
pad001
pad0NN
pad100
pad1NN
…
field3
Cache Line
© 2013 IBM Corporation
So what happened? (Alternate version)
104
field1
…
pad001
pad0NN
pad100
pad1NN
…
field2 field3
© 2013 IBM Corporation
CACHE CAPACITY Spreading things out doesn’t always reduce collisions…
105
© 2013 IBM Corporation
Small data, Big problems
106
byte[]
© 2013 IBM Corporation
Small data, Big problems
107
Cache Line (64 Bytes)
byte[]
© 2013 IBM Corporation
Small data, Big problems
108
Cache Line (64 Bytes)
byte[]
© 2013 IBM Corporation
Small data, Big problems
109
4KB 4KB
Cache Line (64 Bytes)
byte[]
© 2013 IBM Corporation
Small data, Big problems
110
4KB 4KB
Cache Line (64 Bytes)
byte[]
© 2013 IBM Corporation
Small data, Big problems
111
4KB 4KB
Cache Line (64 Bytes)
byte[]
© 2013 IBM Corporation
Small data, Big problems
112
4KB 4KB
Cache Line (64 Bytes)
byte[]
© 2013 IBM Corporation
Small data, Big problems
113
4KB 4KB
Cache Line (64 Bytes)
byte[]
© 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[]
© 2013 IBM Corporation
Example
115
© 2013 IBM Corporation
Cache “capacity” is less than you think
116
CPU: Wikipedia Commons https://en.wikipedia.org/wiki/Central_processing_unit
Cache
© 2013 IBM Corporation
Cache “capacity” is less than you think
117
CPU: Wikipedia Commons https://en.wikipedia.org/wiki/Central_processing_unit
Cache
© 2013 IBM Corporation
Cache “capacity” is less than you think
118
CPU: Wikipedia Commons https://en.wikipedia.org/wiki/Central_processing_unit
Cache
© 2013 IBM Corporation
Cache “capacity” is less than you think
119
CPU: Wikipedia Commons https://en.wikipedia.org/wiki/Central_processing_unit
Cache
© 2013 IBM Corporation
Cache “capacity” is less than you think
120
CPU: Wikipedia Commons https://en.wikipedia.org/wiki/Central_processing_unit
Cache
© 2013 IBM Corporation
Cache “capacity” is less than you think
121
CPU: Wikipedia Commons https://en.wikipedia.org/wiki/Central_processing_unit
Cache
© 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
© 2013 IBM Corporation
HOW MEMORY WORKS Before I forget, a few more things about…
123
© 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
© 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
© 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
© 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
© 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
© 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
© 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
© 2013 IBM Corporation
Non Uniform Memory Architecture
• JVMs do have support • Balanced GC policy • -‐Xnuma
• Plaaorm commands for thronling / afini4zing • Taskset • Numactl
• Virtualiza4on
131
© 2013 IBM Corporation
Resource on Memory
132
© 2013 IBM Corporation
PARTING REMARKS And finally…
133
© 2013 IBM Corporation
? 134
© 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