Default max heap size

Sergejs Melderis sergey.melderis at gmail.com
Mon Aug 29 10:34:42 PDT 2011


Hello.
I am trying to figure out how the hotspot chooses the default maximum heap size.
I posted this  question to stackoverflow, but got no answers.
I don't want to repeat it here, so here is the question
http://stackoverflow.com/questions/7194526/hotspot-default-max-heap-size

I searched the jdk source code, for the place where it is calculated.
I found function set_heap_size defined here
http://hg.openjdk.java.net/jdk6/jdk6/hotspot/file/dc40301aed45/src/share/vm/runtime/arguments.cpp

If am not wrong, the calculation happens in the following lines

if (FLAG_IS_DEFAULT(MaxHeapSize)) {
   julong reasonable_max = phys_mem / MaxRAMFraction;

   if (phys_mem <= MaxHeapSize * MinRAMFraction) {
     // Small physical memory, so use a minimum fraction of it for the heap
     reasonable_max = phys_mem / MinRAMFraction;
   } else {
     // Not-small physical memory, so require a heap at least
     // as large as MaxHeapSize
     reasonable_max = MAX2(reasonable_max, (julong)MaxHeapSize);
   }


MaxRAMFraction is 4, so reasonable_max is phys_mem / 4. So, unless
physical memory is very small,
the reasonable_max will be MAX2(reasonable_max, (julong)MaxHeapSize);

MAX2 is defined as
#define MAX2(a, b) (((a) < (b)) ? (b) : (a))

At the end reasonable_max is set as MaxHeapSize
FLAG_SET_ERGO(uintx, MaxHeapSize, (uintx)reasonable_max);

If I plug in the memory size on my test machine, the reasonable_max
will be very close to what I get from jmap -heap.
With RAM of 8, 16 GB, or more, the MaxHeapSize will be greater than 1
GB, which contradicts the documentation
http://www.oracle.com/technetwork/java/javase/gc-tuning-6-140523.html#par_gc.ergonomics.default_size

Thanks,

Sergey.


More information about the hotspot-gc-use mailing list