DevNexus 2018 – Garbage Collection in Java 9

Title: Garbage Collection in Java 9
Speakers: Chandra Guntur

For more blog posts, see the DevNexus 2018 live blogging table of contents


Areas of memory

  • By thread
  • Method area
  • Runtime constant pool
  • Heap

Definitions

  • Types of collectors – serial (one thread; stopping all app threads), parallel (multiple threads, but still stops all app threads), concurrent (doesn’t stop app)
  • Can mark objects precisely or conservatively
  • Can run all at once or incrementally
  • Can move reachable objects or just release unreachable objects

Patterns

  • reference counting
    • simplest algorithm
    • keeps a counter for each object
    • obsolete for commercial JVMs
  • mark/sweep/compact
    • change marker type if used
    • remove if not used
    • compact – like Windows defragment
  • copying
    • similar to mark/sweep/compact except copies object when used instead of marking
    • the copying operating compacts/defragments since copied to adjacent memories
  • Java 5 introduced generational GC
    • start young
    • most objects go away rather than getting promoted to older generation
    • generations – eden, survivor, tenured
  • Java 5 – 8 had Concurrent Mark-Sweep (CMS)
    • serial collection and tenured generation
    • most popular GC in Java 5-8
    • deprecated in Java 9

Problems

  • inconsistent pause type
  • poor performance for large memory heaps
  • focused more on live objects than garbage

Java 9 – G1GC (Garbage First Garbage Collector)

  • new default in Java 9
  • region – contiguous unit of memory
  • heap divided into 2048+ regions of equal size – may be 1-32MB each
  • each region has a generation (free, eden, survivor, tenured) or be part of a “humongous” allocation
  • humongous objects
    • use complete (or multiple contiguous) regions
    • must be the size 50% of a region or more.
  • goal of  consistent pause time
  • life of a region
    • objects get created and stored in “young” half
    • at some point, does initial mark where concurrent marking process determines which objects are alive. young collection continues in parallel.
    • then does re-mark to confirm still alive. young collection still continues
    • decides if should reclaim space now or wait
    • then does space reclamation
  • young collection includes survivor promotion and tenured promotion
  • java -XX:+PrintFlagsInitial -version > output – print the initial defaults to a file since it is a long list – always same at startup by OS
  • java -XX:+PrintFlagsFinal -version > output – print the initial defaults to a file since it is a long list – changes based on actual running
  • there were lots of involved details. hard to have that as the last session of the day :).

My take

I’m not a fan of “ignore the text; read it later” presentations. That is what the appendix or notes view is for. I’d rather have the pictures and key points be bigger. Chandra even zoomed in on the diagram. It cold have had a whole slide to itself. That said, the presentation was clear and easy to follow.

Leave a Reply

Your email address will not be published. Required fields are marked *