Garbage
Collection in
Java
Ondřej Kratochvíl
▷ Young
Allocation of new objects
Often collected
Minor garbage collection when full - Stop the World event
▷ Old
Stores long surviving objects (also Stop the World)
Major garbage collection
JVM Generations
▷ Permanent (Tenured)
Metadata for JVM
class/method descriptors
Data stored at runtime based on classes in use
Can be collected - when space is needed and JVM does no
longer need some old classes
included in Full garbage collection
JVM Generations
▷ New object is allocated in New generation in eden space
▷ When eden space fills up, minor GC is triggered
Referenced objects are moved to first survivor space, age++
▷ At the next minor GC, referenced objects are moved to
SECOND survivor space
▷ After each minor GC, the spaces switch
▷ If referenced object’s age > threshold, it gets promoted to
Old generation
GC Process - Young generation
▷ Serial GC
Mark-Sweep-Compact algorithm in the old generation
For small memory/small amount of CPU cores
▷ Parallel GC (Throughput GC)
Multithreaded for young generation
▷ Parallel Old GC
Parallel for both generations
▷ CMS GC (Concurrent mark-sweep)
Low pause time
Objects are swept while other are still being marked
GC types
Díky za pozornost!
Otázky?
Ondřej Kratochvíl
ondrej.kratochvil@keyup.eu

Garbage Collection in Java

  • 1.
  • 2.
    ▷ Young Allocation ofnew objects Often collected Minor garbage collection when full - Stop the World event ▷ Old Stores long surviving objects (also Stop the World) Major garbage collection JVM Generations
  • 3.
    ▷ Permanent (Tenured) Metadatafor JVM class/method descriptors Data stored at runtime based on classes in use Can be collected - when space is needed and JVM does no longer need some old classes included in Full garbage collection JVM Generations
  • 4.
    ▷ New objectis allocated in New generation in eden space ▷ When eden space fills up, minor GC is triggered Referenced objects are moved to first survivor space, age++ ▷ At the next minor GC, referenced objects are moved to SECOND survivor space ▷ After each minor GC, the spaces switch ▷ If referenced object’s age > threshold, it gets promoted to Old generation GC Process - Young generation
  • 5.
    ▷ Serial GC Mark-Sweep-Compactalgorithm in the old generation For small memory/small amount of CPU cores ▷ Parallel GC (Throughput GC) Multithreaded for young generation ▷ Parallel Old GC Parallel for both generations ▷ CMS GC (Concurrent mark-sweep) Low pause time Objects are swept while other are still being marked GC types
  • 6.
    Díky za pozornost! Otázky? OndřejKratochvíl ondrej.kratochvil@keyup.eu