How does G1 separate new gen and old gen?

Concepts

  • Collet Set(CSet): collecatable-region set. Survivors in the CSet will be moved to antoher region. LT 1% of heap size
  • Remembmered Set(RS): RS records Points-into,i.e., object references in other regions that use this region’s objects. It is a (region address, set of card table index) hashtable
  • Snapshot-At-The-Beginning (SATB): previous bitmap and next bitmap
  • Eviction failure (EF): new gen not able to find regions to accept survivors
  • jdk9 default, separate heap into same size regions. Some for new gen, and some for old gen.
    • Each block can be one of Eden/Survivor/Old. Note that new gen will still do recycle/promotion when it is full.
    • New gen GC is similar to ParNew, will STW and copy to survivor or old gen
  • Designed to handle cases where stop-the-world is unacceptable,e.g., HFT.
  • Humogous Object goes directly to old gen, may use mutliple continous regions to hold it

Steps (for mixed GC)

  • Initital Marking (IM)
    • concurrently clean up next marking bitmap,
    • pause all user threads, and scan and tag all DIRECTLY reachable objects from root in each region
    • Put the top value to the next top at mark start(TAMS)
    • resume all user threads
    • Root region scan - G1 scans survivor regions, and mark all referenced objects
  • Concurrent Marking
    • scan based on the objects found in IM
    • Use remembered set logs to track what is object relationship is changed concurrently
  • Final marking pause
    • process RSL and update RS.
    • process SATB logs
  • Live Data Counting and Cleanup
    • Note that the cleanup trigger time is based on max gc pause allowed and a few other steps

Optimization & Tuning

  • Goal is to avoid full gc and EF
  • Don’t set NewRatio yourself
  • Prioritize maxGCPauseMillis (default 200 ms) instead of configing others
  • Default Heap space reachs 45% usage will trigger concurrent