Large Heaps for the JVM
daniel Thu, 07/01/2010 - 9:27am
Local copy of Big Heaps and Intimate Shared Memory (ISM)
Using a Large Heap
Heaps larger than 2GB are available starting with J2SE 1.3.1. These are options that can be useed to tune the use of memory by the JVM. The values given should not be taken as suggestions; best values for your application will vary and should be set by measurement.
-Xms3g -Xmx3g
This example sets the minimum and maximum total heap size to 3GB. The default maximum size is 64MB, but for many server applications it makes sense to be much larger. The g suffix may be replaced by m to measure in megabytes.
Ordinarily the JVM consumes as little memory as possible, starting with a heap of the minimum size specified by the -Xms flag, and adaptively growing as required up to the maximum specified by -Xmx. Setting these to the same value avoids being conservative, and will often improve startup time.
-XX:+AggressiveHeap
This option instructs the JVM to push memory use to the limit: the overall heap is more than 3850MB, the allocation area of each thread is 256K, the memory management policy defers collection as long as possible, and (beginning with J2SE 1.3.1_02) some GC activity is done in parallel.
Because this option sets heap size, do not use the -Xms or -Xmx options in conjunction with -XX:+AggressiveHeap. Doing so will cause the options to override each other's settings for heap size.
This option should be used with caution. Because it makes the JVM greedy with memory resources, it is not appropriate for many programs and makes it easier to run out of memory. For example, by using most of the 4GB address space for heap, some programs will run out of space for stack memory. In such cases -Xss may sometimes help by reducing stack requirements.
- Log in to post comments