Dumps From a Java Process

Redirected from Diagnostics

Originally Wiki'd By: Brad Galla 23-Aug-2013 13:36 CDT

*nix

This section lists methods to obtain dumps on *nix-based platforms

All Java Versions

The 'kill' command on *nix machines will invoke a thread dump when the highest level of killing a process is inflicted. To perform the highest level of kill, and to generate a thread dump of the process that is being eradicated, run the following command:

Command Level Explanation
kill -3 SIGQUIT - Sends a quit command to the process; causes thread dump to stdout
-9 SIGKILL - Kills the process; causes thread dump to stdout

NOTE: -9 WILL TERMINATE PROCESS. USE -3 IF PROCESS TERMINATION IS NOT DESIRED. (see Comments:Dumps From a Java Process page)

Dump Table

OS Command Arguments Description Java
*nix jstack (Thread Dump) -m process-id# Prints mixed threads (Java & C++) on a specified process ID# 5
jmap (Heap Dump) process-id# Performs shared object mappings on the specified process ID#
-heap process-id# Performs a heap dump on the specified process ID#
-histo process-id# Prints the histogram for the specified process ID#
jstack (Thread Dump) -l process-id# Prints long listing information (locks, synchronizers, etc.) on a specified process ID# 6, 7
-l -F process-id# Force a stack dump when jstack isn't responding
jmap (Heap Dump) -dump:format=b,file=filename process-id# Dumps the memory map of the target process-ID# to an hprof file within the current directory (or specified directory if you expand upon filename)

Windows

This section lists methods to obtain fresh dumps on Windows-based platforms

All Java Versions

Action Command/Arguments Description
Thread Dump from Console Window [CTRL]+[BREAK] This will print the thread dump directly to the console window. This text can then be extracted from the console and thrown in a text-editor for easier reading
Thread Dump from Windows Service

at 17:34 cmd /c %JAVA_HOME%\bin\jstack.exe -l process-id# ^>C:\stack.txt 2^>^&1

Due to security designs of Windows Services, a scheduled task must be setup to get a dump on a Windows Service. If you run this command from an Administrative Command Prompt, set it for 1 minute ahead of your current time. If you set it after the time has elapsed, it will run the next day instead. You can run "at" without options to make sure your command is scheduled appropriately. See the example below for a screenshot showing how to do this

Dump Table

OS Command Arguments Description Java
Windows
jmap (Heap Dump) -dump:format=b,file=filename process-id# Dumps the memory map of the target process-ID# to an hprof file within the current directory (or specified directory if you expand upon filename) 6, 7
jstack (Thread Dump) -l process-id# Prints long listing information (locks, synchronizers, etc.) on a specified process ID#
-l -F process-id# Force a stack dump when jstack isn't responding

Appendix A: References

Command Java 5 Reference Java 6 Reference Java 7 Reference
jmap jmap - Memory Map jmap - Memory Map jmap - Memory Map
jstack jstack - Stack Trace jstack - Stack Trace jstack - Stack Trace

Appendix B: Known Issues

Java 4

Java 4 does not support jstack.

Java 5

Java 5 has shown intermittent support on Windows when using jstack. Some notable cases include:

  • Using a 64-bit operating system and a 32-bit JVM
    • Will cause jstack to fail with the message Monitoring is not supported for the selected JVM.

Appendix C: Anthill Specific

On versions 3.7.5+, you should be able to get an anthill-specific thread dump by navigating to System --> Server Settings --> Diagnostics --> View CPU Thread Usage.


Appendix D: JVisualVM

If the JDK is installed (Java 6 or greater), one method for retrieving any type of dump can be done through JVisualVM. JVisualVM is a GUI for analyzing Java processes, as well as getting detailed & intricate info on heaps, available threads, CPU usage, etc. To attempt to get any dumps from JVisualVM:

# STEP SCREENSHOT
1 Either through a command prompt, a terminal window, or the Run window, fire up JVisualVM.
JVisualVM Initial Screen
JVisualVM Initial Screen
2 (OPTIONAL) Perform any calibration if needed.
3 Locate the java process you wish to analyze
JVisualVM Java Process Selected
JVisualVM Java Process Selected
4 Click on Applications, and then select an appropriate dump
Which dump would you like
Which dump would you like to be taken
Heap Dump if generating a heap dump (appears in the temp directory)
Thread Dump if generating a thread dump (appears within JVisualVM's thread window)


Appendix E: Windows Services Thread Dump Example

An example set of steps to take a thread dump from a Windows Service.

# STEP SCREENSHOT
1 Verify what processes are running on the system with both 'jps' and 'Windows Task Manager'
Screenshot showing JPS & Task Manager being ran to identify PIDs.
Screenshot showing JPS & Task Manager being ran to identify PIDs.
2 Prepare the command in a high-quality text editor
Forming the command in Notepad++
Forming the command in Notepad++
3 Execute the command from an Administrative Command Prompt. Note that it has to be ran under an Administrative Command Prompt for full system access.
Commands moved from Notepad++ to command prompt.
Commands moved from Notepad++ to command prompt.
4 Verify that scheduled tasks exist.
'at' commands exist
'at' commands exist
5 Observe that thread dumps have been created in the location of your choice.
Thread dumps and heap dumps have been created.
6 Compress & Send in Supportal ticket.
Thread dumps and heap dumps have been created and compressed.

Appendix F: Processes

Any newer AnthillPro server has two server processes:

  • Main Server Process (%JAVA_HOME%\bin\java -classpath ...\apache-activemq\conf...)
  • ActiveMQ Broker Process (-Xmx512m -XX:MaxPermSize=192m -Dderby.system.home...)

Please make sure to take dumps of both when dumping!