In this article we are going to see the jhat commands.
What is jhat?
jhat command purses the java heap dump file and launches a web server to brows heap dumps.
It supports, pre defined queries, OQL(object query language).
How to create heap dumps?
We need to use any of following options to create heap dumps.
- Running JVM with -XX:+HeapDumpOnOutOfMemoryError
- JvisualVM (GUI)
I will provide separate blog on heap dumps.
jhat [options] [heap-dump-file]
jhat Options :
- stack (false/true) : Turn off tracking object allocation call stack. Default is true
- refs (false/true) : Turn off tracking of references to objects. Default is true.
- port (port-number) : Set the port-number for the jhat’s HTTP server. Default is 7000.
- exclude (exclude-file) : Specify a file that lists data members that should be excluded from the “reachable objects” query.
- baseline (baseline-dump-file) : Specify a baseline heap dump. It is useful while comparing two heap dumps
- debug (int) : Sets debug level for this tool. 0=no debug . Higher values for more verbose modes.
- J(option) : Passes option to the Java virtual machine on which jhat is running.
Usage: jhat [-stack <bool>] [-refs <bool>] [-port <port>] [-baseline <file>] [-debug <int>] [-version] [-h|-help] <file> -J<flag> Pass <flag> directly to the runtime system. For example, -J-mx512m to use a maximum heap size of 512MB -stack false: Turn off tracking object allocation call stack. -refs false: Turn off tracking of references to objects -port <port>: Set the port for the HTTP server. Defaults to 7000 -exclude <file>: Specify a file that lists data members that should be excluded from the reachableFrom query. -baseline <file>: Specify a baseline object dump. Objects in both heap dumps with the same ID and same class will be marked as not being "new". -debug <int>: Set debug level. 0: No debug output 1: Debug hprof file parsing 2: Debug hprof file parsing, no server -version Report version number -h|-help Print this help and exit <file> The file to read
Mainly this tool is used for comparing and debugging a hep dump(specially when server is having problems or test fail while processing).