This slide will explain about building blocks of JVM optimization for you java based application.
It explains basics of heap concepts and different type of java garbage collectors.
3. Overview of java garbage collectors
• Live objects vs Dead objects
• Runs automatically by JVM
• Cannot force JVM to run gc (System.gc())
• Demon thread called garbage collector
• Involves 3 steps
– Mark
– Sweep/Delete
– Compacting / defragmentation (time consuming)
• Minor garbage collection vs Major garbage
collection
4. Heap concepts
• Heap is divided in different sections
– Young generation
• Eden space
• Survivor space from
• Survivor space to
– Old generation (tenured space)
• Use for caching and long term survivor objects
6. Garbage collector types
• Serial collector
– Single thread shared between application and GC
– Used for small heap
– Used for less responsive applications
• Concurrent collector
– Runs concurrent to your application,
– doesn’t wait for old generation to be full
– Pause application during mark operation
– Used for low pause application
• Parallel collector
– Uses multiple CPU cores to perform GC
– Uses multiple threads for mark, sweep and fragmentation operations
– Wait for old generation to be full
– Pause application during all operations
– Used for batch processing or high throughput applications
• G1GC
– Highly customizable, can specify the time you want to run concurrent and parallel processor
– More garbage area collects first
– Option to specify maximum pause timings
8. JVM Tuning options
• -XX:+UseSerialGC
• -XX:+UseParallelGC
• -XX:+UseParallelOldGC
• -XX:+UseConcMarkSweepGC
• -XX:+UseG1GC
• -Xmsvalue : min amount of heap allocated
• -Xmxvalue : max amount of heap allocated
• -XX:NewRatio=ratio of young vs old generation
• -XX:NewSize=memory for eden space
• -XX:MaxNewSize=size memory for new generation space
• -XX:Permsize=size, used to define space for meta data and static objects
• -XX:+PrintGCDetails prints garbage collector details
• -Xloggc:gc.log where gc.log is a filename to store gc logs
• -verbose:gc for debugging gc logs