Typically, in a Java virtual machine (JVM) environment, a startup parameter such as −Xmx can be used to define the maximum heap memory that a particular virtual machine can use. Subsequently, if the virtual machine needs more memory than the maximum specified memory, it will throw an out-of-memory error (OOME). Generally, an out-of-memory error makes the virtual machine useless, and usually, via another startup parameter or by default, the virtual machine is terminated.
An −Xmx value that is set too high can result in swapping at the operating system (OS) level and/or long old (full) garbage collection pause times which can degrade JVM performance considerably. Although some JVMs can release the unused heap memory back to the OS by compacting the heap, they do so incrementally so as not to adversely affect garbage collection (GC) pause time, and thus a JVM may stay at high heap usage for a long time. This increases the probability of swapping and long old GC pause times.
The problem becomes more pronounced when several JVMs are run on a host machine. A high −Xmx value combined with a conservative heap compaction and release policy will reduce the number of JVMs that can be run on a host without causing swapping. It is not unusual to see many of these JVMs using heap memory, referred to as committed or allocated memory, much less than the maximum specified heap memory for much of the time.