Determining maximum heap size | Using shared classes


6.4.4 Expansion and contraction


Tuning heap expansion and shrinkage policies will improve application performance by reducing the amount of time spent paging.

The ideal situation is to have a heap that never changes size.

If the heap does change size significantly and often during an application's lifetime, then it is worth the effort to tune heap expansion and shrinkage policies.

In addition, investigate whether increasing the page size will help application performance.

Runtime options used to set heap expansion and shrinkage policies...

Runtime option Description
-Xmine<size> Minimum amount by which the garbage collector expands the heap.

Typically, the garbage collector expands the heap by the amount required to restore the free space to 30% (or the amount specified using -Xminf). The -Xmine option sets the expansion to be at least the specified value. For example, -Xmine50M sets the expansion size to a minimum of 50 MB.

Default, the minimum expansion size is 1 MB.

-Xminf<size> Minimum percentage of heap that should be free after a garbage collection.

If the free space falls below this amount, the JVM attempts to expand the heap. Specify the size as a decimal value in the range 0-1; for example, a value of -Xminf0.3 requests the minimum free space to be 30% of the heap.

By default, the minimum value is 0.3.

-Xmaxe<size> Maximum amount by which the garbage collector expands the heap.

Typically, the garbage collector expands the heap when the amount of free space falls below 30% (or the amount specified using -Xminf), by the amount required to restore the free space to 30%. The -Xmaxe option limits the expansion to the specified value. For example, -Xmaxe10M limits the expansion to 10 MB.

Default, there is no maximum expansion size.

-Xmaxf<size> Maximum percentage of heap that must be free after a garbage collection.

If the free space exceeds this amount, the JVM attempts to shrink the heap. Specify the size as a decimal value in the range 0-1. For example, -Xmaxf0.5 sets the maximum free space to 50%.

Default value is 0.6 (60%).

-Xmint<value> Minimum percentage of time which should be spent in Garbage Collection.

If the percentage of time drops below this value, the JVM attempts to shrink the heap. Specify the percentage as a decimal in the range 0-1. For example, -Xmint0.1 sets the minimum time spent in Garbage Collection to 10%.

Default value is 5%.

-Xmaxt<value> Maximum percentage of time which should be spent in Garbage Collection.

If the percentage of time rises above this value, the JVM attempts to expand the heap. Specify the percentage as a decimal in the range 0-1. For example, -Xmaxt0.2 sets the maximum time spent in Garbage Collection to 20%.

Default value is 13%.

Example 6-3 shows what an expansion of the heap looks like in verbosegc. Note that the expansion will be contained within an allocation failure or possibly some other GC event.

Example 6-4 shows what a contraction of the heap looks like in verbosegc.

Example 6-5 shows a default heap expansion which results in 30% free heap.

<af type="tenured"
    id="5"
    timestamp="Wed Oct 11 10:53:49 2006"
    intervalms="409.840">

  <minimum requested_bytes="4120" />
  <time exclusiveaccessms="0.485" />

  <tenured freebytes="0" totalbytes="23528448" percent="0" >

    <soa freebytes="0"
         totalbytes="21411840"
         percent="0" />

    <loa freebytes="0"
         totalbytes="2116608"
         percent="0" />

  </tenured>

  <gc type="global" id="5" totalid="5" intervalms="409.937">

    <expansion type="tenured"
               amount="9783296"
               newsize="33311744"
               timetaken="8.881"
               reason="insufficient free space following gc" />

    <refs_cleared soft="0" weak="3" phantom="0" />
    <finalization objectsqueued="2" />

    <timesms mark="19.728"
             sweep="0.265"
             compact="0.000"
             total="28.949" />

    <tenured freebytes="9999056"
             totalbytes="33311744"
             percent="30" >

      <soa freebytes="9999056"
           totalbytes="33311744"
           percent="30" />

      <loa freebytes="0"
           totalbytes="0"
           percent="0" />

    </tenured>

  </gc>
  <tenured freebytes="9994936" totalbytes="33311744" percent="30" >

    <soa freebytes="9994936"
         totalbytes="33311744"
         percent="30" />

    <loa freebytes="0"
         totalbytes="0"
         percent="0" />

  </tenured>
  <time totalms="29.517" />
</af>

Expansion and contraction runtime options for heap.

Heap expansion and contraction runtime options

Next: 6.5 Using shared classes