Java Reference

In-Depth Information

if ((96 MB * MinRAMFraction) > Physical Memory) {

Default Xmx = Physical Memory / MinRAMFraction;

}

The initial heap size choice is similar, though it has fewer complications. The initial heap

size value is determined like this:

Default Xms = MaxRAM / InitialRAMFraction

As can be concluded from the default minimum heap sizes, the default value of the
Ini-

tialRAMFraction
flag is 64. The one caveat here occurs if that value is less than 5 MB—or,

strictly speaking, less than the values specified by
-XX:OldSize=
N
(which defaults to 4 MB)

plus
-XX:NewSize=
N
(which defaults to 1 MB). In that case, the sum of the old and new sizes

is used as the initial heap size.

QUICK SUMMARY

1. The calculations for the default initial and maximum heap sizes are fairly straight-

forward on most machines.

2. Around the edges, these calculations can be quite involved.

Summary

The past two chapters have spent a lot of time delving into the deep details of how GC (and

its various algorithms) work. If GC is taking longer than you'd like, knowing how all of that

works should aid you in taking the necessary steps to improve things.

Now that we understand all the details, let's take a step back to determine an approach to

choosing and tuning a garbage collector. Here's a quick set of questions to ask yourself to

help put everything in context:

Can your application tolerate some full GC pauses?

If so, then the throughput collector will likely offer the best performance, while using

less CPU and a smaller heap than other collectors. If not, then choose a concurrent col-

lector—for smaller heaps, either CMS or G1. For larger heaps, G1.