SlideShare a Scribd company logo
1 of 58
Download to read offline
Garbage First andYou	

!
The new* Garbage Collector in the JVM
Kai Koenig	

@AgentK
Web/Mobile Developer since the late 1990s
Interested in: Java & JVM, CFML, Functional
Programming, Go, JS, Android, Raspberry Pi
!
And this is my view of the world…
Me
1.The JVM and Garbage Collection in 5 mins

2.Academic ideas behind G1

3.The G1 collector

4.Tuning G1 and practical implications

5. Further changes in Java 8	

Agenda
1. JVM and GC in 

5 minutes
Fundamentals
The most simplistic view of the JVM:	

!
“Java virtual machine (JVM) interprets
compiled Java binary code (called bytecode)
for a computer’s processor (or hardware
platform) so that it can perform a Java
program's instructions.”
1.1 JVM Architecture
High Level view (1)
Bytecode in .class files
has the same semantics
as the .java code
High Level view (II)
Java stack vs heap memory
Each method call creates a new stack frame,
which has an operand stack, array of local vars
and a program counter.	



→ Seen ‘Stack Traces’ in a Java Error before?	

!
Exception	
  in	
  thread	
  "main"	
  java.lang.NullPointerException	
  
	
  	
  	
  	
  	
  	
  	
  	
  at	
  com.example.myproject.Book.getTitle(Book.java:16)	
  
	
  	
  	
  	
  	
  	
  	
  	
  at	
  com.example.myproject.Author.getBookTitles(Author.java:25)	
  
	
  	
  	
  	
  	
  	
  	
  	
  at	
  com.example.myproject.Bootstrap.main(Bootstrap.java:14)
Stack and Heap
1.2 Garbage Collection
Heap management
The JVM has no way of knowing the lifespan of a
certain object in advance.	

Generational Memory Management is a solution
to overcome this issue and fragmentation:	

	

 -Young Generation	

	

 - Old Generation / Tenured Generation	

	

 - Sometimes: Permanent Generation
Contiguous generational heap
Garbage Collector selection criteria
Efficiency / Throughput	

Concurrency 	

Overhead	

JVM version you’re on	

!
YG Collectors: Parallel
Parallel MaC (since Java 1.4.2) distributes the
Marking and Copying phases over multiple
threads.	

The actual collection is still stop-the-world, but
for a much shorter period of time.	

YG default since Java 5 if machine has 2+ cores
or CPUs, otherwise: -XX:+UseParallelGC.	

!
OG Collectors: Concurrent
Up to Java 6/7 Concurrent Mark-and-Sweep is
the preferred OG collector if you want to
minimise stop-the-world collections.	

CMS via -XX:+UseConcMarkSweepGC
Well suited for larger heaps (but be aware of
fragmentation), there’s an ‘incremental’ mode for
systems with 1-2 CPU cores.	

Stop-the-world and concurrent collections
2. Academic ideas behind G1
“Garbage-First Garbage Collection”
Research paper originally published in 2004 by
David Detlefs, Christine Flood, Steve Heller and
Tony Printezis of Sun Research.	

!
The actual research project started in the late
1990s to overcome common issues in Garbage
Collection techniques known and used at the
time.
Core ideas
Four core elements:	

	

 - SATB concurrent marking algorithm	

	

 - Better way to achieve a real-time goal	

	

 - Get rid of a contiguous heap and use regions	

	

 - Compacting and predictable
Snapshot-at-the-beginning
SATB does a periodic analysis of global
reachability (liveness) and provide completeness.	

Results:	

	

 - Accurate counts of live data in each region

	

 - Completeness: garbage is eventually identified

	

 -Very low pause time	

!
‘Soft’ real-time goal and regions
Before G1, garbage collectors tried to achieve
hard real time goals by:	

	

 - making collection interruptible

	

 - working on the granularity of object levels.	

G1 works on a coarser granularity of regions:	

	

 - Chooses regions to collect that match goal

	

 - Collection of a region can be delayed	

!
3.The G1 Collector
3.1 Basics
G1 (Garbage First)
G1 is a ‘replacement’ for CMS in Java 7+	

Benefits:	

	

 - Consistently low-pause	

	

 - Adaptable	

	

 - Less fragmentation than CMS	

	

 - Less need for ongoing tuning	

	

 - Best collector for a really large heap
Fundamental ideas (I)
Minimum of 6 GB heap, if below - consider
staying with CMS	

Enable: -XX:+UseG1GC	

Provide minimal set of expectations and let G1
do the job:	

	

 - Heap size (min/max)

	

 - How much CPU time can the application use?

	

 - How much CPU time can G1 use?
Fundamental ideas (II)
‘Main’ setup parameter: 

-XX:MaxGCPauseMillis=<n>	

G1 is not an OG-only collector like CMS	

G1 splits the whole area of heap memory:	

	

 - ~2000 regions

	

 - Size between 1-32 MB each

	

 - usually automatically chosen by the JVM	

!
Region setup in G1
Note:There is another region type H (humongous)
3.2 G1YoungGen
AYG collection in G1 (before)
Non-Allocated
Old Generation
Young Generation
Recently copiedYG
AYG collection in G1 (stop-the-world)
Non-Allocated
Old Generation
Young Generation
Recently copiedYG
AYG collection in G1 (result)
Non-Allocated
Old Generation
Young Generation
Recently copiedYG
YG in G1 - Summary
TheYG is a set of non-contiguous regions, which
helps resizing after a collection.	

YG collections in G1 are stop-the-world events
and all application threads will stop.	

YG collections are done in multiple, parallel
threads.	

Leftover (alive) objects → move to a survivor or
OG region.
3.3 G1 OldGen
G1 and the OG - overview (I)
1. Initial Mark (stop-the-world and piggybacking
on aYG collection)	

2. Root Region Scan (blocksYG from happening)	

3. Concurrent Marking	

4. Remark (stop-the-world and due to a new
algorithm much faster than CMS)
G1 and the OG - overview (II)
5. Cleanup (stop-the-world and concurrent)	

6. Copying (stop-the-world, piggybacking onYG
collections)	

!
!
!
!
OG collection in G1(initial marking)
Marks root regions with references to OG objects.
Non-Allocated
Old Generation
Young Generation
Recently copiedYG
Recently copied OG
OG collection in G1(concurrent marking)
Marks empty regions and calculates object ‘liveness’.
X
X
Non-Allocated
Old Generation
Young Generation
Recently copiedYG
Recently copied OG
An OG collection in G1(remark)
Empty regions are removed and reclaimed.
Non-Allocated
Old Generation
Young Generation
Recently copiedYG
Recently copied OG
An OG collection in G1(cleanup & copy)
Region with lowest liveness get collected withYG
collections (‘mixed’ collections).
Non-Allocated
Old Generation
Young Generation
Recently copiedYG
Recently copied OG
An OG collection in G1(result)
Collection is done and leftovers are compacted.
Non-Allocated
Old Generation
Young Generation
Recently copiedYG
Recently copied OG
OG in G1 - Summary
Concurrent Marking:	

	

 - Liveness info determines where to collect

	

 - No sweeping phase like in CMS	

Remark:	

	

 - SATB algorithm much faster than CMS

	

 - Completely empty regions are reclaimed	

Cleanup: optimised for ‘mixed’ collections
4.Tuning G1
Do not trust consultants, blog posts, mailing list
discussions etc. telling you what the ‘best’ JVM
settings would be.	

!
There is no such thing as global best settings.
JVM settings depend on the environment, the
application and the projected/actual usage.
JVM settings and logging
How do you find out what’s
happening in your JVM?	

-XX:+PrintGC
-XX:+PrintGCDetails
-XX:+PrintGCTimeStamps
or	

-XX:+PrintGCDateStamps
[GC 64781K->22983K(71360K), 0.0242084 secs]	

[GC 68487K->25003K(77888K), 0.0194041 secs]	

[Full GC 25003K->20302K(89600K), 0.1713420 secs]	

[GC 70670K->21755K(90048K), 0.0054093 secs]	

[GC 71913K->46558K(94912K), 0.0295257 secs]	

[Full GC 46558K->45267K(118336K), 0.2144038 secs]	

[GC 88214K->84651K(133056K), 0.0674443 secs]	

[Full GC 84651K->84633K(171648K), 0.1739369 secs]	

[GC 117977K->115114K(180736K), 0.0623399 secs]	

[GC 158613K->157136K(201152K), 0.0591171 secs]	

[Full GC 157136K->157098K(254784K), 0.1868453 secs]	

[GC 160678K->160455K(261184K), 0.0536678 secs]	

01/24 19:36:22 Debug [scheduler-1] - Next mail spool run in 15 seconds.	

[GC 202912K->200819K(268288K), 0.0625820 secs]	

[Full GC 200819K->200776K(332224K), 0.2121724 secs]	

[GC 213293K->212423K(339520K), 0.0426462 secs]	

[GC 259465K->256115K(340288K), 0.0645039 secs]	

[Full GC 256115K->255462K(418432K), 0.3226731 secs]	

[GC 281947K->279651K(421760K), 0.0530268 secs]	

[GC 331073K->323785K(422720K), 0.0695117 secs]	

[Full GC 323785K->323697K(459264K), 0.2139458 secs]	

[Full GC 364365K->361525K(459264K), 0.2180439 secs]	

[Full GC 400859K->400859K(459264K), 0.1702890 secs]	

[Full GC 400859K->43989K(274112K), 0.2642407 secs]	

[GC 95197K->93707K(273216K), 0.0338568 secs]	

[GC 146978K->140363K(276032K), 0.0664380 secs]	

[GC 193696K->189635K(277952K), 0.0630006 secs]	

[Full GC 189635K->189604K(425920K), 0.1913979 secs]	

[GC 219773K->205157K(426048K), 0.0442126 secs]
The two main tuning parameters for G1
-XX:MaxGCPauseMillis
Soft goal target for maximum GC pause time -
default 200ms
-XX:InitiatingHeapOccupancyPercent
Percentage of heap occupancy to start
concurrent GC cycle
Good practice
Avoid setting absolute generation sizes with G1:	

	

 - Breaks self-optimisation and target times

	

 - Causes issues in region sizing & distribution	

Avoid evacuation failures (‘space overflow’):	

	

 - Increase heap promotion ceiling (default 10)

	

 	

 -XX:G1ReservePercent 

	

 - Increase # of marking threads

	

 	

 -XX:ConcGCThreads
Real-world observations (I)
G1 has a noticeable tradeoff between latency
and throughput:	

	

 - G1: ~90-92% throughput goal

	

 - Parallel Hotspot GC: ~98-99% goal	

If you want higher throughput - relax the pause
time goal.
Real-world observations (II)
‘Mixed’ GCs are on the more expensive end in
G1.You can tamper with the criteria through
experimental settings*:	

	

 -XX:G1MixedGCLiveThresholdPercent	



	

 -XX:G1HeapWastePercent
!
* Might not be available on your platform, CPU
architecture or JVM version.
Real-world observations (III)
CPU usage tends to increase ~5-15% when using
G1 vs. CMS.	

G1 seems to be better in reclaiming the
maximum heap sized used.	

The more uniform your object size distribution
is, the better is CMS over G1.With a very
heterogenous object size distribution, G1 tends
to be better.
5. Changes in Java 8
Most of the previous is
valid for Java 7 and 8 -
but…
G1 string de-duplication
Java 8u_20 brings a new String de-duplication
optimisation.	

G1 collector can now identify strings that are
duplicated across the heap and repoint them to
the ‘same’ internal char[] representation: 	

-XX:+UseStringDeduplicationJVM
Java 8 and the PermGen
It’s gone and it’s been replaced by a Metaspace
(Oracle’s JRockit actually never had a PermGen).
Class metadata is now stored in native memory.	

!
A word of warning: Oracle tries to sell the
Metaspace as the new piece of awesomeness
that ‘just works’, but it still needs observation
and tuning!
Retired JVM GC combinations
Some rarely-used combinations of garbage
collectors have been deprecated:	

http://openjdk.java.net/jeps/173	

!
Important: iCMS has been deprecated!	

!
!
Additional Resources
Garbage Collection with Garbage First Research Paper:

http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.63.6386&rep=rep1&type=pdf	

Understanding G1 logs: 

https://blogs.oracle.com/poonam/entry/understanding_g1_gc_logs	

“The JVM is your friend” - my more general GC talk at cf.Objective() 2014:

http://www.slideshare.net/AgentK/jvm-isyourfriend	

Java Performance:The Definitive Guide

http://www.amazon.com/Java-Performance-The-Definitive-Guide/dp/1449358454	

!
Photo credits
https://www.flickr.com/photos/aigle_dore/6973012997/

https://www.flickr.com/photos/65694112@N05/6147388744

https://www.flickr.com/photos/teclasorg/2852716491

https://www.flickr.com/photos/salendron/5390633053

https://www.flickr.com/photos/tim_ellis/2269499855

https://www.flickr.com/photos/apocalust/5729262611

https://www.flickr.com/photos/fkhuckel/16995618202

https://www.flickr.com/photos/poetprince/3389459474

https://www.flickr.com/photos/mario-mancuso/8331716569

https://www.flickr.com/photos/openindiana/16277077790/

Get in touch
Kai Koenig	

kai@ventego-creative.co.nz

www.ventego-creative.co.nz

www.bloginblack.de



Twitter: @AgentK

More Related Content

What's hot

GC Tuning in the HotSpot Java VM - a FISL 10 Presentation
GC Tuning in the HotSpot Java VM - a FISL 10 PresentationGC Tuning in the HotSpot Java VM - a FISL 10 Presentation
GC Tuning in the HotSpot Java VM - a FISL 10 PresentationLudovic Poitou
 
JVM and Garbage Collection Tuning
JVM and Garbage Collection TuningJVM and Garbage Collection Tuning
JVM and Garbage Collection TuningKai Koenig
 
JVM Garbage Collection Tuning
JVM Garbage Collection TuningJVM Garbage Collection Tuning
JVM Garbage Collection Tuningihji
 
Performance tuning jvm
Performance tuning jvmPerformance tuning jvm
Performance tuning jvmPrem Kuppumani
 
Fight with Metaspace OOM
Fight with Metaspace OOMFight with Metaspace OOM
Fight with Metaspace OOMLeon Chen
 
G1 collector and tuning and Cassandra
G1 collector and tuning and CassandraG1 collector and tuning and Cassandra
G1 collector and tuning and CassandraChris Lohfink
 
The JVM is your friend
The JVM is your friendThe JVM is your friend
The JVM is your friendKai Koenig
 
JVM @ Taobao - QCon Hangzhou 2011
JVM @ Taobao - QCon Hangzhou 2011JVM @ Taobao - QCon Hangzhou 2011
JVM @ Taobao - QCon Hangzhou 2011Kris Mok
 
淺談 Java GC 原理、調教和 新發展
淺談 Java GC 原理、調教和新發展淺談 Java GC 原理、調教和新發展
淺談 Java GC 原理、調教和 新發展Leon Chen
 
Java Garbage Collection - How it works
Java Garbage Collection - How it worksJava Garbage Collection - How it works
Java Garbage Collection - How it worksMindfire Solutions
 
Memory management for_android_apps
Memory management for_android_appsMemory management for_android_apps
Memory management for_android_appsBin Shao
 
Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...
Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...
Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...Monica Beckwith
 
Low pause GC in HotSpot
Low pause GC in HotSpotLow pause GC in HotSpot
Low pause GC in HotSpotjClarity
 
Jvm Performance Tunning
Jvm Performance TunningJvm Performance Tunning
Jvm Performance Tunningguest1f2740
 
Shenandoah GC: Java Without The Garbage Collection Hiccups (Christine Flood)
Shenandoah GC: Java Without The Garbage Collection Hiccups (Christine Flood)Shenandoah GC: Java Without The Garbage Collection Hiccups (Christine Flood)
Shenandoah GC: Java Without The Garbage Collection Hiccups (Christine Flood)Red Hat Developers
 
Elastic JVM for Scalable Java EE Applications Running in Containers #Jakart...
Elastic JVM  for Scalable Java EE Applications  Running in Containers #Jakart...Elastic JVM  for Scalable Java EE Applications  Running in Containers #Jakart...
Elastic JVM for Scalable Java EE Applications Running in Containers #Jakart...Jelastic Multi-Cloud PaaS
 
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 UsageJelastic Multi-Cloud PaaS
 
Hadoop world g1_gc_forh_base_v4
Hadoop world g1_gc_forh_base_v4Hadoop world g1_gc_forh_base_v4
Hadoop world g1_gc_forh_base_v4YanpingWang
 

What's hot (20)

GC Tuning in the HotSpot Java VM - a FISL 10 Presentation
GC Tuning in the HotSpot Java VM - a FISL 10 PresentationGC Tuning in the HotSpot Java VM - a FISL 10 Presentation
GC Tuning in the HotSpot Java VM - a FISL 10 Presentation
 
JVM and Garbage Collection Tuning
JVM and Garbage Collection TuningJVM and Garbage Collection Tuning
JVM and Garbage Collection Tuning
 
Basics of JVM Tuning
Basics of JVM TuningBasics of JVM Tuning
Basics of JVM Tuning
 
JVM Garbage Collection Tuning
JVM Garbage Collection TuningJVM Garbage Collection Tuning
JVM Garbage Collection Tuning
 
Performance tuning jvm
Performance tuning jvmPerformance tuning jvm
Performance tuning jvm
 
Fight with Metaspace OOM
Fight with Metaspace OOMFight with Metaspace OOM
Fight with Metaspace OOM
 
G1 collector and tuning and Cassandra
G1 collector and tuning and CassandraG1 collector and tuning and Cassandra
G1 collector and tuning and Cassandra
 
The JVM is your friend
The JVM is your friendThe JVM is your friend
The JVM is your friend
 
JVM @ Taobao - QCon Hangzhou 2011
JVM @ Taobao - QCon Hangzhou 2011JVM @ Taobao - QCon Hangzhou 2011
JVM @ Taobao - QCon Hangzhou 2011
 
淺談 Java GC 原理、調教和 新發展
淺談 Java GC 原理、調教和新發展淺談 Java GC 原理、調教和新發展
淺談 Java GC 原理、調教和 新發展
 
Java Garbage Collection - How it works
Java Garbage Collection - How it worksJava Garbage Collection - How it works
Java Garbage Collection - How it works
 
Memory management for_android_apps
Memory management for_android_appsMemory management for_android_apps
Memory management for_android_apps
 
Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...
Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...
Garbage First Garbage Collector (G1 GC) - Migration to, Expectations and Adva...
 
Low pause GC in HotSpot
Low pause GC in HotSpotLow pause GC in HotSpot
Low pause GC in HotSpot
 
Jvm Performance Tunning
Jvm Performance TunningJvm Performance Tunning
Jvm Performance Tunning
 
Shenandoah GC: Java Without The Garbage Collection Hiccups (Christine Flood)
Shenandoah GC: Java Without The Garbage Collection Hiccups (Christine Flood)Shenandoah GC: Java Without The Garbage Collection Hiccups (Christine Flood)
Shenandoah GC: Java Without The Garbage Collection Hiccups (Christine Flood)
 
Memory in Android
Memory in AndroidMemory in Android
Memory in Android
 
Elastic JVM for Scalable Java EE Applications Running in Containers #Jakart...
Elastic JVM  for Scalable Java EE Applications  Running in Containers #Jakart...Elastic JVM  for Scalable Java EE Applications  Running in Containers #Jakart...
Elastic JVM for Scalable Java EE Applications Running in Containers #Jakart...
 
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
 
Hadoop world g1_gc_forh_base_v4
Hadoop world g1_gc_forh_base_v4Hadoop world g1_gc_forh_base_v4
Hadoop world g1_gc_forh_base_v4
 

Viewers also liked

Csp and http headers
Csp and http headersCsp and http headers
Csp and http headersdevObjective
 
Front end-modernization
Front end-modernizationFront end-modernization
Front end-modernizationdevObjective
 
Paying off emotional debt
Paying off emotional debtPaying off emotional debt
Paying off emotional debtdevObjective
 
Naked and afraid Offline mobile
Naked and afraid Offline mobileNaked and afraid Offline mobile
Naked and afraid Offline mobiledevObjective
 
"If i were big boss on Radio" (tugas UAS Manajemen Media Massa 2014)
"If i were big boss on Radio" (tugas UAS Manajemen Media Massa 2014)"If i were big boss on Radio" (tugas UAS Manajemen Media Massa 2014)
"If i were big boss on Radio" (tugas UAS Manajemen Media Massa 2014)Nur Maiia
 
Who owns Software Security
Who owns Software SecurityWho owns Software Security
Who owns Software SecuritydevObjective
 
Web hackingtools 2015
Web hackingtools 2015Web hackingtools 2015
Web hackingtools 2015devObjective
 
Node without servers aws-lambda
Node without servers aws-lambdaNode without servers aws-lambda
Node without servers aws-lambdadevObjective
 
Using type script to build better apps
Using type script to build better appsUsing type script to build better apps
Using type script to build better appsdevObjective
 
LÍNEA DEL TIEMPO PLANEACIÓN Y GESTIÓN EDUCATIVA ENJ
LÍNEA DEL TIEMPO PLANEACIÓN Y GESTIÓN EDUCATIVA ENJLÍNEA DEL TIEMPO PLANEACIÓN Y GESTIÓN EDUCATIVA ENJ
LÍNEA DEL TIEMPO PLANEACIÓN Y GESTIÓN EDUCATIVA ENJmadihe2
 

Viewers also liked (13)

Csp and http headers
Csp and http headersCsp and http headers
Csp and http headers
 
Catalogo Brasil aromaticos
Catalogo Brasil aromaticosCatalogo Brasil aromaticos
Catalogo Brasil aromaticos
 
Front end-modernization
Front end-modernizationFront end-modernization
Front end-modernization
 
Paying off emotional debt
Paying off emotional debtPaying off emotional debt
Paying off emotional debt
 
Naked and afraid Offline mobile
Naked and afraid Offline mobileNaked and afraid Offline mobile
Naked and afraid Offline mobile
 
I am-designer
I am-designerI am-designer
I am-designer
 
"If i were big boss on Radio" (tugas UAS Manajemen Media Massa 2014)
"If i were big boss on Radio" (tugas UAS Manajemen Media Massa 2014)"If i were big boss on Radio" (tugas UAS Manajemen Media Massa 2014)
"If i were big boss on Radio" (tugas UAS Manajemen Media Massa 2014)
 
Fusion Reactor
Fusion ReactorFusion Reactor
Fusion Reactor
 
Who owns Software Security
Who owns Software SecurityWho owns Software Security
Who owns Software Security
 
Web hackingtools 2015
Web hackingtools 2015Web hackingtools 2015
Web hackingtools 2015
 
Node without servers aws-lambda
Node without servers aws-lambdaNode without servers aws-lambda
Node without servers aws-lambda
 
Using type script to build better apps
Using type script to build better appsUsing type script to build better apps
Using type script to build better apps
 
LÍNEA DEL TIEMPO PLANEACIÓN Y GESTIÓN EDUCATIVA ENJ
LÍNEA DEL TIEMPO PLANEACIÓN Y GESTIÓN EDUCATIVA ENJLÍNEA DEL TIEMPO PLANEACIÓN Y GESTIÓN EDUCATIVA ENJ
LÍNEA DEL TIEMPO PLANEACIÓN Y GESTIÓN EDUCATIVA ENJ
 

Similar to Garbage First and You!

JVM Performance Tuning
JVM Performance TuningJVM Performance Tuning
JVM Performance TuningJeremy Leisy
 
Taming Java Garbage Collector
Taming Java Garbage CollectorTaming Java Garbage Collector
Taming Java Garbage CollectorDaya Atapattu
 
“Show Me the Garbage!”, Garbage Collection a Friend or a Foe
“Show Me the Garbage!”, Garbage Collection a Friend or a Foe“Show Me the Garbage!”, Garbage Collection a Friend or a Foe
“Show Me the Garbage!”, Garbage Collection a Friend or a FoeHaim Yadid
 
[Jbcn 2016] Garbage Collectors WTF!?
[Jbcn 2016] Garbage Collectors WTF!?[Jbcn 2016] Garbage Collectors WTF!?
[Jbcn 2016] Garbage Collectors WTF!?Alonso Torres
 
Garbage collection
Garbage collectionGarbage collection
Garbage collectionMudit Gupta
 
Вячеслав Блинов «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
 
Jvm problem diagnostics
Jvm problem diagnosticsJvm problem diagnostics
Jvm problem diagnosticsDanijel Mitar
 
Javaday 2022 - Remèdes aux oomkill, warm-ups, et lenteurs pour des conteneur...
Javaday 2022 - Remèdes aux oomkill, warm-ups, et lenteurs pour des conteneur...Javaday 2022 - Remèdes aux oomkill, warm-ups, et lenteurs pour des conteneur...
Javaday 2022 - Remèdes aux oomkill, warm-ups, et lenteurs pour des conteneur...Jean-Philippe BEMPEL
 
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 2020Jelastic Multi-Cloud PaaS
 
An introduction to G1 collector for busy developers
An introduction to G1 collector for busy developersAn introduction to G1 collector for busy developers
An introduction to G1 collector for busy developersSanjoy Kumar Roy
 
Java gc and JVM optimization
Java gc  and JVM optimizationJava gc  and JVM optimization
Java gc and JVM optimizationRajan Jethva
 
JVM memory management & Diagnostics
JVM memory management & DiagnosticsJVM memory management & Diagnostics
JVM memory management & DiagnosticsDhaval Shah
 
Performance Tuning - Understanding Garbage Collection
Performance Tuning - Understanding Garbage CollectionPerformance Tuning - Understanding Garbage Collection
Performance Tuning - Understanding Garbage CollectionHaribabu Nandyal Padmanaban
 
Taming GC Pauses for Humongous Java Heaps in Spark Graph Computing-(Eric Kacz...
Taming GC Pauses for Humongous Java Heaps in Spark Graph Computing-(Eric Kacz...Taming GC Pauses for Humongous Java Heaps in Spark Graph Computing-(Eric Kacz...
Taming GC Pauses for Humongous Java Heaps in Spark Graph Computing-(Eric Kacz...Spark Summit
 
Jvm & Garbage collection tuning for low latencies application
Jvm & Garbage collection tuning for low latencies applicationJvm & Garbage collection tuning for low latencies application
Jvm & Garbage collection tuning for low latencies applicationQuentin Ambard
 

Similar to Garbage First and You! (20)

Jvm is-your-friend
Jvm is-your-friendJvm is-your-friend
Jvm is-your-friend
 
JVM Performance Tuning
JVM Performance TuningJVM Performance Tuning
JVM Performance Tuning
 
Taming Java Garbage Collector
Taming Java Garbage CollectorTaming Java Garbage Collector
Taming Java Garbage Collector
 
“Show Me the Garbage!”, Garbage Collection a Friend or a Foe
“Show Me the Garbage!”, Garbage Collection a Friend or a Foe“Show Me the Garbage!”, Garbage Collection a Friend or a Foe
“Show Me the Garbage!”, Garbage Collection a Friend or a Foe
 
[Jbcn 2016] Garbage Collectors WTF!?
[Jbcn 2016] Garbage Collectors WTF!?[Jbcn 2016] Garbage Collectors WTF!?
[Jbcn 2016] Garbage Collectors WTF!?
 
JVM Magic
JVM MagicJVM Magic
JVM Magic
 
Garbage collection
Garbage collectionGarbage collection
Garbage collection
 
Hotspot gc
Hotspot gcHotspot gc
Hotspot gc
 
Вячеслав Блинов «Java Garbage Collection: A Performance Impact»
Вячеслав Блинов «Java Garbage Collection: A Performance Impact»Вячеслав Блинов «Java Garbage Collection: A Performance Impact»
Вячеслав Блинов «Java Garbage Collection: A Performance Impact»
 
Jvm problem diagnostics
Jvm problem diagnosticsJvm problem diagnostics
Jvm problem diagnostics
 
Javaday 2022 - Remèdes aux oomkill, warm-ups, et lenteurs pour des conteneur...
Javaday 2022 - Remèdes aux oomkill, warm-ups, et lenteurs pour des conteneur...Javaday 2022 - Remèdes aux oomkill, warm-ups, et lenteurs pour des conteneur...
Javaday 2022 - Remèdes aux oomkill, warm-ups, et lenteurs pour des conteneur...
 
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
 
Java performance tuning
Java performance tuningJava performance tuning
Java performance tuning
 
An introduction to G1 collector for busy developers
An introduction to G1 collector for busy developersAn introduction to G1 collector for busy developers
An introduction to G1 collector for busy developers
 
[BGOUG] Java GC - Friend or Foe
[BGOUG] Java GC - Friend or Foe[BGOUG] Java GC - Friend or Foe
[BGOUG] Java GC - Friend or Foe
 
Java gc and JVM optimization
Java gc  and JVM optimizationJava gc  and JVM optimization
Java gc and JVM optimization
 
JVM memory management & Diagnostics
JVM memory management & DiagnosticsJVM memory management & Diagnostics
JVM memory management & Diagnostics
 
Performance Tuning - Understanding Garbage Collection
Performance Tuning - Understanding Garbage CollectionPerformance Tuning - Understanding Garbage Collection
Performance Tuning - Understanding Garbage Collection
 
Taming GC Pauses for Humongous Java Heaps in Spark Graph Computing-(Eric Kacz...
Taming GC Pauses for Humongous Java Heaps in Spark Graph Computing-(Eric Kacz...Taming GC Pauses for Humongous Java Heaps in Spark Graph Computing-(Eric Kacz...
Taming GC Pauses for Humongous Java Heaps in Spark Graph Computing-(Eric Kacz...
 
Jvm & Garbage collection tuning for low latencies application
Jvm & Garbage collection tuning for low latencies applicationJvm & Garbage collection tuning for low latencies application
Jvm & Garbage collection tuning for low latencies application
 

More from devObjective

Raspberry Pi a la CFML
Raspberry Pi a la CFMLRaspberry Pi a la CFML
Raspberry Pi a la CFMLdevObjective
 
Effective version control
Effective version controlEffective version control
Effective version controldevObjective
 
My SQL Skills Killed the Server
My SQL Skills Killed the ServerMy SQL Skills Killed the Server
My SQL Skills Killed the ServerdevObjective
 
Authentication Control
Authentication ControlAuthentication Control
Authentication ControldevObjective
 
Multiply like rabbits with rabbit mq
Multiply like rabbits with rabbit mqMultiply like rabbits with rabbit mq
Multiply like rabbits with rabbit mqdevObjective
 
Intro to TDD & BDD
Intro to TDD & BDDIntro to TDD & BDD
Intro to TDD & BDDdevObjective
 
Rethink Async with RXJS
Rethink Async with RXJSRethink Async with RXJS
Rethink Async with RXJSdevObjective
 
I'm a Team Lead Now What?
I'm a Team Lead Now What?I'm a Team Lead Now What?
I'm a Team Lead Now What?devObjective
 
Api management from the Trenches
Api management from the TrenchesApi management from the Trenches
Api management from the TrenchesdevObjective
 
Hey! My website is slow where is the problem?
Hey! My website is slow where is the problem?Hey! My website is slow where is the problem?
Hey! My website is slow where is the problem?devObjective
 
Get Grulping with Javascript task runners
Get Grulping with Javascript task runnersGet Grulping with Javascript task runners
Get Grulping with Javascript task runnersdevObjective
 
Adaptive Development in a Creative World
Adaptive Development in a Creative WorldAdaptive Development in a Creative World
Adaptive Development in a Creative WorlddevObjective
 
How do I write testable javascript?
How do I write testable javascript?How do I write testable javascript?
How do I write testable javascript?devObjective
 
Building software products in a weekend
Building software products in a weekendBuilding software products in a weekend
Building software products in a weekenddevObjective
 
The Future of CSS with Web components
The Future of CSS with Web componentsThe Future of CSS with Web components
The Future of CSS with Web componentsdevObjective
 
Dependency Injection: Why is awesome and why should I care?
Dependency Injection: Why is awesome and why should I care?Dependency Injection: Why is awesome and why should I care?
Dependency Injection: Why is awesome and why should I care?devObjective
 
Building Multi-Tenant SaaS Apps
Building Multi-Tenant SaaS AppsBuilding Multi-Tenant SaaS Apps
Building Multi-Tenant SaaS AppsdevObjective
 

More from devObjective (20)

Lets git together
Lets git togetherLets git together
Lets git together
 
Raspberry Pi a la CFML
Raspberry Pi a la CFMLRaspberry Pi a la CFML
Raspberry Pi a la CFML
 
Command box
Command boxCommand box
Command box
 
Effective version control
Effective version controlEffective version control
Effective version control
 
My SQL Skills Killed the Server
My SQL Skills Killed the ServerMy SQL Skills Killed the Server
My SQL Skills Killed the Server
 
Authentication Control
Authentication ControlAuthentication Control
Authentication Control
 
Multiply like rabbits with rabbit mq
Multiply like rabbits with rabbit mqMultiply like rabbits with rabbit mq
Multiply like rabbits with rabbit mq
 
Preso slidedeck
Preso slidedeckPreso slidedeck
Preso slidedeck
 
Intro to TDD & BDD
Intro to TDD & BDDIntro to TDD & BDD
Intro to TDD & BDD
 
Rethink Async with RXJS
Rethink Async with RXJSRethink Async with RXJS
Rethink Async with RXJS
 
I'm a Team Lead Now What?
I'm a Team Lead Now What?I'm a Team Lead Now What?
I'm a Team Lead Now What?
 
Api management from the Trenches
Api management from the TrenchesApi management from the Trenches
Api management from the Trenches
 
Hey! My website is slow where is the problem?
Hey! My website is slow where is the problem?Hey! My website is slow where is the problem?
Hey! My website is slow where is the problem?
 
Get Grulping with Javascript task runners
Get Grulping with Javascript task runnersGet Grulping with Javascript task runners
Get Grulping with Javascript task runners
 
Adaptive Development in a Creative World
Adaptive Development in a Creative WorldAdaptive Development in a Creative World
Adaptive Development in a Creative World
 
How do I write testable javascript?
How do I write testable javascript?How do I write testable javascript?
How do I write testable javascript?
 
Building software products in a weekend
Building software products in a weekendBuilding software products in a weekend
Building software products in a weekend
 
The Future of CSS with Web components
The Future of CSS with Web componentsThe Future of CSS with Web components
The Future of CSS with Web components
 
Dependency Injection: Why is awesome and why should I care?
Dependency Injection: Why is awesome and why should I care?Dependency Injection: Why is awesome and why should I care?
Dependency Injection: Why is awesome and why should I care?
 
Building Multi-Tenant SaaS Apps
Building Multi-Tenant SaaS AppsBuilding Multi-Tenant SaaS Apps
Building Multi-Tenant SaaS Apps
 

Recently uploaded

Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 

Recently uploaded (20)

Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 

Garbage First and You!

  • 1. Garbage First andYou ! The new* Garbage Collector in the JVM Kai Koenig @AgentK
  • 2. Web/Mobile Developer since the late 1990s Interested in: Java & JVM, CFML, Functional Programming, Go, JS, Android, Raspberry Pi ! And this is my view of the world… Me
  • 3.
  • 4. 1.The JVM and Garbage Collection in 5 mins
 2.Academic ideas behind G1
 3.The G1 collector
 4.Tuning G1 and practical implications
 5. Further changes in Java 8 Agenda
  • 5. 1. JVM and GC in 
 5 minutes
  • 6. Fundamentals The most simplistic view of the JVM: ! “Java virtual machine (JVM) interprets compiled Java binary code (called bytecode) for a computer’s processor (or hardware platform) so that it can perform a Java program's instructions.”
  • 8. High Level view (1) Bytecode in .class files has the same semantics as the .java code
  • 10. Java stack vs heap memory Each method call creates a new stack frame, which has an operand stack, array of local vars and a program counter. 
 → Seen ‘Stack Traces’ in a Java Error before? ! Exception  in  thread  "main"  java.lang.NullPointerException                  at  com.example.myproject.Book.getTitle(Book.java:16)                  at  com.example.myproject.Author.getBookTitles(Author.java:25)                  at  com.example.myproject.Bootstrap.main(Bootstrap.java:14)
  • 13. Heap management The JVM has no way of knowing the lifespan of a certain object in advance. Generational Memory Management is a solution to overcome this issue and fragmentation: -Young Generation - Old Generation / Tenured Generation - Sometimes: Permanent Generation
  • 15. Garbage Collector selection criteria Efficiency / Throughput Concurrency Overhead JVM version you’re on !
  • 16. YG Collectors: Parallel Parallel MaC (since Java 1.4.2) distributes the Marking and Copying phases over multiple threads. The actual collection is still stop-the-world, but for a much shorter period of time. YG default since Java 5 if machine has 2+ cores or CPUs, otherwise: -XX:+UseParallelGC. !
  • 17. OG Collectors: Concurrent Up to Java 6/7 Concurrent Mark-and-Sweep is the preferred OG collector if you want to minimise stop-the-world collections. CMS via -XX:+UseConcMarkSweepGC Well suited for larger heaps (but be aware of fragmentation), there’s an ‘incremental’ mode for systems with 1-2 CPU cores. Stop-the-world and concurrent collections
  • 18. 2. Academic ideas behind G1
  • 19. “Garbage-First Garbage Collection” Research paper originally published in 2004 by David Detlefs, Christine Flood, Steve Heller and Tony Printezis of Sun Research. ! The actual research project started in the late 1990s to overcome common issues in Garbage Collection techniques known and used at the time.
  • 20. Core ideas Four core elements: - SATB concurrent marking algorithm - Better way to achieve a real-time goal - Get rid of a contiguous heap and use regions - Compacting and predictable
  • 21. Snapshot-at-the-beginning SATB does a periodic analysis of global reachability (liveness) and provide completeness. Results: - Accurate counts of live data in each region
 - Completeness: garbage is eventually identified
 -Very low pause time !
  • 22. ‘Soft’ real-time goal and regions Before G1, garbage collectors tried to achieve hard real time goals by: - making collection interruptible
 - working on the granularity of object levels. G1 works on a coarser granularity of regions: - Chooses regions to collect that match goal
 - Collection of a region can be delayed !
  • 25. G1 (Garbage First) G1 is a ‘replacement’ for CMS in Java 7+ Benefits: - Consistently low-pause - Adaptable - Less fragmentation than CMS - Less need for ongoing tuning - Best collector for a really large heap
  • 26. Fundamental ideas (I) Minimum of 6 GB heap, if below - consider staying with CMS Enable: -XX:+UseG1GC Provide minimal set of expectations and let G1 do the job: - Heap size (min/max)
 - How much CPU time can the application use?
 - How much CPU time can G1 use?
  • 27. Fundamental ideas (II) ‘Main’ setup parameter: 
 -XX:MaxGCPauseMillis=<n> G1 is not an OG-only collector like CMS G1 splits the whole area of heap memory: - ~2000 regions
 - Size between 1-32 MB each
 - usually automatically chosen by the JVM !
  • 28. Region setup in G1 Note:There is another region type H (humongous)
  • 30. AYG collection in G1 (before) Non-Allocated Old Generation Young Generation Recently copiedYG
  • 31. AYG collection in G1 (stop-the-world) Non-Allocated Old Generation Young Generation Recently copiedYG
  • 32. AYG collection in G1 (result) Non-Allocated Old Generation Young Generation Recently copiedYG
  • 33. YG in G1 - Summary TheYG is a set of non-contiguous regions, which helps resizing after a collection. YG collections in G1 are stop-the-world events and all application threads will stop. YG collections are done in multiple, parallel threads. Leftover (alive) objects → move to a survivor or OG region.
  • 35. G1 and the OG - overview (I) 1. Initial Mark (stop-the-world and piggybacking on aYG collection) 2. Root Region Scan (blocksYG from happening) 3. Concurrent Marking 4. Remark (stop-the-world and due to a new algorithm much faster than CMS)
  • 36. G1 and the OG - overview (II) 5. Cleanup (stop-the-world and concurrent) 6. Copying (stop-the-world, piggybacking onYG collections) ! ! ! !
  • 37. OG collection in G1(initial marking) Marks root regions with references to OG objects. Non-Allocated Old Generation Young Generation Recently copiedYG Recently copied OG
  • 38. OG collection in G1(concurrent marking) Marks empty regions and calculates object ‘liveness’. X X Non-Allocated Old Generation Young Generation Recently copiedYG Recently copied OG
  • 39. An OG collection in G1(remark) Empty regions are removed and reclaimed. Non-Allocated Old Generation Young Generation Recently copiedYG Recently copied OG
  • 40. An OG collection in G1(cleanup & copy) Region with lowest liveness get collected withYG collections (‘mixed’ collections). Non-Allocated Old Generation Young Generation Recently copiedYG Recently copied OG
  • 41. An OG collection in G1(result) Collection is done and leftovers are compacted. Non-Allocated Old Generation Young Generation Recently copiedYG Recently copied OG
  • 42. OG in G1 - Summary Concurrent Marking: - Liveness info determines where to collect
 - No sweeping phase like in CMS Remark: - SATB algorithm much faster than CMS
 - Completely empty regions are reclaimed Cleanup: optimised for ‘mixed’ collections
  • 44. Do not trust consultants, blog posts, mailing list discussions etc. telling you what the ‘best’ JVM settings would be. ! There is no such thing as global best settings. JVM settings depend on the environment, the application and the projected/actual usage.
  • 45. JVM settings and logging How do you find out what’s happening in your JVM? -XX:+PrintGC -XX:+PrintGCDetails -XX:+PrintGCTimeStamps or -XX:+PrintGCDateStamps [GC 64781K->22983K(71360K), 0.0242084 secs] [GC 68487K->25003K(77888K), 0.0194041 secs] [Full GC 25003K->20302K(89600K), 0.1713420 secs] [GC 70670K->21755K(90048K), 0.0054093 secs] [GC 71913K->46558K(94912K), 0.0295257 secs] [Full GC 46558K->45267K(118336K), 0.2144038 secs] [GC 88214K->84651K(133056K), 0.0674443 secs] [Full GC 84651K->84633K(171648K), 0.1739369 secs] [GC 117977K->115114K(180736K), 0.0623399 secs] [GC 158613K->157136K(201152K), 0.0591171 secs] [Full GC 157136K->157098K(254784K), 0.1868453 secs] [GC 160678K->160455K(261184K), 0.0536678 secs] 01/24 19:36:22 Debug [scheduler-1] - Next mail spool run in 15 seconds. [GC 202912K->200819K(268288K), 0.0625820 secs] [Full GC 200819K->200776K(332224K), 0.2121724 secs] [GC 213293K->212423K(339520K), 0.0426462 secs] [GC 259465K->256115K(340288K), 0.0645039 secs] [Full GC 256115K->255462K(418432K), 0.3226731 secs] [GC 281947K->279651K(421760K), 0.0530268 secs] [GC 331073K->323785K(422720K), 0.0695117 secs] [Full GC 323785K->323697K(459264K), 0.2139458 secs] [Full GC 364365K->361525K(459264K), 0.2180439 secs] [Full GC 400859K->400859K(459264K), 0.1702890 secs] [Full GC 400859K->43989K(274112K), 0.2642407 secs] [GC 95197K->93707K(273216K), 0.0338568 secs] [GC 146978K->140363K(276032K), 0.0664380 secs] [GC 193696K->189635K(277952K), 0.0630006 secs] [Full GC 189635K->189604K(425920K), 0.1913979 secs] [GC 219773K->205157K(426048K), 0.0442126 secs]
  • 46. The two main tuning parameters for G1 -XX:MaxGCPauseMillis Soft goal target for maximum GC pause time - default 200ms -XX:InitiatingHeapOccupancyPercent Percentage of heap occupancy to start concurrent GC cycle
  • 47. Good practice Avoid setting absolute generation sizes with G1: - Breaks self-optimisation and target times
 - Causes issues in region sizing & distribution Avoid evacuation failures (‘space overflow’): - Increase heap promotion ceiling (default 10)
 -XX:G1ReservePercent 
 - Increase # of marking threads
 -XX:ConcGCThreads
  • 48. Real-world observations (I) G1 has a noticeable tradeoff between latency and throughput: - G1: ~90-92% throughput goal
 - Parallel Hotspot GC: ~98-99% goal If you want higher throughput - relax the pause time goal.
  • 49. Real-world observations (II) ‘Mixed’ GCs are on the more expensive end in G1.You can tamper with the criteria through experimental settings*: -XX:G1MixedGCLiveThresholdPercent 
 -XX:G1HeapWastePercent ! * Might not be available on your platform, CPU architecture or JVM version.
  • 50. Real-world observations (III) CPU usage tends to increase ~5-15% when using G1 vs. CMS. G1 seems to be better in reclaiming the maximum heap sized used. The more uniform your object size distribution is, the better is CMS over G1.With a very heterogenous object size distribution, G1 tends to be better.
  • 51. 5. Changes in Java 8
  • 52. Most of the previous is valid for Java 7 and 8 - but…
  • 53. G1 string de-duplication Java 8u_20 brings a new String de-duplication optimisation. G1 collector can now identify strings that are duplicated across the heap and repoint them to the ‘same’ internal char[] representation: -XX:+UseStringDeduplicationJVM
  • 54. Java 8 and the PermGen It’s gone and it’s been replaced by a Metaspace (Oracle’s JRockit actually never had a PermGen). Class metadata is now stored in native memory. ! A word of warning: Oracle tries to sell the Metaspace as the new piece of awesomeness that ‘just works’, but it still needs observation and tuning!
  • 55. Retired JVM GC combinations Some rarely-used combinations of garbage collectors have been deprecated: http://openjdk.java.net/jeps/173 ! Important: iCMS has been deprecated! ! !
  • 56. Additional Resources Garbage Collection with Garbage First Research Paper:
 http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.63.6386&rep=rep1&type=pdf Understanding G1 logs: 
 https://blogs.oracle.com/poonam/entry/understanding_g1_gc_logs “The JVM is your friend” - my more general GC talk at cf.Objective() 2014:
 http://www.slideshare.net/AgentK/jvm-isyourfriend Java Performance:The Definitive Guide
 http://www.amazon.com/Java-Performance-The-Definitive-Guide/dp/1449358454 !
  • 58. Get in touch Kai Koenig kai@ventego-creative.co.nz
 www.ventego-creative.co.nz
 www.bloginblack.de
 
 Twitter: @AgentK