Java GC -XXSoftMaxHeapSize Flag

The -XXSoftMaxHeapSize 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 (-XX:+UseZGC).

1. -XXSoftMaxHeapSize=<bytes>

The size of this flag is set in the number of bytes. When it is set, the garbage collector will strive to not grow the heap beyond the specified size, unless the GC decides it’s necessary to do so to avoid OutOfMemoryError.

Its value can not be set greater than the maximum heap size (-Xmx).

Bt default, its value is equal to the maximum heap size.


2. Changing value at runtime

This flag is manageable. Flags marked as manageable are dynamically writeable through the JDK management interface ( API) and also through JConsole.

HotSpotDiagnosticMXBean can be directly accessed and controlled from jconsole. In “MBeans” tab, choose -> HotSpotDiagnoticMXBean -> Operations -> setVMOption.

From the right panel, we can invoke the set operations on HotSpotDiagnosticMXBean and thereby explicitly manage any manageable JVM flag.

Set VM Options
Setting VM Options

Drop me your questions in comments.

Happy Learning !!

Was this post helpful?

Join 7000+ Fellow Programmers

Subscribe to get new post notifications, industry updates, best practices, and much more. Directly into your inbox, for free.

Leave a Comment


A blog about Java and its related technologies, the best practices, algorithms, interview questions, scripting languages, and Python.