For example, to examine any Java object,
use the inspect command, as shown in
To look at heap boundaries, we can
use the universe command, as shown in
Listing 3 and Listing 4 show the complete list of commands available with
JAVA IN ACTION
There are some other very handy small
utilities bundled with SA. Let’s see how
to use them and how their output looks:
■ ■ FinalizerInfo prints details on the
finalizable objects, as shown in
■ ■ HeapDumper dumps the heap in
HPROF format, as shown in Listing 6.
■ ■ PermStat prints the permanent generation statistics, as shown in Listing 7.
■ ■ PMap prints the process map of the
process (see Listing 8), much like the
Oracle Solaris pmap tool does.
■ ■ SOQL, the Structured Object Query
Language tool, is an SQL-like language that we can use to query the
Java heap, as shown in Listing 9. JHat
also provides an interface for using
this language, and pretty good documentation on this language is also
available in JHat.
(see Listing 10). It is a command-line
on this utility can be found in the open
source Java HotSpot VM repository in
the file hotspot/agent/doc/ jsdb.html.
hsdb> inspect 0x23f50a20
instance of Oop for java/lang/Thread 0x23f50a20 0x23f50a20 (size = 104)
_metadata._klass: InstanceKlass for java/lang/Thread 0x38966700 Oop @
name: [C 0x23f50ac0 Oop for [C 0x23f50ac0
threadQ: null null
target: null null
group: Oop for java/lang/ThreadGroup 0x23f50840 Oop for java/lang/ThreadGroup 0x23f50840
contextClassLoader: Oop for sun/misc/Launcher$AppClassLoader 0x23f7b398 Oop
for sun/misc/Launcher$AppClassLoader 0x23f7b398
inheritedAccessControlContext: Oop for java/security/AccessControlContext @
0x23f50ad8 Oop for java/security/AccessControlContext 0x23f50ad8
threadLocals: Oop for java/lang/ThreadLocal$ThreadLocalMap 0x23f7c960 Oop
for java/lang/ThreadLocal$ThreadLocalMap 0x23f7c960
inheritable ThreadLocals: null null
parkBlocker: null null
blocker: null null
blockerLock: Oop for java/lang/Object 0x23f50ab8 Oop for java/lang/Object @
uncaughtExceptionHandler: null nullCheck heap boundaries
ADOPT A JSR
Find your JSR here
Download all listings in this issue as text
Let’s Get Our Hands Dirty
Let’s get a real feel for the SA tools and
debug a Java program crash using them.
I have a simple program of Java Native
Interface (JNI) code that writes to a byte
array beyond its size limit, which results
in overwriting and corrupting the object
that follows it in the Java heap. This
causes the program to crash when the
garbage collector tries to scan the heap.