SlideShare a Scribd company logo
Java Garbage Collector:
Friend or Foe
Krasimir Semerdzhiev
Development Architect / SAP Labs Bulgaria
Agenda
1. Brief historical view
2. Myths and Urban legends
3. GC machinery
4. Try to stay out of trouble
History of Garbage Collection
A long time ago, in a galaxy far far away…
* Counting from [McCarthy 1959]
McCarthy (1959)
LISt Processor (LISP)
Reference counting (IBM)
Naive Mark/sweep GC
Semi-space collector
1959*
Knuth (1973/1978)
Copying collector
Mark/sweep GC
Mark/don’t sweep GC
1970 1990 2000 2011
Appel (1988), Baker (1992)
Generational GC
Train GC
Stop the world
Cheng-Blelloch (2001)
Concurrent
Parallel
Real-Time GC
2003
Bacon, Cheng, Rajan (2003)
Metronome GC
Garbage first GC (G1)
Ergonomics
20091995
Agenda
1. Brief historical view
2. Myths and Urban legends
3. GC machinery
4. Try to stay out of trouble
5. Tools for the masses
Myths
Java and C/C++ performance
Is C/C++ faster than Java?
The short answer: it depends.
/Cliff Click
Myths
My GC cleans up tons of memory – what’s going on.
String s = "c"?
= ref + 8 + (12 + 2) + 4 + 4 + 4 > 34 bytes.
/** The value is used for character storage. */
private final char value[];
/** The offset is the first index of the storage that is used. */
private final int offset;
/** The count is the number of characters in the String. */
private final int count;
/** Cache the hash code for the string */
private int hash; // Default to 0
/** use serialVersionUID from JDK 1.0.2 for interoperability */
private static final long serialVersionUID =
-6849794470754667710L;
Is Java bad at memory management?
public static void main(String[] args) throws Exception {
final long start = Runtime.getRuntime().freeMemory();
final byte[][] arrays = new byte[100][];
for (int i = 0; i < arrays.length; i++) {
arrays[i] = new byte[100];
long current = Runtime.getRuntime().freeMemory();
System.out.println(start + " " + current);
Thread.sleep(1000);
}
}
Agenda
1. Brief historical view
2. Myths and Urban legends
3. GC machinery*
4. Try to stay out of trouble
5. Tony Printezis
* Credits for the GC insights go to
Tony Printezis and his excellent
J1 sessions
Garbage collector
Let’s start with a simple memory example…
Garbage collector
Mark-Sweep
Root object
Mark-Sweep
Garbage collector
Mark-Sweep
Root object
Mark-Sweep – Marking…
Garbage collector
Mark-Sweep
Root object
Free List Root
Mark-Sweep – Sweeping…
Garbage collector
Let’s try another one …
Garbage collector
Mark-Compact
Root object
Mark-Compact
Garbage collector
Mark-Compact
Root object
Mark-Compact – Marking…
Garbage collector
Mark-Compact
Root object
Mark-Sweep – Compacting…
Free Pointer
Garbage collector
Let’s try another one …
Garbage collector
Copying
Root object
Copying
From space
To space Free and unused
Garbage collector
Copying
Root object
Copying – Evacuation
From space
To space Free and unused
Garbage collector
Copying
Root object
Copying – Flipping
From space
To space Free and unused
Free Pointer
Garbage collector
Let’s try another one … ;o)
Garbage collector
Generational Garbage Collection
Generational Garbage Collection – moving to more modern times
Young generation
Old Generation
Allocations
Promotion
Java Heap
Hotspot JVM
Memory layout
Hotspot JVM (Java) heap layout
Young generation
Old Generation
Perm Generation
Everything
else
Java Heap
Hotspot JVM
Memory layout
Hotspot JVM (Java) heap layout
Young generation
Old Generation
Perm Generation
Everything
else
Maximum size is limited:
■ 32 bit -> 2Gb
■ 64 bit -> way larger
If 2Gb is the max for the process – you can’t get it all
for the Java heap only!
Hotspot JVM
Memory layout
Hotspot JVM (Java) heap layout
Survivor spaces
Old Generation
Perm Generation
Young generation
unused
Eden
From To
Hotspot JVM
Memory layout
Hotspot JVM (Java) – (Small) GC running
Survivor spaces
Old Generation
Perm Generation
Young generation
unused
Eden
From To
Hotspot JVM
Memory layout
Hotspot JVM (Java) – (Minor) GC running
Survivor spaces
Old Generation
Perm Generation
Young generation
unused
Eden
From To
Hotspot JVM
Memory details
-Xmx, -Xms, -Xmn
 Control the Java Object heap size only
 Doesn’t have impact on Perm size, native heap and the Thread stack size
-XX:PermSize, -XX:MaxPermSize
 Stores class definitions, methods, statis fields
 Common reason for OOM errors.
-Xss
 Configures the stack size of every thread.
-XX:+UseTLAB, -XX:-UseTLAB, -XX:+PrintTLAB
 Enables the Thread Local Allocation Buffer.
 Since Java SE 1.5 – this is automatically tuned to each and every thread.
TCP Connection buffer sizes – allocated in native space
 Use Socket.setSendBufferSize(int) and Socket.setReceiveBufferSize(int).
 OS will use the smaller of the two or will simply ignore that setting.
Object allocation statistics:
■ Up to 98% of new objects are
short-lived
■ Up to 98% die before another
Mb is allocated
Agenda
1. Brief historical view
2. Myths and Urban legends
3. GC machinery
4. Try to stay out of trouble
OutOfMemoryError
How to proceed?
java.lang.OutOfMemoryError: PermGen space
 Increase the Perm Space – will help if there is no code generation happening
 In case of a leak – the only solution is frequent system restart.
java.lang.OutOfMemoryError: unable to create new native thread
 Decrease –Xmx or –Xss
java.lang.StackOverflowError
 Increase –Xss or fix the corresponding algorithm
IOException: Too many open files (for example)
 Increase the OS file handle limit per process
 Check for leaking file handles
 Physical limit of the VM is 2048 ZIP/JAR files opened at the same time.
java.lang.OutOfMemoryError: Direct buffer memory
 Direct mapped memory – used for java.nio.ByteBuffer
 Increase -XX:MaxDirectMemorySize
Finalizer methods
Good or bad
Again short answer: it depends ;-)
Infrastructure components
 Might be used for debugging/tracing purposes
 Major scenario – closing of critical backend resources
 All finalizer methods are collected separately. No mass-wipe is performed on them!
 Never, ever throw an exception in a finalizer!
Applications
 Avoid finalizers by all means!
Per-request created objects
 Avoid finalizers by all means!
Finalizer queue
Working threads
Finalizer thread (singleton)
Response time peaks
without CMS
All those are full GCs…
No more full GCs…
Response time peaks
with CMS
Garbage Collection Strategies
Does it pay off to play with that?
-XX:+UseSerialGC
 Default state before Java 5. Obsolete!
-XX:+UseParallelGC - Parallel Scavange GC (1.4.2)
 Works on Young Generation only
 Use -XX:ParallelGCThreads to configure it
-XX:+UseParNewGC - Parallel New-Gen GC (5.0)
 Use also –XX:SurvivorRatio and –XX:MaxTenuringThreshold to
define the lifespan of objects in the eden space.
 -XX:+CMSClassUnloadingEnabled to trigger concurrent cleanup of
the Perm space
-XX:+UseConcMarkSweepGC - Concurrent Old-Gen GC
 Default since Java SE 5.
-XX:+UseParallelOldGC - Concurrent Old-Gen GC (5.0)
 Parallel Compaction of Old space
Terms:
• Serial – 1 thing at a
time
• Parallel – work is
done in multiple
threads
• Concurrent – work
happens
simultaneously
Garbage Collection Ergonomics
What’s that?
New way to configure GC – specify:
 Max pause time goal (-XX:MaxGCPauseMillis)
 Throughput goal (-XX:GCTimeRatio)
 Assumes minimal footprint goal
 Use -XX:+UseParallelGC with those.
 Garbage First (G1) GC will be the default in Java SE 7. Released
with JDK 1.6.0_u14 for non-productive usage.
 Enable that for testing via:
 -XX:+UnlockExperimentalVMOptions
 -XX:+UseG1GC
Analyzing Garbage Collection output
Getting GC output is critical for further analysis!
 -verbose:gc get 1 line per GC run with some basic inf
 -XX:+PrintGCDetails get more extended info (perm, eden, tenured)
 -XX:+PrintGCTimeStamps get timestamps since the start of the VM. Allows correlation
 -XX:-TraceClassUnloading get also the unloaded classes – helps tracing leaks
 -Xloggc:gc.log direct GC output to a special file instead of the process output
 -XX:+HeapDumpOnOutOfMemoryError Heap dump generation on OutOfMemory
GC Viewer
GC output viewer
 Import the gc.out file.
 Correlate over time
 So far the most
comprehensive viewer
 Stay tuned and monitor
the Eclipse news ;-)
Visual VM
Supplied by Oracle with JDK
 Free and very comprehensive
 Evolves together with the VM.
 Focus shifting from that to
Mission Control (the Jrockit
profiling solution)
Eclipse Memory Analyzer
Developed by SAP and IBM in Eclipse
 Track GC roots
 Do what-if analysis
 SQL-like query language
 Custom filters
 Track Leaking
classloaders
Garbage Collection – the universal settings
There are NO universal settings! Sorry. :(
 G1 is the first GC, trying to go in that direction and leave the self-tuning to the VM
 You have to test with realistic load!
 You have to test on realistic hardware!
 Tune the GC as you fix the memory leaks which will inevitably show up.
 Try to find the balance of uptime/restart intervals.
Contact Questions?
Krasimir Semerdzhiev
krasimir.semerdzhiev@sap.com

More Related Content

What's hot

第11回 配信講義 計算科学技術特論A(2021)
第11回 配信講義 計算科学技術特論A(2021)第11回 配信講義 計算科学技術特論A(2021)
第11回 配信講義 計算科学技術特論A(2021)
RCCSRENKEI
 
Exploring Garbage Collection
Exploring Garbage CollectionExploring Garbage Collection
Exploring Garbage Collection
ESUG
 
Shared Memory Performance: Beyond TCP/IP with Ben Cotton, JPMorgan
Shared Memory Performance: Beyond TCP/IP with Ben Cotton, JPMorganShared Memory Performance: Beyond TCP/IP with Ben Cotton, JPMorgan
Shared Memory Performance: Beyond TCP/IP with Ben Cotton, JPMorgan
Hazelcast
 
Ping to Pong
Ping to PongPing to Pong
Ping to Pong
Matt Provost
 
JVM Garbage Collection Tuning
JVM Garbage Collection TuningJVM Garbage Collection Tuning
JVM Garbage Collection Tuning
ihji
 
Am I reading GC logs Correctly?
Am I reading GC logs Correctly?Am I reading GC logs Correctly?
Am I reading GC logs Correctly?
Tier1 App
 
On heap cache vs off-heap cache
On heap cache vs off-heap cacheOn heap cache vs off-heap cache
On heap cache vs off-heap cache
rgrebski
 
Scheduling in Linux and Web Servers
Scheduling in Linux and Web ServersScheduling in Linux and Web Servers
Scheduling in Linux and Web Servers
David Evans
 
淺談 Java GC 原理、調教和 新發展
淺談 Java GC 原理、調教和新發展淺談 Java GC 原理、調教和新發展
淺談 Java GC 原理、調教和 新發展
Leon Chen
 
Heatmap
HeatmapHeatmap
Java memory problem cases solutions
Java memory problem cases solutionsJava memory problem cases solutions
Java memory problem cases solutions
bluedavy lin
 
Processing Big Data in Realtime
Processing Big Data in RealtimeProcessing Big Data in Realtime
Processing Big Data in RealtimeTikal Knowledge
 
Pain points with M3, some things to address them and how replication works
Pain points with M3, some things to address them and how replication worksPain points with M3, some things to address them and how replication works
Pain points with M3, some things to address them and how replication works
Rob Skillington
 
Fight with Metaspace OOM
Fight with Metaspace OOMFight with Metaspace OOM
Fight with Metaspace OOM
Leon Chen
 
CIFAR-10 for DAWNBench: Wide ResNets, Mixup Augmentation and "Super Convergen...
CIFAR-10 for DAWNBench: Wide ResNets, Mixup Augmentation and "Super Convergen...CIFAR-10 for DAWNBench: Wide ResNets, Mixup Augmentation and "Super Convergen...
CIFAR-10 for DAWNBench: Wide ResNets, Mixup Augmentation and "Super Convergen...
Thom Lane
 
証明駆動開発のたのしみ@名古屋reject会議
証明駆動開発のたのしみ@名古屋reject会議証明駆動開発のたのしみ@名古屋reject会議
証明駆動開発のたのしみ@名古屋reject会議Hiroki Mizuno
 
【論文紹介】Relay: A New IR for Machine Learning Frameworks
【論文紹介】Relay: A New IR for Machine Learning Frameworks【論文紹介】Relay: A New IR for Machine Learning Frameworks
【論文紹介】Relay: A New IR for Machine Learning Frameworks
Takeo Imai
 
FOSDEM 2019: M3, Prometheus and Graphite with metrics and monitoring in an in...
FOSDEM 2019: M3, Prometheus and Graphite with metrics and monitoring in an in...FOSDEM 2019: M3, Prometheus and Graphite with metrics and monitoring in an in...
FOSDEM 2019: M3, Prometheus and Graphite with metrics and monitoring in an in...
Rob Skillington
 
Lrz kurs: big data analysis
Lrz kurs: big data analysisLrz kurs: big data analysis
Lrz kurs: big data analysis
Ferdinand Jamitzky
 

What's hot (20)

第11回 配信講義 計算科学技術特論A(2021)
第11回 配信講義 計算科学技術特論A(2021)第11回 配信講義 計算科学技術特論A(2021)
第11回 配信講義 計算科学技術特論A(2021)
 
Exploring Garbage Collection
Exploring Garbage CollectionExploring Garbage Collection
Exploring Garbage Collection
 
Shared Memory Performance: Beyond TCP/IP with Ben Cotton, JPMorgan
Shared Memory Performance: Beyond TCP/IP with Ben Cotton, JPMorganShared Memory Performance: Beyond TCP/IP with Ben Cotton, JPMorgan
Shared Memory Performance: Beyond TCP/IP with Ben Cotton, JPMorgan
 
Ping to Pong
Ping to PongPing to Pong
Ping to Pong
 
JVM Garbage Collection Tuning
JVM Garbage Collection TuningJVM Garbage Collection Tuning
JVM Garbage Collection Tuning
 
Am I reading GC logs Correctly?
Am I reading GC logs Correctly?Am I reading GC logs Correctly?
Am I reading GC logs Correctly?
 
On heap cache vs off-heap cache
On heap cache vs off-heap cacheOn heap cache vs off-heap cache
On heap cache vs off-heap cache
 
Scheduling in Linux and Web Servers
Scheduling in Linux and Web ServersScheduling in Linux and Web Servers
Scheduling in Linux and Web Servers
 
淺談 Java GC 原理、調教和 新發展
淺談 Java GC 原理、調教和新發展淺談 Java GC 原理、調教和新發展
淺談 Java GC 原理、調教和 新發展
 
Heatmap
HeatmapHeatmap
Heatmap
 
Java memory problem cases solutions
Java memory problem cases solutionsJava memory problem cases solutions
Java memory problem cases solutions
 
Processing Big Data in Realtime
Processing Big Data in RealtimeProcessing Big Data in Realtime
Processing Big Data in Realtime
 
Pain points with M3, some things to address them and how replication works
Pain points with M3, some things to address them and how replication worksPain points with M3, some things to address them and how replication works
Pain points with M3, some things to address them and how replication works
 
Fight with Metaspace OOM
Fight with Metaspace OOMFight with Metaspace OOM
Fight with Metaspace OOM
 
CIFAR-10 for DAWNBench: Wide ResNets, Mixup Augmentation and "Super Convergen...
CIFAR-10 for DAWNBench: Wide ResNets, Mixup Augmentation and "Super Convergen...CIFAR-10 for DAWNBench: Wide ResNets, Mixup Augmentation and "Super Convergen...
CIFAR-10 for DAWNBench: Wide ResNets, Mixup Augmentation and "Super Convergen...
 
証明駆動開発のたのしみ@名古屋reject会議
証明駆動開発のたのしみ@名古屋reject会議証明駆動開発のたのしみ@名古屋reject会議
証明駆動開発のたのしみ@名古屋reject会議
 
【論文紹介】Relay: A New IR for Machine Learning Frameworks
【論文紹介】Relay: A New IR for Machine Learning Frameworks【論文紹介】Relay: A New IR for Machine Learning Frameworks
【論文紹介】Relay: A New IR for Machine Learning Frameworks
 
Kafka short
Kafka shortKafka short
Kafka short
 
FOSDEM 2019: M3, Prometheus and Graphite with metrics and monitoring in an in...
FOSDEM 2019: M3, Prometheus and Graphite with metrics and monitoring in an in...FOSDEM 2019: M3, Prometheus and Graphite with metrics and monitoring in an in...
FOSDEM 2019: M3, Prometheus and Graphite with metrics and monitoring in an in...
 
Lrz kurs: big data analysis
Lrz kurs: big data analysisLrz kurs: big data analysis
Lrz kurs: big data analysis
 

Viewers also liked

Options for running Kubernetes at scale across multiple cloud providers
Options for running Kubernetes at scale across multiple cloud providersOptions for running Kubernetes at scale across multiple cloud providers
Options for running Kubernetes at scale across multiple cloud providers
SAP HANA Cloud Platform
 
risk assessment
risk assessment risk assessment
risk assessment SamMedia1
 
SEO in 2017/18
SEO in 2017/18SEO in 2017/18
SEO in 2017/18
Rand Fishkin
 
Taming the ever-evolving Compliance Beast : Lessons learnt at LinkedIn [Strat...
Taming the ever-evolving Compliance Beast : Lessons learnt at LinkedIn [Strat...Taming the ever-evolving Compliance Beast : Lessons learnt at LinkedIn [Strat...
Taming the ever-evolving Compliance Beast : Lessons learnt at LinkedIn [Strat...
Shirshanka Das
 
Inside Google's Numbers in 2017
Inside Google's Numbers in 2017Inside Google's Numbers in 2017
Inside Google's Numbers in 2017
Rand Fishkin
 

Viewers also liked (6)

Options for running Kubernetes at scale across multiple cloud providers
Options for running Kubernetes at scale across multiple cloud providersOptions for running Kubernetes at scale across multiple cloud providers
Options for running Kubernetes at scale across multiple cloud providers
 
risk assessment
risk assessment risk assessment
risk assessment
 
Eclipse Open Source @ SAP
Eclipse Open Source @ SAPEclipse Open Source @ SAP
Eclipse Open Source @ SAP
 
SEO in 2017/18
SEO in 2017/18SEO in 2017/18
SEO in 2017/18
 
Taming the ever-evolving Compliance Beast : Lessons learnt at LinkedIn [Strat...
Taming the ever-evolving Compliance Beast : Lessons learnt at LinkedIn [Strat...Taming the ever-evolving Compliance Beast : Lessons learnt at LinkedIn [Strat...
Taming the ever-evolving Compliance Beast : Lessons learnt at LinkedIn [Strat...
 
Inside Google's Numbers in 2017
Inside Google's Numbers in 2017Inside Google's Numbers in 2017
Inside Google's Numbers in 2017
 

Similar to [BGOUG] Java GC - Friend or Foe

Performance tuning jvm
Performance tuning jvmPerformance tuning jvm
Performance tuning jvm
Prem Kuppumani
 
7 jvm-arguments-v1
7 jvm-arguments-v17 jvm-arguments-v1
7 jvm-arguments-v1
Tier1 app
 
7 jvm-arguments-Confoo
7 jvm-arguments-Confoo7 jvm-arguments-Confoo
7 jvm-arguments-Confoo
Tier1 app
 
OSCON2012TroubleShootJava
OSCON2012TroubleShootJavaOSCON2012TroubleShootJava
OSCON2012TroubleShootJavaWilliam Au
 
Let's talk about Garbage Collection
Let's talk about Garbage CollectionLet's talk about Garbage Collection
Let's talk about Garbage Collection
Haim Yadid
 
JVM Performance Tuning
JVM Performance TuningJVM Performance Tuning
JVM Performance Tuning
Jeremy Leisy
 
Enhancing the region model of RTSJ
Enhancing the region model of RTSJEnhancing the region model of RTSJ
Enhancing the region model of RTSJ
Universidad Carlos III de Madrid
 
Jvm problem diagnostics
Jvm problem diagnosticsJvm problem diagnostics
Jvm problem diagnostics
Danijel Mitar
 
Software Profiling: Understanding Java Performance and how to profile in Java
Software Profiling: Understanding Java Performance and how to profile in JavaSoftware Profiling: Understanding Java Performance and how to profile in Java
Software Profiling: Understanding Java Performance and how to profile in Java
Isuru Perera
 
State of Java Elasticity. Tuning Java Efficiency - GIDS.JAVA LIVE 2020
State of Java Elasticity. Tuning Java Efficiency - GIDS.JAVA LIVE 2020State of Java Elasticity. Tuning Java Efficiency - GIDS.JAVA LIVE 2020
State of Java Elasticity. Tuning Java Efficiency - GIDS.JAVA LIVE 2020
Jelastic Multi-Cloud PaaS
 
Java8 bench gc
Java8 bench gcJava8 bench gc
Java8 bench gc
Hidetomo Morimoto
 
Mastering java in containers - MadridJUG
Mastering java in containers - MadridJUGMastering java in containers - MadridJUG
Mastering java in containers - MadridJUG
Jorge Morales
 
Choosing Right Garbage Collector to Increase Efficiency of Java Memory Usage
Choosing Right Garbage Collector to Increase Efficiency of Java Memory UsageChoosing Right Garbage Collector to Increase Efficiency of Java Memory Usage
Choosing Right Garbage Collector to Increase Efficiency of Java Memory Usage
Jelastic Multi-Cloud PaaS
 
Solr Troubleshooting - TreeMap approach
Solr Troubleshooting - TreeMap approachSolr Troubleshooting - TreeMap approach
Solr Troubleshooting - TreeMap approach
Alexandre Rafalovitch
 
Solr Troubleshooting - Treemap Approach: Presented by Alexandre Rafolovitch, ...
Solr Troubleshooting - Treemap Approach: Presented by Alexandre Rafolovitch, ...Solr Troubleshooting - Treemap Approach: Presented by Alexandre Rafolovitch, ...
Solr Troubleshooting - Treemap Approach: Presented by Alexandre Rafolovitch, ...
Lucidworks
 
Вячеслав Блинов «Java Garbage Collection: A Performance Impact»
Вячеслав Блинов «Java Garbage Collection: A Performance Impact»Вячеслав Блинов «Java Garbage Collection: A Performance Impact»
Вячеслав Блинов «Java Garbage Collection: A Performance Impact»
Anna Shymchenko
 
Heap & thread dump
Heap & thread dumpHeap & thread dump
Heap & thread dump
Nishit Charania
 
Container Performance Analysis Brendan Gregg, Netflix
Container Performance Analysis Brendan Gregg, NetflixContainer Performance Analysis Brendan Gregg, Netflix
Container Performance Analysis Brendan Gregg, Netflix
Docker, Inc.
 
[CCC-28c3] Post Memory Corruption Memory Analysis
[CCC-28c3] Post Memory Corruption Memory Analysis[CCC-28c3] Post Memory Corruption Memory Analysis
[CCC-28c3] Post Memory Corruption Memory Analysis
Moabi.com
 
JVM Magic
JVM MagicJVM Magic

Similar to [BGOUG] Java GC - Friend or Foe (20)

Performance tuning jvm
Performance tuning jvmPerformance tuning jvm
Performance tuning jvm
 
7 jvm-arguments-v1
7 jvm-arguments-v17 jvm-arguments-v1
7 jvm-arguments-v1
 
7 jvm-arguments-Confoo
7 jvm-arguments-Confoo7 jvm-arguments-Confoo
7 jvm-arguments-Confoo
 
OSCON2012TroubleShootJava
OSCON2012TroubleShootJavaOSCON2012TroubleShootJava
OSCON2012TroubleShootJava
 
Let's talk about Garbage Collection
Let's talk about Garbage CollectionLet's talk about Garbage Collection
Let's talk about Garbage Collection
 
JVM Performance Tuning
JVM Performance TuningJVM Performance Tuning
JVM Performance Tuning
 
Enhancing the region model of RTSJ
Enhancing the region model of RTSJEnhancing the region model of RTSJ
Enhancing the region model of RTSJ
 
Jvm problem diagnostics
Jvm problem diagnosticsJvm problem diagnostics
Jvm problem diagnostics
 
Software Profiling: Understanding Java Performance and how to profile in Java
Software Profiling: Understanding Java Performance and how to profile in JavaSoftware Profiling: Understanding Java Performance and how to profile in Java
Software Profiling: Understanding Java Performance and how to profile in Java
 
State of Java Elasticity. Tuning Java Efficiency - GIDS.JAVA LIVE 2020
State of Java Elasticity. Tuning Java Efficiency - GIDS.JAVA LIVE 2020State of Java Elasticity. Tuning Java Efficiency - GIDS.JAVA LIVE 2020
State of Java Elasticity. Tuning Java Efficiency - GIDS.JAVA LIVE 2020
 
Java8 bench gc
Java8 bench gcJava8 bench gc
Java8 bench gc
 
Mastering java in containers - MadridJUG
Mastering java in containers - MadridJUGMastering java in containers - MadridJUG
Mastering java in containers - MadridJUG
 
Choosing Right Garbage Collector to Increase Efficiency of Java Memory Usage
Choosing Right Garbage Collector to Increase Efficiency of Java Memory UsageChoosing Right Garbage Collector to Increase Efficiency of Java Memory Usage
Choosing Right Garbage Collector to Increase Efficiency of Java Memory Usage
 
Solr Troubleshooting - TreeMap approach
Solr Troubleshooting - TreeMap approachSolr Troubleshooting - TreeMap approach
Solr Troubleshooting - TreeMap approach
 
Solr Troubleshooting - Treemap Approach: Presented by Alexandre Rafolovitch, ...
Solr Troubleshooting - Treemap Approach: Presented by Alexandre Rafolovitch, ...Solr Troubleshooting - Treemap Approach: Presented by Alexandre Rafolovitch, ...
Solr Troubleshooting - Treemap Approach: Presented by Alexandre Rafolovitch, ...
 
Вячеслав Блинов «Java Garbage Collection: A Performance Impact»
Вячеслав Блинов «Java Garbage Collection: A Performance Impact»Вячеслав Блинов «Java Garbage Collection: A Performance Impact»
Вячеслав Блинов «Java Garbage Collection: A Performance Impact»
 
Heap & thread dump
Heap & thread dumpHeap & thread dump
Heap & thread dump
 
Container Performance Analysis Brendan Gregg, Netflix
Container Performance Analysis Brendan Gregg, NetflixContainer Performance Analysis Brendan Gregg, Netflix
Container Performance Analysis Brendan Gregg, Netflix
 
[CCC-28c3] Post Memory Corruption Memory Analysis
[CCC-28c3] Post Memory Corruption Memory Analysis[CCC-28c3] Post Memory Corruption Memory Analysis
[CCC-28c3] Post Memory Corruption Memory Analysis
 
JVM Magic
JVM MagicJVM Magic
JVM Magic
 

More from SAP HANA Cloud Platform

SAP Hack2Build hackathon - SAP Commerce Cloud & Kyma runtime
SAP Hack2Build hackathon - SAP Commerce Cloud & Kyma runtimeSAP Hack2Build hackathon - SAP Commerce Cloud & Kyma runtime
SAP Hack2Build hackathon - SAP Commerce Cloud & Kyma runtime
SAP HANA Cloud Platform
 
Gardener: Managed Kubernetes on Your Terms
Gardener: Managed Kubernetes on Your TermsGardener: Managed Kubernetes on Your Terms
Gardener: Managed Kubernetes on Your Terms
SAP HANA Cloud Platform
 
Kyma: Extending Business systems with Kubernetes, Istio and <fill the blank>.
Kyma: Extending Business systems with Kubernetes, Istio and <fill the blank>.Kyma: Extending Business systems with Kubernetes, Istio and <fill the blank>.
Kyma: Extending Business systems with Kubernetes, Istio and <fill the blank>.
SAP HANA Cloud Platform
 
Using Kubernetes to Extend Enterprise Software
Using Kubernetes to Extend Enterprise Software Using Kubernetes to Extend Enterprise Software
Using Kubernetes to Extend Enterprise Software
SAP HANA Cloud Platform
 
Kubernetes, Istio and Knative - noteworthy practical experience
Kubernetes, Istio and Knative - noteworthy practical experienceKubernetes, Istio and Knative - noteworthy practical experience
Kubernetes, Istio and Knative - noteworthy practical experience
SAP HANA Cloud Platform
 
SAP DKOM 2016 | 30154 | SAP HCP Cloud Extensions Intro
SAP DKOM 2016 | 30154 | SAP HCP Cloud Extensions IntroSAP DKOM 2016 | 30154 | SAP HCP Cloud Extensions Intro
SAP DKOM 2016 | 30154 | SAP HCP Cloud Extensions Intro
SAP HANA Cloud Platform
 
SAP TechEd 2015 | DEV109 | Extending Cloud Solutions from SAP using SAP HANA ...
SAP TechEd 2015 | DEV109 | Extending Cloud Solutions from SAP using SAP HANA ...SAP TechEd 2015 | DEV109 | Extending Cloud Solutions from SAP using SAP HANA ...
SAP TechEd 2015 | DEV109 | Extending Cloud Solutions from SAP using SAP HANA ...
SAP HANA Cloud Platform
 
SAP D-Code/TechEd 2014|DEV203|Extending SuccessFactors using SAP HANA Cloud P...
SAP D-Code/TechEd 2014|DEV203|Extending SuccessFactors using SAP HANA Cloud P...SAP D-Code/TechEd 2014|DEV203|Extending SuccessFactors using SAP HANA Cloud P...
SAP D-Code/TechEd 2014|DEV203|Extending SuccessFactors using SAP HANA Cloud P...
SAP HANA Cloud Platform
 
SAP TechEd 2013: CD105: Extending SuccessFactors EmployeeCentral with apps on...
SAP TechEd 2013: CD105: Extending SuccessFactors EmployeeCentral with apps on...SAP TechEd 2013: CD105: Extending SuccessFactors EmployeeCentral with apps on...
SAP TechEd 2013: CD105: Extending SuccessFactors EmployeeCentral with apps on...
SAP HANA Cloud Platform
 
SAP HANA Cloud Platform Community BOF @ Devoxx 2013
SAP HANA Cloud Platform Community BOF @ Devoxx 2013SAP HANA Cloud Platform Community BOF @ Devoxx 2013
SAP HANA Cloud Platform Community BOF @ Devoxx 2013
SAP HANA Cloud Platform
 
SAP HANA Cloud Platform: The void between your Datacenter and the Cloud
SAP HANA Cloud Platform: The void between your Datacenter and the CloudSAP HANA Cloud Platform: The void between your Datacenter and the Cloud
SAP HANA Cloud Platform: The void between your Datacenter and the Cloud
SAP HANA Cloud Platform
 
SAP HANA Cloud: From Your Datacenter to the Cloud and Back
SAP HANA Cloud: From Your Datacenter to the Cloud and Back  SAP HANA Cloud: From Your Datacenter to the Cloud and Back
SAP HANA Cloud: From Your Datacenter to the Cloud and Back
SAP HANA Cloud Platform
 
OSGI in Java EE servers:Sneak peak
OSGI in Java EE servers:Sneak peakOSGI in Java EE servers:Sneak peak
OSGI in Java EE servers:Sneak peak
SAP HANA Cloud Platform
 
[BGOUG] Memory analyzer
[BGOUG] Memory analyzer[BGOUG] Memory analyzer
[BGOUG] Memory analyzer
SAP HANA Cloud Platform
 
JavaOne 2010: OSGI Migrat
JavaOne 2010: OSGI MigratJavaOne 2010: OSGI Migrat
JavaOne 2010: OSGI Migrat
SAP HANA Cloud Platform
 

More from SAP HANA Cloud Platform (15)

SAP Hack2Build hackathon - SAP Commerce Cloud & Kyma runtime
SAP Hack2Build hackathon - SAP Commerce Cloud & Kyma runtimeSAP Hack2Build hackathon - SAP Commerce Cloud & Kyma runtime
SAP Hack2Build hackathon - SAP Commerce Cloud & Kyma runtime
 
Gardener: Managed Kubernetes on Your Terms
Gardener: Managed Kubernetes on Your TermsGardener: Managed Kubernetes on Your Terms
Gardener: Managed Kubernetes on Your Terms
 
Kyma: Extending Business systems with Kubernetes, Istio and <fill the blank>.
Kyma: Extending Business systems with Kubernetes, Istio and <fill the blank>.Kyma: Extending Business systems with Kubernetes, Istio and <fill the blank>.
Kyma: Extending Business systems with Kubernetes, Istio and <fill the blank>.
 
Using Kubernetes to Extend Enterprise Software
Using Kubernetes to Extend Enterprise Software Using Kubernetes to Extend Enterprise Software
Using Kubernetes to Extend Enterprise Software
 
Kubernetes, Istio and Knative - noteworthy practical experience
Kubernetes, Istio and Knative - noteworthy practical experienceKubernetes, Istio and Knative - noteworthy practical experience
Kubernetes, Istio and Knative - noteworthy practical experience
 
SAP DKOM 2016 | 30154 | SAP HCP Cloud Extensions Intro
SAP DKOM 2016 | 30154 | SAP HCP Cloud Extensions IntroSAP DKOM 2016 | 30154 | SAP HCP Cloud Extensions Intro
SAP DKOM 2016 | 30154 | SAP HCP Cloud Extensions Intro
 
SAP TechEd 2015 | DEV109 | Extending Cloud Solutions from SAP using SAP HANA ...
SAP TechEd 2015 | DEV109 | Extending Cloud Solutions from SAP using SAP HANA ...SAP TechEd 2015 | DEV109 | Extending Cloud Solutions from SAP using SAP HANA ...
SAP TechEd 2015 | DEV109 | Extending Cloud Solutions from SAP using SAP HANA ...
 
SAP D-Code/TechEd 2014|DEV203|Extending SuccessFactors using SAP HANA Cloud P...
SAP D-Code/TechEd 2014|DEV203|Extending SuccessFactors using SAP HANA Cloud P...SAP D-Code/TechEd 2014|DEV203|Extending SuccessFactors using SAP HANA Cloud P...
SAP D-Code/TechEd 2014|DEV203|Extending SuccessFactors using SAP HANA Cloud P...
 
SAP TechEd 2013: CD105: Extending SuccessFactors EmployeeCentral with apps on...
SAP TechEd 2013: CD105: Extending SuccessFactors EmployeeCentral with apps on...SAP TechEd 2013: CD105: Extending SuccessFactors EmployeeCentral with apps on...
SAP TechEd 2013: CD105: Extending SuccessFactors EmployeeCentral with apps on...
 
SAP HANA Cloud Platform Community BOF @ Devoxx 2013
SAP HANA Cloud Platform Community BOF @ Devoxx 2013SAP HANA Cloud Platform Community BOF @ Devoxx 2013
SAP HANA Cloud Platform Community BOF @ Devoxx 2013
 
SAP HANA Cloud Platform: The void between your Datacenter and the Cloud
SAP HANA Cloud Platform: The void between your Datacenter and the CloudSAP HANA Cloud Platform: The void between your Datacenter and the Cloud
SAP HANA Cloud Platform: The void between your Datacenter and the Cloud
 
SAP HANA Cloud: From Your Datacenter to the Cloud and Back
SAP HANA Cloud: From Your Datacenter to the Cloud and Back  SAP HANA Cloud: From Your Datacenter to the Cloud and Back
SAP HANA Cloud: From Your Datacenter to the Cloud and Back
 
OSGI in Java EE servers:Sneak peak
OSGI in Java EE servers:Sneak peakOSGI in Java EE servers:Sneak peak
OSGI in Java EE servers:Sneak peak
 
[BGOUG] Memory analyzer
[BGOUG] Memory analyzer[BGOUG] Memory analyzer
[BGOUG] Memory analyzer
 
JavaOne 2010: OSGI Migrat
JavaOne 2010: OSGI MigratJavaOne 2010: OSGI Migrat
JavaOne 2010: OSGI Migrat
 

Recently uploaded

GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 

Recently uploaded (20)

GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 

[BGOUG] Java GC - Friend or Foe

  • 1. Java Garbage Collector: Friend or Foe Krasimir Semerdzhiev Development Architect / SAP Labs Bulgaria
  • 2. Agenda 1. Brief historical view 2. Myths and Urban legends 3. GC machinery 4. Try to stay out of trouble
  • 3. History of Garbage Collection A long time ago, in a galaxy far far away… * Counting from [McCarthy 1959] McCarthy (1959) LISt Processor (LISP) Reference counting (IBM) Naive Mark/sweep GC Semi-space collector 1959* Knuth (1973/1978) Copying collector Mark/sweep GC Mark/don’t sweep GC 1970 1990 2000 2011 Appel (1988), Baker (1992) Generational GC Train GC Stop the world Cheng-Blelloch (2001) Concurrent Parallel Real-Time GC 2003 Bacon, Cheng, Rajan (2003) Metronome GC Garbage first GC (G1) Ergonomics 20091995
  • 4. Agenda 1. Brief historical view 2. Myths and Urban legends 3. GC machinery 4. Try to stay out of trouble 5. Tools for the masses
  • 5. Myths Java and C/C++ performance Is C/C++ faster than Java? The short answer: it depends. /Cliff Click
  • 6. Myths My GC cleans up tons of memory – what’s going on. String s = "c"? = ref + 8 + (12 + 2) + 4 + 4 + 4 > 34 bytes. /** The value is used for character storage. */ private final char value[]; /** The offset is the first index of the storage that is used. */ private final int offset; /** The count is the number of characters in the String. */ private final int count; /** Cache the hash code for the string */ private int hash; // Default to 0 /** use serialVersionUID from JDK 1.0.2 for interoperability */ private static final long serialVersionUID = -6849794470754667710L;
  • 7. Is Java bad at memory management? public static void main(String[] args) throws Exception { final long start = Runtime.getRuntime().freeMemory(); final byte[][] arrays = new byte[100][]; for (int i = 0; i < arrays.length; i++) { arrays[i] = new byte[100]; long current = Runtime.getRuntime().freeMemory(); System.out.println(start + " " + current); Thread.sleep(1000); } }
  • 8. Agenda 1. Brief historical view 2. Myths and Urban legends 3. GC machinery* 4. Try to stay out of trouble 5. Tony Printezis * Credits for the GC insights go to Tony Printezis and his excellent J1 sessions
  • 9. Garbage collector Let’s start with a simple memory example…
  • 12. Garbage collector Mark-Sweep Root object Free List Root Mark-Sweep – Sweeping…
  • 13. Garbage collector Let’s try another one …
  • 17. Garbage collector Let’s try another one …
  • 18. Garbage collector Copying Root object Copying From space To space Free and unused
  • 19. Garbage collector Copying Root object Copying – Evacuation From space To space Free and unused
  • 20. Garbage collector Copying Root object Copying – Flipping From space To space Free and unused Free Pointer
  • 21. Garbage collector Let’s try another one … ;o)
  • 22. Garbage collector Generational Garbage Collection Generational Garbage Collection – moving to more modern times Young generation Old Generation Allocations Promotion
  • 23. Java Heap Hotspot JVM Memory layout Hotspot JVM (Java) heap layout Young generation Old Generation Perm Generation Everything else
  • 24. Java Heap Hotspot JVM Memory layout Hotspot JVM (Java) heap layout Young generation Old Generation Perm Generation Everything else Maximum size is limited: ■ 32 bit -> 2Gb ■ 64 bit -> way larger If 2Gb is the max for the process – you can’t get it all for the Java heap only!
  • 25. Hotspot JVM Memory layout Hotspot JVM (Java) heap layout Survivor spaces Old Generation Perm Generation Young generation unused Eden From To
  • 26. Hotspot JVM Memory layout Hotspot JVM (Java) – (Small) GC running Survivor spaces Old Generation Perm Generation Young generation unused Eden From To
  • 27. Hotspot JVM Memory layout Hotspot JVM (Java) – (Minor) GC running Survivor spaces Old Generation Perm Generation Young generation unused Eden From To
  • 28. Hotspot JVM Memory details -Xmx, -Xms, -Xmn  Control the Java Object heap size only  Doesn’t have impact on Perm size, native heap and the Thread stack size -XX:PermSize, -XX:MaxPermSize  Stores class definitions, methods, statis fields  Common reason for OOM errors. -Xss  Configures the stack size of every thread. -XX:+UseTLAB, -XX:-UseTLAB, -XX:+PrintTLAB  Enables the Thread Local Allocation Buffer.  Since Java SE 1.5 – this is automatically tuned to each and every thread. TCP Connection buffer sizes – allocated in native space  Use Socket.setSendBufferSize(int) and Socket.setReceiveBufferSize(int).  OS will use the smaller of the two or will simply ignore that setting. Object allocation statistics: ■ Up to 98% of new objects are short-lived ■ Up to 98% die before another Mb is allocated
  • 29. Agenda 1. Brief historical view 2. Myths and Urban legends 3. GC machinery 4. Try to stay out of trouble
  • 30. OutOfMemoryError How to proceed? java.lang.OutOfMemoryError: PermGen space  Increase the Perm Space – will help if there is no code generation happening  In case of a leak – the only solution is frequent system restart. java.lang.OutOfMemoryError: unable to create new native thread  Decrease –Xmx or –Xss java.lang.StackOverflowError  Increase –Xss or fix the corresponding algorithm IOException: Too many open files (for example)  Increase the OS file handle limit per process  Check for leaking file handles  Physical limit of the VM is 2048 ZIP/JAR files opened at the same time. java.lang.OutOfMemoryError: Direct buffer memory  Direct mapped memory – used for java.nio.ByteBuffer  Increase -XX:MaxDirectMemorySize
  • 31. Finalizer methods Good or bad Again short answer: it depends ;-) Infrastructure components  Might be used for debugging/tracing purposes  Major scenario – closing of critical backend resources  All finalizer methods are collected separately. No mass-wipe is performed on them!  Never, ever throw an exception in a finalizer! Applications  Avoid finalizers by all means! Per-request created objects  Avoid finalizers by all means! Finalizer queue Working threads Finalizer thread (singleton)
  • 32. Response time peaks without CMS All those are full GCs…
  • 33. No more full GCs… Response time peaks with CMS
  • 34. Garbage Collection Strategies Does it pay off to play with that? -XX:+UseSerialGC  Default state before Java 5. Obsolete! -XX:+UseParallelGC - Parallel Scavange GC (1.4.2)  Works on Young Generation only  Use -XX:ParallelGCThreads to configure it -XX:+UseParNewGC - Parallel New-Gen GC (5.0)  Use also –XX:SurvivorRatio and –XX:MaxTenuringThreshold to define the lifespan of objects in the eden space.  -XX:+CMSClassUnloadingEnabled to trigger concurrent cleanup of the Perm space -XX:+UseConcMarkSweepGC - Concurrent Old-Gen GC  Default since Java SE 5. -XX:+UseParallelOldGC - Concurrent Old-Gen GC (5.0)  Parallel Compaction of Old space Terms: • Serial – 1 thing at a time • Parallel – work is done in multiple threads • Concurrent – work happens simultaneously
  • 35. Garbage Collection Ergonomics What’s that? New way to configure GC – specify:  Max pause time goal (-XX:MaxGCPauseMillis)  Throughput goal (-XX:GCTimeRatio)  Assumes minimal footprint goal  Use -XX:+UseParallelGC with those.  Garbage First (G1) GC will be the default in Java SE 7. Released with JDK 1.6.0_u14 for non-productive usage.  Enable that for testing via:  -XX:+UnlockExperimentalVMOptions  -XX:+UseG1GC
  • 36. Analyzing Garbage Collection output Getting GC output is critical for further analysis!  -verbose:gc get 1 line per GC run with some basic inf  -XX:+PrintGCDetails get more extended info (perm, eden, tenured)  -XX:+PrintGCTimeStamps get timestamps since the start of the VM. Allows correlation  -XX:-TraceClassUnloading get also the unloaded classes – helps tracing leaks  -Xloggc:gc.log direct GC output to a special file instead of the process output  -XX:+HeapDumpOnOutOfMemoryError Heap dump generation on OutOfMemory
  • 37. GC Viewer GC output viewer  Import the gc.out file.  Correlate over time  So far the most comprehensive viewer  Stay tuned and monitor the Eclipse news ;-)
  • 38. Visual VM Supplied by Oracle with JDK  Free and very comprehensive  Evolves together with the VM.  Focus shifting from that to Mission Control (the Jrockit profiling solution)
  • 39. Eclipse Memory Analyzer Developed by SAP and IBM in Eclipse  Track GC roots  Do what-if analysis  SQL-like query language  Custom filters  Track Leaking classloaders
  • 40. Garbage Collection – the universal settings There are NO universal settings! Sorry. :(  G1 is the first GC, trying to go in that direction and leave the self-tuning to the VM  You have to test with realistic load!  You have to test on realistic hardware!  Tune the GC as you fix the memory leaks which will inevitably show up.  Try to find the balance of uptime/restart intervals.