jps(JVM Process Status Tool):列出正在运行的虚拟机进程,并显示虚拟机执行主类(Main Class,main()函数所在的类)名称以及这些进程的本地虚拟机唯一ID(Local Virtual Machine Identifier,LVMID)。
虽然功能比较单一,但它是使用频率最高的JDK命令行工具,因为其他的JDK工具大多需要输入它查询到的LVMID来确定要监控的是哪一个虚拟机进程。
对于本地虚拟机进程来说,LVMID与操作系统的进程ID(Process Identifier,PID)是一致的,使用Windows的任务管理器或者UNIX的ps命令也可以查询到虚拟机进程的LVMID,但如果同时启动了多个虚拟机进程,无法根据进程名称定位时,那就只能依赖jps命令显示主类的功能才能区分了。
命令格式:
usage: jps [-help]
jps [-q] [-mlvV] [<hostid>]
Definitions:
<hostid>: <hostname>[:<port>]
option参数:
示例:
$ jps -l
13560 sun.tools.jps.Jps
8940 org.jetbrains.jps.cmdline.Launcher
jinfo(JVM Configuration Info):实时查看和调整虚拟机运行参数。
命令格式:
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
option参数:
示例:
$ jinfo -flags 8940
Attaching to process ID 8940, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.172-b11
Non-default VM flags: -XX:CICompilerCount=3 -XX:InitialHeapSize=132120576 -XX:MaxHeapSize=734003200 -XX:MaxNewSize=244318208 -XX:MinHeapDeltaBytes=524288 -XX:NewSize=44040192 -XX:OldSize=88080384 -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseFastUnorderedTimeStamps -XX:-UseLargePagesIndi
vidualAllocation -XX:+UseParallelGC
Command line: -Xmx700m -Djava.awt.headless=true -Djava.endorsed.dirs="" -Djdt.compiler.useSingleThread=true -Dpreload.project.path=D:/gitPrj/morris-book/后端开发/Java/JVM -Dpreload.config.path=C:/Users/wj65651/.IntelliJIdea2018.1/config/options -Dexternal.project.config=C:\Users\wj65651\.IntelliJIdea201
8.1\system\external_build_system\jvm.664992bf -Dcompile.parallel=false -Drebuild.on.dependency.change=true -Djava.net.preferIPv4Stack=true -Dio.netty.initialSeedUniquifier=-6591130954637100000 -Dfile.encoding=GBK -Duser.language=zh -Duser.country=CN -Didea.paths.selector=IntelliJIdea2018.1 -Didea.home.pa
th=D:\Program Files\JetBrains\IntelliJ IDEA 2018.1.4 -Didea.config.path=C:\Users\wj65651\.IntelliJIdea2018.1\config -Didea.plugins.path=C:\Users\wj65651\.IntelliJIdea2018.1\config\plugins -Djps.log.dir=C:/Users/wj65651/.IntelliJIdea2018.1/system/log/build-log -Djps.fallback.jdk.home=D:/Program Files/JetB
rains/IntelliJ IDEA 2018.1.4/jre64 -Djps.fallback.jdk.version=1.8.0_152-release -Dio.netty.noUnsafe=true -Djava.io.tmpdir=C:/Users/wj65651/.IntelliJIdea2018.1/system/compile-server/jvm_30d198c8/_temp_ -Djps.backward.ref.index.builder=true
jstat(JVM Statistics Monitoring):用于监视虚拟机运行时状态信息的命令,它可以显示出虚拟机进程中的类装载、内存、垃圾收集、JIT编译等运行数据。
命令格式:
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.
参数:
options参数:
$ jstat -options
-class
-compiler
-gc
-gccapacity
-gccause
-gcmetacapacity
-gcnew
-gcnewcapacity
-gcold
-gcoldcapacity
-gcutil
-printcompilation
类加载的行为统计,监视类装载、卸载数量、总空间以及耗费的时间。
示例:
$ jstat -class 8940
Loaded Bytes Unloaded Bytes Time
3152 5933.9 0 0.0 0.87
JIT编译器行为统计,输出JIT编译过的方法数量耗时等。
示例:
$ jstat -compiler 8940
Compiled Failed Invalid Time FailedType FailedMethod
1075 0 0 0.89 0
垃圾回收堆的行为统计。
示例:
$ jstat -gc 8940 250 3
S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU YGC YGCT FGC FGCT GCT
5120.0 5120.0 0.0 4439.7 32768.0 31665.7 86016.0 16464.0 13696.0 13279.9 1664.0 1584.6 1 0.004 0 0.000 0.004
5120.0 5120.0 0.0 4439.7 32768.0 31665.7 86016.0 16464.0 13696.0 13279.9 1664.0 1584.6 1 0.004 0 0.000 0.004
5120.0 5120.0 0.0 4439.7 32768.0 31665.7 86016.0 16464.0 13696.0 13279.9 1664.0 1584.6 1 0.004 0 0.000 0.004
C即Capacity 总容量,U即Used 已使用的容量,单位为KB。
各个垃圾回收代容量和他们相应的空间统计。
示例:
$ jstat -gccapacity 8940
NGCMN NGCMX NGC S0C S1C EC OGCMN OGCMX OGC OC MCMN MCMX MC CCSMN CCSMX CCSC YGC FGC
43008.0 238592.0 43008.0 5120.0 5120.0 32768.0 86016.0 478208.0 86016.0 86016.0 0.0 1060864.0 13696.0 0.0 1048576.0 1664.0 1 0
新生代垃圾回收统计。
示例:
$ jstat -gcnew 8940
S0C S1C S0U S1U TT MTT DSS EC EU YGC YGCT
5120.0 5120.0 0.0 4439.7 7 15 5120.0 32768.0 31665.7 1 0.004
新生代与其相应的内存空间的统计。
示例:
$ jstat -gcnewcapacity 8940
NGCMN NGCMX NGC S0CMX S0C S1CMX S1C ECMX EC YGC FGC
43008.0 238592.0 43008.0 79360.0 5120.0 79360.0 5120.0 237568.0 32768.0 1 0
老年代垃圾回收统计。
示例
$ jstat -gcold 8940
MC MU CCSC CCSU OC OU YGC FGC FGCT GCT
13696.0 13279.9 1664.0 1584.6 86016.0 16464.0 1 0 0.000 0.004
老生代与其相应的内存空间的统计。
示例:
$ jstat -gcoldcapacity 8940
OGCMN OGCMX OGC OC YGC FGC FGCT GCT
86016.0 478208.0 86016.0 86016.0 1 0 0.000 0.004
元数据空间统计。
示例:
$ jstat -gcmetacapacity 8940
MCMN MCMX MC CCSMN CCSMX CCSC YGC FGC FGCT GCT
0.0 1060864.0 13696.0 0.0 1048576.0 1664.0 1 0 0.000 0.004
圾收集统计概述(百分比)。
示例:
$ jstat -gcutil 8940
S0 S1 E O M CCS YGC YGCT FGC FGCT GCT
0.00 86.71 96.64 19.14 96.96 95.23 1 0.004 0 0.000 0.004
垃圾收集统计概述(同-gcutil),附加最近两次垃圾回收事件的原因。
$ jstat -gccause 13116
S0 S1 E O M CCS YGC YGCT FGC FGCT GCT LGCC GCC
58.73 0.00 82.00 47.46 81.01 85.00 18 2.539 8 1.685 4.224 Allocation Failure No GC
输出JIT编译的方法信息。
$ jstat -printcompilation 13116
Compiled Size Type Method
83 43 1 java/nio/Buffer position
jmap(Memory Map for Java):用于生成堆转储快照(一般称为heapdump或dump文件)。
jmap的作用并不仅仅是为了获取dump文件,它还可以查询finalize执行队列、Java堆和永久代的详细信息,如空间使用率、当前用的是哪种收集器等。和jinfo命令一样,jmap有不少功能在Windows平台下都是受限的,除了生成dump文件的-dump选项和用于查看每个类的实例、空间占用统计的-histo选项在所有操作系统都提供之外,其余选项都只能在Linux/Solaris下使用。
命令格式:
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
-clstats to print class loader 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
option参数:
示例:
$ jmap -heap 8940
Attaching to process ID 8940, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.172-b11
using thread-local object allocation.
Parallel GC with 4 thread(s)
Heap Configuration:
MinHeapFreeRatio = 0
MaxHeapFreeRatio = 100
MaxHeapSize = 734003200 (700.0MB)
NewSize = 44040192 (42.0MB)
MaxNewSize = 244318208 (233.0MB)
OldSize = 88080384 (84.0MB)
NewRatio = 2
SurvivorRatio = 8
MetaspaceSize = 21807104 (20.796875MB)
CompressedClassSpaceSize = 1073741824 (1024.0MB)
MaxMetaspaceSize = 17592186044415 MB
G1HeapRegionSize = 0 (0.0MB)
Heap Usage:
PS Young Generation
Eden Space:
capacity = 33554432 (32.0MB)
used = 32425712 (30.923568725585938MB)
free = 1128720 (1.0764312744140625MB)
96.63615226745605% used
From Space:
capacity = 5242880 (5.0MB)
used = 4546224 (4.3356170654296875MB)
free = 696656 (0.6643829345703125MB)
86.71234130859375% used
To Space:
capacity = 5242880 (5.0MB)
used = 0 (0.0MB)
free = 5242880 (5.0MB)
0.0% used
PS Old Generation
capacity = 88080384 (84.0MB)
used = 16859168 (16.078155517578125MB)
free = 71221216 (67.92184448242188MB)
19.14066133045015% used
5329 interned Strings occupying 483136 bytes.
jhat(JVM Heap Analysis Tool)命令与jmap搭配使用,来分析jmap生成的堆转储快照。jhat内置了一个微型的HTTP/HTML服务器,生成dump文件的分析结果后,可以在浏览器中查看。
jhat的分析功能相对来说比较简陋,VisualVM以及专业用于分析dump文件的Eclipse Memory Analyzer、IBM HeapAnalyzer等工具,都能实现比jhat更强大更专业的分析功能。
命令格式:
$ jhat -help
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"
jstack(Stack Trace for Java):用于生成虚拟机当前时刻的线程快照(一般称为threaddump或者javacore文件)。线程快照就是当前虚拟机内每一条线程正在执行的方法堆栈的集合,生成线程快照的主要目的是定位线程出现长时间停顿的原因,如线程间死锁、死循环、请求外部资源导致的长时间等待等都是导致线程长时间停顿的常见原因。线程出现停顿的时候通过jstack来查看各个线程的调用堆栈,就可以知道没有响应的线程到底在后台做些什么事情,或者等待着什么资源。
命令格式:
$ jstack -help
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
option参数:
示例:
$ jstack -l 8940
2018-12-04 15:50:27
Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.172-b11 mixed mode):
"NettythreadDeathWatcher-2-1" #14 daemon prio=1 os_prio=-2 tid=0x00000000591e6000 nid=0x1e30 waiting on condition [0x000000005b16f000]
java.lang.Thread.State: TIMED_WAITING (sleeping)
at java.lang.Thread.sleep(Native Method)
at io.netty.util.ThreadDeathWatcher$Watcher.run(ThreadDeathWatcher.java:152)
at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:138)
at java.lang.Thread.run(Thread.java:748)
Locked ownable synchronizers:
- None
... ...
"VM Thread" os_prio=2 tid=0x0000000054e84000 nid=0x37ac runnable
"GC task thread#0 (ParallelGC)" os_prio=0 tid=0x0000000002a03800 nid=0x4200 runnable
"GC task thread#1 (ParallelGC)" os_prio=0 tid=0x0000000002a05000 nid=0x3b48 runnable
"GC task thread#2 (ParallelGC)" os_prio=0 tid=0x0000000002a07000 nid=0x3a90 runnable
"GC task thread#3 (ParallelGC)" os_prio=0 tid=0x0000000002a08800 nid=0x2654 runnable
"VM Periodic Task Thread" os_prio=2 tid=0x00000000563c2800 nid=0x4208 waiting on condition
JNI global references: 255
版权说明 : 本文为转载文章, 版权归原作者所有 版权申明
原文链接 : https://morris131.blog.csdn.net/article/details/107883577
内容来源于网络,如有侵权,请联系作者删除!