最近一直在上项目,导致博主天天加班幸福感爆棚,有木有。
平时一直没有关注过JVM,最近上了一个新的项目,它对内存的需求量比较大,导致目前项目在用的JVM参数不能满足他的需求。起初还没发现是这方面问题,后来在启动的时候报错了,一报错不要紧,要紧就要紧在博主我要调整JVM的参数了。调整参数也不要紧,更要紧的是调不对很让我着急。
因此,我就百谷了下,对JVM的相关内容突击了一下,受益匪浅啊。
废话不扯了,下面就是我的学习笔记啦。本篇博文就和大家分享下平时去分析JVM以及排故障时需要用到的几款工具。
目前常用的几款工具有jps、jinfo、jstack、jstat和jmap等,这里就介绍这几款喽。
jps 用来查看所有的jvm进程,包括进程ID,进程启动的路径等。博主平时都是用ps过滤的。 jinfo负责观察进程运行环境参数,包括Java System属性和JVM命令行参数。当系统崩溃时,jinfo可以从core文件里面知道崩溃的Java应用程序的配置信息 jstack 用来观察 jvm 中当前所有线程的运行情况和线程当前状态。 当系统崩溃时,如果java程序崩溃生成core文件,jstack工具可以用来获得core文件的java sta ck和native stack的信息,从而可以轻松地知道java程序是如何崩溃和在程序何处发生问题。 当系统hung住时,jstack工具可以附属到正在运行的java程序中,看到当时运行的java程序的java stack和native stack的信息, 如果现在运行的java程序呈现hung的状态,jstack是非常有用的。 jstat 利用JVM内建的指令对Java应用程序的资源和性能进行实时的命令行的监控,包括了对进程的classloader,compiler,gc情况;可以用来监视VM内存内的各种堆和非堆的大小及其内存使用量,以及加载类的数量。 jmap 用来监视进程运行中的jvm物理内存的占用情况,该进程内存内,所有对象的情况,例如产生了哪些对象,对象数量。当系统崩溃时,jmap 可以从core文件或进程中获得内存的具体匹配情况,包括Heap size, Perm size等。
以上就是几个常用工具的简介喽,平时工作环境中(linux环境),通过这几个命令再结合常用的文本处理工具(sed、awk)可以快速查看到自己感兴趣的数据,是不是很赞啊。
下面就针对每一个工具,展开进行介绍。
=========================== 分 割 线 ===============================
JPS命令
jps(Java Virtual Machine Process Status Tool)是JDK 1.5提供的一个显示当前所有java进程pid的命令,简单实用,非常适合在linux/unix平台上简单察看当前java进程的一些简单情况。
ps命令我们经常用到,这个命令主要是用来显示当前系统的进程情况。比如有哪些进程及其 id。jps命令也是一样,它的作用是显示当前系统的java进程情况及其id号。我们可以通过它来查看我们到底启动了几个java进程(因为每一个java程序都会独占一个java虚拟机实例)以及他们的进程号(为下面几个程序做准备),并可通过opt来查看这些进程的详细启动参数。
用法:
jps [-q] [-mlvV] []
常用选项:
-q 安静,只显示pid,不显示class名称,jar文件名和传递给main 方法的参数 -m 输出传递给main 方法的参数,在嵌入式jvm上可能是null -l (显示完整路径) -v (显示传递给JVM的命令行参数) -V (显示通过flag文件传递给JVM的参数) hostid是主机id,默认localhost
例子:
[root@autorepair-web01-rj autorepair-web01-rj.btr /home/apps/repair-web] # jps 4214 Bootstrap 18096 jar 26423 Jps [root@autorepair-web01-rj autorepair-web01-rj.btr /home/apps/repair-web] # jps -q 4214 18096 26438 [root@autorepair-web01-rj autorepair-web01-rj.btr /home/apps/repair-web] # jps -m 4214 Bootstrap start 18096 jar 26453 Jps -m [root@autorepair-web01-rj autorepair-web01-rj.btr /home/apps/repair-web] # jps -l 4214 org.apache.catalina.startup.Bootstrap 18096 logmon.jar 26468 sun.tools.jps.Jps [root@autorepair-web01-rj autorepair-web01-rj.btr /home/apps/repair-web] # jps -v 4214 Bootstrap -Djava.util.logging.config.file=/usr/local/apache-tomcat-7.0.53/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Xms2560m -Xmx2560m -Xmn680m -Xss256k -XX:PermSize=240m -XX:MaxPermSize=240m -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:CMSFullGCsBeforeCompaction=5 -XX:+UseCMSCompactAtFullCollection -XX:+CMSClassUnloadingEnabled -XX:+DisableExplicitGC -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -Djava.endorsed.dirs=/usr/local/apache-tomcat-7.0.53/endorsed -Dcatalina.base=/usr/local/apache-tomcat-7.0.53 -Dcatalina.home=/usr/local/apache-tomcat-7.0.53 -Djava.io.tmpdir=/usr/local/apache-tomcat-7.0.53/temp 18096 jar -Xms64m -Xmx64m -Duser.timezone=Asia/Shanghai -Dclient.encoding.override=UTF-8 -Dfile.encoding=UTF-8 26483 Jps -Denv.class.path=.:/usr/local/jdk/lib/dt.jar:/usr/local/jdk/lib/tools.jar -Dapplication.home=/usr/local/jdk1.7.0_55 -Xms8m [root@autorepair-web01-rj autorepair-web01-rj.btr /home/apps/repair-web] # jps -V 4214 Bootstrap 26512 Jps 18096 jar
详细情况请参考官方文档:http://java.sun.com/j2se/1.5.0/docs/tooldocs/share/jps.html
JINFO命令
jinfo命令用来输出给定 java 进程的所有配置信息,包括 java 系统属性和 jvm 命令行标记等。
用法:
jinfo [ option ] pid jinfo [ option ] executable core jinfo [ option ] [server-id@]remote-hostname-or-IP
常用选项:
-flags 打印命令行参数 -sysprops 打印系统属性
常用参数:
pid 进程号 executable 产生 core dump 的 java executable core core file remote-hostname-or-IP 主机名或ip server-id 远程主机上的debug server的唯一id
例子:
[root@autorepair-web01-rj autorepair-web01-rj.btr /home/apps/repair-web] # jinfo 4214 # 这个命令包含了 JDK 和 JVM 运行起来时的一些属性 Attaching to process ID 4214, please wait... Debugger attached successfully. Server compiler detected. JVM version is 24.55-b03 Java System Properties: java.runtime.name = Java(TM) SE Runtime Environment java.vm.version = 24.55-b03 sun.boot.library.path = /usr/local/jdk1.7.0_55/jre/lib/amd64 shared.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 java.util.logging.config.file = /usr/local/apache-tomcat-7.0.53/conf/logging.properties tomcat.util.buf.StringCache.byte.enabled = true sun.os.patch.level = unknown sun.java.launcher = SUN_STANDARD user.country = US user.dir = /home/apps/repair-web java.vm.specification.name = Java Virtual Machine Specification java.runtime.version = 1.7.0_55-b13 org.apache.catalina.startup.TldConfig.jarsToSkip = tomcat7-websocket.jar java.awt.graphicsenv = sun.awt.X11GraphicsEnvironment os.arch = amd64 java.endorsed.dirs = /usr/local/apache-tomcat-7.0.53/endorsed line.separator = java.io.tmpdir = /usr/local/apache-tomcat-7.0.53/temp java.vm.specification.vendor = Oracle Corporation java.util.logging.manager = org.apache.juli.ClassLoaderLogManager java.naming.factory.url.pkgs = org.apache.naming os.name = Linux sun.jnu.encoding = UTF-8 java.library.path = /usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib tomcat.util.scan.DefaultJarScanner.jarsToSkip = bootstrap.jar,commons-daemon.jar,tomcat-juli.jar,annotations-api.jar,el-api.jar,jsp-api.jar,servlet-api.jar,websocket-api.jar,catalina.jar,catalina-ant.jar,catalina-ha.jar,catalina-tribes.jar,jasper.jar,jasper-el.jar,ecj-*.jar,tomcat-api.jar,tomcat-util.jar,tomcat-coyote.jar,tomcat-dbcp.jar,tomcat-jni.jar,tomcat-spdy.jar,tomcat-i18n-en.jar,tomcat-i18n-es.jar,tomcat-i18n-fr.jar,tomcat-i18n-ja.jar,tomcat-juli-adapters.jar,catalina-jmx-remote.jar,catalina-ws.jar,tomcat-jdbc.jar,tools.jar,commons-beanutils*.jar,commons-codec*.jar,commons-collections*.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,jstl.jar,geronimo-spec-jaxrpc*.jar,wsdl4j*.jar,ant.jar,ant-junit*.jar,aspectj*.jar,jmx.jar,h2*.jar,hibernate*.jar,httpclient*.jar,jmx-tools.jar,jta*.jar,log4j.jar,log4j-1*.jar,mail*.jar,slf4j*.jar,xercesImpl.jar,xmlParserAPIs.jar,xml-apis.jar,junit.jar,junit-*.jar,hamcrest*.jar,org.hamcrest*.jar,ant-launcher.jar,cobertura-*.jar,asm-*.jar,dom4j-*.jar,icu4j-*.jar,jaxen-*.jar,jdom-*.jar,jetty-*.jar,oro-*.jar,servlet-api-*.jar,tagsoup-*.jar,xmlParserAPIs-*.jar,xom-*.jar java.class.version = 51.0 java.specification.name = Java Platform API Specification sun.management.compiler = HotSpot 64-Bit Tiered Compilers os.version = 2.6.32-431.el6.x86_64 user.home = / org.apache.catalina.startup.ContextConfig.jarsToSkip = user.timezone = Asia/Shanghai catalina.useNaming = true java.awt.printerjob = sun.print.PSPrinterJob file.encoding = UTF-8 java.specification.version = 1.7 catalina.home = /usr/local/apache-tomcat-7.0.53 user.name = nobody java.class.path = /usr/local/apache-tomcat-7.0.53/bin/bootstrap.jar:/usr/local/apache-tomcat-7.0.53/bin/tomcat-juli.jar java.naming.factory.initial = org.apache.naming.java.javaURLContextFactory package.definition = sun.,java.,org.apache.catalina.,org.apache.coyote.,org.apache.tomcat.,org.apache.jasper. java.vm.specification.version = 1.7 sun.arch.data.model = 64 sun.java.command = org.apache.catalina.startup.Bootstrap start java.home = /usr/local/jdk1.7.0_55/jre user.language = en java.specification.vendor = Oracle Corporation awt.toolkit = sun.awt.X11.XToolkit java.vm.info = mixed mode java.version = 1.7.0_55 java.ext.dirs = /usr/local/jdk1.7.0_55/jre/lib/ext:/usr/java/packages/lib/ext sun.boot.class.path = /usr/local/jdk1.7.0_55/jre/lib/resources.jar:/usr/local/jdk1.7.0_55/jre/lib/rt.jar:/usr/local/jdk1.7.0_55/jre/lib/sunrsasign.jar:/usr/local/jdk1.7.0_55/jre/lib/jsse.jar:/usr/local/jdk1.7.0_55/jre/lib/jce.jar:/usr/local/jdk1.7.0_55/jre/lib/charsets.jar:/usr/local/jdk1.7.0_55/jre/lib/jfr.jar:/usr/local/jdk1.7.0_55/jre/classes server.loader = java.vendor = Oracle Corporation catalina.base = /usr/local/apache-tomcat-7.0.53 file.separator = / java.vendor.url.bug = http://bugreport.sun.com/bugreport/ common.loader = ${catalina.base}/lib,${catalina.base}/lib/*.jar,${catalina.home}/lib,${catalina.home}/lib/*.jar sun.io.unicode.encoding = UnicodeLittle sun.font.fontmanager = sun.awt.X11FontManager sun.cpu.endian = little package.access = sun.,org.apache.catalina.,org.apache.coyote.,org.apache.tomcat.,org.apache.jasper. sun.cpu.isalist = VM Flags: -Djava.util.logging.config.file=/usr/local/apache-tomcat-7.0.53/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Xms2560m -Xmx2560m -Xmn680m -Xss256k -XX:PermSize=240m -XX:MaxPermSize=240m -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:CMSFullGCsBeforeCompaction=5 -XX:+UseCMSCompactAtFullCollection -XX:+CMSClassUnloadingEnabled -XX:+DisableExplicitGC -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -Djava.endorsed.dirs=/usr/local/apache-tomcat-7.0.53/endorsed -Dcatalina.base=/usr/local/apache-tomcat-7.0.53 -Dcatalina.home=/usr/local/apache-tomcat-7.0.53 -Djava.io.tmpdir=/usr/local/apache-tomcat-7.0.53/temp [root@autorepair-web01-rj autorepair-web01-rj.btr /home/apps/repair-web] # jinfo -sysprops 4214 # 包含 JDK 运行起来时的一些属性 Attaching to process ID 4214, please wait... Debugger attached successfully. Server compiler detected. JVM version is 24.55-b03 java.runtime.name = Java(TM) SE Runtime Environment java.vm.version = 24.55-b03 sun.boot.library.path = /usr/local/jdk1.7.0_55/jre/lib/amd64 shared.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 java.util.logging.config.file = /usr/local/apache-tomcat-7.0.53/conf/logging.properties tomcat.util.buf.StringCache.byte.enabled = true sun.os.patch.level = unknown sun.java.launcher = SUN_STANDARD user.country = US user.dir = /home/apps/repair-web java.vm.specification.name = Java Virtual Machine Specification java.runtime.version = 1.7.0_55-b13 org.apache.catalina.startup.TldConfig.jarsToSkip = tomcat7-websocket.jar java.awt.graphicsenv = sun.awt.X11GraphicsEnvironment os.arch = amd64 java.endorsed.dirs = /usr/local/apache-tomcat-7.0.53/endorsed line.separator = java.io.tmpdir = /usr/local/apache-tomcat-7.0.53/temp java.vm.specification.vendor = Oracle Corporation java.util.logging.manager = org.apache.juli.ClassLoaderLogManager java.naming.factory.url.pkgs = org.apache.naming os.name = Linux sun.jnu.encoding = UTF-8 java.library.path = /usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib tomcat.util.scan.DefaultJarScanner.jarsToSkip = bootstrap.jar,commons-daemon.jar,tomcat-juli.jar,annotations-api.jar,el-api.jar,jsp-api.jar,servlet-api.jar,websocket-api.jar,catalina.jar,catalina-ant.jar,catalina-ha.jar,catalina-tribes.jar,jasper.jar,jasper-el.jar,ecj-*.jar,tomcat-api.jar,tomcat-util.jar,tomcat-coyote.jar,tomcat-dbcp.jar,tomcat-jni.jar,tomcat-spdy.jar,tomcat-i18n-en.jar,tomcat-i18n-es.jar,tomcat-i18n-fr.jar,tomcat-i18n-ja.jar,tomcat-juli-adapters.jar,catalina-jmx-remote.jar,catalina-ws.jar,tomcat-jdbc.jar,tools.jar,commons-beanutils*.jar,commons-codec*.jar,commons-collections*.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,jstl.jar,geronimo-spec-jaxrpc*.jar,wsdl4j*.jar,ant.jar,ant-junit*.jar,aspectj*.jar,jmx.jar,h2*.jar,hibernate*.jar,httpclient*.jar,jmx-tools.jar,jta*.jar,log4j.jar,log4j-1*.jar,mail*.jar,slf4j*.jar,xercesImpl.jar,xmlParserAPIs.jar,xml-apis.jar,junit.jar,junit-*.jar,hamcrest*.jar,org.hamcrest*.jar,ant-launcher.jar,cobertura-*.jar,asm-*.jar,dom4j-*.jar,icu4j-*.jar,jaxen-*.jar,jdom-*.jar,jetty-*.jar,oro-*.jar,servlet-api-*.jar,tagsoup-*.jar,xmlParserAPIs-*.jar,xom-*.jar java.class.version = 51.0 java.specification.name = Java Platform API Specification sun.management.compiler = HotSpot 64-Bit Tiered Compilers os.version = 2.6.32-431.el6.x86_64 user.home = / org.apache.catalina.startup.ContextConfig.jarsToSkip = user.timezone = Asia/Shanghai catalina.useNaming = true java.awt.printerjob = sun.print.PSPrinterJob file.encoding = UTF-8 java.specification.version = 1.7 catalina.home = /usr/local/apache-tomcat-7.0.53 user.name = nobody java.class.path = /usr/local/apache-tomcat-7.0.53/bin/bootstrap.jar:/usr/local/apache-tomcat-7.0.53/bin/tomcat-juli.jar java.naming.factory.initial = org.apache.naming.java.javaURLContextFactory package.definition = sun.,java.,org.apache.catalina.,org.apache.coyote.,org.apache.tomcat.,org.apache.jasper. java.vm.specification.version = 1.7 sun.arch.data.model = 64 sun.java.command = org.apache.catalina.startup.Bootstrap start java.home = /usr/local/jdk1.7.0_55/jre user.language = en java.specification.vendor = Oracle Corporation awt.toolkit = sun.awt.X11.XToolkit java.vm.info = mixed mode java.version = 1.7.0_55 java.ext.dirs = /usr/local/jdk1.7.0_55/jre/lib/ext:/usr/java/packages/lib/ext sun.boot.class.path = /usr/local/jdk1.7.0_55/jre/lib/resources.jar:/usr/local/jdk1.7.0_55/jre/lib/rt.jar:/usr/local/jdk1.7.0_55/jre/lib/sunrsasign.jar:/usr/local/jdk1.7.0_55/jre/lib/jsse.jar:/usr/local/jdk1.7.0_55/jre/lib/jce.jar:/usr/local/jdk1.7.0_55/jre/lib/charsets.jar:/usr/local/jdk1.7.0_55/jre/lib/jfr.jar:/usr/local/jdk1.7.0_55/jre/classes server.loader = java.vendor = Oracle Corporation catalina.base = /usr/local/apache-tomcat-7.0.53 file.separator = / java.vendor.url.bug = http://bugreport.sun.com/bugreport/ common.loader = ${catalina.base}/lib,${catalina.base}/lib/*.jar,${catalina.home}/lib,${catalina.home}/lib/*.jar sun.io.unicode.encoding = UnicodeLittle sun.font.fontmanager = sun.awt.X11FontManager sun.cpu.endian = little package.access = sun.,org.apache.catalina.,org.apache.coyote.,org.apache.tomcat.,org.apache.jasper. sun.cpu.isalist = [root@autorepair-web01-rj autorepair-web01-rj.btr /home/apps/repair-web] # jinfo -flags 4214 # 包含 JVM 运行起来时的一些属性 Attaching to process ID 4214, please wait... Debugger attached successfully. Server compiler detected. JVM version is 24.55-b03 -Djava.util.logging.config.file=/usr/local/apache-tomcat-7.0.53/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Xms2560m -Xmx2560m -Xmn680m -Xss256k -XX:PermSize=240m -XX:MaxPermSize=240m -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:CMSFullGCsBeforeCompaction=5 -XX:+UseCMSCompactAtFullCollection -XX:+CMSClassUnloadingEnabled -XX:+DisableExplicitGC -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -Djava.endorsed.dirs=/usr/local/apache-tomcat-7.0.53/endorsed -Dcatalina.base=/usr/local/apache-tomcat-7.0.53 -Dcatalina.home=/usr/local/apache-tomcat-7.0.53 -Djava.io.tmpdir=/usr/local/apache-tomcat-7.0.53/temp
JSTACK命令
该命令打印java线程的堆栈跟踪,可以得知哪些线程被阻塞或正等待,以便于查找如线程死锁的原因
用法:
jstack [ option ] pid jstack [ option ] executable core jstack [ option ] [server-id@]remote-hostname-or-IP
常用选项:
-F 当’jstack [-l] pid’没有相应的时候强制打印栈信息 -l 长列表. 打印关于锁的附加信息,例如属于java.util.concurrent的ownable synchronizers列表. -m 打印java和native c/c++框架的所有栈信息.
常用参数:
core 将被打印信息的core dump文件 remote-hostname-or-IP 远程debug服务的主机名或ip server-id 唯一id,假如一台主机上多个远程debug服务 pid 需要被打印配置信息的java进程id,可以用jps查询
例子:
[root@autorepair-web01-rj autorepair-web01-rj.btr /home/apps/repair-web] # jstack -F 18096 Attaching to process ID 18096, please wait... Debugger attached successfully. Server compiler detected. JVM version is 24.55-b03 Deadlock Detection: No deadlocks found. Thread 18105: (state = BLOCKED) Thread 18104: (state = BLOCKED) - java.lang.Object.wait(long) @bci=0 (Interpreted frame) - java.lang.ref.ReferenceQueue.remove(long) @bci=44, line=135 (Interpreted frame) - java.lang.ref.ReferenceQueue.remove() @bci=2, line=151 (Interpreted frame) - java.lang.ref.Finalizer$FinalizerThread.run() @bci=16, line=189 (Interpreted frame) Thread 18103: (state = BLOCKED) - java.lang.Object.wait(long) @bci=0 (Interpreted frame) - java.lang.Object.wait() @bci=2, line=503 (Interpreted frame) - java.lang.ref.Reference$ReferenceHandler.run() @bci=46, line=133 (Interpreted frame) Thread 18097: (state = BLOCKED) - java.lang.Thread.sleep(long) @bci=0 (Interpreted frame) - logmon.logmon.main(java.lang.String[]) @bci=262, line=200 (Interpreted frame) [root@autorepair-web01-rj autorepair-web01-rj.btr /home/apps/repair-web] # jstack -F -l 18096 Attaching to process ID 18096, please wait... Debugger attached successfully. Server compiler detected. JVM version is 24.55-b03 Deadlock Detection: No deadlocks found. Thread 18105: (state = BLOCKED) Locked ownable synchronizers: - None Thread 18104: (state = BLOCKED) - java.lang.Object.wait(long) @bci=0 (Interpreted frame) - java.lang.ref.ReferenceQueue.remove(long) @bci=44, line=135 (Interpreted frame) - java.lang.ref.ReferenceQueue.remove() @bci=2, line=151 (Interpreted frame) - java.lang.ref.Finalizer$FinalizerThread.run() @bci=16, line=189 (Interpreted frame) Locked ownable synchronizers: - None Thread 18103: (state = BLOCKED) - java.lang.Object.wait(long) @bci=0 (Interpreted frame) - java.lang.Object.wait() @bci=2, line=503 (Interpreted frame) - java.lang.ref.Reference$ReferenceHandler.run() @bci=46, line=133 (Interpreted frame) Locked ownable synchronizers: - None Thread 18097: (state = BLOCKED) - java.lang.Thread.sleep(long) @bci=0 (Interpreted frame) - logmon.logmon.main(java.lang.String[]) @bci=262, line=200 (Interpreted frame) Locked ownable synchronizers: - None [root@autorepair-web01-rj autorepair-web01-rj.btr /home/apps/repair-web] # jstack -m 18096 Attaching to process ID 18096, please wait... Debugger attached successfully. Server compiler detected. JVM version is 24.55-b03 Deadlock Detection: No deadlocks found. ----------------- 18097 ----------------- 0x00000034aa60b98e __pthread_cond_timedwait + 0x13e 0x00007ffe57d44174 _ZN2os5sleepEP6Threadlb + 0x254 0x00007ffe57bac662 JVM_Sleep + 0x342 0x00007ffe4d012738 * java.lang.Thread.sleep(long) bci:0 (Interpreted frame) 0x00007ffe4d006058 * logmon.logmon.main(java.lang.String[]) bci:262 line:200 (Interpreted frame) 0x00007ffe4d0004e70x00007ffe57b274b5 _ZN9JavaCalls11call_helperEP9JavaValueP12methodHandleP17JavaCallArgumentsP6Thread + 0x365 0x00007ffe57b25f18 _ZN9JavaCalls4callEP9JavaValue12methodHandleP17JavaCallArgumentsP6Thread + 0x28 0x00007ffe57b5f109 _ZL17jni_invoke_staticP7JNIEnv_P9JavaValueP8_jobject11JNICallTypeP10_jmethodIDP18JNI_ArgumentPusherP6Thread + 0x219 0x00007ffe57b68192 jni_CallStaticVoidMethod + 0x162 0x00007ffe5839b6d9 JavaMain + 0x7e9 ----------------- 18098 ----------------- 0x00000034aa60b5bc __pthread_cond_wait + 0xcc 0x00007ffe57d05b2f _ZN7Monitor5IWaitEP6Threadl + 0xef 0x00007ffe57d062be _ZN7Monitor4waitEblb + 0x22e 0x00007ffe57a7e953 _ZN13GCTaskManager8get_taskEj + 0x43 0x00007ffe57a80018 _ZN12GCTaskThread3runEv + 0x188 0x00007ffe57d44668 _ZL10java_startP6Thread + 0x108 ----------------- 18099 ----------------- 0x00000034aa60b5bc __pthread_cond_wait + 0xcc 0x00007ffe57d05b2f _ZN7Monitor5IWaitEP6Threadl + 0xef 0x00007ffe57d062be _ZN7Monitor4waitEblb + 0x22e 0x00007ffe57a7e953 _ZN13GCTaskManager8get_taskEj + 0x43 0x00007ffe57a80018 _ZN12GCTaskThread3runEv + 0x188 0x00007ffe57d44668 _ZL10java_startP6Thread + 0x108 ----------------- 18100 ----------------- 0x00000034aa60b5bc __pthread_cond_wait + 0xcc 0x00007ffe57d05b2f _ZN7Monitor5IWaitEP6Threadl + 0xef 0x00007ffe57d062be _ZN7Monitor4waitEblb + 0x22e 0x00007ffe57a7e953 _ZN13GCTaskManager8get_taskEj + 0x43 0x00007ffe57a80018 _ZN12GCTaskThread3runEv + 0x188 0x00007ffe57d44668 _ZL10java_startP6Thread + 0x108 ----------------- 18101 ----------------- 0x00000034aa60b5bc __pthread_cond_wait + 0xcc 0x00007ffe57d05b2f _ZN7Monitor5IWaitEP6Threadl + 0xef 0x00007ffe57d062be _ZN7Monitor4waitEblb + 0x22e 0x00007ffe57a7e953 _ZN13GCTaskManager8get_taskEj + 0x43 0x00007ffe57a80018 _ZN12GCTaskThread3runEv + 0x188 0x00007ffe57d44668 _ZL10java_startP6Thread + 0x108 ----------------- 18102 ----------------- 0x00000034aa60b98e __pthread_cond_timedwait + 0x13e 0x00007ffe57d05dde _ZN7Monitor5IWaitEP6Threadl + 0x39e 0x00007ffe57d062be _ZN7Monitor4waitEblb + 0x22e 0x00007ffe57ec9649 _ZN8VMThread4loopEv + 0x339 0x00007ffe57ec9950 _ZN8VMThread3runEv + 0x70 0x00007ffe57d44668 _ZL10java_startP6Thread + 0x108 ----------------- 18103 ----------------- 0x00000034aa60b5bc __pthread_cond_wait + 0xcc 0x00007ffe57d32a4d _ZN13ObjectMonitor4waitElbP6Thread + 0x9bd 0x00007ffe57ba4148 JVM_MonitorWait + 0x168 0x00007ffe4d012738 * java.lang.Object.wait(long) bci:0 (Interpreted frame) 0x00007ffe4d006058 * java.lang.Object.wait() bci:2 line:503 (Interpreted frame) 0x00007ffe4d006058 * java.lang.ref.Reference$ReferenceHandler.run() bci:46 line:133 (Interpreted frame) 0x00007ffe4d0004e7 0x00007ffe57b274b5 _ZN9JavaCalls11call_helperEP9JavaValueP12methodHandleP17JavaCallArgumentsP6Thread + 0x365 0x00007ffe57b25f18 _ZN9JavaCalls4callEP9JavaValue12methodHandleP17JavaCallArgumentsP6Thread + 0x28 0x00007ffe57b261e7 _ZN9JavaCalls12call_virtualEP9JavaValue11KlassHandleP6SymbolS4_P17JavaCallArgumentsP6Thread + 0x197 0x00007ffe57b26307 _ZN9JavaCalls12call_virtualEP9JavaValue6Handle11KlassHandleP6SymbolS5_P6Thread + 0x47 0x00007ffe57ba2215 _ZL12thread_entryP10JavaThreadP6Thread + 0xe5 0x00007ffe57e7c70f _ZN10JavaThread17thread_main_innerEv + 0xdf 0x00007ffe57e7c815 _ZN10JavaThread3runEv + 0xf5 0x00007ffe57d44668 _ZL10java_startP6Thread + 0x108 ----------------- 18104 ----------------- 0x00000034aa60b5bc __pthread_cond_wait + 0xcc 0x00007ffe57d32a4d _ZN13ObjectMonitor4waitElbP6Thread + 0x9bd 0x00007ffe57ba4148 JVM_MonitorWait + 0x168 0x00007ffe4d012738 * java.lang.Object.wait(long) bci:0 (Interpreted frame) 0x00007ffe4d006058 * java.lang.ref.ReferenceQueue.remove(long) bci:44 line:135 (Interpreted frame) 0x00007ffe4d006233 * java.lang.ref.ReferenceQueue.remove() bci:2 line:151 (Interpreted frame) 0x00007ffe4d006233 * java.lang.ref.Finalizer$FinalizerThread.run() bci:16 line:189 (Interpreted frame) 0x00007ffe4d0004e7 0x00007ffe57b274b5 _ZN9JavaCalls11call_helperEP9JavaValueP12methodHandleP17JavaCallArgumentsP6Thread + 0x365 0x00007ffe57b25f18 _ZN9JavaCalls4callEP9JavaValue12methodHandleP17JavaCallArgumentsP6Thread + 0x28 0x00007ffe57b261e7 _ZN9JavaCalls12call_virtualEP9JavaValue11KlassHandleP6SymbolS4_P17JavaCallArgumentsP6Thread + 0x197 0x00007ffe57b26307 _ZN9JavaCalls12call_virtualEP9JavaValue6Handle11KlassHandleP6SymbolS5_P6Thread + 0x47 0x00007ffe57ba2215 _ZL12thread_entryP10JavaThreadP6Thread + 0xe5 0x00007ffe57e7c70f _ZN10JavaThread17thread_main_innerEv + 0xdf 0x00007ffe57e7c815 _ZN10JavaThread3runEv + 0xf5 0x00007ffe57d44668 _ZL10java_startP6Thread + 0x108 ----------------- 18105 ----------------- 0x00000034aa60d930 sem_wait + 0x30 0x00007ffe57d3c7a5 _ZL19signal_thread_entryP10JavaThreadP6Thread + 0x95 0x00007ffe57e7c70f _ZN10JavaThread17thread_main_innerEv + 0xdf 0x00007ffe57e7c815 _ZN10JavaThread3runEv + 0xf5 0x00007ffe57d44668 _ZL10java_startP6Thread + 0x108 ----------------- 18106 ----------------- 0x00000034aa60b5bc __pthread_cond_wait + 0xcc 0x00007ffe57d05b2f _ZN7Monitor5IWaitEP6Threadl + 0xef 0x00007ffe57d06336 _ZN7Monitor4waitEblb + 0x2a6 0x00007ffe579774d8 _ZN12CompileQueue3getEv + 0x128 0x00007ffe5797b5ca _ZN13CompileBroker20compiler_thread_loopEv + 0x13a 0x00007ffe57e7c70f _ZN10JavaThread17thread_main_innerEv + 0xdf 0x00007ffe57e7c815 _ZN10JavaThread3runEv + 0xf5 0x00007ffe57d44668 _ZL10java_startP6Thread + 0x108 ----------------- 18107 ----------------- 0x00000034aa60b5bc __pthread_cond_wait + 0xcc 0x00007ffe57d05b2f _ZN7Monitor5IWaitEP6Threadl + 0xef 0x00007ffe57d06336 _ZN7Monitor4waitEblb + 0x2a6 0x00007ffe579774d8 _ZN12CompileQueue3getEv + 0x128 0x00007ffe5797b5ca _ZN13CompileBroker20compiler_thread_loopEv + 0x13a 0x00007ffe57e7c70f _ZN10JavaThread17thread_main_innerEv + 0xdf 0x00007ffe57e7c815 _ZN10JavaThread3runEv + 0xf5 0x00007ffe57d44668 _ZL10java_startP6Thread + 0x108 ----------------- 18108 ----------------- 0x00000034aa60b5bc __pthread_cond_wait + 0xcc 0x00007ffe57d05b2f _ZN7Monitor5IWaitEP6Threadl + 0xef 0x00007ffe57d062be _ZN7Monitor4waitEblb + 0x22e 0x00007ffe57dd3998 _ZN13ServiceThread20service_thread_entryEP10JavaThreadP6Thread + 0x198 0x00007ffe57e7c70f _ZN10JavaThread17thread_main_innerEv + 0xdf 0x00007ffe57e7c815 _ZN10JavaThread3runEv + 0xf5 0x00007ffe57d44668 _ZL10java_startP6Thread + 0x108 ----------------- 18109 ----------------- 0x00000034aa60b98e __pthread_cond_timedwait + 0x13e 0x00007ffe57d05dde _ZN7Monitor5IWaitEP6Threadl + 0x39e 0x00007ffe57d062be _ZN7Monitor4waitEblb + 0x22e 0x00007ffe57e78941 _ZNK13WatcherThread5sleepEv + 0x71 0x00007ffe57e78c4e _ZN13WatcherThread3runEv + 0x5e 0x00007ffe57d44668 _ZL10java_startP6Thread + 0x108 ----------------- 18096 ----------------- 0x00000034aa60822d pthread_join + 0x10d
JSTAT命令
用于输出指定 java 进程的统计信息
用法:
jstat -
常用选项(附带每个选项的输出列名介绍):
class:统计classloader的行为 compiler:统计hotspot just-in-time编译器的行为 gc:统计gc行为 gccapacity:统计堆中代的容量、空间 gccause:垃圾收集统计,包括最近引用垃圾收集的事件,基本同gcutil,比gcutil多了两列 gcnew:统计新生代的行为 gcnewcapacity:统计新生代的大小和空间 gcold:统计旧生代的行为 gcoldcapacity:统计旧生代的大小和空间 gcpermcapacity:统计永久代的大小和空间 gcutil:垃圾收集统计 printcompilation:hotspot编译方法统计 -h n 每n个样本,显示header一次 -t n 在第一列显示时间戳列,时间戳时从jvm启动开始计算就是进程号 interval是监控时间间隔,单位为微妙,不提供就意味着单次输出 count是最大输出次数,不提供且监控时间间隔有值的话, 就无限打印
例子:
class选项:
[root@autorepair-web01-rj autorepair-web01-rj.btr /home/apps/repair-web] # jstat -class 4214 2000 10 (每隔2秒监控一次,一共做10次) Loaded Bytes Unloaded Bytes Time 9197 18418. 0 0 0.0 12.49 9197 18418. 0 0 0.0 12.49
列名介绍:
Column | Description |
Loaded | 被读入类的数量 |
Bytes | 被读入的字节数(K) |
Unloaded | 被卸载类的数量 |
Bytes | 被卸载的字节数(K) |
Time | 花费在load和unload类的时间 |
compiler选项
[root@autorepair-web01-rj autorepair-web01-rj.btr /home/apps/repair-web] # jstat -compiler 4214 Compiled Failed Invalid Time FailedType FailedMethod 3080 0 0 101.41 0
列名介绍:
Column |
Description |
Compiled | 被执行的编译任务的数量 |
Failed | 失败的编译任务的数量 |
Invalid | 无效的编译任务的数量 |
Time | 花费在执行编译任务的时间 |
FailedType | 最近失败编译的编译类弄 |
FailedMethod | 最近失败编译的类名和方法名 |
GC选项:
[root@autorepair-web01-rj autorepair-web01-rj.btr /home/apps/repair-web] # jstat -gc 4214 2000 10 S0C S1C S0U S1U EC EU OC OU PC PU YGC YGCT FGC FGCT GCT 69632.0 69632.0 0.0 3902.9 557056.0 10783.2 1925120.0 1479208.6 245760.0 56451.5 51 9.852 9 11.002 20.854 69632.0 69632.0 0.0 3902.9 557056.0 10783.2 1925120.0 1479208.6 245760.0 56451.5 51 9.852 9 11.002 20.854
列名介绍:
Column | Description |
S0C | 当前S0的容量 (KB) |
S1C | 当前S1的容量 (KB) |
S0U | S0的使用 (KB) |
S1U | S1的使用 (KB) |
EC | 当前eden的容量(KB) |
EU | eden的使用 (KB) |
OC | 当前old的容量(KB) |
OU | old的使用 (KB) |
PC | 当前perm的容量 (KB) |
PU | perm的使用 (KB) |
YGC | young代gc的次数 |
YGCT | young代gc花费的时间 |
FGC | full gc的次数 |
FGCT | full gc的时间 |
GCT | 垃圾收集收集的总时间 |
gccapacity选项:
[root@autorepair-web01-rj autorepair-web01-rj.btr /home/apps/repair-web]
# jstat -gccapacity 4214
NGCMN NGCMX NGC S0C S1C EC OGCMN OGCMX OGC OC PGCMN PGCMX PGC PC YGC FGC
696320.0 696320.0 696320.0 69632.0 69632.0 557056.0 1925120.0 1925120.0 1925120.0 1925120.0 245760.0 245760.0 245760.0 245760.0 51 9
列名介绍:
Column |
Description |
NGCMN | 年轻代的最小容量 (KB) |
NGCMX |
年轻代的最大容量 (KB) |
NGC |
当前年轻代的容量 (KB) |
S0C |
当前S0的空间 (KB) |
S1C |
当前S1的空间 (KB) |
EC |
当前eden的空间 (KB) |
OGCMN |
年老代的最小容量 (KB) |
OGCMX |
年老代的最大容量 (KB) |
OGC |
当前年老代的容量 (KB) |
OC |
当前年老代的空间 (KB) |
PGCMN |
永久代的最小容量 (KB) |
PGCMX |
永久代的最大容量 (KB) |
PGC |
当前永久代的容量 (KB) |
PC |
当前永久代的空间 (KB) |
YGC |
年轻代gc的次数 |
FGC | full gc的次数 |
gccause参数:
[root@autorepair-web01-rj autorepair-web01-rj.btr /home/apps/repair-web] # jstat -gccause 4214 S0 S1 E O P YGC YGCT FGC FGCT GCT LGCC GCC 0.00 5.60 16.72 76.84 22.97 51 9.852 9 11.002 20.854 Allocation Failure No GC
列名介绍:
Column |
Description |
LGCC |
最近垃圾回收的原因 |
GCC | 当前垃圾回收的原因 |
gcnew选项:
[root@autorepair-web01-rj autorepair-web01-rj.btr /home/apps/repair-web]
# jstat -gcnew 4214
S0C S1C S0U S1U TT MTT DSS EC EU YGC YGCT
69632.0 69632.0 0.0 3902.9 6 6 34816.0 557056.0 53634.1 51 9.852
列名介绍:
Column |
Description |
S0C |
当前S0空间 (KB) |
S1C |
当前S1空间 (KB) |
S0U |
S0空间使用 (KB) |
S1U |
S1空间使用 (KB) |
TT |
Tenuring threshold |
MTT |
最大的tenuring threshold |
DSS |
希望的Survivor大小 (KB) |
EC |
当前eden空间 (KB) |
EU |
eden空间使用 (KB) |
YGC |
年轻代gc次数 |
YGCT | 年轻代垃圾收集时间 |
gcnewcapacity选项:
[root@autorepair-web01-rj autorepair-web01-rj.btr /home/apps/repair-web] # jstat -gcnewcapacity 4214 NGCMN NGCMX NGC S0CMX S0C S1CMX S1C ECMX EC YGC FGC 696320.0 696320.0 696320.0 69632.0 69632.0 69632.0 69632.0 557056.0 557056.0 51 9
参数介绍:
Column |
Description |
NGCMN | 最小的年轻代的容量 (KB) |
NGCMX |
最大的年轻代的容量 (KB) |
NGC |
当前年轻代的容量 (KB) |
S0CMX |
最大的S0空间 (KB) |
S0C |
当前S0空间 (KB) |
S1CMX |
最大的S1空间 (KB) |
S1C |
当前S1空间 (KB) |
ECMX |
最大eden空间 (KB) |
EC |
当前eden空间 (KB) |
YGC |
年轻代gc数量 |
FGC | full gc数量 |
gcold选项:
[root@autorepair-web01-rj autorepair-web01-rj.btr /home/apps/repair-web] # jstat -gcold 4214 PC PU OC OU YGC FGC FGCT GCT 245760.0 56451.8 1925120.0 1479208.6 51 9 11.002 20.854
列名介绍:
Column |
Description |
PC | 当前perm空间 (KB) |
PU | perm空间使用 (KB) |
OC | 当前old空间 (KB) |
OU | old空间使用 (KB) |
YGC | 年轻代gc次数 |
FGC | full gc次数 |
FGCT | full gc时间 |
GCT | 垃圾收集总时间 |
gcoldcapacity选项:
[root@autorepair-web01-rj autorepair-web01-rj.btr /home/apps/repair-web] # jstat -gcoldcapacity 4214 OGCMN OGCMX OGC OC YGC FGC FGCT GCT 1925120.0 1925120.0 1925120.0 1925120.0 51 9 11.002 20.854
列名介绍:
Column |
Description |
OGCMN |
最小年老代容量 (KB) |
OGCMX | 最大年老代容量(KB) |
OGC | 当前年老代容量 (KB) |
OC | 当前年老代空间 (KB) |
YGC | 年轻代gc次数 |
FGC | full gc次数 |
FGCT | full gc时间 |
GCT | 垃圾收集总时间 |
gcpermcapacity选项:
[root@autorepair-web01-rj autorepair-web01-rj.btr /home/apps/repair-web] # jstat -gcpermcapacity 4214 PGCMN PGCMX PGC PC YGC FGC FGCT GCT 245760.0 245760.0 245760.0 245760.0 51 9 11.002 20.854
列名介绍:
Column |
Description |
PGCMN | 永久代最小容量 (KB) |
PGCMX | 永久代最大容量 (KB) |
PGC | 当前永久代的容量 (KB) |
PC | 当前永久代的空间 (KB) |
YGC | 年轻代gc次数 |
FGC | full gc次数 |
FGCT | full gc时间 |
GCT | 垃圾收集总时间 |
gcutil选项:
[root@autorepair-web01-rj autorepair-web01-rj.btr /home/apps/repair-web] # jstat -gcutil 4214 2000 10 S0 S1 E O P YGC YGCT FGC FGCT GCT 0.00 5.60 0.82 76.84 22.97 51 9.852 9 11.002 20.854 0.00 5.60 0.82 76.84 22.97 51 9.852 9 11.002 20.854
列名介绍:
Column |
Description |
S1 | S1使用百分比 |
E | eden使用百分比 |
O | old使用百分比 |
P | perm使用百分比 |
YGC | 年轻代gc次数 |
YGCT | 年轻代gc时间 |
FGC | full gc次数 |
FGCT | full gc时间 |
GCT | 垃圾收集总时间 |
printcompilation选项:
[root@autorepair-web01-rj autorepair-web01-rj.btr /home/apps/repair-web] # jstat -printcompilation 4214 Compiled Size Type Method 3080 262 1 org/apache/catalina/session/ManagerBase processExpires
列名介绍:
Column |
Description |
Compiled | 被执行的编译任务的数量 |
Size | 方法字节码的字节数 |
Type | 编译类型 |
Method | 编译方法的类名和方法名。类名使用"/" 代替 "." 作为空间分隔符. 方法名是给出类的方法名. 格式是一致于HotSpot - XX:+PrintComplation 选项 |
JMAP命令
jmap命令可以获得运行中的jvm的堆的快照,从而可以离线分析堆,以检查内存泄漏,检查一些严重影响性能的大对象的创建,检查系统中什么对象最多,各种对象所占内存的大小等等
用法:
jmap [option]jmap [option] jmap [option] [server_id@]
常用选项:
-dump:format=b,file=pid # dump堆到文件,format指定输出格式,live指明是活着的对象,file指定文件名 -finalizerinfo # 打印等待回收对象的信息 -heap # 打印heap的概要信息,GC使用的算法,heap的配置及wise heap的使用情况,可以用此来判断内存目前的使用情况以及垃圾回收情况 -histo[:live] # 打印堆的对象统计,包括对象数、内存大小等等 (因为在dump:live前会进行full gc,因此不加live的堆大小要大于加live堆的大小 ) -permstat # 打印classload类装载器和 jvm heap长久层的信息. 包含包括每个装载器的名字,活跃,地址,父装载器,和其总共加载的类大小。另外,内部String的数量和占用内存数也会打印出来. -F # 强制,强迫.在pid没有相应的时候使用-dump或者-histo参数. 在这个模式下,live子参数无效. -J # 传递参数给jmap启动的jvm. ,如:-J-Xms256m
例子:
[root@autorepair-web01-rj autorepair-web01-rj.btr /root] # jmap -heap 4214 Attaching to process ID 4214, please wait... Debugger attached successfully. Server compiler detected. JVM version is 24.55-b03 using parallel threads in the new generation. using thread-local object allocation. Concurrent Mark-Sweep GC Heap Configuration: # 堆配置情况 MinHeapFreeRatio = 40 # 最小堆的使用比例 MaxHeapFreeRatio = 70 # 最大堆的可用比例 MaxHeapSize = 2684354560 (2560.0MB) # 最大堆空间大小 NewSize = 713031680 (680.0MB) # 新生代分配大小 MaxNewSize = 713031680 (680.0MB) # 最大可用新生代分配大小 OldSize = 5439488 (5.1875MB) # 老年代大小 NewRatio = 2 # 新生代比例 SurvivorRatio = 8 # 新生代与suvivor的比例 PermSize = 251658240 (240.0MB) # perm区大小 MaxPermSize = 251658240 (240.0MB) # 最大可分配perm区大小 G1HeapRegionSize = 0 (0.0MB) # G1堆区大小 Heap Usage: # 堆使用情况 New Generation (Eden + 1 Survivor Space): # 新生代(伊甸区 + survior空间) capacity = 641728512 (612.0MB) # 伊甸区容量 used = 507109064 (483.6168899536133MB) # 已经使用大小 free = 134619448 (128.38311004638672MB) # 剩余容量 79.0223676394793% used # 使用比例 Eden Space: # 伊甸区 capacity = 570425344 (544.0MB) # 伊甸区容量 used = 503156488 (479.84741973876953MB) # 伊甸区使用 free = 67268856 (64.15258026123047MB) # 伊甸区当前剩余容量 88.2072462755091% used # 伊甸区使用情况 From Space: # survior1区 capacity = 71303168 (68.0MB) # survior1区容量 used = 3952576 (3.76947021484375MB) # surviror1区已使用情况 free = 67350592 (64.23052978515625MB) # surviror1区剩余容量 5.543338551240809% used # survior1区使用比例 To Space: # survior2 区 capacity = 71303168 (68.0MB) # survior2区容量 used = 0 (0.0MB) # survior2区已使用情况 free = 71303168 (68.0MB) # survior2区剩余容量 0.0% used # survior2区使用比例 concurrent mark-sweep generation: # 老生代使用情况 capacity = 1971322880 (1880.0MB) # 老生代容量 used = 1514740296 (1444.5689163208008MB) # 老生代已使用容量 free = 456582584 (435.4310836791992MB) # 老生代剩余容量 76.83877214472345% used # 老生代使用比例 Perm Generation: # perm区使用情况 capacity = 251658240 (240.0MB) # perm区容量 used = 57814400 (55.1361083984375MB) # perm区已使用容量 free = 193843840 (184.8638916015625MB) # perm区剩余容量 22.973378499348957% used # perm区使用比例 28645 interned Strings occupying 3168232 bytes.
OK!
以上就是几个工具的详解了,希望能对大家有所帮助!