In JDK 8, The default maximum heap size is
1/4th of the physical memory or 1GB
And it can be overridden using the -Xmx switch:
You can override this default using the -Xmx command-line option.
The Xmx switch works with bytes, not fractions. Is there a straightforward way of setting the maximum heap to X percent of the physical memory of a machine?
Edit:
Why, you ask? Well, first of all curiosity. I find it strange that the default Xmx is defined in terms of a fraction of the physical memory but as soon as I touch it then it' is suddenly an absolute value. Second, if I deploy the same (or similar) app to two different servers and one of them has more physical memory I'd like to have the option of automatically getting the JVM to take advantage of the extra memory. It doesn't always make sense, but sometimes it does.
The obvious solution is to use a shell script that checks the amount of free space and calculates the Xmx, but that seems like a clunky solution. I imagine it should be somehow possible with pure Java.