JDK-8295373 : java/javaw: add -Xmx variant to specify percentage of physical RAM
  • Type: Enhancement
  • Component: tools
  • Sub-Component: launcher
  • Priority: P4
  • Status: New
  • Resolution: Unresolved
  • Submitted: 2022-10-14
  • Updated: 2022-10-17
Related Reports
Relates :  
Description
When deploying a desktop application to a large group of customers it is nearly impossible to provide a single "good" value for maximum heap size.  One solution would be to add custom logic to install4j-generated installer to calculate the "good" value and let the user either choose it or change to something else.

It might be more useful to provide a variant of -Xmx option (or indeed any other options that take memory size, such as -Xmn -Xms) that would take percentage of physical RAM.

An obvious suggestion to use -Xmx<number>% might run afoul of some platform/shell idiosyncrasies, so perhaps -Xmx<number>pct might be better.
Comments
HotSpot VM options can be provided to the java launcher. For JDK 19, you'll find MaxRAMPercentage and others documented here: https://docs.oracle.com/en/java/javase/19/docs/specs/man/java.html
17-10-2022

Thank you, [~alanb], for a prompt response! Any change this option graduates from "unstable hotspot" options to a standard java/javaw option? Also, why would it be limited to 100%? This looks like an unnecessary limitation. And the last question, is there a way to list all XX options apart from `-XX:+PrintFlagsFinal` ? Notice nothing comes up in a search: https://docs.oracle.com/search/?q=MinRAMPercentage&pg=1&size=10&product=en%2Fjava%2Fjavase%2F19&category=en%2Fjava&showfirstpage=true&lang=en
17-10-2022

See JDK-8186248 for the flags that were added in JDK 10.
15-10-2022