For example, to examine any Java object,
use the inspect command, as shown in
Listing 1.
To look at heap boundaries, we can
use the universe command, as shown in
Listing 2.
Listing 3 and Listing 4 show the complete list of commands available with
this tool.
COMMUNITY
JAVA IN ACTION
Other Tools
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
Listing 5.
■ ■ 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.
■ ■ JSDB, the JavaScript Debugger, provides a JavaScript interface to SA
(see Listing 10). It is a command-line
JavaScript shell based on Mozilla’s
Rhino JavaScript engine. More details
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)
_mark: 1
_metadata._klass: InstanceKlass for java/lang/Thread 0x38966700 Oop @
0x38966700
name: [C 0x23f50ac0 Oop for [C 0x23f50ac0
priority: 5
threadQ: null null
eetop: 4758528
single_step: false
daemon: false
stillborn: false
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
stackSize: 0
nativeParkEventPointer: 0
tid: 1
threadStatus: 5
parkBlocker: null null
blocker: null null
blockerLock: Oop for java/lang/Object 0x23f50ab8 Oop for java/lang/Object @
0x23f50ab8
uncaughtExceptionHandler: null nullCheck heap boundaries
GIVE BACK!
ADOPT A JSR
Find your JSR here
ABOUT US
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.