Listing out some of the useful Java debugging tools
jinfo prints the system properties or the command line flags that were used to start the VM.
/opt/sun/jdk/java/bin/jinfo
jmap prints memory related statistics for a running VM or core file
/opt/sun/jdk/java/bin/jmap
jmap -heap
GC algorithm specific information, Heap configuration, Heap usage summary
jmap -histo
number of objects, memory size in bytes, and fully qualified class name for each class
jmap -permstat
statistics for the objects in the permanent generation. The permanent generation is the area of heap that holds all the reflective data of the virtual machine itself, such as class and method objects. Configuring the size of the permanent generation can be important for applications that dynamically generate and load a very large number of classes
A “live” or “dead” indication – indicates whether the loader object will be garbage collected in the future.
http://java.sun.com/j2se/1.5.0/docs/tooldocs/share/jmap.info
jstack prints the stack traces of all threads that are attached to the virtual machine.
can be useful when trying to diagnose a number of issues such as deadlocks or hangs
– thread dump can be obtained by sending the process a QUIT signal
/opt/sun/jdk/java/bin/jstack
jstack
jstack -m : to print mixed stack.
jstack
java.lang.Thread.run() @bci=11, line=595 (Interpreted frame)
| | | | |
| | | | +– Method compiled/interpreted?
| | | +——————— Source line number
| | +—————————— Byte code index
| +——————————————- Method name
+—————————————————————— Fully qualified class name
Frames prefixed with ‘*’ are Java frames, and others are native C/C++ frames.
jconsole provide information on performance and resource consumption of running
applications in a GUI.
– useful information such as thread usage, memory consumption, and details
about class loading, runtime compilation, and the operating system within time range as shot as 1min.
– useful for diagnosis on problems such as memory leaks, excessive class loading or running threads.
– jconsole can attach to any application that is started with the JMX agent.
[-Dcom.sun.management.jmxremote]
/opt/sun/jdk/java/bin/jconsole
jconsole
jps lists the instrumented HotSpot Virtual Machines on the target system
– can output the arguments passed to the application’s main method, the complete list of VM arguments, and the full package name of mail class.
/opt/sun/jdk/java/bin/jps
jps
jstat provides information on performance and resource consumption of running
applications.
– usefule for diagnosis on performance issues, and in particular issues related to heap sizing and garbage collection
– tale multiple samples continously and analyse
/opt/sun/jdk/java/bin/jstat
jstat – : where option can be
• -class – prints statistics on the behavior of the class loader.
• -compiler – prints statistics of the behavior of the HotSpot compiler.
• -gc – prints statistics of the behavior of the garbage collected heap.
• -gccapacity – prints statistics of the capacities of the generations and their corresponding spaces.
• -gccause – prints the summary of garbage collection statistics (same as -gcutil), with the cause of
the last and current (if applicable) garbage collection events.
• -gcnew – prints statistics of the behavior of the new generation.
• -gcnewcapacity – prints statistics of the sizes of the new generations and its corresponding spaces.
• -gcold – prints statistics of the behavior of the old and permanent generations.
• -gcoldcapacity – prints statistics of the sizes of the old generation.
• -gcpermcapacity – print statistics of the sizes of the permanent generation.
• -gcutil – prints a summary of garbage collection statistics.
• -printcompilation – prints HotSpot compilation method statistics.
HPROF is capable of presenting CPU usage, heap allocation statistics and monitor contention
profiles. By default information is written out to java.hprof.txt.
$JAVA_HOME/demo/jvmti/hprof/
java -agentlib:hprof
java -agentlib:hprof=help to list all options
Examples:
– Get sample cpu information every 20 millisec, with a stack depth of 3:
java -agentlib:hprof=cpu=samples,interval=20,depth=3 classname
- Get heap usage information based on the allocation sites:
java -agentlib:hprof=heap=sites classname
http://java.sun.com/developer/technicalArticles/Programming/HPROF.html