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

Introduction of Java GC Tuning and Java Java Mission Control
Introduction of Java GC Tuning and Java Java Mission ControlIntroduction of Java GC Tuning and Java Java Mission Control
Introduction of Java GC Tuning and Java Java Mission ControlLeon Chen
 
Diagnosing Your Application on the JVM
Diagnosing Your Application on the JVMDiagnosing Your Application on the JVM
Diagnosing Your Application on the JVMStaffan Larsen
 
JVM Garbage Collection Tuning
JVM Garbage Collection TuningJVM Garbage Collection Tuning
JVM Garbage Collection Tuningihji
 
Java Performance Monitoring & Tuning
Java Performance Monitoring & TuningJava Performance Monitoring & Tuning
Java Performance Monitoring & TuningMuhammed Shakir
 
Tuning Java GC to resolve performance issues
Tuning Java GC to resolve performance issuesTuning Java GC to resolve performance issues
Tuning Java GC to resolve performance issuesSergey Podolsky
 
Let's talk about Garbage Collection
Let's talk about Garbage CollectionLet's talk about Garbage Collection
Let's talk about Garbage CollectionHaim Yadid
 
"What's New in HotSpot JVM 8" @ JPoint 2014, Moscow, Russia
"What's New in HotSpot JVM 8" @ JPoint 2014, Moscow, Russia "What's New in HotSpot JVM 8" @ JPoint 2014, Moscow, Russia
"What's New in HotSpot JVM 8" @ JPoint 2014, Moscow, Russia Vladimir Ivanov
 
Modern Java Workshop
Modern Java WorkshopModern Java Workshop
Modern Java WorkshopSimon Ritter
 
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
 
Java performance monitoring
Java performance monitoringJava performance monitoring
Java performance monitoringSimon Ritter
 
JVM @ Taobao - QCon Hangzhou 2011
JVM @ Taobao - QCon Hangzhou 2011JVM @ Taobao - QCon Hangzhou 2011
JVM @ Taobao - QCon Hangzhou 2011Kris Mok
 
자바 성능 강의
자바 성능 강의자바 성능 강의
자바 성능 강의Terry Cho
 
Java profiling Do It Yourself (jug.msk.ru 2016)
Java profiling Do It Yourself (jug.msk.ru 2016)Java profiling Do It Yourself (jug.msk.ru 2016)
Java profiling Do It Yourself (jug.msk.ru 2016)aragozin
 
GC Tuning Confessions Of A Performance Engineer
GC Tuning Confessions Of A Performance EngineerGC Tuning Confessions Of A Performance Engineer
GC Tuning Confessions Of A Performance EngineerMonica Beckwith
 
I know why your Java is slow
I know why your Java is slowI know why your Java is slow
I know why your Java is slowaragozin
 
Efficient Memory and Thread Management in Highly Parallel Java Applications
Efficient Memory and Thread Management in Highly Parallel Java ApplicationsEfficient Memory and Thread Management in Highly Parallel Java Applications
Efficient Memory and Thread Management in Highly Parallel Java Applicationspkoza
 
What's New in the JVM in Java 8?
What's New in the JVM in Java 8?What's New in the JVM in Java 8?
What's New in the JVM in Java 8?Azul Systems Inc.
 
Jvm Performance Tunning
Jvm Performance TunningJvm Performance Tunning
Jvm Performance Tunningguest1f2740
 

What's hot (19)

Introduction of Java GC Tuning and Java Java Mission Control
Introduction of Java GC Tuning and Java Java Mission ControlIntroduction of Java GC Tuning and Java Java Mission Control
Introduction of Java GC Tuning and Java Java Mission Control
 
Diagnosing Your Application on the JVM
Diagnosing Your Application on the JVMDiagnosing Your Application on the JVM
Diagnosing Your Application on the JVM
 
JVM Garbage Collection Tuning
JVM Garbage Collection TuningJVM Garbage Collection Tuning
JVM Garbage Collection Tuning
 
Java Performance Monitoring & Tuning
Java Performance Monitoring & TuningJava Performance Monitoring & Tuning
Java Performance Monitoring & Tuning
 
Tuning Java GC to resolve performance issues
Tuning Java GC to resolve performance issuesTuning Java GC to resolve performance issues
Tuning Java GC to resolve performance issues
 
Let's talk about Garbage Collection
Let's talk about Garbage CollectionLet's talk about Garbage Collection
Let's talk about Garbage Collection
 
Java performance tuning
Java performance tuningJava performance tuning
Java performance tuning
 
"What's New in HotSpot JVM 8" @ JPoint 2014, Moscow, Russia
"What's New in HotSpot JVM 8" @ JPoint 2014, Moscow, Russia "What's New in HotSpot JVM 8" @ JPoint 2014, Moscow, Russia
"What's New in HotSpot JVM 8" @ JPoint 2014, Moscow, Russia
 
Modern Java Workshop
Modern Java WorkshopModern Java Workshop
Modern Java Workshop
 
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
 
Java performance monitoring
Java performance monitoringJava performance monitoring
Java performance monitoring
 
JVM @ Taobao - QCon Hangzhou 2011
JVM @ Taobao - QCon Hangzhou 2011JVM @ Taobao - QCon Hangzhou 2011
JVM @ Taobao - QCon Hangzhou 2011
 
자바 성능 강의
자바 성능 강의자바 성능 강의
자바 성능 강의
 
Java profiling Do It Yourself (jug.msk.ru 2016)
Java profiling Do It Yourself (jug.msk.ru 2016)Java profiling Do It Yourself (jug.msk.ru 2016)
Java profiling Do It Yourself (jug.msk.ru 2016)
 
GC Tuning Confessions Of A Performance Engineer
GC Tuning Confessions Of A Performance EngineerGC Tuning Confessions Of A Performance Engineer
GC Tuning Confessions Of A Performance Engineer
 
I know why your Java is slow
I know why your Java is slowI know why your Java is slow
I know why your Java is slow
 
Efficient Memory and Thread Management in Highly Parallel Java Applications
Efficient Memory and Thread Management in Highly Parallel Java ApplicationsEfficient Memory and Thread Management in Highly Parallel Java Applications
Efficient Memory and Thread Management in Highly Parallel Java Applications
 
What's New in the JVM in Java 8?
What's New in the JVM in Java 8?What's New in the JVM in Java 8?
What's New in the JVM in Java 8?
 
Jvm Performance Tunning
Jvm Performance TunningJvm Performance Tunning
Jvm Performance Tunning
 

Similar to Garbage First and you

JVM Performance Tuning
JVM Performance TuningJVM Performance Tuning
JVM Performance TuningJeremy Leisy
 
JVM and Garbage Collection Tuning
JVM and Garbage Collection TuningJVM and Garbage Collection Tuning
JVM and Garbage Collection TuningKai Koenig
 
Taming Java Garbage Collector
Taming Java Garbage CollectorTaming Java Garbage Collector
Taming Java Garbage CollectorDaya Atapattu
 
G1 Garbage Collector - Big Heaps and Low Pauses?
G1 Garbage Collector - Big Heaps and Low Pauses?G1 Garbage Collector - Big Heaps and Low Pauses?
G1 Garbage Collector - Big Heaps and Low Pauses?C2B2 Consulting
 
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
 
“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
 
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
 
Вячеслав Блинов «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
 

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
 
JVM and Garbage Collection Tuning
JVM and Garbage Collection TuningJVM and Garbage Collection Tuning
JVM and Garbage Collection Tuning
 
Taming Java Garbage Collector
Taming Java Garbage CollectorTaming Java Garbage Collector
Taming Java Garbage Collector
 
G1 Garbage Collector - Big Heaps and Low Pauses?
G1 Garbage Collector - Big Heaps and Low Pauses?G1 Garbage Collector - Big Heaps and Low Pauses?
G1 Garbage Collector - Big Heaps and Low Pauses?
 
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
 
“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
 
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...
 
Вячеслав Блинов «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
 
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
 

More from Kai Koenig

Why a whole country skipped a day - Fun with Timezones
Why a whole country skipped a day - Fun with Timezones Why a whole country skipped a day - Fun with Timezones
Why a whole country skipped a day - Fun with Timezones Kai Koenig
 
Android 103 - Firebase and Architecture Components
Android 103 - Firebase and Architecture ComponentsAndroid 103 - Firebase and Architecture Components
Android 103 - Firebase and Architecture ComponentsKai Koenig
 
Android 102 - Flow, Layouts and other things
Android 102 - Flow, Layouts and other thingsAndroid 102 - Flow, Layouts and other things
Android 102 - Flow, Layouts and other thingsKai Koenig
 
Android 101 - Building a simple app with Kotlin in 90 minutes
Android 101 - Building a simple app with Kotlin in 90 minutesAndroid 101 - Building a simple app with Kotlin in 90 minutes
Android 101 - Building a simple app with Kotlin in 90 minutesKai Koenig
 
Kotlin Coroutines and Android sitting in a tree - 2018 version
Kotlin Coroutines and Android sitting in a tree - 2018 versionKotlin Coroutines and Android sitting in a tree - 2018 version
Kotlin Coroutines and Android sitting in a tree - 2018 versionKai Koenig
 
Kotlin Coroutines and Android sitting in a tree
Kotlin Coroutines and Android sitting in a treeKotlin Coroutines and Android sitting in a tree
Kotlin Coroutines and Android sitting in a treeKai Koenig
 
Improving your CFML code quality
Improving your CFML code qualityImproving your CFML code quality
Improving your CFML code qualityKai Koenig
 
Summer of Tech 2017 - Kotlin/Android bootcamp
Summer of Tech 2017 - Kotlin/Android bootcampSummer of Tech 2017 - Kotlin/Android bootcamp
Summer of Tech 2017 - Kotlin/Android bootcampKai Koenig
 
2017: Kotlin - now more than ever
2017: Kotlin - now more than ever2017: Kotlin - now more than ever
2017: Kotlin - now more than everKai Koenig
 
Anko - The Ultimate Ninja of Kotlin Libraries?
Anko - The Ultimate Ninja of Kotlin Libraries?Anko - The Ultimate Ninja of Kotlin Libraries?
Anko - The Ultimate Ninja of Kotlin Libraries?Kai Koenig
 
Coding for Android on steroids with Kotlin
Coding for Android on steroids with KotlinCoding for Android on steroids with Kotlin
Coding for Android on steroids with KotlinKai Koenig
 
API management with Taffy and API Blueprint
API management with Taffy and API BlueprintAPI management with Taffy and API Blueprint
API management with Taffy and API BlueprintKai Koenig
 
Little Helpers for Android Development with Kotlin
Little Helpers for Android Development with KotlinLittle Helpers for Android Development with Kotlin
Little Helpers for Android Development with KotlinKai Koenig
 
Introduction to Data Mining
Introduction to Data MiningIntroduction to Data Mining
Introduction to Data MiningKai Koenig
 
Real World Lessons in jQuery Mobile
Real World Lessons in jQuery MobileReal World Lessons in jQuery Mobile
Real World Lessons in jQuery MobileKai Koenig
 
Regular Expressions 101
Regular Expressions 101Regular Expressions 101
Regular Expressions 101Kai Koenig
 
There's a time and a place
There's a time and a placeThere's a time and a place
There's a time and a placeKai Koenig
 
Clojure - an introduction (and some CFML)
Clojure - an introduction (and some CFML)Clojure - an introduction (and some CFML)
Clojure - an introduction (and some CFML)Kai Koenig
 
AngularJS for designers and developers
AngularJS for designers and developersAngularJS for designers and developers
AngularJS for designers and developersKai Koenig
 
Cryptography for developers
Cryptography for developersCryptography for developers
Cryptography for developersKai Koenig
 

More from Kai Koenig (20)

Why a whole country skipped a day - Fun with Timezones
Why a whole country skipped a day - Fun with Timezones Why a whole country skipped a day - Fun with Timezones
Why a whole country skipped a day - Fun with Timezones
 
Android 103 - Firebase and Architecture Components
Android 103 - Firebase and Architecture ComponentsAndroid 103 - Firebase and Architecture Components
Android 103 - Firebase and Architecture Components
 
Android 102 - Flow, Layouts and other things
Android 102 - Flow, Layouts and other thingsAndroid 102 - Flow, Layouts and other things
Android 102 - Flow, Layouts and other things
 
Android 101 - Building a simple app with Kotlin in 90 minutes
Android 101 - Building a simple app with Kotlin in 90 minutesAndroid 101 - Building a simple app with Kotlin in 90 minutes
Android 101 - Building a simple app with Kotlin in 90 minutes
 
Kotlin Coroutines and Android sitting in a tree - 2018 version
Kotlin Coroutines and Android sitting in a tree - 2018 versionKotlin Coroutines and Android sitting in a tree - 2018 version
Kotlin Coroutines and Android sitting in a tree - 2018 version
 
Kotlin Coroutines and Android sitting in a tree
Kotlin Coroutines and Android sitting in a treeKotlin Coroutines and Android sitting in a tree
Kotlin Coroutines and Android sitting in a tree
 
Improving your CFML code quality
Improving your CFML code qualityImproving your CFML code quality
Improving your CFML code quality
 
Summer of Tech 2017 - Kotlin/Android bootcamp
Summer of Tech 2017 - Kotlin/Android bootcampSummer of Tech 2017 - Kotlin/Android bootcamp
Summer of Tech 2017 - Kotlin/Android bootcamp
 
2017: Kotlin - now more than ever
2017: Kotlin - now more than ever2017: Kotlin - now more than ever
2017: Kotlin - now more than ever
 
Anko - The Ultimate Ninja of Kotlin Libraries?
Anko - The Ultimate Ninja of Kotlin Libraries?Anko - The Ultimate Ninja of Kotlin Libraries?
Anko - The Ultimate Ninja of Kotlin Libraries?
 
Coding for Android on steroids with Kotlin
Coding for Android on steroids with KotlinCoding for Android on steroids with Kotlin
Coding for Android on steroids with Kotlin
 
API management with Taffy and API Blueprint
API management with Taffy and API BlueprintAPI management with Taffy and API Blueprint
API management with Taffy and API Blueprint
 
Little Helpers for Android Development with Kotlin
Little Helpers for Android Development with KotlinLittle Helpers for Android Development with Kotlin
Little Helpers for Android Development with Kotlin
 
Introduction to Data Mining
Introduction to Data MiningIntroduction to Data Mining
Introduction to Data Mining
 
Real World Lessons in jQuery Mobile
Real World Lessons in jQuery MobileReal World Lessons in jQuery Mobile
Real World Lessons in jQuery Mobile
 
Regular Expressions 101
Regular Expressions 101Regular Expressions 101
Regular Expressions 101
 
There's a time and a place
There's a time and a placeThere's a time and a place
There's a time and a place
 
Clojure - an introduction (and some CFML)
Clojure - an introduction (and some CFML)Clojure - an introduction (and some CFML)
Clojure - an introduction (and some CFML)
 
AngularJS for designers and developers
AngularJS for designers and developersAngularJS for designers and developers
AngularJS for designers and developers
 
Cryptography for developers
Cryptography for developersCryptography for developers
Cryptography for developers
 

Recently uploaded

Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZABSYZ Inc
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecturerahul_net
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxAndreas Kunz
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxReal-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxRTS corp
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identityteam-WIBU
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Rob Geurden
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 

Recently uploaded (20)

Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZ
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecture
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxReal-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identity
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 

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