JVM Shenandoah Garbage Collector

2024-07-03

Enabling Shenandoah Garbage Collector in JVM

The Shenandoah Garbage Collector is a low-pause-time garbage collector introduced in JDK 12, designed to perform garbage collection work concurrently with the running Java application. It aims to minimize pause times by allowing most of the garbage collection tasks, including compaction, to happen in parallel.

Steps to Enable Shenandoah Garbage Collector

  1. JVM Version: Shenandoah is available starting from JDK 12. Make sure you're using JDK 12 or newer.

  2. Command-Line Option: To enable Shenandoah, you need to pass the -XX:+UseShenandoahGC option when launching your Java application:

    java -XX:+UseShenandoahGC -jar your-application.jar
    
  3. Heap Size Specifications: Similar to other garbage collectors, it’s recommended to set initial and maximum heap sizes using -Xms and -Xmx to ensure efficient memory management. For example:

    java -Xms1g -Xmx8g -XX:+UseShenandoahGC -jar your-application.jar
    
  4. Tuning Parameters: Shenandoah also provides options for tuning its performance:

    • -XX:ShenandoahMaxPauseMillis=<n>: Set the target maximum pause time in milliseconds.
    • -XX:ShenandoahHeapRegionSize=<n>: Specify the size of each heap region.
    • -XX:ShenandoahCompactionRatio=<n>: Control the memory compaction behavior.
  5. Monitoring and Logging: To monitor Shenandoah’s performance, enable GC logging with:

    -Xlog:gc*
    

Example Command

Here's how you would invoke your application with Shenandoah enabled, along with heap sizing and logging:

java -Xms1g -Xmx8g -XX:+UseShenandoahGC -Xlog:gc* -jar your-application.jar

This command sets up the Shenandoah collector with specific heap sizes and enables detailed garbage collection logging.


Additional Characteristics of Shenandoah

Considerations