JVM调优之jhat

jhat - Java Heap Analysis Tool

JHAT命令解析Java堆转储文件并启动WebServer。jhat允许您使用您最喜欢的WebBrowser浏览堆转储。JHAT支持预先设计的查询(例如“show all instances of a known class "Foo"”)以及OQL((Object Query Language对象查询语言)——一种查询堆转储的类似SQL的查询语言。可以在http://localhost:7000/oqlhelp/查看有关OQL的使用说明。这个工具是实验性的,在JDK的未来版本中可能不可用。

这里有一些生成java堆转储文件的方法:

  • jmap -dump 在运行时获取堆转储
  • jconsole  在运行时通过hotspotdiagnosticmxbean获取堆转储
  • -XX:+HeapDumpOnOutOfMemoryError  启动java程序时通过使用-XX:+HeapDumpOnOutOfMemoryError命令,使程序在抛出OutOfMemoryError时自动生成堆转储
  • 使用hprof
jhat -h
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

For a dump file that contains multiple heap dumps,
you may specify which dump in the file
by appending "#<number>" to the file name, i.e. "foo.hprof#3".

All boolean options default to "true"
  • 使用方式:

jhat [ options ] <heap-dump-file>

options

Options,操作选项,如果要用的话必须紧跟在jhat后面。

heap-dump-file

要查看的java二进制堆转储文件. 如果一个 dump file包含了多个heap dumps,可以在文件后面拼接#<number>来查看某个堆, i.e. "foo.hprof#3"。

-stack false/true

关闭对象在堆栈中的追踪,注意,如果在堆转储中分配站点信息不可用,则必须将此标志设置为false。默认值为true。
Turn off tracking object allocation call stack. Note that if allocation site information is not available in the heap dump, you have to set this flag to false. Default is true.


-refs false/true

关闭对对象引用的跟踪。默认值为true。默认情况下,为堆中的所有对象计算返回指针(指向给定对象a.k.a引用或传入引用的对象)。
Turn off tracking of references to objects. Default is true. By default, back pointers (objects pointing to a given object a.k.a referrers or in-coming references) are calculated for all objects in the heap.


-port port-number
指定server端口,默认是7000。


-exclude exclude-file

指定一个列出应从“reachable objects”查询中排除的数据成员的文件。例如,如果文件列出java.lang.string.value,那么每当计算从特定对象“o”可访问的对象列表时,将不考虑涉及java.lang.string.value字段的引用路径。
Specify a file that lists data members that should be excluded from the "reachable objects" query. For example, if the file lists java.lang.String.value, then, whenever list of objects reachable from a specific object "o" are calculated, reference paths involving java.lang.String.value field will not considered.


-baseline baseline-dump-file

指定基线堆转储(baseline heap dump)。两个堆转储中具有相同object ID的的对象将不会标记为“new”。其他对象将标记为“new”。这在比较两个不同的堆转储时很有用。


-debug int

设置debug级别,0表示没有debug输出,这个值越高,输出的模式更详细。

-version

打印版本号并退出。

eg:

jhat -version
jhat version 2.0 (java version 1.8.0_73)


-J<flag>
指定jhat的jvm命令。eg:jhat -J-Xmx512m.

猜你喜欢

转载自blog.csdn.net/top_explore/article/details/95166138