jps指令能够列出正在运行的虚拟机进程,及这些进程的本地虚拟机唯一
ID(LVMID,Local Virtual Machine Identifier)
例如
[root@VM-8-2-centos ~]# jps
10692 Jps
16964 jar
选项 | 作用 |
---|---|
-q | 只输出id |
-m | 输出虚拟机进程启动时, 传递给main的参数 |
-l | 输出主类全名,如果启动的是jar包 |
-v | 输出虚拟机进程启动参数 |
[root@VM-8-2-centos ~]# jps -q
16964
11676
[root@VM-8-2-centos ~]# jps -m
11828 Jps -m
16964 jar --spring.profiles.active=prod --auth.formCheck=true
[root@VM-8-2-centos ~]# jps -l
16964 sign-0.0.1-SNAPSHOT.jar
12008 sun.tools.jps.Jps
[root@VM-8-2-centos ~]# jps -v
12401 Jps -Dapplication.home=/usr/local/jdk1.8.0_241 -Xms8m
16964 jar
jstat监视虚拟机各种运行状态信息的命令行工具,它将是运行期定位虚拟机性能问题的常用工具
选项 | 作用 |
---|---|
-class | 监视类加载数量、卸载数量、总空间,以及类装载所需时间 |
-gc | 监视Java堆的状态 |
-gcutil | 监视内容于-gc类似,但主要关注空间使用百分比 |
-gccause | 和-gcutil一样,但会输出上一次gc原因 |
【vmid】可以通过jps -l
获取
[root@VM-8-2-centos dian-xhf]# jstat -class 16964
Loaded Bytes Unloaded Bytes Time
10284 19390.6 0 0.0 6.60
[root@VM-8-2-centos dian-xhf]# jstat -gc 16964
S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU YGC YGCT FGC FGCT GCT
12288.0 8192.0 0.0 0.0 147968.0 26136.3 55808.0 25116.2 59136.0 56068.7 7680.0 7058.2 15 0.223 3 0.341 0.564
-jstat -gcutil 【vmid】 【查看Java堆占用百分比】
[root@VM-8-2-centos dian-xhf]# jstat -gcutil 16964
S0 S1 E O M CCS YGC YGCT FGC FGCT GCT
0.00 0.00 17.66 45.00 94.81 91.90 15 0.223 3 0.341 0.564
- S0 幸存0区域
- S1 幸存1区域
- E 伊甸园区
- O 老年区
- M 元空间 【有可能是P,表示永久代。具体的和jdk版本有关,笔者jdk版本是8】
- YGC 年轻代的GC,也就是Minor GC ,轻量GC ,
次数15
- YGCT 轻量GC所耗时间
0.223
秒- FGC 重量级GC次数
3
- FGCT 重量级GC所耗时间
0.341
秒- GCT 所有GC所耗费时间
0.564
秒
jinfo能实时查看和调整虚拟机各项参数
jps -v 可以查询虚拟机启动时,
显示指定的参数
,但如果想查看默认的参数,可以通过-flag的方式指定查看
选项 | 作用 |
---|---|
-flag | 打印vm的参数,name的值 |
-flag [+|-] | 开启或禁止vm的name参数 |
-flag |
设置虚拟机参数name=flag |
-flags | 打印虚拟机参数 |
-sysprops | 打印Java系统的配置 |
[root@VM-8-2-centos dian-xhf]# jinfo -flags 16964
Attaching to process ID 16964, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.241-b07
Non-default VM flags: -XX:CICompilerCount=2 -XX:InitialHeapSize=33554432 -XX:MaxHeapSize=524288000 -XX:MaxNewSize=174587904 -XX:MinHeapDeltaBytes=524288 -XX:NewSize=11010048 -XX:OldSize=22544384 -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseParallelGC
Command line:
[root@VM-8-2-centos dian-xhf]# jinfo -flag CICompilerCount 16964
-XX:CICompilerCount=2
[root@VM-8-2-centos dian-xhf]# jinfo -sysprops 16964
Attaching to process ID 16964, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.241-b07
java.runtime.name = Java(TM) SE Runtime Environment
java.vm.version = 25.241-b07
sun.boot.library.path = /usr/local/jdk1.8.0_241/jre/lib/amd64
java.protocol.handler.pkgs = org.springframework.boot.loader
java.vendor.url = http://java.oracle.com/
java.vm.vendor = Oracle Corporation
path.separator = :
file.encoding.pkg = sun.io
java.vm.name = Java HotSpot(TM) 64-Bit Server VM
sun.os.patch.level = unknown
sun.java.launcher = SUN_STANDARD
user.country = US
user.dir = /usr/local/xhf/sign
java.vm.specification.name = Java Virtual Machine Specification
PID = 16964
java.runtime.version = 1.8.0_241-b07
java.awt.graphicsenv = sun.awt.X11GraphicsEnvironment
os.arch = amd64
java.endorsed.dirs = /usr/local/jdk1.8.0_241/jre/lib/endorsed
CONSOLE_LOG_CHARSET = UTF-8
line.separator =
java.io.tmpdir = /tmp
java.vm.specification.vendor = Oracle Corporation
os.name = Linux
FILE_LOG_CHARSET = UTF-8
sun.jnu.encoding = UTF-8
java.library.path = /usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
spring.beaninfo.ignore = true
java.specification.name = Java Platform API Specification
java.class.version = 52.0
sun.management.compiler = HotSpot 64-Bit Tiered Compilers
os.version = 3.10.0-1160.88.1.el7.x86_64
user.home = /root
user.timezone = Asia/Shanghai
catalina.useNaming = false
java.awt.printerjob = sun.print.PSPrinterJob
file.encoding = UTF-8
java.specification.version = 1.8
catalina.home = /tmp/tomcat.9001.5870235700103250174
user.name = root
java.class.path = sign-0.0.1-SNAPSHOT.jar
java.vm.specification.version = 1.8
sun.arch.data.model = 64
sun.java.command = sign-0.0.1-SNAPSHOT.jar --spring.profiles.active=prod --auth.formCheck=true
java.home = /usr/local/jdk1.8.0_241/jre
user.language = en
java.specification.vendor = Oracle Corporation
awt.toolkit = sun.awt.X11.XToolkit
java.vm.info = mixed mode
java.version = 1.8.0_241
java.ext.dirs = /usr/local/jdk1.8.0_241/jre/lib/ext:/usr/java/packages/lib/ext
sun.boot.class.path = /usr/local/jdk1.8.0_241/jre/lib/resources.jar:/usr/local/jdk1.8.0_241/jre/lib/rt.jar:/usr/local/jdk1.8.0_241/jre/lib/sunrsasign.jar:/usr/local/jdk1.8.0_241/jre/lib/jsse.jar:/usr/local/jdk1.8.0_241/jre/lib/jce.jar:/usr/local/jdk1.8.0_241/jre/lib/charsets.jar:/usr/local/jdk1.8.0_241/jre/lib/jfr.jar:/usr/local/jdk1.8.0_241/jre/classes
java.awt.headless = true
java.vendor = Oracle Corporation
catalina.base = /tmp/tomcat.9001.5870235700103250174
file.separator = /
java.vendor.url.bug = http://bugreport.sun.com/bugreport/
sun.io.unicode.encoding = UnicodeLittle
sun.cpu.endian = little
sun.cpu.isalist =
jmap命令用于生成堆转储快照
选项 | 作用 |
---|---|
-dump | 生成Java堆内存快照,格式为-dump:[live,]format=b,file= |
-heap | 显示Java堆详细信息 |
[root@VM-8-2-centos dian-xhf]# jmap -dump:format=b,file=dian.bin 13056
Dumping heap to /usr/local/xhf/dian-xhf/dian.bin ...
Heap dump file created
[root@VM-8-2-centos dian-xhf]# ls
backup demo-0.0.1-SNAPSHOT.jar dian.bin LOG_PATH_IS_UNDEFINED start.sh stop.sh
jmap
option的官方介绍
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: 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= dump heap to
Example: jmap -dump:live,format=b,file=heap.bin
-F force. Use with -dump: or -histo
to force a heap dump or histogram when does not
respond. The "live" suboption is not supported
in this mode.
-h | -help to print this help message
-J to pass directly to the runtime system
JDK提供jhat(JVM Heap Analysis Tool)命令与jmap搭配使用,来分析jmap生成的堆转储快照。jhat内置了一个微型的HTTP/Web服务器,生成堆转储快照的分析结果后,可以在浏览器中查看
基本不用,除非没有其它工具,因此本文不在记录相关指令
jstack(Stack Trace for Java)命令用于生成虚拟机当前时刻的线程快照。
选项 | 作用 |
---|---|
-F | 强制输出线程堆栈 |
-m | 打印Java和本地方法栈(c/c++的栈信息) |
-l | 除了堆信息,打印额外的锁信息 |