Is it possible to unset a JVM option?

Viewed 346

Our app server, OpenLiberty, supports config defaults and overrides as defined at https://openliberty.io/docs/latest/reference/config/server-configuration-overview.html#jvm-options

Options are read and provided to the JVM in order. If you provide multiple options, then they are all seen by the JVM.

Currently, we're setting an initial min heap size for our server (via configDropins/defaults/jvm.options). I'd like it to be possible to override that min heap size with the JVM's default (as if -Xms was never specified).

I confirmed that I can pass a new value to -Xms via configDropins/overrides, but what I'd really like to do is somehow override the initial setting so that it takes the JVM default (instead of a different custom value). I tried setting -Xms (with no value) in the override, but it seems to just use the value from configDropins/defaults.

There is a good related question at Duplicated Java runtime options : what is the order of preference? wrt how common JVMs handles duplicate options and a choice exceprt from one of the answers:

there are often deeply nested command lines from batch files where people can only add to the end, and want to make that the winner.

This makes me hope that maybe I'm not alone in wanting this feature. Does anyone know if there's already some way to achieve it?

1 Answers

To be honest, you should not set heap sizes, when running in containers. Since Java8 there is built in support via UseContainerSupport setting which adjusts available heap size based on the container memory limits.

If you want to fine tune that you could use -XX:MaxRAMPercentage / -XX:InitialRAMPercentage settings.

This allows you to change heap sizes in more dynamic way, without the need of rebuilding the image.

Update
Based on https://www.ibm.com/docs/en/sdk-java-technology/8?topic=options-xxinitialrampercentage InitialRAMPercentage is kind of -Xms equivalent:

-XX:InitialRAMPercentage=N  Set initial heap size as a percentage of total memory  

Note: 
If you set a value for -Xms, the -XX:InitialRAMPercentage option is ignored. 
If you set a value for -Xmx, the -XX:MaxRAMPercentage option is ignored.
Related