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 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
 
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
 
«Большие объёмы данных и сборка мусора в 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 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
 
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
 
«Большие объёмы данных и сборка мусора в 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

WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard37
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKJago de Vreede
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMKumar Satyam
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)Samir Dash
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 

Recently uploaded (20)

WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 

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.