[TOC]
jdk命令行工具
0.概览
名称
作用
jps
JVM Process Status Tool,显示系统中所有的Hotspot虚拟机进程
jstat
JVM Statistics Monitoring Tool,用于收集HotSpot虚拟机各方面的运行数据
jinfo
Configuration info for java,显示虚拟机配置信息
jmap
Memory Map for java,生成虚拟机的内存转储快照(heapdump文件)
jhat
JVM Heapdump Browser,用于分析heapdump文件,会建立一个HTTP/HTML服务器,用户可以在浏览器上查看分析结果
jstack
Stack Trace for java,显示虚拟机的线程快照
1.jps:虚拟机进程查看工具
JVM Process Status Tool,显示指定系统内所有的HotSpot虚拟机进程,类似于Linux中的ps命令。
命令格式
选项及示例
1 2 3 4 5 6 [~]$ jps -help usage: jps [-help] jps [-q] [-mlvV] [<hostid>] Definitions: <hostid>: <hostname>[:<port>]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 [~]$ jps 30784 Bootstrap 26949 Jps [~]$ jps -q //仅输出虚拟机进程id,省略主类 30784 26966 [~]$ jps -m //输出虚拟机进程启用的时候传递给主类main()函数的参数 30784 Bootstrap 26981 Jps -m [~]$ jps -l //输出主类的全类名,如果进程执行的是jar包,输出Jar路径 30784 com.sankuai.mms.boot.Bootstrap 26998 sun.tools.jps.Jps [~]$ jps -v //输出虚拟机进程启动时JVM参数 30784 Bootstrap -Dfile.encoding=UTF-8 -Dsun.jnu.encoding=UTF-8 -Djava.io.tmpdir=/tmp -Djava.net.preferIPv6Addresses=false -Xmx4g -Xms4g -Xmn1g -XX:SurvivorRatio=8 -XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=256m -XX:+HeapDumpOnOutOfMemoryError -XX:ReservedCodeCacheSize=128m -XX:InitialCodeCacheSize=128m -XX:+DisableExplicitGC -XX:+PrintGCDetails -XX:+PrintHeapAtGC -XX:+PrintTenuringDistribution -XX:+UseConcMarkSweepGC -XX:+PrintGCTimeStamps -XX:+PrintGCDateStamps -XX:CMSFullGCsBeforeCompaction=0 -XX:+UseCMSCompactAtFullCollection -XX:CMSInitiatingOccupancyFraction=80 -Xloggc:/opt/logs/etcp-code-service/.gc.log -XX:ErrorFile=/opt/logs/etcp-code-service/.vmerr.log -XX:HeapDumpPath=/opt/logs/etcp-code-service/.heaperr.log -Djetty.appkey= -Djetty.context=/ -Djetty.logs=/opt/logs/etcp-code-service -Djetty.webroot=/opt/meituan/apps/etcp-code-service/webroot 27012 Jps -Dapplication.home=/usr/local/jdk1.7.0_76 -Xms8m
常用命令
jps -lmv
2.jstat:虚拟机统计信息监控工具
jstat(JVM Statistics Monitoring Tool)
用来监视虚拟机各种运行状态信息。可以显示类装载、内存、垃圾收集、JTI编译等运行数据
命令格式
jstat [option] [vmid] [interval] [count]
1 2 3 4 5 6 7 8 jstat -<option> [-t] [-h<lines>] <vmid> [<interval> [<count>]] -t参数可以在输出信息前加一个timestamp列,显示程序的运行时间 -h参数可以在周期性数据输出时,输出多少行数据后,跟着输出一个表头信息。 -interval参数用于指定统计数据的输出周期,单位是毫秒 -count参数用于指定输出的次数
举例:
1 2 3 4 jstat -gcutil 1234 1000 5 1234:vmid 1000:每隔1000ms打印一次 5:一共打印5次
选项及示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 [~]$ jstat -help Usage: jstat -help|-options jstat -<option> [-t] [-h<lines>] <vmid> [<interval> [<count>]] Definitions: <option> An option reported by the -options option <vmid> Virtual Machine Identifier. A vmid takes the following form: <lvmid>[@<hostname>[:<port>]] Where <lvmid> is the local vm identifier for the target Java virtual machine, typically a process id; <hostname> is the name of the host running the target Java virtual machine; and <port> is the port number for the rmiregistry on the target host. See the jvmstat documentation for a more complete description of the Virtual Machine Identifier. <lines> Number of samples between header lines. <interval> Sampling interval. The following forms are allowed: <n>["ms" |"s" ] Where <n> is an integer and the suffix specifies the units as milliseconds("ms" ) or seconds ("s" ) . The default units are "ms". <count> Number of samples to take before terminating. -J<flag> Pass <flag> directly to the runtime system.
选项主要分为3类
类装载、垃圾收集、运行期编译状况
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 -class //监视类装载、卸载数量、总空间以及类装载所耗费的时间 -gc //监视JAVA 堆状况,包括Eden 区、两个Survivor 区、老年代、永久代等的容量、已用空间、GC 时间合计等信息 -gccapacity //监视内容与-gc 基本相同,但输出主要关注java 堆各个区域使用到的最大、最小空间 -gcutil //监视内容与-gc 基本相同,但输出主要关注已使用空间占总空间的百分比 -gccause //与-gcutil 功能一样,但是会额外输出导致上一次GC 产生的原因 -gcnew //监视新生代的GC 状况 -gcnewcapacity //监视内容与-gcnew 基本相同,输出主要关注使用到的最大、最小空间 -gcold //监视老年代的GC 状况 -gcoldcapacity //监视内容与-gcold 基本相同,输出主要关注使用到的最大、最小空间 -gcpermcapacity //输出永久代使用到的最大、最小空间 -compiler //输出JIT 编译器编译过的方法、耗时等信息 -printcompilation //输出已经被JIT 编译的方法
-class
1 2 3 4 5 6 7 8 9 10 11 12 13 [~]$ jstat -class 192610 500ms 5 Loaded Bytes Unloaded Bytes Time 13021 26691.8 0 0.0 29.06 13021 26691.8 0 0.0 29.06 13021 26691.8 0 0.0 29.06 13021 26691.8 0 0.0 29.06 13021 26691.8 0 0.0 29.06 Loaded:载入类的数量 Bytes:载入类的合计大小 Unloaded:卸载类的数量 Bytes:卸载类的合计大小 Time:加载类和卸载类上花费的时间
-gc
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 [~]$ jstat -gc 192610 1000ms 5 Warning: Unresolved Symbol: sun.gc.generation.2.space.0.capacity substituted NaN Warning: Unresolved Symbol: sun.gc.generation.2.space.0.used substituted NaN S0C S1C S0U S1U EC EU OC OU PC PU YGC YGCT FGC FGCT GCT 104832.0 104832.0 2687.7 0.0 838912.0 708187.2 3145728.0 321489.3 � � 100 6.148 0 0.000 6.148 104832.0 104832.0 2687.7 0.0 838912.0 708191.6 3145728.0 321489.3 � � 100 6.148 0 0.000 6.148 104832.0 104832.0 2687.7 0.0 838912.0 708191.6 3145728.0 321489.3 � � 100 6.148 0 0.000 6.148 104832.0 104832.0 2687.7 0.0 838912.0 708201.2 3145728.0 321489.3 � � 100 6.148 0 0.000 6.148 104832.0 104832.0 2687.7 0.0 838912.0 708254.4 3145728.0 321489.3 � � 100 6.148 0 0.000 6.148 S0C:年轻代中第一个survivor(幸存区)的容量 (KB) S1C:年轻代中第二个survivor(幸存区)的容量 (KB) S0U:年轻代中第一个survivor(幸存区)目前已使用空间 (KB) S1U:年轻代中第二个survivor(幸存区)目前已使用空间 (KB) EC:年轻代中Eden(伊甸园)的容量 (KB) EU:年轻代中Eden(伊甸园)目前已使用空间 (KB) OC:Old代的容量 (KB) OU:Old代目前已使用空间 (KB) PC:Perm(持久代)的容量 (KB) //java8中已经移除持久代 PU:Perm(持久代)目前已使用空间 (KB) //java8中已经移除持久代 YGC:从应用程序启动到采样时年轻代中gc次数 YGCT:从应用程序启动到采样时年轻代中gc所用时间(s) FGC:从应用程序启动到采样时old代(全gc)gc次数 FGCT:从应用程序启动到采样时old代(全gc)gc所用时间(s) GCT:从应用程序启动到采样时gc用的总时间(s)
-gccapacity
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 [~]$ jstat -gccapacity 192610 100ms 5 Warning: Unresolved Symbol: sun.gc.generation.2.minCapacity substituted NaN Warning: Unresolved Symbol: sun.gc.generation.2.maxCapacity substituted NaN Warning: Unresolved Symbol: sun.gc.generation.2.capacity substituted NaN Warning: Unresolved Symbol: sun.gc.generation.2.space.0.capacity substituted NaN NGCMN NGCMX NGC S0C S1C EC OGCMN OGCMX OGC OC PGCMN PGCMX PGC PC YGC FGC 1048576.0 1048576.0 1048576.0 104832.0 104832.0 838912.0 3145728.0 3145728.0 3145728.0 3145728.0 � � � � 103 0 1048576.0 1048576.0 1048576.0 104832.0 104832.0 838912.0 3145728.0 3145728.0 3145728.0 3145728.0 � � � � 103 0 1048576.0 1048576.0 1048576.0 104832.0 104832.0 838912.0 3145728.0 3145728.0 3145728.0 3145728.0 � � � � 103 0 1048576.0 1048576.0 1048576.0 104832.0 104832.0 838912.0 3145728.0 3145728.0 3145728.0 3145728.0 � � � � 103 0 1048576.0 1048576.0 1048576.0 104832.0 104832.0 838912.0 3145728.0 3145728.0 3145728.0 3145728.0 � � � � 103 0 NGCMN:年轻代(young)中初始化(最小)的大小 (KB) 【New Generation Capacity Min】 NGCMX:年轻代(young)的最大容量 (KB) NGC:年轻代(young)中当前的容量 (KB) OGCMN:old代中初始化(最小)的大小 (KB) OGCMX:old代的最大容量 (KB) PGCMN:perm代中初始化(最小)的大小 (KB) PGCMX:perm代的最大容量 (KB)
-gcutil
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 [~]$ jstat -gcutil 192610 100ms 5 Warning: Unresolved Symbol: sun.gc.generation.2.space.0.capacity substituted NaN Warning: Unresolved Symbol: sun.gc.generation.2.space.0.used substituted NaN Warning: Unresolved Symbol: sun.gc.generation.2.space.0.capacity substituted NaN S0 S1 E O P YGC YGCT FGC FGCT GCT 0.00 4.08 26.22 10.22 � 103 6.240 0 0.000 6.240 0.00 4.08 26.23 10.22 � 103 6.240 0 0.000 6.240 0.00 4.08 26.23 10.22 � 103 6.240 0 0.000 6.240 0.00 4.08 26.23 10.22 � 103 6.240 0 0.000 6.240 0.00 4.08 26.23 10.22 � 103 6.240 0 0.000 6.240 S0:年轻代中第一个survivor(幸存区)已使用的占当前容量百分比 S1:年轻代中第二个survivor(幸存区)已使用的占当前容量百分比 E:年轻代中Eden(伊甸园)已使用的占当前容量百分比 O:old代已使用的占当前容量百分比 P:perm代已使用的占当前容量百分比 YGC:年轻代经过的GC次数 YGCT:年轻代GC时间 FGC:老年代经过的GC次数 FGCT:老年代GC时间 GCT:所有GC总时间
-gccause
1 2 3 4 5 6 7 8 9 10 11 12 13 [~]$ jstat -gccause 192610 100ms 5 Warning: Unresolved Symbol: sun.gc.generation.2.space.0.capacity substituted NaN Warning: Unresolved Symbol: sun.gc.generation.2.space.0.used substituted NaN Warning: Unresolved Symbol: sun.gc.generation.2.space.0.capacity substituted NaN S0 S1 E O P YGC YGCT FGC FGCT GCT LGCC GCC 0.00 4.08 56.14 10.22 � 103 6.240 0 0.000 6.240 Allocation Failure No GC 0.00 4.08 56.14 10.22 � 103 6.240 0 0.000 6.240 Allocation Failure No GC 0.00 4.08 56.14 10.22 � 103 6.240 0 0.000 6.240 Allocation Failure No GC 0.00 4.08 56.14 10.22 � 103 6.240 0 0.000 6.240 Allocation Failure No GC 0.00 4.08 56.14 10.22 � 103 6.240 0 0.000 6.240 Allocation Failure No GC LGCC:上次GC的原因【Last GC Cause】 GCC:当前GC的原因
-gcnew
1 2 3 4 5 6 7 8 9 10 11 12 [~]$ jstat -gcnew 192610 100ms 5 S0C S1C S0U S1U TT MTT DSS EC EU YGC YGCT 104832.0 104832.0 0.0 4276.9 15 15 52416.0 838912.0 541449.0 103 6.240 104832.0 104832.0 0.0 4276.9 15 15 52416.0 838912.0 541466.0 103 6.240 104832.0 104832.0 0.0 4276.9 15 15 52416.0 838912.0 541468.2 103 6.240 104832.0 104832.0 0.0 4276.9 15 15 52416.0 838912.0 541468.2 103 6.240 104832.0 104832.0 0.0 4276.9 15 15 52416.0 838912.0 541468.2 103 6.240 TT:新生代对象晋升到老年代的年龄。Tenuring threshold(提升阈值) MTT:新生代对象晋升到老年代的年龄的最大值。最大的tenuring threshold DSS:所需的Survivor大小。survivor区域大小 (KB)
-gcnewcapacity
1 2 3 4 5 6 7 8 9 10 11 [~]$ jstat -gcnewcapacity 192610 100ms 5 NGCMN NGCMX NGC S0CMX S0C S1CMX S1C ECMX EC YGC FGC 1048576.0 1048576.0 1048576.0 104832.0 104832.0 104832.0 104832.0 838912.0 838912.0 103 0 1048576.0 1048576.0 1048576.0 104832.0 104832.0 104832.0 104832.0 838912.0 838912.0 103 0 1048576.0 1048576.0 1048576.0 104832.0 104832.0 104832.0 104832.0 838912.0 838912.0 103 0 1048576.0 1048576.0 1048576.0 104832.0 104832.0 104832.0 104832.0 838912.0 838912.0 103 0 1048576.0 1048576.0 1048576.0 104832.0 104832.0 104832.0 104832.0 838912.0 838912.0 103 0 S0CMX:最大的S0空间 (KB) S1CMX:最大的S1空间(KB) ECMX:最大eden空间 (KB)
-compiler
1 2 3 4 5 6 7 8 9 10 11 12 13 [~]$ jstat -compiler 192610 100ms 5 Compiled Failed Invalid Time FailedType FailedMethod 60656 17 0 283.55 1 com/alibaba/fastjson/parser/deserializer/JavaBeanDeserializer deserialze 60656 17 0 283.55 1 com/alibaba/fastjson/parser/deserializer/JavaBeanDeserializer deserialze 60656 17 0 283.55 1 com/alibaba/fastjson/parser/deserializer/JavaBeanDeserializer deserialze 60656 17 0 283.55 1 com/alibaba/fastjson/parser/deserializer/JavaBeanDeserializer deserialze 60656 17 0 283.55 1 com/alibaba/fastjson/parser/deserializer/JavaBeanDeserializer deserialze Compiled:编译任务执行的次数 Failed:编译失败的次数 Invalid:编译不可用的次数 FailedType:最后一次编译失败的类型 FailedMethod:最后一次编译失败的类名和方法名
-printcompilation
1 2 3 4 5 6 7 8 9 10 11 12 [~]$ jstat -printcompilation 192610 100ms 5 Compiled Size Type Method 60663 5 1 java/lang/ThreadLocal access$400 60663 5 1 java/lang/ThreadLocal access$400 60663 5 1 java/lang/ThreadLocal access$400 60663 5 1 java/lang/ThreadLocal access$400 60663 5 1 java/lang/ThreadLocal access$400 Compiled:编译任务执行的次数 Size:方法字节码的字节数 Type:编译类型 Method:编译方法的类名和方法名。类名使用”/” 代替 “.” 作为空间分隔符. 方法名是给出类的方法名. 格式是同HotSpot - XX:+PrintComplation选项一致
3.jinfo:java配置信息查看工具
jinfo(JVM Configuration info)这个命令作用是实时查看和调整虚拟机运行参数,甚至支持在运行时修改部分参数。
jps -v命令只能查看到显示指定的参数,如果想要查看未被显示指定的参数的值就要使用jinfo口令
命令格式
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 [~]$ jinfo -help Usage: jinfo [option] <pid> (to connect to running process) jinfo [option] <executable <core> (to connect to a core file) jinfo [option] [server_id@]<remote server IP or hostname> (to connect to remote debug server) where <option> is one of: -flag <name> to print the value of the named VM flag -flag [+|-]<name> to enable or disable the named VM flag -flag <name>=<value> to set the named VM flag to the given value -flags to print VM flags -sysprops to print Java system properties <no option> to print both of the above -h | -help to print this help message
1 jinfo [option] [args] LVMID
选项及示例
1 2 3 -flag <name>:打印JVM指定参数值 -flag [+|-]<name>:设置指定JVM参数的布尔值 -flag <name>=<value>:设置指定JVM参数的值
参数使用示例
1.查看参数值
1 2 [~]$ jinfo -flag SurvivorRatio 192610 -XX:SurvivorRatio=8
2.修改参数值
1 [~]$ jinfo -flag +PrintGCDetails 192610
4.jmap:Java内存映射工具
jmap(Memory Map for Java)命令用于生成堆转储快照heapdump。
如果不使用这个命令,还可以使用-XX:+HeapDumpOnOutOfMemoryError参数来让虚拟机出现OOM的时候生成。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 [sankuai@set -xr-cx-etcp-code-test02 ~]$ jmap Usage: jmap [option] <pid> (to connect to running process) jmap [option] <executable <core> (to connect to a core file) jmap [option] [server_id@]<remote server IP or hostname> (to connect to remote debug server) where <option> is one of: <none> to print same info as Solaris pmap -heap to print java heap summary -histo[:live] to print histogram of java object heap; if the "live" suboption is specified, only count live objects -permstat to print permanent generation statistics -finalizerinfo to print information on objects awaiting finalization -dump:<dump-options> to dump java heap in hprof binary format dump-options: live dump only live objects; if not specified, all objects in the heap are dumped. format=b binary format file=<file> dump heap to <file> Example: jmap -dump:live,format=b,file=heap.bin <pid> -F force. Use with -dump:<dump-options> <pid> or -histo to force a heap dump or histogram when <pid> does not respond. The "live" suboption is not supported in this mode. -h | -help to print this help message -J<flag> to pass <flag> directly to the runtime system
命令格式
选项及示例
参数包括
1 2 3 4 5 6 dump : 生成堆转储快照 finalizerinfo : 显示在F-Queue队列等待Finalizer线程执行finalizer方法的对象 heap : 显示Java堆详细信息 histo : 显示堆中对象的统计信息 permstat : to print permanent generation statistics F : 当-dump没有响应时,强制生成dump快照
-dump:生成dump文件
1 2 3 4 5 6 jmap -dump:live,format=b,file=<filename> pid //dump堆到文件,format=b指定输出格式为二进制知识,live指明是活着的对象,file指定文件名 [~]$ jmap -dump:live,format=b,file=dump.hprof 25052 Dumping heap to /home/sankuai/dump.hprof ... Heap dump file created
-heap:输出堆的概要信息
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 jmap -heap pid [~]$ ./jmap -heap 192610 Attaching to process ID 192610 , please wait... Debugger attached successfully. Server compiler detected. JVM version is 25.45 -b02 using parallel threads in the new generation. using thread-local object allocation. Concurrent Mark-Sweep GC Heap Configuration: MinHeapFreeRatio = 40 MaxHeapFreeRatio = 70 MaxHeapSize = 4294967296 (4096.0 MB) NewSize = 1073741824 (1024.0 MB) MaxNewSize = 1073741824 (1024.0 MB) OldSize = 3221225472 (3072.0 MB) NewRatio = 2 SurvivorRatio = 8 MetaspaceSize = 268435456 (256.0 MB) CompressedClassSpaceSize = 1073741824 (1024.0 MB) MaxMetaspaceSize = 268435456 (256.0 MB) G1HeapRegionSize = 0 (0.0 MB) Heap Usage: New Generation (Eden + 1 Survivor Space) : capacity = 966393856 (921.625 MB) used = 641636608 (611.912353515625 MB) free = 324757248 (309.712646484375 MB) 66.39493866980877 % used Eden Space: capacity = 859045888 (819.25 MB) used = 637358448 (607.8323822021484 MB) free = 221687440 (211.41761779785156 MB) 74.19376041527597 % used From Space: capacity = 107347968 (102.375 MB) used = 4278160 (4.0799713134765625 MB) free = 103069808 (98.29502868652344 MB) 3.9853199643238706 % used To Space: capacity = 107347968 (102.375 MB) used = 0 (0.0 MB) free = 107347968 (102.375 MB) 0.0 % used concurrent mark-sweep generation: capacity = 3221225472 (3072.0 MB) used = 230203712 (219.53936767578125 MB) free = 2991021760 (2852.4606323242188 MB) 7.146463791529338 % used 40359 interned Strings occupying 4225896 bytes.
-histo:(histogram 直方图)
打印堆的对象统计,包括对象数、内存大小等等 (因为在dump:live前会进行full gc,如果带上live则只统计活对象,因此不加live的堆大小要大于加live堆的大小 )
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 [sankuai@set -xr-cx-etcp-code-test02 bin]$ jmap -histo:live 192610 |more num #instances #bytes class name ---------------------------------------------- 1 : 46961 131287216 [B 2 : 97908 11794768 [C 3 : 97796 3129472 java.util.HashMap$Node 4 : 96182 2308368 java.lang.String 5 : 40884 1962432 java.util.zip.Inflater 6 : 19559 1721192 java.lang.reflect.Method 7 : 41890 1675600 java.lang.ref.Finalizer 8 : 13968 1601808 java.lang.Class 9 : 40355 1291360 java.util.concurrent.ConcurrentHashMap$Node 10 : 18310 1216328 [Ljava.lang.Object; 11 : 8753 1120216 [Ljava.util.HashMap$Node; 12 : 25015 1000600 java.util.WeakHashMap$Entry 13 : 40884 981216 java.util.zip.ZStreamRef 14 : 35328 847872 io.netty.buffer.PoolThreadCache$MemoryRegionCache$Entry 15 : 16585 796080 org.aspectj.weaver.reflect.ShadowMatchImpl 16 : 15397 684208 [Z 17 : 16585 530720 org.aspectj.weaver.patterns.ExposedState 18 : 965 500552 [Ljava.util.concurrent.ConcurrentHashMap$Node; 19 : 582 469072 [Ljava.util.WeakHashMap$Entry; 20 : 10759 430360 java.util.LinkedHashMap$Entry 21 : 6367 425216 [I 22 : 11721 375072 java.lang.ref.WeakReference 23 : 6664 373184 java.util.LinkedHashMap 24 : 10486 335552 java.util.Hashtable$Entry 25 : 6118 293664 java.util.HashMap 26 : 18146 290336 java.lang.Integer 27 : 9961 239056 [Lorg.aspectj.weaver.ast.Var; 28 : 9721 233304 java.lang.Long 29 : 9096 218304 java.util.ArrayList 30 : 5303 212120 java.util.TreeMap$Entry 31 : 5158 206320 java.lang.ref.SoftReference 32 : 8806 191152 [Ljava.lang.Class; 33 : 3742 174048 [Ljava.lang.String; 34 : 5170 165440 org.jacoco.agent.rt.internal_b0d6a23.core.data.ExecutionData 35 : 80 142592 [Lio.netty.buffer.PoolThreadCache$MemoryRegionCache$Entry; 36 : 2073 132672 java.util.concurrent.ConcurrentHashMap 37 : 5514 132336 java.beans.MethodRef 38 : 1634 130720 java.lang.reflect.Constructor 39 : 411 119296 [Ljava.util.Hashtable$Entry; 40 : 6966 111456 java.lang.Object 41 : 293 110168 java.lang.Thread 42 : 1069 102624 org.springframework.beans.GenericTypeAwarePropertyDescriptor 43 : 3984 95616 java.util.concurrent.atomic.AtomicLong 44 : 62 91416 [Ljava.nio.ByteBuffer; 45 : 3712 89088 org.springframework.core.MethodClassKey 46 : 3661 87864 sun.reflect.generics.tree.SimpleClassTypeSignature 47 : 1500 84000 java.beans.MethodDescriptor 48 : 1162 83664 java.lang.reflect.Field 49 : 2447 78304 java.util.LinkedList 50 : 3132 75168 java.util.jar.Attributes$Name 51 : 2924 70176 java.util.LinkedList$Node
1 2 3 4 5 6 7 8 9 10 class name 表示对象类型B byte C char D double F float I int J long Z boolean [ 数组,如[I表示int[] [L+类名 其他对象
5.jhat
jhat(JVM Heap Analysis Tool)与jmap配合使用,来分析jmap生成的heapdump。
jhat内置了一个HTTP/HTML服务器,可以在浏览器中查看dump文件的分析结果。
一般不用jhat来分析dump文件,jhat功能比较简陋。
一般会download dump文件到本地,使用Eclipse Memory Analyzer(MAT)等工具进行分析。
6.jstack:Java堆栈跟踪工具
jstack用于生成java虚拟机当前时刻的线程快照。线程快照是当前java虚拟机内每一条线程正在执行的方法堆栈的集合。
生成线程快照的主要目的是定位线程出现长时间停顿的原因,如线程间死锁、死循环、请求外部资源导致的长时间等待等。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 [sankuai@set-xr-cx-etcp-code-test02 bin]$ jstack Usage: jstack [-l] <pid> (to connect to running process) jstack -F [-m] [-l] <pid> (to connect to a hung process) jstack [-m] [-l] <executable> <core> (to connect to a core file) jstack [-m] [-l] [server_id@]<remote server IP or hostname> (to connect to a remote debug server) Options: -F to force a thread dump. Use when jstack <pid> does not respond (process is hung) -m to print both java and native frames (mixed mode) -l long listing. Prints additional information about locks -h or -help to print this help message
命令格式
选项及示例
1 2 3 -F : 当正常输出请求不被响应时,强制输出线程堆栈 -l : 除堆栈外,显示关于锁的附加信息 -m : 如果调用到本地方法的话,可以显示C/C++的堆栈
java
java -XX:+PrintCommandLineFlags -version
打印手动设置的参数
java -XX:+PrintFlagsFinal -version | grep :
打印虚拟机所有参数
jmap -heap
参考资料