I was expecting Runtime.maxMemory() to return exactly the -Xmx but it returns a lower value. So what does it return?
3 Answers
The interpretation of the -Xmx flag is VM-dependent. Some VMs, including HotSpot, enforce a lower bound on the effective value of this option. The CCC proposal should not have mentioned the -Xmx flag in this way.
Comments
Returns the maximum amount of memory that the Java virtual machine will attempt to use, jvm may not use all the memory you have defined as -Xmx parameter for just heap.
3 Comments
Specify the maximum size, in bytes, of the memory allocation pool. This value must a multiple of 1024 greater than 2MB. Append the letter k or K to indicate kilobytes, or m or M to indicate megabytes. The default value is 64MB. The upper limit for this value will be approximately 4000m on Solaris 7 and Solaris 8 SPARC platforms and 2000m on Solaris 2.6 and x86 platforms, minus overhead amounts. Examples:
-Xmx83886080 -Xmx81920k -Xmx80m
Returns the maximum amount of memory that the Java virtual machine will attempt to use. If there is no inherent limit then the value Long.MAX_VALUE will be returned.