Introduction to Java Heap dump file analysis tool jhat, heapjhat
Jhat is a Java heap Analyzes Tool ). after JDK6u7, it becomes standard. this command requires some Java development experience. The official website does not provide technical support and customer service for this tool.
Usage:
jhat [ options ] heap-dump-file
Parameters:
Options: optional command line parameters. See the following Options
Heap-dump-file: the binary Java heap dump file to be viewed ). If a dump file contains multiple heap dumps, you can add#<number>
Specifies which dump to parse, such:myfile.hprof#3
Example
The jmap dump can be implemented as follows:
jmap -dump:file=DumpFileName.txt,format=b pid
For example:
C:\Users\Administrator\Desktop>jmap -dump:file=D:/javaDump.hprof,format=b 3614Dumping heap to D:\javaDump.hprof ...Heap dump file created
Among them, 3614 is the ID of the java Process viewed through tasklist or task manager after Tomcat is started. Generally, jmap needs to be consistent or compatible with the java version to be exported successfully. if you do not know how to use it, enterjmap
, Orjmap -h
The prompt is displayed.
Then use the jhat command for analysis, as shown below:
Jhat-J-Xmx1024m D:/javaDump. hprof... a bunch of information... Snapshot resolved. Started HTTP server on port 7000 Server is ready.
The jhat-J parameter is because the default JVM heap memory may not be enough to load the entire dump file. adjust the parameter as needed. The port number is 7000 as prompted,
Then, access http: // localhost: 7000/in the browser to view the relevant information.
Detailed description
The jhat command parses the Java heap dump file and starts a web server. then, use the browser to view/view the heap dumped by dump. the jhat command supports pre-designed queries, such as displaying all instances of a class. OQL and Object Query Language are also supported ). OQL is similar to SQL and used to query heap dump. OQL-related help information can be found at the bottom of the server page provided by the jhat command. If the default port is used, the OQL help page is http: // localhost: 7000/oqlhelp/
Java generates multiple methods of heap dumping:
- Use
jmap -dump
You can obtain heap dump when JVM is running (refer to the example above). For more information, see jmap (1)
- Use
jconsole
Option: Use HotSpotDiagnosticMXBean to get a heap dump from the runtime. See jconsole (1) andHotSpotDiagnosticMXBean
The Interface Description of: http://docs.oracle.com/javase/8/docs/jre/api/management/extension/com/sun/management/HotSpotDiagnosticMXBean.html.
- If you specify
-XX:+HeapDumpOnOutOfMemoryError
If an OutOfMemoryError is thrown, the heap dump is automatically executed.
- Use
hprof
Command. See A Heap/CPU Profiling Tool: http://docs.oracle.com/javase/8/docs/technotes/samples/hprof.html
Options-stack false | true
Close the tracking object allocation call stack ). If the allocation location information is unavailable in the heap dump, you must set this flag to false. The default value istrue
.
-Refs false | true
Disable object reference tracking (tracking of references to objects ). The default value istrue
By default, the returned pointer is an object pointing to another specific object, such as a reverse link or input reference (referrers or incoming references). All objects in the heap are counted/calculated.
-Port-number
Set the port number of the jhat HTTP server. Default Value7000
.
-Exclude-file
Specifies the data member list file to be excluded during object query (a file that lists data members that shocould be excluded from the reachable objects query ). For example, if the file column listsjava.lang.String.value
The reference path involvesjava.lang.String.value
Will be excluded.
-Baseline exclude-file
Specifies a baseline heap dump ). Objects with the same object ID in the two heap dumps will be marked as not new (marked as not being new ). other objects are marked as new ). it is useful when comparing two different heap dumps.
-Debug int
Set the debug level.0
Indicates that no debugging information is output. A greater value indicates a more detailed debug information.
-Version
After the instance is started, it only displays version information and exits.
-H
Displays help information and exits.-help
-Help
Displays help information and exits.-h
-J <flag>
Because the jhat Command actually starts a JVM for execution, you can use-J to input some startup parameters when starting the JVM. For example,-J-Xmx512m
The maximum heap memory used by the Java virtual machine running jhat is 512 MB. If multiple JVM startup parameters are required, multiple-Jxxxxxx are input.
For more information, see:
- Jmap (1)
- Jconsole (1)
- One Heap/CPU Performance Analysis Tool
Link: https://docs.oracle.com/javase/jp/8/technotes/tools/unix/jhat.html
GitHub: https://github.com/cncounter/translation/blob/master/tiemao_2014/jhat/jhat.md
Original Article Date:
Translation Date:
Translated by: Tie