Más contenido relacionado La actualidad más candente (15) Similar a JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry (20) JavaOne 2013: Garbage Collection Unleashed - Demystifying the Wizardry1. © 2013 IBM Corporation
Ryan
A.
Sciampacone
–
Managed
Run4me
Architect
24
September
2013
Garbage
Collec4on
Unleashed
Demys4fying
the
Wizardry
2. © 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
3. © 2013 IBM Corporation
Your
Speaker:
Ryan
A.
Sciampacone
• Run4me
Architect
@
IBM
(JTC)
• Interpreters
• Garbage
Collec4on
• Plaaorm
interfacing
/
op4miza4on
• Hardware
exploita4on
(E)
ryan_sciampacone@ca.ibm.com
(T)
@rsciampacone
• Visit
the
IBM
Booth
#5112
to
meet
other
IBM
Developers
3
4. © 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
5. © 2013 IBM Corporation
UP
TO
SPEED
Let’s
get
everyone…
5
6. © 2013 IBM Corporation
Compac4on
6
Thread Graphic: Wikimedia Commons http://en.m.wikipedia.org/wiki/File:Process_vs._thread.svg
?
Allocate
Heap
Object
Thread
7. © 2013 IBM Corporation
Compac4on
7
Thread Graphic: Wikimedia Commons http://en.m.wikipedia.org/wiki/File:Process_vs._thread.svg
?
Allocate
Heap
Object
Thread
8. © 2013 IBM Corporation
Compac4on
8
Thread Graphic: Wikimedia Commons http://en.m.wikipedia.org/wiki/File:Process_vs._thread.svg
?
Allocate
Heap
Object
Thread
9. © 2013 IBM Corporation
Compac4on
9
Thread Graphic: Wikimedia Commons http://en.m.wikipedia.org/wiki/File:Process_vs._thread.svg
Allocate
Heap
Object
Thread
10. © 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
11. © 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
12. © 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
13. © 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
14. © 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
15. © 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
16. © 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
17. © 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
18. © 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
19. © 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
20. © 2013 IBM Corporation
Stop
the
World
20
Duke Logo: © Oracle
Recycle Symbol: Creative Commons http://commons.wikimedia.org/wiki/File:Recycle.jpg
21. © 2013 IBM Corporation
Concurrent
21
Duke Logo: © Oracle
Recycle Symbol: Creative Commons http://commons.wikimedia.org/wiki/File:Recycle.jpg
Java
Ac4vity
GC
Ac4vity
22. © 2013 IBM Corporation
Parallel
22
Duke Logo: © Oracle
Recycle Symbol: Creative Commons http://commons.wikimedia.org/wiki/File:Recycle.jpg
Java
Ac4vity
GC
Ac4vity
…
23. © 2013 IBM Corporation
ALLOCATION
Quick
look
at
the
mechanics
of…
23
24. © 2013 IBM Corporation
Alloca4on
24
Padlock: Public domain http://en.wikipedia.org/wiki/File:Viking_Age_lock.png
Heap
Object
Thread
Allocate
25. © 2013 IBM Corporation
Alloca4on
25
Padlock: Public domain http://en.wikipedia.org/wiki/File:Viking_Age_lock.png
Heap
Object
Thread
Allocate
26. © 2013 IBM Corporation
Alloca4on
26
Padlock: Public domain http://openclipart.org/detail/22179/lock-by-nicubunu
Heap
Object
Thread
Allocate
Private
Buffer
27. © 2013 IBM Corporation
Alloca4on
27
Padlock: Public domain http://openclipart.org/detail/22179/lock-by-nicubunu
Heap
Object
Thread
Allocate
28. © 2013 IBM Corporation
Alloca4on
28
Padlock: Public domain http://openclipart.org/detail/22179/lock-by-nicubunu
Heap
Object
Thread
Allocate
29. © 2013 IBM Corporation
FINALIZATION
Gekng
around
to
eventually
talking
about
something
you
inevitably
have
to…
29
30. © 2013 IBM Corporation
The
meaning
of
“in
scope”
30
31. © 2013 IBM Corporation
The
meaning
of
“in
scope”
31
Simple
Finalizer
32. © 2013 IBM Corporation
The
meaning
of
“in
scope”
32
Create
instance
of
finalizable
object
33. © 2013 IBM Corporation
The
meaning
of
“in
scope”
33
No
references
to
the
finalizable
object
at
this
point
34. © 2013 IBM Corporation
The
meaning
of
“in
scope”
34
Will
obj
be
finalized?
36. © 2013 IBM Corporation
Perhaps
a
bit
more
dangerous…
36
37. © 2013 IBM Corporation
THE
ORDER
OF
THINGS
Finaliza4on
37
38. © 2013 IBM Corporation
What
can
we
expect
as
output?
38
40. © 2013 IBM Corporation
So
what
happened?
40
New Old
FinalizableObject(2)
FinalizableObject(1)
41. © 2013 IBM Corporation
So
what
happened?
41
New Old
FinalizableObject(2)
FinalizableObject(1)
42. © 2013 IBM Corporation
So
what
happened?
42
New Old
FinalizableObject(2)
FinalizableObject(1)
GC
43. © 2013 IBM Corporation
So
what
happened?
43
New Old
FinalizableObject(2)
FinalizableObject(1)
GC
Tenure
44. © 2013 IBM Corporation
So
what
happened?
44
New Old
FinalizableObject(2)
FinalizableObject(1)
45. © 2013 IBM Corporation
So
what
happened?
45
New Old
FinalizableObject(2)
FinalizableObject(1)
46. © 2013 IBM Corporation
So
what
happened?
46
New Old
FinalizableObject(2)
FinalizableObject(1)
47. © 2013 IBM Corporation
So
what
happened?
47
New Old
FinalizableObject(2)
FinalizableObject(1)
GC
48. © 2013 IBM Corporation
So
what
happened?
48
New Old
FinalizableObject(2)
FinalizableObject(1)
GC
Finalized!
49. © 2013 IBM Corporation
ANCHOR
POINTS
AND
GC
Finaliza4on
49
50. © 2013 IBM Corporation
What
about
anchor
points?
50
finalize()finalize()
51. © 2013 IBM Corporation
What
about
anchor
points?
51
53. © 2013 IBM Corporation
Why
only
one?
53
finalize()finalize()
54. © 2013 IBM Corporation
Why
only
one?
54
finalize()finalize()
55. © 2013 IBM Corporation
Why
only
one?
55
New Old
56. © 2013 IBM Corporation
Why
only
one?
56
New Old
Allocate?
57. © 2013 IBM Corporation
Why
only
one?
57
New Old
Allocate?
58. © 2013 IBM Corporation
Why
only
one?
58
New Old
Allocate?
Allocate?
59. © 2013 IBM Corporation
Why
only
one?
59
New Old
Allocate?
Allocate?
GC
60. © 2013 IBM Corporation
ICEBERGS
What
lies
beneath
the
surface…
60
61. © 2013 IBM Corporation61
Iceberg: Jesus Diaz, Gizmodo
62. © 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
65. © 2013 IBM Corporation
Not
all
memory
is
“heap”
memory
65
Heap
Object
Na4ve
Resource
66. © 2013 IBM Corporation
Not
all
memory
is
“heap”
memory
66
Heap
Object
Na4ve
Resource
67. © 2013 IBM Corporation
Not
all
memory
is
“heap”
memory
67
Heap
Object
Na4ve
Resource
72. © 2013 IBM Corporation
Keep
track
/
Use
facili4es
available
• Plenty
of
process
monitoring
somware
out
there
• Consider
resource
limi4ng
/
thronling
facili4es
72
73. © 2013 IBM Corporation
SHARING
MEMORY
Two
for
me
and
one
for
you…
73
74. © 2013 IBM Corporation
Two
threads
and
one
field
74
Object
Thread
field1
field2
field<N>
…
“Same”
75. © 2013 IBM Corporation
Two
threads
and
one
field
75
Object
Thread
field1
field2
field<N>
…
field1
field2
field<N>
…
“Different”
77. © 2013 IBM Corporation
The
CPU
Cache
(High
level)
77
CPU: Wikipedia Commons https://en.wikipedia.org/wiki/Central_processing_unit
(0x1F89DB04)
Memory
CPU
78. © 2013 IBM Corporation
The
CPU
Cache
(High
level)
78
CPU: Wikipedia Commons https://en.wikipedia.org/wiki/Central_processing_unit
(0x1F89DB04)
Memory
CPU
Cache
79. © 2013 IBM Corporation
The
CPU
Cache
(High
level)
79
CPU: Wikipedia Commons https://en.wikipedia.org/wiki/Central_processing_unit
(0x1F89DB04)
Memory
CPU
Cache
80. © 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
81. © 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
82. © 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
83. © 2013 IBM Corporation
Two
threads
and
two
fields
83
Object
Thread
field1
field2
field<N>
…
“Same”
84. © 2013 IBM Corporation
Two
threads
and
two
fields
84
Object
Thread
field1
field2
field<N>
…
field1
field2
field<N>
…
“Different”
86. © 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
87. © 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
88. © 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
89. © 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
90. © 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
91. © 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
92. © 2013 IBM Corporation
FIELD
ORDERING
When
ordering
pizza
you
expect
the
crust
on
the
bonom…
92
93. © 2013 IBM Corporation
Subclass
with
fields
“far
apart”
93
94. © 2013 IBM Corporation
Subclass
with
fields
“far
apart”
94
95. © 2013 IBM Corporation
Two
threads
and
two
fields
and
one
subclass
95
Object
Thread
field1
field2
…
pad001
pad0NN
pad100 “Second”
pad1NN
…
field3
96. © 2013 IBM Corporation
Two
threads
and
two
fields
and
one
subclass
96
Object
Thread
field1
field2
…
pad001
pad0NN
pad100
pad1NN
…
“Third”
field3
99. © 2013 IBM Corporation
So
what
happened?
99
field1
field2
…
pad001
pad0NN
pad100
pad1NN
…
field3
100. © 2013 IBM Corporation
So
what
happened?
100
field1
field2
…
pad001
pad0NN
pad100
pad1NN
…
field3
101. © 2013 IBM Corporation
So
what
happened?
101
field1 field2
…
pad001
pad0NN
pad100
pad1NN
…
field3
102. © 2013 IBM Corporation
So
what
happened?
102
field1 field2
…
pad001
pad0NN
pad100
pad1NN
…
field3
103. © 2013 IBM Corporation
So
what
happened?
103
field1 field2
…
pad001
pad0NN
pad100
pad1NN
…
field3
Cache
Line
104. © 2013 IBM Corporation
So
what
happened?
(Alternate
version)
104
field1
…
pad001
pad0NN
pad100
pad1NN
…
field2 field3
105. © 2013 IBM Corporation
CACHE
CAPACITY
Spreading
things
out
doesn’t
always
reduce
collisions…
105
106. © 2013 IBM Corporation
Small
data,
Big
problems
106
byte[]
107. © 2013 IBM Corporation
Small
data,
Big
problems
107
Cache
Line
(64
Bytes)
byte[]
108. © 2013 IBM Corporation
Small
data,
Big
problems
108
Cache
Line
(64
Bytes)
byte[]
109. © 2013 IBM Corporation
Small
data,
Big
problems
109
4KB
4KB
Cache
Line
(64
Bytes)
byte[]
110. © 2013 IBM Corporation
Small
data,
Big
problems
110
4KB
4KB
Cache
Line
(64
Bytes)
byte[]
111. © 2013 IBM Corporation
Small
data,
Big
problems
111
4KB
4KB
Cache
Line
(64
Bytes)
byte[]
112. © 2013 IBM Corporation
Small
data,
Big
problems
112
4KB
4KB
Cache
Line
(64
Bytes)
byte[]
113. © 2013 IBM Corporation
Small
data,
Big
problems
113
4KB
4KB
Cache
Line
(64
Bytes)
byte[]
114. © 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[]
116. © 2013 IBM Corporation
Cache
“capacity”
is
less
than
you
think
116
CPU: Wikipedia Commons https://en.wikipedia.org/wiki/Central_processing_unit
Cache
117. © 2013 IBM Corporation
Cache
“capacity”
is
less
than
you
think
117
CPU: Wikipedia Commons https://en.wikipedia.org/wiki/Central_processing_unit
Cache
118. © 2013 IBM Corporation
Cache
“capacity”
is
less
than
you
think
118
CPU: Wikipedia Commons https://en.wikipedia.org/wiki/Central_processing_unit
Cache
119. © 2013 IBM Corporation
Cache
“capacity”
is
less
than
you
think
119
CPU: Wikipedia Commons https://en.wikipedia.org/wiki/Central_processing_unit
Cache
120. © 2013 IBM Corporation
Cache
“capacity”
is
less
than
you
think
120
CPU: Wikipedia Commons https://en.wikipedia.org/wiki/Central_processing_unit
Cache
121. © 2013 IBM Corporation
Cache
“capacity”
is
less
than
you
think
121
CPU: Wikipedia Commons https://en.wikipedia.org/wiki/Central_processing_unit
Cache
122. © 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
123. © 2013 IBM Corporation
HOW
MEMORY
WORKS
Before
I
forget,
a
few
more
things
about…
123
124. © 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
125. © 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
126. © 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
127. © 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
128. © 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
129. © 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
130. © 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
131. © 2013 IBM Corporation
Non
Uniform
Memory
Architecture
• JVMs
do
have
support
• Balanced
GC
policy
• -‐Xnuma
• Plaaorm
commands
for
thronling
/
afini4zing
• Taskset
• Numactl
• Virtualiza4on
131
132. © 2013 IBM Corporation
Resource
on
Memory
132
133. © 2013 IBM Corporation
PARTING
REMARKS
And
finally…
133
135. © 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