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

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
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
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
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetEnjoy Anytime
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
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
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Hyundai Motor Group
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 

Recently uploaded (20)

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
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
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
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
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
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 

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.