Java Debugging

From Training Material
Revision as of 17:50, 24 November 2014 by Cesar Chew (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
title
Java Debugging
author
Sam Bashton

Debugging Java applications ⌘

  • Debugging tools are more limited on RHEL5
  • Still many options


Showing JVM properties ⌘

 jinfo <java process id>


Showing heap usage ⌘

  • You can see the heap usage of an application with jmap
 jmap <java process id>


Showing object heap usage ⌘

 jmap -histo <java process id>
  • It may be necessary to 'force' on newer Java versions:
 jmap -F -histo <java process id>


Taking a thread dump ⌘

  • Shows more details on what an application is doing
  • Dumps thread output to stdout
 - If you started your Java process redirecting stdout to /dev/null,
   you're out of luck..
  • Take two thread dumps to show stuck threads
  pkill -3 java; sleep 5; pkill -3 java


Take a stack trace ⌘

  • `jstack <java process id>`
  • If the app uses JNI, take a mixed-mode trace:
 jstack -m <java process id>


Showing garbage collection details ⌘

  • Start the JVM with `-verbose:gc` to get details about garbage collection printed to stdout on each collection
 For even more verbosity, use `-XX:+PrintGCDetails


Disabling explicit garbage collection ⌘

  • Applications can manually invoke full garbage collection by calling `System.gc()`
  • This can be disabled by adding command line option
 -XX:+DisableExplicitGC` at JVM startup


Exercise ⌘

  • Try all of the mentioned techniques on your tomcat instance

Visualization⌘

  • jvisualvm