当前位置: 移动技术网 > IT编程>开发语言>Java > java自带命令行工具jmap、jhat与jinfo的使用实例代码详解

java自带命令行工具jmap、jhat与jinfo的使用实例代码详解

2019年07月22日  | 移动技术网IT编程  | 我要评论

java自带命令行工具(jmap,jhat,jinfo)

(1)jmap

1.作用

打印进程,core文件,和远程进程的共享对象存储map或堆存储器的详细信息。

2.使用

jmap[options]pid
jmap[options]executablecore
jmap[options][pid]server-id@]remote-hostname-or-ip

如果指定的进程是在64位java虚拟机(jvm)上运行,那么你可能需要指定-j-d64选项,例如:jmap -j-d64 -heap pid。

3.参数选项

3.1

当不使用选项,该jmap命令打印共享对象映射

c:\users\administrator>jmap9208
attachingtoprocessid9208,pleasewait...
debuggerattachedsuccessfully.
servercompilerdetected.
jvmversionis24.75-b04
0x00000000623c00008016kd:\java\jdk1.7.0_75\jre\bin\server\jvm.dll
0x0000000062ba0000840kd:\java\jdk1.7.0_75\jre\bin\msvcr100.dll
0x0000000062cc0000144kd:\java\jdk1.7.0_75\jre\bin\sunec.dll
0x0000000062cf000068kd:\java\jdk1.7.0_75\jre\bin\nio.dll
0x0000000062d10000100kd:\java\jdk1.7.0_75\jre\bin\net.dll
0x0000000062d30000160kd:\java\jdk1.7.0_75\jre\bin\java.dll
0x00000000634d000084kd:\java\jdk1.7.0_75\jre\bin\zip.dll
0x000000006595000044kd:\java\jdk1.7.0_75\jre\bin\sunmscapi.dll
0x000000006596000060kd:\java\jdk1.7.0_75\jre\bin\verify.dll
0x000000006597000044kd:\java\jdk1.7.0_75\jre\bin\management.dll
...

3.2

-dump:[live,] format=b, file=filename

转储java堆hprof二进制格式。指定live,标识转储active状态的对象。生成的文件可以由jhat命令查看。

c:\users\administrator>jmap-dump:format=b,file=9208_0413.hprof9208
dumpingheaptoc:\users\administrator\9208_0413.hprof...
heapdumpfilecreated

3.3-finalizerinfo

打印将要结束的对象的信息

c:\users\administrator>jmap-finalizerinfo9208
attachingtoprocessid9208,pleasewait...
debuggerattachedsuccessfully.
servercompilerdetected.
jvmversionis24.75-b04
numberofobjectspendingforfinalization:0

3.4 -heap

打印垃圾收集和heap摘要信息,以及生成-wise 堆使用的堆摘要

c:\users\administrator>jmap-heap9208
attachingtoprocessid9208,pleasewait...
debuggerattachedsuccessfully.
servercompilerdetected.
jvmversionis24.75-b04
 
usingthread-localobjectallocation.
parallelgcwith4thread(s)
 
heapconfiguration:
minheapfreeratio=0
maxheapfreeratio=100
maxheapsize=2124414976(2026.0mb)
newsize=1310720(1.25mb)
maxnewsize=17592186044415mb
oldsize=5439488(5.1875mb)
newratio=2
survivorratio=8
permsize=21757952(20.75mb)
maxpermsize=85983232(82.0mb)
g1heapregionsize=0(0.0mb)
 
heapusage:
psyounggeneration
edenspace:
capacity=68157440(65.0mb)
used=16646688(15.875518798828125mb)
free=51510752(49.124481201171875mb)
24.423875075120193%used
fromspace:
capacity=5242880(5.0mb)
used=5228248(4.986045837402344mb)
free=14632(0.01395416259765625mb)
99.72091674804688%used
tospace:
capacity=15728640(15.0mb)
used=0(0.0mb)
free=15728640(15.0mb)
0.0%used
psoldgeneration
capacity=88080384(84.0mb)
used=27239848(25.977943420410156mb)
free=60840536(58.022056579589844mb)
30.9261231195359%used
pspermgeneration
capacity=22020096(21.0mb)
used=15369592(14.657585144042969mb)
free=6650504(6.342414855957031mb)
69.7980244954427%used
 10057internedstringsoccupying867832bytes.

3.5 -histo[:live]

打印堆的直方图

num#instances#bytesclassname
----------------------------------------------
...
877:132[lcom.sun.jndi.ldap.pool.pool;
878:232com.sun.org.apache.xerces.internal.impl.dv.dtd.entitydatatypevalidator
879:232java.lang.shutdown$lock
880:132org.apache.coyote.http11.http11protocol$http11connectionhandler
881:232com.sun.org.apache.xerces.internal.impl.xmldocumentscannerimpl$dtddriver
882:132java.lang.reflect.weakcache$cachekey
883:132java.text.fieldposition
884:132java.util.concurrent.atomic.atomicreferencefieldupdater$atomicreferencefieldupdaterimpl
885:232sun.security.x509.certificateversion
886:232[lorg.apache.catalina.deploy.contextenvironment;
887:132[lorg.apache.tomcat.util.net.abstractendpoint$acceptor$acceptorstate;
888:132sun.nio.cs.standardcharsets
...

3.6 -clstats

java 堆的wise统计。1.7.0_75不支持该项

(2)jhat

2.1作用

分析java堆。该jhat命令解析java堆转储文件并启动web服务器。jhat命令可以让你浏览堆转储。支持oql语法。

2.2使用

jhat [ options ] heap-dump-file

2.3参数说明

1.-stack false|true

关闭跟踪对象分配调用堆栈。默认值是true。

-refs false|true

关闭对象的引用的跟踪。默认为true。

-port port-number

设置端口的jhathttp服务器。默认值是7000。

-exclude exclude-file

指定列出了应当从可及的对象查询排除数据成员的文件

-baseline exclude-file

指定基准堆转储。在具有相同的对象id两个堆转储对象被标记为不是新对象。这是用于比较两个不同的堆转储有用。

-debug int

0级表示没有调试输出

c:\users\administrator>jhat-port80009208_0413.hprof
readingfrom9208_0413.hprof...
dumpfilecreatedthuapr1321:18:58cst2017
snapshotread,resolving...
resolving389761objects...
chasingreferences,expect77dots..........................................................................
eliminatingduplicatereferences............................................................................
snapshotresolved.
startedhttpserveronport8000
serverisready.

接下来,就可以通过浏览器访问查看。。

(3)jinfo

3.1作用

生成的配置信息。如果指定的进程是在64位jvm上运行,那么你可能需要指定-j-d64选项

3.2使用

jinfo[option]pid
jinfo[option]executablecore
jinfo[option][servier-id]remote-hostname-or-ip

3.3选项参数

no-option:既打印命令行标志和系统属性键值对。

-flag name

打印名和指定的命令行标志的值。

-flag [+|-]name

开启或禁止指定的布尔命令行标志。

-flag name=value

设置指定的命令行标志为指定值。

-flags

打印命令行标志传递给jvm。

-sysprops

打印java系统属性键值对。

打印进程的命令行参数

c:\users\administrator>jinfo-flags9208
attachingtoprocessid9208,pleasewait...
debuggerattachedsuccessfully.
servercompilerdetected.
jvmversionis24.75-b04
 -djava.util.logging.config.file=d:\apache-tomcat-7.0.67\conf\logging.properties-djava.util.logging.manager=org.apache.juli.classloaderlogmanager
-djava.endorsed.dirs=d:\apache-tomcat-7.0.67\endorsed-dcatalina.base=d:\apache-tomcat-7.0.67-dcatalina.home=d:\apache-tomcat-7.0.67-djava.io.
tmpdir=d:\apache-tomcat-7.0.67\temp
#在catalina.sh中可以找到设置的地方

打印参数值

#值类型参数
c:\users\administrator>jinfo-flagnewsize9208
-xx:newsize=1310720
 
#开关类型参数
c:\users\administrator>jinfo-flagprintgc9208
-xx:-printgc
 
c:\users\administrator>jinfo-flagxmn9208
nosuchflag'xmn'

可以总结出:-xms,-xmn系列参数不能通过jinfo指定或打印;jinfo命令作用于-xx:***格式的参数。

设置参数值

c:\users\administrator>jinfo-flagprintgc9208
-xx:-printgc
 
c:\users\administrator>jinfo-flag+printgc9208
 
c:\users\administrator>jinfo-flagprintgc9208
-xx:+printgc
//2windows环境总是失败
 
c:\users\administrator>jinfo-flagpermsize=217500009208
exceptioninthread"main"java.io.ioexception:commandfailedintargetvm
atsun.tools.attach.windowsvirtualmachine.execute(windowsvirtualmachine.java:112)
atsun.tools.attach.hotspotvirtualmachine.executecommand(hotspotvirtualmachine.java:217)
atsun.tools.attach.hotspotvirtualmachine.setflag(hotspotvirtualmachine.java:190)
atsun.tools.jinfo.jinfo.flag(jinfo.java:123)
atsun.tools.jinfo.jinfo.main(jinfo.java:76)

希望本篇文章对您有所帮助

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网