This content has been marked as final. Show 1 reply
zbontarj wrote:Sun's JVM does some rounding of the heap size based on other variables. In particular, -XX:NewSize=<ns>, which is the initial size of the young generation and -XX:OldSize=<os>, the initial size of the old generation The default value of NewSize is platform-dependent, but in the range 1-3MiB; the default OldSize is 4M. The heap size (-Xmx) value is rounded up to match these.
When I run it with a limit of 2 MB like so
it should crash with java.lang.OutOfMemoryError because the size of the array is approximately 4 MB. But on my computer (64bit Linux) the program runs without any Errors being thrown.
$ java -Xmx2M Main
Clearly it's not ideal since the value you explicitly specified (-Xmx2m) is being changed to be compatible with default values that you didn't specify, instead of the other way around. FWIW, I think it was done this way to avoid being too pedantic and exiting with an error when incompatible settings were given on the command line, but clearly it could be improved. If it's important to you, you can file a bug.