Java Virtual Machine (JVM) Heap Sizing

Report on JVM Heap sizing ( based on various web resources):


32-bit JRE

The maximum theoretical heap limit for the 32-bit JVM is 4G. Due to various additional constraints such as available swap, kernel address space usage, memory fragmentation, and VM overhead, in practice the limit can be much lower. On most modern 32-bit Windows systems the maximum heap size will range from 1.4G to 1.6G. On 32-bit Solaris kernels the address space is limited to 2G. On 64-bit operating systems running the 32-bit VM, the max heap size can be higher, approaching 4G on many Solaris systems.

64-bit JRE

A 64-bit capable J2SE is an implementation of the Java SDK that runs in the 64-bit environment of a 64-bit OS on a 64-bit processor. The primary advantage of running Java in a 64-bit environment is the larger address space. This allows for a much larger Java heap size and an increased maximum number of Java Threads, which is needed for certain kinds of large or long-running applications. We can run things under the 32-bit JRE on a 64-bit OS without any problems. All existing 100% pure Java programs would continue running just as they do under a 32-bit VM.


If Java application requires a very large heap we should use a 64-bit VM on a version of the operating system that supports 64-bit applications. Using the 64-bit will cause the JRE to run in server mode, which has a slower startup time, and then on top of that, the 64-bit JRE may result in a performance degradation. So experts suggests that unless we have a compelling reason, to switch, we’re fine staying with the 32-bit.


We need to use the -d64 switch to request the 64-bit JVM. E.g., We could specify even 20GB heap size ( -Xmx20g), but if the total of the memory needed by all the processes on our machine ever exceeds the physical memory on our machine, we are likely to end up paging. Garbage collections will be slow. A larger heap will cause garbage collection pauses to increase because there is more heap to scan.

Conclusions:

* The maximum allowable heap size for 32-bit JVMs on 32 bit systems is 2GB(depends).
* If java application requires a very large heap (> 2GB) you should use a 64-bit VM on a version of the operating system that supports 64-bit applications
* Or divide large application into smaller applications, and assign each application 2GB heap.
* The maximum allowable heap size for 32-bit JVMs on 64 bit systems is 4GB (on solaris).
* It’s fine staying with the 32-bit JVM even on 64 bit systems (unless there is a strong reason).


References:

http://www.ddj.com/architect/184405993
http://benjchristensen.com/2007/02/16/32-bit-versus-64-bit-jdk-memory-usage/
http://java.sun.com/docs/hotspot/HotSpotFAQ.html
http://java.sun.com/docs/hotspot/gc5.0/gc_tuning_5.html
http://java.sun.com/javase/technologies/hotspot/vmoptions.jsp

Advertisements
This entry was posted in java, Technical. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s