Java Reference
In-Depth Information
from the way the Java Native Interface (JNI) identifies object types; see the JNI reference
documentation for more details.)
In this example (which comes from running a variation of the sample stock servlet in an ap-
plication server), the inclusion of the BigDecimal class is something to pursue: we know the
sample code produces a lot of transient BigDecimal objects, but having so many stay around
in the heap is not what we might ordinarily expect. The output from GC.class_histogram
includes only live objects, though the command does not force a full GC.
Similar output is available by running this command:
% jmap -histo process_id
The output from jmap includes objects that are eligible to be collected (dead objects). To
force a full GC prior to seeing the histogram, run this command instead:
% jmap -histo:live process_id
Histograms are quite small, so gathering one for every test in an automated system can be
quite helpful. Still, because they take a few seconds to obtain, they should not be taken dur-
ing a performance measurement steady state.
Heap Dumps
Histograms are great at identifying issues caused by allocating too many instances of one or
two particular classes, but for deeper analysis, a heap dump is required. There are many tools
that can look at heap dumps, and most of them can connect to a live program to generate the
dump. It is often easier to generate the dump from the command line, which can be done
with either of the following commands:
% jcmd process_id GC.heap_dump /path/to/heap_dump.hprof
% jmap -dump:live,file=/path/to/heap_dump.hprof process_id
Search WWH ::

Custom Search