常用命令查找文档站点:https://docs.oracle.com/javase/8/docs/technotes/tools/unix/index.html
输出所有参数的名称和默认值,默认不包括Diagnostic和Experimental的参数。可以配合
-XX:+UnlockDiagnosticVMOptions
和-XX:UnlockExperimentalVMOptions
使用
注意:这里列举出来的所有参数值,大体分为两类。一类是 “=” 的表示默认值;一类是 “ := ” 的表示是被用户或者JVM修改后的值。
查看使用格式:
jps -help
usage: jps [-help]
jps [-q] [-mlvV] []
Definitions:
: [:]
$> jps -q
28680
23789
23651
特别注意,在嵌入式jvm上可能是null
$> jps -m
28715 Jps -m
23789 BossMain
23651 Resin -socketwait 32768 -stdout /data/aoxj/resin/log/stdout.log -stderr /data/aoxj/resin/log/stderr.log
# -l 输出应用程序main class的完整package名 或者 应用程序的jar文件完整路径名
$> jps -l
28729 sun.tools.jps.Jps
23789 com.asiainfo.aimc.bossbi.BossMain
23651 com.caucho.server.resin.Resin
$> jps -v
23789 BossMain
28802 Jps -Denv.class.path=/data/aoxj/bossbi/twsecurity/java/trustwork140.jar:/data/aoxj/bossbi/twsecurity/java/:/data/aoxj/bossbi/twsecurity/java/twcmcc.jar:/data/aoxj/jdk15/lib/rt.jar:/data/aoxj/jdk15/lib/tools.jar -Dapplication.home=/data/aoxj/jdk15 -Xms8m
23651 Resin -Xss1m -Dresin.home=/data/aoxj/resin -Dserver.root=/data/aoxj/resin -Djava.util.logging.manager=com.caucho.log.LogManagerImpl -Djavax.management.builder.initial=com.caucho.jmx.MBeanServerBuilderImpl
jinfo
是 JDK
自带的命令,可以用来查看正在运行的 java
应用程序的扩展参数,包括Java System属性和JVM命令行参数;也可以动态的修改正在运行的 JVM
一些参数。当系统崩溃时,jinfo可以从core文件里面知道崩溃的Java应用程序的配置信息。基本语法是:jinfo [ option ] pid
Option:
选项 | 选项说明 |
---|---|
no option | 输出全部的参数和系统属性 |
-flag name | 输出对应名称的参数 |
-flag [+/-] name | 开启或者关闭对应名称的参数,只有被标记为 manageable 的参数才可以被动态修改 |
-flag name=value | 设定对应名称的参数 |
-flags | 输出全部的参数 |
-sysprops | 输出系统属性 |
#输入
jinfo -flags 7663
#输出
Attaching to process ID 7663, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.121-b13
Non-default VM flags: -XX:CICompilerCount=4 -XX:InitialHeapSize=268435456 -XX:MaxHeapSize=4294967296 -XX:MaxNewSize=1431306240 -XX:MinHeapDeltaBytes=524288 -XX:NewSize=89128960 -XX:OldSize=179306496 -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseFastUnorderedTimeStamps -XX:+UseParallelGC
Command line: -javaagent:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=49834:/Applications/IntelliJ IDEA.app/Contents/bin -Dfile.encoding=UTF-8
其中,
不包含上图的前缀 -XX:
等,不是 jinfo -flag -XX:NewSize 7663
,而是 jinfo -flag NewSize 7663
,不包含 -XX:
。
#输入
jinfo -flag NewSize 7663
#输出
-XX:NewSize=89128960
用于打开或关闭指定的参数
打印当前java进程中设定的系统环境参数
#输入
jinfo -sysprops 7663
#输出
Attaching to process ID 7663, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.121-b13
java.runtime.name = Java(TM) SE Runtime Environment
java.vm.version = 25.121-b13
sun.boot.library.path = /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib
gopherProxySet = false
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 = CN
user.dir = /Users/davis/workspace/intellij/cw-javaagent-demo
java.vm.specification.name = Java Virtual Machine Specification
java.runtime.version = 1.8.0_121-b13
java.awt.graphicsenv = sun.awt.CGraphicsEnvironment
os.arch = x86_64
java.endorsed.dirs = /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/endorsed
line.separator =
java.io.tmpdir = /var/folders/5n/6g464jd97r13x39t5w69ybfr0000gn/T/
java.vm.specification.vendor = Oracle Corporation
os.name = Mac OS X
sun.jnu.encoding = UTF-8
java.library.path = /Users/davis/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.
java.specification.name = Java Platform API Specification
java.class.version = 52.0
sun.management.compiler = HotSpot 64-Bit Tiered Compilers
os.version = 10.15.5
http.nonProxyHosts = local|*.local|169.254/16|*.169.254/16
user.home = /Users/davis
user.timezone = Asia/Shanghai
java.awt.printerjob = sun.lwawt.macosx.CPrinterJob
file.encoding = UTF-8
java.specification.version = 1.8
user.name = davis
java.class.path = /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/deploy.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/ext/cldrdata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/ext/dnsns.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/ext/jaccess.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/ext/jfxrt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/ext/localedata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/ext/nashorn.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/ext/sunec.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/ext/sunjce_provider.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/ext/sunpkcs11.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/ext/zipfs.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/javaws.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/jce.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/jfr.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/jfxswt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/jsse.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/management-agent.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/plugin.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/resources.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/rt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/lib/ant-javafx.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/lib/dt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/lib/javafx-mx.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/lib/jconsole.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/lib/packager.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/lib/sa-jdi.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/lib/tools.jar:/Users/davis/workspace/intellij/cw-javaagent-demo/target/classes:/Users/davis/maven/net/sourceforge/jtds/jtds/1.2.6/jtds-1.2.6.jar:/Users/davis/maven/jstl/jstl/1.2/jstl-1.2.jar:/Users/davis/maven/taglibs/standard/1.1.2/standard-1.1.2.jar:/Users/davis/maven/org/mybatis/mybatis/3.2.8/mybatis-3.2.8.jar:/Users/davis/maven/org/mybatis/mybatis-spring/1.2.2/mybatis-spring-1.2.2.jar:/Users/davis/maven/redis/clients/jedis/2.5.2/jedis-2.5.2.jar:/Users/davis/maven/org/apache/commons/commons-pool2/2.0/commons-pool2-2.0.jar:/Users/davis/maven/mysql/mysql-connector-java/5.1.39/mysql-connector-java-5.1.39.jar:/Users/davis/maven/org/springframework/spring-aop/4.1.1.RELEASE/spring-aop-4.1.1.RELEASE.jar:/Users/davis/maven/aopalliance/aopalliance/1.0/aopalliance-1.0.jar:/Users/davis/maven/org/springframework/spring-aspects/4.1.1.RELEASE/spring-aspects-4.1.1.RELEASE.jar:/Users/davis/maven/org/aspectj/aspectjweaver/1.8.2/aspectjweaver-1.8.2.jar:/Users/davis/maven/org/springframework/spring-beans/4.1.1.RELEASE/spring-beans-4.1.1.RELEASE.jar:/Users/davis/maven/org/springframework/spring-context/4.1.1.RELEASE/spring-context-4.1.1.RELEASE.jar:/Users/davis/maven/org/springframework/spring-context-support/4.1.1.RELEASE/spring-context-support-4.1.1.RELEASE.jar:/Users/davis/maven/org/springframework/spring-core/4.1.1.RELEASE/spring-core-4.1.1.RELEASE.jar:/Users/davis/maven/commons-logging/commons-logging/1.1.3/commons-logging-1.1.3.jar:/Users/davis/maven/org/springframework/spring-expression/4.1.1.RELEASE/spring-expression-4.1.1.RELEASE.jar:/Users/davis/maven/org/springframework/spring-instrument/4.1.1.RELEASE/spring-instrument-4.1.1.RELEASE.jar:/Users/davis/maven/org/springframework/spring-instrument-tomcat/4.1.1.RELEASE/spring-instrument-tomcat-4.1.1.RELEASE.jar:/Users/davis/maven/org/springframework/spring-jdbc/4.1.1.RELEASE/spring-jdbc-4.1.1.RELEASE.jar:/Users/davis/maven/org/springframework/spring-jms/4.1.1.RELEASE/spring-jms-4.1.1.RELEASE.jar:/Users/davis/maven/org/springframework/spring-messaging/4.1.1.RELEASE/spring-messaging-4.1.1.RELEASE.jar:/Users/davis/maven/org/springframework/spring-orm/4.1.1.RELEASE/spring-orm-4.1.1.RELEASE.jar:/Users/davis/maven/org/springframework/spring-oxm/4.1.1.RELEASE/spring-oxm-4.1.1.RELEASE.jar:/Users/davis/maven/org/springframework/spring-test/4.1.1.RELEASE/spring-test-4.1.1.RELEASE.jar:/Users/davis/maven/org/springframework/spring-tx/4.1.1.RELEASE/spring-tx-4.1.1.RELEASE.jar:/Users/davis/maven/org/springframework/spring-web/4.1.1.RELEASE/spring-web-4.1.1.RELEASE.jar:/Users/davis/maven/org/springframework/spring-webmvc/4.1.1.RELEASE/spring-webmvc-4.1.1.RELEASE.jar:/Users/davis/maven/org/springframework/spring-webmvc-portlet/4.1.1.RELEASE/spring-webmvc-portlet-4.1.1.RELEASE.jar:/Users/davis/maven/org/springframework/spring-websocket/4.1.1.RELEASE/spring-websocket-4.1.1.RELEASE.jar:/Users/davis/maven/commons-fileupload/commons-fileupload/1.3.1/commons-fileupload-1.3.1.jar:/Users/davis/maven/commons-io/commons-io/2.2/commons-io-2.2.jar:/Users/davis/maven/commons-dbcp/commons-dbcp/1.2.2/commons-dbcp-1.2.2.jar:/Users/davis/maven/commons-pool/commons-pool/1.4/commons-pool-1.4.jar:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar
java.vm.specification.version = 1.8
sun.arch.data.model = 64
sun.java.command = com.cw.tsb.jvm.JVMTest
java.home = /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre
user.language = zh
java.specification.vendor = Oracle Corporation
awt.toolkit = sun.lwawt.macosx.LWCToolkit
java.vm.info = mixed mode
java.version = 1.8.0_121
java.ext.dirs = /Users/davis/Library/Java/Extensions:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/ext:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java
sun.boot.class.path = /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/resources.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/rt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/sunrsasign.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/jsse.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/jce.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/jfr.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/classes
java.vendor = Oracle Corporation
file.separator = /
java.vendor.url.bug = http://bugreport.sun.com/bugreport/
sun.io.unicode.encoding = UnicodeBig
sun.cpu.endian = little
socksNonProxyHosts = local|*.local|169.254/16|*.169.254/16
ftp.nonProxyHosts = local|*.local|169.254/16|*.169.254/16
sun.cpu.isalist =
Usage:
jstack [-l]
(to connect to running process)
jstack -F [-m] [-l]
(to connect to a hung process)
jstack [-m] [-l]
(to connect to a core file)
Options:
-F 强制打印线程栈信息,在jstack 命令没有响应的时候添加该选项可以实现强制打印
-m (mix)混合模式,可以打印 Java 栈和本地方法栈
-l (long listing)长列表模式. 额外打印关于锁的信息
线程状态转移图:
Java语言定义了6种线程池状态:
Dump文件的线程状态一般其实就以下3种:
Monitor的工作原理图如下:
jmap(Java Virtual Machine Memory Map)是JDK提供的一个可以生成Java虚拟机的堆转储快照dump文件的命令行工具。除此以外,jmap命令还可以查看finalize执行队列、Java堆和方法区的详细信息,比如空间使用率、当前使用的什么垃圾回收器、分代情况等等。
命令语法:
jmap [options] pid
命令参数说明:
option
:jmap命令的可选参数。如果没有指定这个参数,jinfo命令会显示Java虚拟机进程的内存映像信息,如下图:pid
:要打印配置信息的Java虚拟机的进程ID。想要要获取运行的Java虚拟机进程的列表,可以使用ps命令(Linux系统中)或tasklist命令(Windows系统中),如果Java虚拟机进程没有在单独的docker实例中运行,可以使用jps命令。
显示Java堆的如下信息:
显示Java堆中对象的统计信息,包括:对象数量、占用内存大小(单位:字节)和类的完全限定名。比如:
要获得某个对象的大小,可以将其总大小除以该对象类型的数量。如果指定了live
参数,则只计算活动的对象。比如:
显示Java堆中元空间的类加载器的统计信息,包括:
null
。显示在F-Queue中等待Finalizer线程执行finalize方法的对象。比如:
生成Java虚拟机的堆转储快照dump文件。具体说明如下:
live
参数是可选的,如果指定,则只转储堆中的活动对象;如果没有指定,则转储堆中的所有对象。format=b
表示以hprof二进制格式转储Java堆的内存。file=
用于指定快照dump文件的文件名。强制模式。如果指定的pid没有响应,可以配合-dump
或-histo
一起使用。此模式下,不支持live参数。比如:
命令用法:jstat [-命令选项] [vmid] [间隔时间/毫秒] [查询次数]
C:\Users\Administrator>jstat -help
Usage: jstat -help|-options
jstat -
option 可以从下面参数中选择
jstat -options