Java Reference
In-Depth Information
Full Control Over Heap Size
Sizing the Heap discussed the default values for the initial minimum and maximum size of
the heap. Those values are dependent on the amount of memory on the machine as well as
the JVM in use, and the data presented there had a number of corner cases to it. If you're
curious about the full details about how the default heap size is actually calculated, this sec-
tion will explain the details. Those details include some very low-level tuning flags; in cer-
tain circumstances, it might be more convenient to adjust the way those calculations are done
(rather than simply setting the heap size). This might be the case if, for example, you want to
run multiple JVMs with a common (but adjusted) set of ergonomic heap sizes. For the most
part, the real goal of this section is to complete the explanation of how those default values
are chosen.
The default sizes are based on the amount of memory on a machine, which can be set with
the -XX:MaxRAM= N flag. Normally, that value is calculated by the JVM by inspecting the
amount of memory on the machine. However, the JVM limits MaxRAM to 1 GB for the client
compiler, 4 GB for 32-bit server compilers, and 128 GB for 64-bit compilers. The maximum
heap size is one-quarter of MaxRAM . This is why the default heap size can vary: if the physical
memory on a machine is less than MaxRAM , the default heap size is one-quarter of that. But
even if hundreds of gigabytes of RAM are available, the most the JVM will use by default is
32 GB: one-quarter of 128 GB.
The default maximum heap calculation is actually this:
Default Xmx = MaxRAM / MaxRAMFraction
Hence, the default maximum heap can also be set by adjusting the value of the -
XX:MaxRAMFraction= N flag, which defaults to 4. Finally, just to keep things interesting, the
-XX:ErgoHeapSizeLimit= N flag can also be set to a maximum default value that the JVM
should use. That value is 0 by default (meaning to ignore it); otherwise, that limit is used if it
is smaller than MaxRAM / MaxRAMFraction .
On the other hand, on a machine with a very small amount of physical memory, the JVM
wants to be sure it leaves enough memory for the operating system. This is why the JVM
will limit the maximum heap to 96 MB or less on machines with only 192 MB of memory.
That calculation is based on the value of the -XX:MinRAMFraction= N flag, which defaults to
2:
Search WWH ::




Custom Search