Professional Documents
Culture Documents
Javaoptimizationtwjug
Javaoptimizationtwjug
Leon Chen ()
Ericsson
Oracle
Java Roadmap
JRockit
Hotspot
HotRockit
Java SE Roadmap
7u21
Java Client Security Enhancements
App Store Packaging tools
2013
Lambda
JVM Convergence
JavaScript Interop
JavaFX 8
3D API
Java SE Embedded support
Enhanced HTML5 support
JDK 9
Modularity Jigsaw
Interoperability
Cloud
Ease of Use
JavaFX JSR
Optimizations
JDK 8u40
2014
2015
2016
NetBeans IDE 8
JDK 8u20
NetBeans IDE 9
JDK 8 support
Scene Builder 2.0 support
Deterministic G1
Java Mission Control 6.0
Improved JRE installer
App bundling
enhancements
JDK 9 support
Scene Builder 3.0 support
JavaFX 8 support
Enhanced Java IDE support
JVM GC Tuning
64-bit
Windows/Linux: different JVM, Solaris: add -d64
-XX:+UseCompressedOops (default JDK6_23+)
Compressed references: 32GB Max (26GB best)
-Xmx: 26G (compressed) / unlimited (regular)
class Test {
private List<User> userList =
new ArrayList<User>();
user = null;
//No use
}
Tracing GC Example
Runtime
Stack
Hea
p
A
Tracing GC Example
Runtime
Stack
Hea
p
A
Tracing GC Example
Runtime
Stack
Heap
A
Tracing GC Example
Runtime
Stack
Heap
A
Tracing GC Example
Runtime
Stack
Heap
A
Tracing GC Example
Runtime
Stack
Heap
A
K
H
Garbage Collection
Tune GC ?
GC Performance
Performance GC
!!!
GC Logging in Production
Dont be afraid to enable GC logging in production
Very helpful when diagnosing production issues
GC logging in production
I shoot them!
Also useful:
-Xloggc:<file>
Rotate GC Log, After Java 1.6_34 (or 1.7_2):
-XX:+UseGCLogFileRotation
-XX:NumberOfGCLogFiles=5
-XX:GCLogFileSize=10M
Native
Young
Old
Young Generation
Eden where new objects get
instantiated
2 Survivor Spaces to hold live
objects during minor GC
Old Generation
For tenured objects
Permanent Generation
JVM meta data
Hotspot Internals
Generations & Object Lifecycle
Eden
S0
S1
Hotspot Internals
Object lifecycle
Number
indicates
Age
Hotspot Internals
Object lifecycle
Hotspot Internals
Object lifecycle
Hotspot Internals
Object lifecycle
Hotspot Internals
Object lifecycle
Hotspot Internals
Object lifecycle
Hotspot Internals
Object lifecycle
Hotspot GC Tuning
Footprint
(Heap Size)
Throughput
Latencies
Footprint
(Heap Size)
Throughput
Latencies
Hotspot Tuning
Sizing Heap
GC log example:
GC Triggered
Heap Usage
Size of
long lived objects
-Xmn768m
-Xms2g Xmx2g
Native
GC Fundamentals
Garbage Distribution Objects die young
GC Fundamentals
Garbage Distribution - Generational Collection
Memory Leak
How do you know there is memory leak?
OOM (OutOfMemory) after a while (a few hours/a few days)
Memory used for long lived objects increases over time
Usually not a JVM problem, but a problem in application
Long lived
objects
SoftReference
Used for cache
GCed any time after there are no strong references to the referent,
but is typically retained until memory is low.
PhantomReference
Used for housekeeping (without using finalize, dont use
finalize)
Footprint
(Heap Size)
Throughput
Latencies
Throughput GCs
Move most work to GC pauses
Application threads do as little as possible
Least overall GC overhead
Application Requirement
Different applications have different requirements
Higher Throughput:
Web application: pauses during garbage collection may be
tolerable, or simply obscured by network latencies
Batch processing
Lower Latencies:
Interactive graphics application
-XX:+UseSerialGC
-XX:+UseParNewGC
G1
-XX:+UseG1GC
-XX:+UseConcMarkSweepGC
-XX:+UseParallelOldGC
http://blogs.sun.com/jonthecollector/entry/our_collectors
-XX:+UseSerialGC
-XX:+UseParNewGC
G1
-XX:+UseG1GC
-XX:+UseConcMarkSweepGC
-XX:+UseParallelOldGC
http://blogs.sun.com/jonthecollector/entry/our_collectors
Serial Collector
Serial
App Thread
GC Thread
-XX:+UseSerialGC
-XX:+UseParNewGC
G1
-XX:+UseG1GC
-XX:+UseConcMarkSweepGC
-XX:+UseParallelOldGC
http://blogs.sun.com/jonthecollector/entry/our_collectors
Serial
App Thread
GC Thread
-XX:+UseSerialGC
-XX:+UseParNewGC
G1
-XX:+UseG1GC
-XX:+UseConcMarkSweepGC
-XX:+UseParallelOldGC
http://blogs.sun.com/jonthecollector/entry/our_collectors
CMS Collector
App Thread
GC Thread
App Thread
GC Thread
Young
Serial
Copying
Collector
(default)
2+ CPUs
Parallel Copying
Collector
-XX:+UseParNewGC
Throughput Collectors
1 CPU
Serial
Copying
Collector
(default)
Heap Sizes
2+ CPUs
Parallel Scavenge
Collector
-XX:NewSize
-XX:MaxNewSize
-XX:SurvivorRatio
-XX:+UseParallelGC
Concurrent Collector
MarkCompact
Collector
(default)
Old
Permanent
XX:+UseConcMarkSwe
epGC
MarkCompact
Collector
(default)
Parallel Old
-Xms
-XX:+UseParallelOldGC
-Xmx
-XX:PermSize
-XX:MaxPermSize
G1 Collector
The Garbage-First Collector
G1 Collector
The Garbage-First Collector
App Thread
GC Thread
G1 Garbage First
Heap Layout
Region Type
Eden
S
S
Survivor
Old
Free
CMS vs G1 Collectors
GC Comparison
GC Comparison
GC Comparison
Cons
Heuristics in place but not fine tuned yet
Has a larger memory footprint
More concurrent work compared to other collectors
Tuning:
Garbage First Garbage Collector Tuning
http://www.oracle.com/technetwork/articles/java/g1gc-1984535.html
References
Hotspot Resources
Java Performance Charlie Hunt, Binu John
Hotspot Tuning Book
Java (JRockit)
Mission Control
Java SE Advanced
New
Java SE Advanced
* Oracles JRE
* JRockit JDKs
* Java(JRockit) Mission
Control
* Monitoring and
Management features
(including APIs for EM
integration)
93
94
95
96
SLA
Breach
Server
restart
[Sun 21:00]
[Sun 24:00]
XXXX
Analyze
logs
[Mon 09:30]
Turn on
detailed
logging
[Tue 13:00]
Analyze
logs
[Fri 09:00]
Turn off
detailed
logging
[Fri 24:00]
Analyze Logs
and JFR
[Mon 09:30]
98
How to use?
Thank you!