SlideShare a Scribd company logo
1 of 12
Garbage Collection in Java

“Heap storage for objects is reclaimed by an automatic
      storage management system. Objects are never
                                 explicitly de-allocated”
               –Java Virtual Machine Specification [1]
Java Variable Flavours
• Stack
  – Local variables holding
    primitives.
                               10
  – Local variable of
    reference typewill point
    at heap memory.
• Heap
  – Objects.
  – Primitive fields of an
    object.
Mark and Sweep Approach
• Simplest. Garbage collector algorithm.
• Recover and reuse.Heap memoryno longer in use.
• Algorithm.
   – Stop-the-world.Non-deterministicpauses stop allthe
     running threads.
   – Start.From live objectswalks through the tree of
     references.
   – Mark.As liveany object on the route.
   – Sweep.Everything left is garbage and can be collected.
Generational Garbage Collector
•   Mark-and-sweep. Improved.
•   Weak generational hypothesis [2].
     – Mostobjectsbecome unreachable
        quickly.
     – Fewreferencesfrom older to young                                        Eden




                                                     Young Generation
        objects exist.
•   Areas of memory.                                                      Survivor
     – Eden.Most new objects (very large                                From          To
        objects directly to old generation).




                                                Generation
     – Survivor.Survived, one holds

                                                   Old
                                                                         Tenured
        object, the other empty.
     – Tenured.Promoted longer-lived
        objects.                                                         PermGen
     – PermGen.Not strictly in heap, internal
        structures (i.e. class definitions).
Escape Analysis
• Recent change.Java 6u23.
• Local variables.Onlyused
  inside the method.
   – No passedinto other
     methods.
   – No returned.
• No heap.Object created on
  the method stack frame
   – Reduce objects of young   10
     collections.
   – Memory used freed when
     method returns.
Concurrent Mark-Sweep in Action
•   Two short pauses.Per GC cycle, initial mark and
    remark.
                                                                     Marking/Pre-cleaning        Sweeping
•   Initial Mark.Identifies set of objectsimmediately
    reachable outside old generation.

•   Concurrent marking phase.Marks all live
    objectstransitively reachable from this set.
     • Object graph can change.Not alllive objects are
         guaranteed to be marked.
•   Pre-cleaning.Revisitingobjects modified concurrently
    with the marking phase.
                                                           Initial Mark                     Remark


•   Second Pause (Remark).Revisits objects modified
    during concurrent marking phase.                                         Running application thread
•   Concurrent sweep phase.Deallocates garbage                               Running GC thread
    objects without relocatingthe live ones.
CMS Pros/Cons
•   Advantages.
     – Two pauses. No one single pause.
     – Concurrency. App and GC run in parallel.
•   Disadvantages.                                       Start sweeping

     – Extra overhead.
     – Freelists. Free space not contiguous.
     – Large Java heap req.Marking cycle lasts
        morethan stop-the-world, spacereclaimed at       End sweeping
        the end.
     – App runs concurrently.Old
        generationpotentially increases during
        marking phase.
     – Floating garbage. Not guaranteed all
        garbage objects.
     – Fragmentation issue.Lack of
        compaction, possible not efficient use of free
        space [3].
Garbage-First GC (G1) in Action
•   Features.
    Parallel, concurrent, incrementally
    compacting low-pause.
•   Heap layout.Split into regions.
•   Region.Equal-sized chunks.
•   Pause goal.How long app can pause for
    GC while running (20 ms every 5 min).
•   Pause.Objects evacuatedfrom one or                         Marking

    more regions to a single region.
•   Statistics.Average a region takes to
    collect.
•   G1?. Knows mostly empty regions.
     – Collects.Inthis regions first.
     – Concentrates.Collect on areas likely
                                              GC       GC                  GC
         to be full of garbage.
                                                   Running application thread

                                                   Running GC thread
G1 Pros/Cons
•   Advantages.
     – High performance.
     – Pause time goals. Prevent interruption proportional to heap or live-data size.
     – Compact and free up memory.Continuously work to reduce fragmentation.
     – Concurrent global marking phase. Determine liveness of the objects.
     – Pause prediction model.
         • Meet user-defined pause time target with high probability.
         • Selects number of regions to collect based on the time target.
•   Disadvantages.
     – Target. Multi-processor machines with large memories.
Comparison
•   G1.                                    •   CMS.
     – Compacting collector.                    – No compaction.
     – Avoid free list, rely on regions.        – No control.
     – More predictable pauses.            •   ParallelOld.
     – User can specify pause targets.          – Whole-heap compaction, long
•   Switch to G1.                                  pauses.
     – More than 50% heap occupied              – No control.
        with live data.
     – Allocation and promotion rate
        varies significantly.
     – Undesired long collection and
        compaction pauses (0.5s to 1s)
References
[1] Lindholm, Tim, and Frank Yellin. Java Virtual Machine Specification, Second Edition.
     Addison-Wesley, Reading, MA, 1999.
[2] Charlie Hunt, Binu John. Java Performance, First Edition. Pearson, 2011.
[3] Jones, Richard, and Rafael Lins. Garbage Collection. John Wiley &
     Sons, Ltd.,WestSussex, PO19 IUD, England, 1996.
[4] Memory Management in the Java HotSpot Virtual Machine. Sun
     Mircrosystem, April 2006.
[5] B.J. Evans, M. Verburg. Well-Grounded Java Developer. Manning, 2012.
Questions?

More Related Content

Similar to Garbage collection Overview

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
 
[Jbcn 2016] Garbage Collectors WTF!?
[Jbcn 2016] Garbage Collectors WTF!?[Jbcn 2016] Garbage Collectors WTF!?
[Jbcn 2016] Garbage Collectors WTF!?Alonso Torres
 
Java Garbage Collector and The Memory Model
Java Garbage Collector and The Memory ModelJava Garbage Collector and The Memory Model
Java Garbage Collector and The Memory ModelErnesto Arroyo Ron
 
.NET Core, ASP.NET Core Course, Session 4
.NET Core, ASP.NET Core Course, Session 4.NET Core, ASP.NET Core Course, Session 4
.NET Core, ASP.NET Core Course, Session 4aminmesbahi
 
JVM memory metrics and rules for detecting possible OOM caused crash
JVM memory metrics and rules for detecting possible OOM caused crashJVM memory metrics and rules for detecting possible OOM caused crash
JVM memory metrics and rules for detecting possible OOM caused crashAtharva Bhingarkar
 
JVM memory metrics and rules for detecting likely OOM caused crash
JVM memory metrics and rules for detecting likely OOM caused crashJVM memory metrics and rules for detecting likely OOM caused crash
JVM memory metrics and rules for detecting likely OOM caused crashAjit Bhingarkar
 
«Большие объёмы данных и сборка мусора в Java
«Большие объёмы данных и сборка мусора в Java«Большие объёмы данных и сборка мусора в Java
«Большие объёмы данных и сборка мусора в JavaOlga Lavrentieva
 
Let's talk about Garbage Collection
Let's talk about Garbage CollectionLet's talk about Garbage Collection
Let's talk about Garbage CollectionHaim Yadid
 
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
 
Java garbage collection & GC friendly coding
Java garbage collection  & GC friendly codingJava garbage collection  & GC friendly coding
Java garbage collection & GC friendly codingMd Ayub Ali Sarker
 
Tuning IBMs Generational GC
Tuning IBMs Generational GCTuning IBMs Generational GC
Tuning IBMs Generational GCChris Bailey
 
Diagnosing Problems in Production - Cassandra
Diagnosing Problems in Production - CassandraDiagnosing Problems in Production - Cassandra
Diagnosing Problems in Production - CassandraJon Haddad
 
“Show Me the Garbage!”, Understanding Garbage Collection
“Show Me the Garbage!”, Understanding Garbage Collection“Show Me the Garbage!”, Understanding Garbage Collection
“Show Me the Garbage!”, Understanding Garbage CollectionHaim Yadid
 
Java gc and JVM optimization
Java gc  and JVM optimizationJava gc  and JVM optimization
Java gc and JVM optimizationRajan Jethva
 
02D-Memory Management in Java.pptx
02D-Memory Management in Java.pptx02D-Memory Management in Java.pptx
02D-Memory Management in Java.pptxAnhNhatNguyen5
 
Chronicles Of Garbage Collection (GC)
Chronicles Of Garbage Collection (GC)Chronicles Of Garbage Collection (GC)
Chronicles Of Garbage Collection (GC)Techizzaa
 
JVM Performance Tuning
JVM Performance TuningJVM Performance Tuning
JVM Performance TuningJeremy Leisy
 

Similar to Garbage collection Overview (20)

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)
 
[Jbcn 2016] Garbage Collectors WTF!?
[Jbcn 2016] Garbage Collectors WTF!?[Jbcn 2016] Garbage Collectors WTF!?
[Jbcn 2016] Garbage Collectors WTF!?
 
Java Garbage Collector and The Memory Model
Java Garbage Collector and The Memory ModelJava Garbage Collector and The Memory Model
Java Garbage Collector and The Memory Model
 
Garbage Collection .Net
Garbage Collection .NetGarbage Collection .Net
Garbage Collection .Net
 
.NET Core, ASP.NET Core Course, Session 4
.NET Core, ASP.NET Core Course, Session 4.NET Core, ASP.NET Core Course, Session 4
.NET Core, ASP.NET Core Course, Session 4
 
JVM memory metrics and rules for detecting possible OOM caused crash
JVM memory metrics and rules for detecting possible OOM caused crashJVM memory metrics and rules for detecting possible OOM caused crash
JVM memory metrics and rules for detecting possible OOM caused crash
 
JVM memory metrics and rules for detecting likely OOM caused crash
JVM memory metrics and rules for detecting likely OOM caused crashJVM memory metrics and rules for detecting likely OOM caused crash
JVM memory metrics and rules for detecting likely OOM caused crash
 
«Большие объёмы данных и сборка мусора в Java
«Большие объёмы данных и сборка мусора в Java«Большие объёмы данных и сборка мусора в Java
«Большие объёмы данных и сборка мусора в Java
 
Let's talk about Garbage Collection
Let's talk about Garbage CollectionLet's talk about Garbage Collection
Let's talk about 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)
 
Javasession10
Javasession10Javasession10
Javasession10
 
Java garbage collection & GC friendly coding
Java garbage collection  & GC friendly codingJava garbage collection  & GC friendly coding
Java garbage collection & GC friendly coding
 
Tuning IBMs Generational GC
Tuning IBMs Generational GCTuning IBMs Generational GC
Tuning IBMs Generational GC
 
Diagnosing Problems in Production - Cassandra
Diagnosing Problems in Production - CassandraDiagnosing Problems in Production - Cassandra
Diagnosing Problems in Production - Cassandra
 
“Show Me the Garbage!”, Understanding Garbage Collection
“Show Me the Garbage!”, Understanding Garbage Collection“Show Me the Garbage!”, Understanding Garbage Collection
“Show Me the Garbage!”, Understanding Garbage Collection
 
Java gc and JVM optimization
Java gc  and JVM optimizationJava gc  and JVM optimization
Java gc and JVM optimization
 
Open GeoSocial API
Open GeoSocial APIOpen GeoSocial API
Open GeoSocial API
 
02D-Memory Management in Java.pptx
02D-Memory Management in Java.pptx02D-Memory Management in Java.pptx
02D-Memory Management in Java.pptx
 
Chronicles Of Garbage Collection (GC)
Chronicles Of Garbage Collection (GC)Chronicles Of Garbage Collection (GC)
Chronicles Of Garbage Collection (GC)
 
JVM Performance Tuning
JVM Performance TuningJVM Performance Tuning
JVM Performance Tuning
 

Recently uploaded

SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
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
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 

Recently uploaded (20)

SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
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
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 

Garbage collection Overview

  • 1. Garbage Collection in Java “Heap storage for objects is reclaimed by an automatic storage management system. Objects are never explicitly de-allocated” –Java Virtual Machine Specification [1]
  • 2. Java Variable Flavours • Stack – Local variables holding primitives. 10 – Local variable of reference typewill point at heap memory. • Heap – Objects. – Primitive fields of an object.
  • 3. Mark and Sweep Approach • Simplest. Garbage collector algorithm. • Recover and reuse.Heap memoryno longer in use. • Algorithm. – Stop-the-world.Non-deterministicpauses stop allthe running threads. – Start.From live objectswalks through the tree of references. – Mark.As liveany object on the route. – Sweep.Everything left is garbage and can be collected.
  • 4. Generational Garbage Collector • Mark-and-sweep. Improved. • Weak generational hypothesis [2]. – Mostobjectsbecome unreachable quickly. – Fewreferencesfrom older to young Eden Young Generation objects exist. • Areas of memory. Survivor – Eden.Most new objects (very large From To objects directly to old generation). Generation – Survivor.Survived, one holds Old Tenured object, the other empty. – Tenured.Promoted longer-lived objects. PermGen – PermGen.Not strictly in heap, internal structures (i.e. class definitions).
  • 5. Escape Analysis • Recent change.Java 6u23. • Local variables.Onlyused inside the method. – No passedinto other methods. – No returned. • No heap.Object created on the method stack frame – Reduce objects of young 10 collections. – Memory used freed when method returns.
  • 6. Concurrent Mark-Sweep in Action • Two short pauses.Per GC cycle, initial mark and remark. Marking/Pre-cleaning Sweeping • Initial Mark.Identifies set of objectsimmediately reachable outside old generation. • Concurrent marking phase.Marks all live objectstransitively reachable from this set. • Object graph can change.Not alllive objects are guaranteed to be marked. • Pre-cleaning.Revisitingobjects modified concurrently with the marking phase. Initial Mark Remark • Second Pause (Remark).Revisits objects modified during concurrent marking phase. Running application thread • Concurrent sweep phase.Deallocates garbage Running GC thread objects without relocatingthe live ones.
  • 7. CMS Pros/Cons • Advantages. – Two pauses. No one single pause. – Concurrency. App and GC run in parallel. • Disadvantages. Start sweeping – Extra overhead. – Freelists. Free space not contiguous. – Large Java heap req.Marking cycle lasts morethan stop-the-world, spacereclaimed at End sweeping the end. – App runs concurrently.Old generationpotentially increases during marking phase. – Floating garbage. Not guaranteed all garbage objects. – Fragmentation issue.Lack of compaction, possible not efficient use of free space [3].
  • 8. Garbage-First GC (G1) in Action • Features. Parallel, concurrent, incrementally compacting low-pause. • Heap layout.Split into regions. • Region.Equal-sized chunks. • Pause goal.How long app can pause for GC while running (20 ms every 5 min). • Pause.Objects evacuatedfrom one or Marking more regions to a single region. • Statistics.Average a region takes to collect. • G1?. Knows mostly empty regions. – Collects.Inthis regions first. – Concentrates.Collect on areas likely GC GC GC to be full of garbage. Running application thread Running GC thread
  • 9. G1 Pros/Cons • Advantages. – High performance. – Pause time goals. Prevent interruption proportional to heap or live-data size. – Compact and free up memory.Continuously work to reduce fragmentation. – Concurrent global marking phase. Determine liveness of the objects. – Pause prediction model. • Meet user-defined pause time target with high probability. • Selects number of regions to collect based on the time target. • Disadvantages. – Target. Multi-processor machines with large memories.
  • 10. Comparison • G1. • CMS. – Compacting collector. – No compaction. – Avoid free list, rely on regions. – No control. – More predictable pauses. • ParallelOld. – User can specify pause targets. – Whole-heap compaction, long • Switch to G1. pauses. – More than 50% heap occupied – No control. with live data. – Allocation and promotion rate varies significantly. – Undesired long collection and compaction pauses (0.5s to 1s)
  • 11. References [1] Lindholm, Tim, and Frank Yellin. Java Virtual Machine Specification, Second Edition. Addison-Wesley, Reading, MA, 1999. [2] Charlie Hunt, Binu John. Java Performance, First Edition. Pearson, 2011. [3] Jones, Richard, and Rafael Lins. Garbage Collection. John Wiley & Sons, Ltd.,WestSussex, PO19 IUD, England, 1996. [4] Memory Management in the Java HotSpot Virtual Machine. Sun Mircrosystem, April 2006. [5] B.J. Evans, M. Verburg. Well-Grounded Java Developer. Manning, 2012.