The -XX:SoftMaxHeapSize flag has been added in hotspot JVM in Java 13 release. Currently, it only has an effect on memory usage when the Z garbage collector is enabled using -XX:+UseZGC
.
1. Using SoftMaxHeapSize Flag
The SoftMaxHeapSize option sets a soft limit on how large the Java heap should grow. When set, the GC will try not to grow the heap size beyond this limit. But, the GC is still allowed to outgrow beyond the specified size if it really needs to perform certain operations such as to avoid OutOfMemoryError
.
- The size of this flag is set in the number of bytes.
- Its value can not be set greater than the maximum heap size (-Xmx).
- By default, its value is equal to the maximum heap size.
-XX:SoftMaxHeapSize=2048m
2. Changing Heap Limit in Runtime
This flag is manageable. Flags marked as manageable are dynamically writeable through the JDK management interface (com.sun.management.HotSpotDiagnosticMXBean
API) and also through JConsole.
HotSpotDiagnosticMXBean can be directly accessed and controlled from jconsole. In “MBeans” tab, choose com.sun.management
-> HotSpotDiagnoticMXBean
-> Operations
-> setVMOption
.
From the right panel, we can invoke the set operations on HotSpotDiagnosticMXBean and thereby explicitly manage any manageable JVM flag.

Drop me your questions in comments.
Happy Learning !!
Comments