SlideShare a Scribd company logo
1 of 19
An introduction to G1 Collector
for busy developers
Sanjoy Kumar Roy
sanjoykr78@gmail.com
09-05-2014
Hotspot Architecture
Method
Area
Heap
Java
Threads
Program
Counter
Registers
Native
Internal
Threads
JIT
Complier
Garbage
Collector
Execution
Engine
Native
Method
Interface
Native
Method
Libraries
Runtime Data Areas
Hotspot Architecture
Method
Area
Heap
Java
Threads
Program
Counter
Registers
Native
Internal
Threads
JIT
Complier
Garbage
Collector
Execution
Engine
Native
Method
Interface
Native
Method
Libraries
Runtime Data Areas
Key components related to performance
Performance Basics
Two main goals
Responsiveness Throughput
Large pause
time
Heap in old garbage collectors
Eden S1 S2 Tenured Permanent
Young Generation Old Generation
Permanent
Generation
Survivor Space
In all older garbage collectors (Serial, Parallel, CMS)
heap is divided into three sections:
All memory objects end up in one of these three sections.
Heap in G1Collector
G1 Collector takes a different approach:
Heap is partitioned into a set of equal-sized heap
regions, each a contiguous range of virtual memory.
Certain region sets are assigned the same roles (eden
/ survior / old) as in the older collections, but there is
not a fixed size for them. This provides greater
flexibility in memory usage.
Heap in G1Collector (cont.)
O
O
E
O
S
E
SO
O Heap is one memory are
split into many fixed
sized regions.
Region size is chosen
by the JVM at start-up.
The JVM generally
targets around 2048
regions varying in size
from 1 to 32Mb.
H
E
E
S
S
E
E
H
E Eden
S Survior
O Old
H Humongous
Empty
G1 Heap Allocation
These regions are mapped into logical representations of
eden, survivor, and old generation spaces
Each region is assigned to one role (eden/survior/old)
Live objects are evacuated (copied / moved) from one region
to another
Regions are designed to be collected in parallel with or
without stopping all other application threads.
There is fourth type of object known as Humongous regions.
These regions are designed to hold objects that are 50% the
size of a standard region or larger. They are stored as a set of
contiguous regions.
The last type of regions would be the unused areas of the
heap.
Garbage First (G1) Garbage Collector
G1 is targeted for multi-processor machines
with large memories.
It meets garbage collection (GC) pause time
goals with a high probability, while achieving
high throughput.
Fully supported JDK 7 update 4 and later
releases.
Garbage collection in G1
When performing garbage collections, G1 operates
in a manner similar to the CMS collector.
G1 performs a concurrent global marking phase to
determine the liveness of objects throughout the
heap.
After the mark phase completes, G1 knows which
regions are mostly empty. It collects in these
regions first, which usually yields a large amount
of free space. This is why this method of garbage
collection is called GARBAGE-FIRST.
G1 does an estimate of how many regions can be
collected within the user specified target time.
Thus the collector has a reasonably accurate
model of the cost of collecting the regions.
It uses this pause prediction model to determine
which and how many regions to collect while
staying within specified the pause time target.
Pause Prediction Model
Evacuation Process in G1
In G1, garbage collected from regions using
evacuation. G1 copies objects from one or more
regions of the heap to a single region on the heap,
and in the process both compacts and frees up
memory.
This evacuation is performed in parallel on multi-
processors, to decrease pause times and increase
throughput. Thus, with each garbage collection, G1
continuously works to reduce fragmentation, working
within user defined pause times.
G1 has both
 Concurrent (runs along with application threads:
refinement, marking, cleanup)
 Parallel (multi-threaded, e.g. Stop the world) phases
Full garbage collections are still single threaded.
G1 is not a real-time collector. It meets the set pause
time target with high probability but not absolute
certainty.
Evacuation Process in G1 (cont.)
G1 Footprint
In G1, JVM process size will likely to be
larger. This is largely related to “accounting”
data structures:
a) Remembered Sets (RSets)
b) Collection Sets (CSets)
Remembered Sets (RSets)
Used to track object references into a given region
There is one RSet per region in the heap
The RSet enables the parallel and independent
collection of a region
The overall footprint impact of RSets is less than 5%
Remembered Sets (RSets)
Collection Sets (CSets)
CSets are the set of regions that will be collected
in a GC
All the live data in a CSet is evacuated (copied or
moved) during a GC
Sets of regions can be eden, survivor, and/or old
generation
CSets have a less than 1% impact on the size of
the JVM.
G1 Collector is designed for applications that:
Can operate concurrently with applications’ threads like
the CMS collector.
More than 50% of Java Heap is occupied with live data.
Has undesired long garbage collection or compaction
pauses (longer than 0.5 to 1 second)
Need more predictable GC pause durations.
Do not want to sacrifice a lot of throughput performance.
Require large heaps with limited GC latency (heap sizes
>= 6 GB & stable and predictable pause time < 0.5 sec)
Thank you.

More Related Content

Similar to An introduction to the G1 garbage collector for busy developers

Garbage Collection in Hotspot JVM
Garbage Collection in Hotspot JVMGarbage Collection in Hotspot JVM
Garbage Collection in Hotspot JVMjaganmohanreddyk
 
Let's talk about Garbage Collection
Let's talk about Garbage CollectionLet's talk about Garbage Collection
Let's talk about Garbage CollectionHaim Yadid
 
Garbage collection
Garbage collectionGarbage collection
Garbage collectionMudit Gupta
 
Memory Management in the Java Virtual Machine(Garbage collection)
Memory Management in the Java Virtual Machine(Garbage collection)Memory Management in the Java Virtual Machine(Garbage collection)
Memory Management in the Java Virtual Machine(Garbage collection)Prashanth Kumar
 
Performance tuning jvm
Performance tuning jvmPerformance tuning jvm
Performance tuning jvmPrem Kuppumani
 
Garbage First and you
Garbage First and youGarbage First and you
Garbage First and youKai Koenig
 
Garbage First and You!
Garbage First and You!Garbage First and You!
Garbage First and You!devObjective
 
HotSpot JVM Tuning
HotSpot JVM TuningHotSpot JVM Tuning
HotSpot JVM TuningGilad Garon
 
Memory Management in Go: Stack, Heap & Garbage Collector
Memory Management in Go: Stack, Heap & Garbage CollectorMemory Management in Go: Stack, Heap & Garbage Collector
Memory Management in Go: Stack, Heap & Garbage CollectorWednesday Solutions
 
Вячеслав Блинов «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
 
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
 
Quick introduction to Java Garbage Collector (JVM GC)
Quick introduction to Java Garbage Collector (JVM GC)Quick introduction to Java Garbage Collector (JVM GC)
Quick introduction to Java Garbage Collector (JVM GC)Marcos García
 
Garbage Collection, Tuning And Monitoring JVM In EBS 11i And R12
Garbage Collection, Tuning And Monitoring JVM In EBS 11i And R12Garbage Collection, Tuning And Monitoring JVM In EBS 11i And R12
Garbage Collection, Tuning And Monitoring JVM In EBS 11i And R12sidg75
 

Similar to An introduction to the G1 garbage collector for busy developers (20)

Garbage Collection in Hotspot JVM
Garbage Collection in Hotspot JVMGarbage Collection in Hotspot JVM
Garbage Collection in Hotspot JVM
 
Jvm Architecture
Jvm ArchitectureJvm Architecture
Jvm Architecture
 
Let's talk about Garbage Collection
Let's talk about Garbage CollectionLet's talk about Garbage Collection
Let's talk about Garbage Collection
 
Garbage collection
Garbage collectionGarbage collection
Garbage collection
 
Memory Management in the Java Virtual Machine(Garbage collection)
Memory Management in the Java Virtual Machine(Garbage collection)Memory Management in the Java Virtual Machine(Garbage collection)
Memory Management in the Java Virtual Machine(Garbage collection)
 
JVM Magic
JVM MagicJVM Magic
JVM Magic
 
ZGC-SnowOne.pdf
ZGC-SnowOne.pdfZGC-SnowOne.pdf
ZGC-SnowOne.pdf
 
Performance tuning jvm
Performance tuning jvmPerformance tuning jvm
Performance tuning jvm
 
Garbage First and you
Garbage First and youGarbage First and you
Garbage First and you
 
Garbage First and You!
Garbage First and You!Garbage First and You!
Garbage First and You!
 
Garbage First & You
Garbage First & YouGarbage First & You
Garbage First & You
 
HotSpot JVM Tuning
HotSpot JVM TuningHotSpot JVM Tuning
HotSpot JVM Tuning
 
Memory Management in Go: Stack, Heap & Garbage Collector
Memory Management in Go: Stack, Heap & Garbage CollectorMemory Management in Go: Stack, Heap & Garbage Collector
Memory Management in Go: Stack, Heap & Garbage Collector
 
Gc in android
Gc in androidGc in android
Gc in android
 
Вячеслав Блинов «Java Garbage Collection: A Performance Impact»
Вячеслав Блинов «Java Garbage Collection: A Performance Impact»Вячеслав Блинов «Java Garbage Collection: A Performance Impact»
Вячеслав Блинов «Java Garbage Collection: A Performance Impact»
 
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
 
Heap Management
Heap ManagementHeap Management
Heap Management
 
Quick introduction to Java Garbage Collector (JVM GC)
Quick introduction to Java Garbage Collector (JVM GC)Quick introduction to Java Garbage Collector (JVM GC)
Quick introduction to Java Garbage Collector (JVM GC)
 
Garbage Collection, Tuning And Monitoring JVM In EBS 11i And R12
Garbage Collection, Tuning And Monitoring JVM In EBS 11i And R12Garbage Collection, Tuning And Monitoring JVM In EBS 11i And R12
Garbage Collection, Tuning And Monitoring JVM In EBS 11i And R12
 
Move from C to Go
Move from C to GoMove from C to Go
Move from C to Go
 

More from Sanjoy Kumar Roy

Arch CoP - Domain Driven Design.pptx
Arch CoP - Domain Driven Design.pptxArch CoP - Domain Driven Design.pptx
Arch CoP - Domain Driven Design.pptxSanjoy Kumar Roy
 
Visualizing Software Architecture Effectively in Service Description
Visualizing Software Architecture Effectively in Service DescriptionVisualizing Software Architecture Effectively in Service Description
Visualizing Software Architecture Effectively in Service DescriptionSanjoy Kumar Roy
 
Hypermedia API and how to document it effectively
Hypermedia API and how to document it effectivelyHypermedia API and how to document it effectively
Hypermedia API and how to document it effectivelySanjoy Kumar Roy
 
An introduction to OAuth 2
An introduction to OAuth 2An introduction to OAuth 2
An introduction to OAuth 2Sanjoy Kumar Roy
 
Microservice architecture design principles
Microservice architecture design principlesMicroservice architecture design principles
Microservice architecture design principlesSanjoy Kumar Roy
 
Lessons learned in developing an agile architecture to reward our customers.
Lessons learned in developing an agile architecture to reward our customers.Lessons learned in developing an agile architecture to reward our customers.
Lessons learned in developing an agile architecture to reward our customers.Sanjoy Kumar Roy
 

More from Sanjoy Kumar Roy (8)

Arch CoP - Domain Driven Design.pptx
Arch CoP - Domain Driven Design.pptxArch CoP - Domain Driven Design.pptx
Arch CoP - Domain Driven Design.pptx
 
Visualizing Software Architecture Effectively in Service Description
Visualizing Software Architecture Effectively in Service DescriptionVisualizing Software Architecture Effectively in Service Description
Visualizing Software Architecture Effectively in Service Description
 
Hypermedia API and how to document it effectively
Hypermedia API and how to document it effectivelyHypermedia API and how to document it effectively
Hypermedia API and how to document it effectively
 
An introduction to OAuth 2
An introduction to OAuth 2An introduction to OAuth 2
An introduction to OAuth 2
 
Transaction
TransactionTransaction
Transaction
 
Microservice architecture design principles
Microservice architecture design principlesMicroservice architecture design principles
Microservice architecture design principles
 
Lessons learned in developing an agile architecture to reward our customers.
Lessons learned in developing an agile architecture to reward our customers.Lessons learned in developing an agile architecture to reward our customers.
Lessons learned in developing an agile architecture to reward our customers.
 
Major Java 8 features
Major Java 8 featuresMajor Java 8 features
Major Java 8 features
 

Recently uploaded

The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendArshad QA
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 

Recently uploaded (20)

The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and Backend
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 

An introduction to the G1 garbage collector for busy developers

  • 1. An introduction to G1 Collector for busy developers Sanjoy Kumar Roy sanjoykr78@gmail.com 09-05-2014
  • 4. Performance Basics Two main goals Responsiveness Throughput Large pause time
  • 5. Heap in old garbage collectors Eden S1 S2 Tenured Permanent Young Generation Old Generation Permanent Generation Survivor Space In all older garbage collectors (Serial, Parallel, CMS) heap is divided into three sections: All memory objects end up in one of these three sections.
  • 6. Heap in G1Collector G1 Collector takes a different approach: Heap is partitioned into a set of equal-sized heap regions, each a contiguous range of virtual memory. Certain region sets are assigned the same roles (eden / survior / old) as in the older collections, but there is not a fixed size for them. This provides greater flexibility in memory usage.
  • 7. Heap in G1Collector (cont.) O O E O S E SO O Heap is one memory are split into many fixed sized regions. Region size is chosen by the JVM at start-up. The JVM generally targets around 2048 regions varying in size from 1 to 32Mb. H E E S S E E H E Eden S Survior O Old H Humongous Empty
  • 8. G1 Heap Allocation These regions are mapped into logical representations of eden, survivor, and old generation spaces Each region is assigned to one role (eden/survior/old) Live objects are evacuated (copied / moved) from one region to another Regions are designed to be collected in parallel with or without stopping all other application threads. There is fourth type of object known as Humongous regions. These regions are designed to hold objects that are 50% the size of a standard region or larger. They are stored as a set of contiguous regions. The last type of regions would be the unused areas of the heap.
  • 9. Garbage First (G1) Garbage Collector G1 is targeted for multi-processor machines with large memories. It meets garbage collection (GC) pause time goals with a high probability, while achieving high throughput. Fully supported JDK 7 update 4 and later releases.
  • 10. Garbage collection in G1 When performing garbage collections, G1 operates in a manner similar to the CMS collector. G1 performs a concurrent global marking phase to determine the liveness of objects throughout the heap. After the mark phase completes, G1 knows which regions are mostly empty. It collects in these regions first, which usually yields a large amount of free space. This is why this method of garbage collection is called GARBAGE-FIRST.
  • 11. G1 does an estimate of how many regions can be collected within the user specified target time. Thus the collector has a reasonably accurate model of the cost of collecting the regions. It uses this pause prediction model to determine which and how many regions to collect while staying within specified the pause time target. Pause Prediction Model
  • 12. Evacuation Process in G1 In G1, garbage collected from regions using evacuation. G1 copies objects from one or more regions of the heap to a single region on the heap, and in the process both compacts and frees up memory. This evacuation is performed in parallel on multi- processors, to decrease pause times and increase throughput. Thus, with each garbage collection, G1 continuously works to reduce fragmentation, working within user defined pause times.
  • 13. G1 has both  Concurrent (runs along with application threads: refinement, marking, cleanup)  Parallel (multi-threaded, e.g. Stop the world) phases Full garbage collections are still single threaded. G1 is not a real-time collector. It meets the set pause time target with high probability but not absolute certainty. Evacuation Process in G1 (cont.)
  • 14. G1 Footprint In G1, JVM process size will likely to be larger. This is largely related to “accounting” data structures: a) Remembered Sets (RSets) b) Collection Sets (CSets)
  • 15. Remembered Sets (RSets) Used to track object references into a given region There is one RSet per region in the heap The RSet enables the parallel and independent collection of a region The overall footprint impact of RSets is less than 5%
  • 17. Collection Sets (CSets) CSets are the set of regions that will be collected in a GC All the live data in a CSet is evacuated (copied or moved) during a GC Sets of regions can be eden, survivor, and/or old generation CSets have a less than 1% impact on the size of the JVM.
  • 18. G1 Collector is designed for applications that: Can operate concurrently with applications’ threads like the CMS collector. More than 50% of Java Heap is occupied with live data. Has undesired long garbage collection or compaction pauses (longer than 0.5 to 1 second) Need more predictable GC pause durations. Do not want to sacrifice a lot of throughput performance. Require large heaps with limited GC latency (heap sizes >= 6 GB & stable and predictable pause time < 0.5 sec)