Java Diagnostics Tools and Options

Introduction
This chapter introduces the various diagnostic and monitoring tools which can be used with J2SE 5.0.
The tools described here include command line utilities, command line options, and log files.
In almost all cases the command line utilities described in this chapter are either included in the Java
2 Platform Standard Edition Development Kit (JDK 5.0), or are operating system tools and utilities.
Although the JDK 5.0 command line utilities are included in the JDK download, it is important to note
that they can be used to diagnose issues and monitor applications that are deployed with the Java 2
Platform Standard Edition Runtime Environment 5.0 (JRE 5.0).
In general, the diagnostic tools and options described in this chapter use various mechanisms to
obtain the information they report. In many cases the mechanisms are specific to the virtual machine
implementation (5.0 in the case of this document), operating system, and version of each.
Consequently, there is some overlap of the information reported by some of the tools. This should be
viewed in the context of the various problems and issues for which these tools are intended. In many
cases only a subset of the tools will be applicable to an issue at a particular point in time.



Caveats and Other Notes

Some of the command line utilities described in this chapter are experimental. The jstack, jinfo,
and jmap utilities are examples of utilities that are experimental. These utilities are subject to change
in future JDK releases, and may not be included in future releases.
The format of log files and other output from command line utilities or options is version specific. For
example, if you develop a script that relies on the format of the fatal error log
(hs_err_pid.log file) then this script may cease to work as expected if the format of the log
file changes in the future.
Command line options that are prefixed with -XX are Java HotSpotTM Virtual Machine specific
options. In general, most -XX options are unsupported, undocumented, and were originally included
for the purposes of testing components of the HotSpot Virtual Machine during its development.
However many -XX options are important for performance tuning and diagnostic purposes, and are
therefore described in this chapter.
In some cases, the command tool utilities described here are not included in the JDK release on all
operating systems. For example, the jstack, jinfo, and jmap command line utilities are included in
the JDK release for Solaris and Linux only. In addition to operating system specific utilities we also
describe a number of diagnostic features and tools that are specific to the Solaris 10 Operating
Environment. Solaris 10 has many advanced diagnostic features that are usable in production
environments, and many of the native tools are capable of providing information that is specific to the
Java Runtime Environment.


Post-Mortem Diagnostics

A number of the options and tools described in this chapter are designed for post-mortem diagnostics.
That is, if the application crashes because of an application or JRE bug, these are the options and tools
that can be used to obtain additional information (either at the time of the crash or later using
information from the crash dump).




Description and Usage Tool or Option
Fatal Error Log The fatal error log (hs_err_.log) contains a lot of
information obtained at the time of the fatal error (crash). In
many cases it will be the first thing to examine when a crash
happens.
-XX:OnError Used to specify a sequence of user-supplied scripts or
commands to be executed when a fatal error (crash) occurs. For
example, on Windows, it can be used to execute a command to
force a crash dump – very useful on systems that do not have
post-mortem debugger configured.
-XX:+ShowMessageBoxOnError Used to suspend the process when a fatal error (crash) occurs.
Depending on the user response it can launch the native
debugger (dbx, gdb, msdev) to attach to the VM. The option is
very useful in the development environment to attach the
native debugger when a crash happens.
jinfo (Solaris and Linux only) The jinfo utility can obtain configuration information from a
core file obtained from a crash (or a core obtained using the
gcore utility).
jmap (Solaris and Linux only) The jmap utility can obtain memory map information,
including a heap histogram, from a core file obtained from a
crash (or a core obtained using the gcore utility)
jstack (Solaris and Linux only) The jstack utility can obtain java and native stack
information from a core file obtained from a crash (or a core
obtained using the gcore utility).
jdb (Solaris and Linux only) The debugger support in the JDK includes an
AttachingConnector which allows jdb, and other Java
Language debuggers to attach to a core file. This can be very
useful when trying to understand what the application was
doing at the time of the crash.
Native tools Each operating system has native tools and utilities that can be
used for post-mortem diagnosis. A list of native tools is
provided later in this chapter.

0 comments:

Post a Comment