jps 查看进程信息
查看当前所有的java进程信息,包括PID、jvm启动参数、main方法参数等。
jps -lvm
jstack 查看线程信息
可以列出线程状态,如下,可见为线程取一个恰当名字的重要性,信息中包含线程状态(WAITING ),以及当前栈信息。如果阻塞的话还会指出阻塞原因(parking to wait for…)。
"TP_PARSE-1-10" #257 prio=5 os_prio=0 tid=0x00007f9908140800 nid=0xdf3 waiting on condition [0x00007f98e62e1000]
java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x00000007014be638> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:144)
at java.lang.Thread.run(Thread.java:748)
Locked ownable synchronizers:
- None
jmap
- 输出堆快照
jmap -dump:live,file=/jmap1 pid
去掉:live可以输出全部
生成的文件可以使用window的jvisualvm.exe打开,这个程序在jdk->bin目录下 - 自动输出
jvm启动参数增加:
HeapDumpOnOutOfMemoryError 和HeapDumpPath控制
-XX:+PrintGCDetails -XX:+PrintGCTimeStamps -Xloggc:../logs/tomcat_gc.log -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=../logs/tomcat_dump.log"
jinfo 输出、修改jvm参数
在java中可以通过System.getProperties()来获取这些信息
可以通过jinfo -flags pid 来查看赋值过的参数
Attaching to process ID 1506, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.221-b11
Java System Properties:
java.vendor = Oracle Corporation
sun.java.launcher = SUN_STANDARD
catalina.base = /opt/dsa/tomcat
sun.management.compiler = HotSpot 64-Bit Tiered Compilers
catalina.useNaming = true
jnidispatch.path = /opt/dsa/tomcat/temp/jna-3506402/jna580278896828689041.tmp
os.name = Linux
sun.boot.class.path = /usr/java/jdk1.8.0_221-amd64/jre/lib/resources.jar:/usr/java/jdk1.8.0_221-amd64/jre/lib/rt.jar:/usr/java/jdk1.8.0_221-amd64/jre/lib/sunrsasign.jar:/usr/java/jdk1.8.0_221-amd64/jre/lib/jsse.jar:/usr/java/jdk1.8.0_221-amd64/jre/lib/jce.jar:/usr/java/jdk1.8.0_221-amd64/jre/lib/charsets.jar:/usr/java/jdk1.8.0_221-amd64/jre/lib/jfr.jar:/usr/java/jdk1.8.0_221-amd64/jre/classes
java.util.logging.config.file = /opt/dsa/tomcat/conf/logging.properties
java.vm.specification.vendor = Oracle Corporation
java.runtime.version = 1.8.0_221-b11
jna.loaded = true
user.name = root
tomcat.util.scan.StandardJarScanFilter.jarsToScan = log4j-taglib*.jar,log4j-web*.jar,log4javascript*.jar,slf4j-taglib*.jar
shared.loader =
tomcat.util.buf.StringCache.byte.enabled = true
user.language = en
java.naming.factory.initial = org.apache.naming.java.javaURLContextFactory
sun.boot.library.path = /usr/java/jdk1.8.0_221-amd64/jre/lib/amd64
jdk.tls.ephemeralDHKeySize = 2048
java.version = 1.8.0_221
java.util.logging.manager = org.apache.juli.ClassLoaderLogManager
user.timezone = Asia/Shanghai
sun.arch.data.model = 64
java.util.concurrent.ForkJoinPool.common.threadFactory = org.apache.catalina.startup.SafeForkJoinWorkerThreadFactory
java.endorsed.dirs = /usr/java/jdk1.8.0_221-amd64/jre/lib/endorsed
sun.cpu.isalist =
sun.jnu.encoding = UTF-8
file.encoding.pkg = sun.io
package.access = sun.,org.apache.catalina.,org.apache.coyote.,org.apache.jasper.,org.apache.tomcat.
file.separator = /
java.specification.name = Java Platform API Specification
java.class.version = 52.0
user.country = US
java.home = /usr/java/jdk1.8.0_221-amd64/jre
java.vm.info = mixed mode
os.version = 3.10.0-1160.el7.x86_64
sun.font.fontmanager = sun.awt.X11FontManager
path.separator = :
java.vm.version = 25.221-b11
java.protocol.handler.pkgs = org.apache.catalina.webresources
java.awt.printerjob = sun.print.PSPrinterJob
sun.io.unicode.encoding = UnicodeLittle
awt.toolkit = sun.awt.X11.XToolkit
package.definition = sun.,java.,org.apache.catalina.,org.apache.coyote.,org.apache.jasper.,org.apache.naming.,org.apache.tomcat.
java.naming.factory.url.pkgs = org.apache.naming
user.home = /root
org.apache.catalina.security.SecurityListener.UMASK = 0027
java.specification.vendor = Oracle Corporation
tomcat.util.scan.StandardJarScanFilter.jarsToSkip = annotations-api.jar,ant-junit*.jar,ant-launcher.jar,ant.jar,asm-*.jar,aspectj*.jar,bootstrap.jar,catalina-ant.jar,catalina-ha.jar,catalina-ssi.jar,catalina-storeconfig.jar,catalina-tribes.jar,catalina.jar,cglib-*.jar,cobertura-*.jar,commons-beanutils*.jar,commons-codec*.jar,commons-collections*.jar,commons-daemon.jar,commons-dbcp*.jar,commons-digester*.jar,commons-fileupload*.jar,commons-httpclient*.jar,commons-io*.jar,commons-lang*.jar,commons-logging*.jar,commons-math*.jar,commons-pool*.jar,dom4j-*.jar,easymock-*.jar,ecj-*.jar,el-api.jar,geronimo-spec-jaxrpc*.jar,h2*.jar,hamcrest-*.jar,hibernate*.jar,httpclient*.jar,icu4j-*.jar,jasper-el.jar,jasper.jar,jaspic-api.jar,jaxb-*.jar,jaxen-*.jar,jdom-*.jar,jetty-*.jar,jmx-tools.jar,jmx.jar,jsp-api.jar,jstl.jar,jta*.jar,junit-*.jar,junit.jar,log4j*.jar,mail*.jar,objenesis-*.jar,oraclepki.jar,oro-*.jar,servlet-api-*.jar,servlet-api.jar,slf4j*.jar,taglibs-standard-spec-*.jar,tagsoup-*.jar,tomcat-api.jar,tomcat-coyote.jar,tomcat-dbcp.jar,tomcat-i18n-*.jar,tomcat-jdbc.jar,tomcat-jni.jar,tomcat-juli-adapters.jar,tomcat-juli.jar,tomcat-util-scan.jar,tomcat-util.jar,tomcat-websocket.jar,tools.jar,websocket-api.jar,wsdl4j*.jar,xercesImpl.jar,xml-apis.jar,xmlParserAPIs-*.jar,xmlParserAPIs.jar,xom-*.jar
java.library.path = /usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
java.vendor.url = http://java.oracle.com/
java.vm.vendor = Oracle Corporation
common.loader = "${catalina.base}/lib","${catalina.base}/lib/*.jar","${catalina.home}/lib","${catalina.home}/lib/*.jar"
java.runtime.name = Java(TM) SE Runtime Environment
sun.java.command = org.apache.catalina.startup.Bootstrap start
java.class.path = /opt/dsa/tomcat/bin/bootstrap.jar:/opt/dsa/tomcat/bin/tomcat-juli.jar
java.vm.specification.name = Java Virtual Machine Specification
java.vm.specification.version = 1.8
catalina.home = /opt/dsa/tomcat
sun.cpu.endian = little
sun.os.patch.level = unknown
java.io.tmpdir = /opt/dsa/tomcat/temp
java.vendor.url.bug = http://bugreport.sun.com/bugreport/
server.loader =
jna.platform.library.path = /usr/lib64:/lib64:/usr/lib:/lib:/usr/local/openssl/lib:/usr/lib64/mysql:/usr/lib64//bind9-export
os.arch = amd64
java.awt.graphicsenv = sun.awt.X11GraphicsEnvironment
java.ext.dirs = /usr/java/jdk1.8.0_221-amd64/jre/lib/ext:/usr/java/packages/lib/ext
user.dir = /opt/dsa/tomcat/bin
line.separator =
java.vm.name = Java HotSpot(TM) 64-Bit Server VM
ignore.endorsed.dirs =
file.encoding = UTF-8
java.specification.version = 1.8
VM Flags:
Non-default VM flags: -XX:CICompilerCount=3 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=null -XX:InitialHeapSize=3221225472 -XX:MaxHeapSize=3221225472 -XX:MaxNewSize=1073741824 -XX:MinHeapDeltaBytes=524288 -XX:NewSize=1073741824 -XX:OldSize=2147483648 -XX:+PrintGC -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseFastUnorderedTimeStamps -XX:+UseParallelGC
Command line: -Djava.util.logging.config.file=/opt/dsa/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Xms3072m -Xmx3072m -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -Xloggc:../logs/tomcat_gc.log -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=../logs/tomcat_dump.log -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 -Dignore.endorsed.dirs= -Dcatalina.base=/opt/dsa/tomcat -Dcatalina.home=/opt/dsa/tomcat -Djava.io.tmpdir=/opt/dsa/tomcat/temp
jstat 输出jvm统计信息(gc、堆信息等)
- 输出堆信息,每1000毫秒一次,共输出20次
jstat -gccapacity 1506 1000 10
NGCMN NGCMX NGC S0C S1C EC OGCMN OGCMX OGC OC MCMN MCMX MC CCSMN CCSMX CCSC YGC FGC
1048576.0 1048576.0 1048576.0 11264.0 11264.0 1026048.0 2097152.0 2097152.0 2097152.0 2097152.0 0.0 1136640.0 98688.0 0.0 1048576.0 10624.0 479 4
NCGCMN 年轻代初始化大小
NGCMX 年轻代最大大小
NGC 年轻代当前大小
S0C 第一幸存区大小
S1C 第二幸存区大小
EC 新生代(伊甸园)大小
OGCMN 老年代初始化大小
OGCMX老年代最大大小
OGC 所有老年代总大小(遗憾的是只有一个老年代)
OC 老年代大小
MCMN 元空间初始化大小
MCMX 元空间最大大小
MC 元空间大小
YGC YoungGC次数
FGC FullGC次数
- 输出pid为1506的虚拟机堆统计信息,每1000毫秒输出一次,每5条输出一次标题,共输出20条
jstat -gc -h 5 -t 1506 1000 20
Timestamp S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU YGC YGCT FGC FGCT GCT
350194.8 11264.0 11264.0 0.0 11261.3 1026048.0 81948.3 2097152.0 132982.0 98688.0 94216.4 10624.0 9872.7 479 4.414 4 0.716 5.130
大小单位均为kb
S0C:第一个幸存区的大小
S1C:第二个幸存区的大小
S0U:第一个幸存区的使用大小
S1U:第二个幸存区的使用大小
EC:伊甸园区的大小
EU:伊甸园区的使用大小
OC:老年代大小
OU:老年代使用大小
MC:方法区大小
MU:方法区使用大小
CCSC:压缩类空间大小
CCSU:压缩类空间使用大小
YGC:年轻代垃圾回收次数
YGCT:年轻代垃圾回收消耗时间
FGC:老年代垃圾回收次数
FGCT:老年代垃圾回收消耗时间
GCT:垃圾回收消耗总时间
- 输出gc原因及gc过程
每隔2000毫秒输出pid为1506的虚拟机gc信息
jstat -gccause 1506 2000
S0 S1 E O M CCS YGC YGCT FGC FGCT GCT LGCC GCC
80.12 0.00 35.39 6.22 95.35 92.81 478 4.403 4 0.716 5.119 Allocation Failure No GC
S0 S0取占用比
S1 S1区占用比
E 伊甸园占用比
O 老年区占用比
M 元数据区占用比
CC 压缩类占用比
YGC YoungGC发生的次数
YGCT 所有的YoungGC总耗时
FGC FullGC发生的次数
FGCT 所有的FullGC总耗时
GCT 所有GC耗时
LGCC 上一次GC原因
GCC 当前正在进行的GC原因
jmap 生成内存快照
java -XX:+PrintFlags* (不怎么用,可能会在未来取消的命令)
- java -XX:+PrintFlagsFinal
查看jvm参数最终值,比如ThreadStackSize等 - java -XX:+PrintFlagsInitial
查看jvm参数初始值 - java -XX:+PrintCommandLineFlags
查看被修改过的参数