Jinfo
jinfo用于观察、修改运行中的java程序的运行环境参数:参数包括Java System属性和JVM命令行参数。
jinfo语法
| jinfo [option] <pid> |
其中<option> 是以下之一:
-flag <name> 打印指定name的 JVM flag
-flag [+|-]<name> 启用或者禁用指定name的 JVM flag
-flag <name>=<value> 设置指定名称的name flag 为给定的值
-flags 打印 JVM flags
-sysprops 打印Java 系统属性
<no option> 不指定任何option,则打印出所有的JVM flags和sysprops
-h | -help 打印帮助信息
观察所有的java系统属性和非默认的JVM Flags
| [root@www wangxiaoxiao]# jinfo 15525
Attaching to process ID 15525, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.65-b01
Java System Properties:
jboss.i18n.generate-proxies = true
java.runtime.name = Java(TM) SE Runtime Environment
java.vm.version = 25.65-b01
sun.boot.library.path = /usr/local/jdk8/jre/lib/amd64
java.protocol.handler.pkgs = null|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 = /data/website
java.vm.specification.name = Java Virtual Machine Specification
PID = 15525
java.runtime.version = 1.8.0_65-b17
java.awt.graphicsenv = sun.awt.X11GraphicsEnvironment
os.arch = amd64
java.endorsed.dirs = /usr/local/jdk8/jre/lib/endorsed
org.jboss.logging.provider = slf4j
line.separator =
java.io.tmpdir = /tmp
java.vm.specification.vendor = Oracle Corporation
os.name = Linux
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 = 2.6.32-431.23.3.el6.x86_64
user.home = /root
user.timezone = Asia/Harbin
catalina.useNaming = false
java.awt.printerjob = sun.print.PSPrinterJob
file.encoding = UTF-8
java.specification.version = 1.8
catalina.home = /tmp/tomcat.4517928592901920395.8081
user.name = root
java.class.path = website-0.0.1-SNAPSHOT.jar
java.vm.specification.version = 1.8
sun.arch.data.model = 64
sun.java.command = website-0.0.1-SNAPSHOT.jar
java.home = /usr/local/jdk8/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_65
java.ext.dirs = /usr/local/jdk8/jre/lib/ext
sun.boot.class.path = /usr/local/jdk8/jre/lib/resources.jar:/usr/local/jdk8/jre/lib/rt.jar:/usr/local/jdk8/jre/lib/sunrsasign.jar:/usr/local/jdk8/jre/lib/jsse.jar:/usr/local/jdk8/jre/lib/jce.jar:/usr/local/jdk8/jre/lib/charsets.jar:/usr/local/jdk8/jre/lib/jfr.jar:/usr/local/jdk8/jre/classes
java.awt.headless = true
java.vendor = Oracle Corporation
catalina.base = /tmp/tomcat.4517928592901920395.8081
file.separator = /
LOG_EXCEPTION_CONVERSION_WORD = %wEx
java.vendor.url.bug = http://bugreport.sun.com/bugreport/
sun.io.unicode.encoding = UnicodeLittle
sun.cpu.endian = little
sun.cpu.isalist =
VM Flags:
Non-default VM flags: -XX:CICompilerCount=2 -XX:+CMSClassUnloadingEnabled -XX:CMSInitiatingOccupancyFraction=70 -XX:+CMSParallelRemarkEnabled -XX:+DisableExplicitGC -XX:InitialHeapSize=134217728 -XX:MaxHeapSize=536870912 -XX:MaxNewSize=134217728 -XX:MinHeapDeltaBytes=196608 -XX:NewSize=134152192 -XX:OldPLABSize=16 -XX:OldSize=65536 -XX:-OmitStackTraceInFastThrow -XX:SoftRefLRUPolicyMSPerMB=0 -XX:SurvivorRatio=8 -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseConcMarkSweepGC -XX:+UseParNewGC
Command line: -Xms128m -Xmx512m -Xmn128m -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=70 -XX:+CMSParallelRemarkEnabled -XX:SoftRefLRUPolicyMSPerMB=0 -XX:+CMSClassUnloadingEnabled -XX:SurvivorRatio=8 -XX:+DisableExplicitGC -XX:-OmitStackTraceInFastThrow -Djava.ext.dirs=/usr/local/jdk8/jre/lib/ext
注意,这里的VM Flags只打印出非默认的参数,对于默认的参数如何查看,请参考:http://ifeve.com/useful-jvm-flags-part-3-printing-all-xx-flags-and-their-values/
修改运行中的JVM Flags
jinfo还能够修改一部分运行期间能够调整的虚拟机参数。例如系统启动时,并没有指定这样的参数-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/java/dump.hprof,这两个参数用于内存dump分析,后面讲解jmap的时候会介绍。
则可以通过jinfo命令进行修改:
jinfo -flag +HeapDumpOnOutOfMemoryError 15525
jinfo -flag HeapDumpPath=/java/dump.hprof 15525
注意:
1、如果运行过程中,通过jinfo修改了,则修改后的值只能通过jinfo看到,jps是看不到的,jps命令只能看到启动时的jvm参数。
2、很多运行参数是不能调整的,如果出现这种异常,说明不能调整:
<pre class="prettyprint linenums lang-java prettyprinted" style="box-sizing: border-box; overflow: auto; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 13px; display: block; padding: 9.5px; margin: 0px 0px 10px; line-height: 1.42857; color: rgb(51, 51, 51); word-break: break-all; overflow-wrap: break-word; background-color: rgb(51, 51, 51); border: 1px solid rgb(204, 204, 204); border-radius: 0px !important; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">
- [root@www wangxiaoxiao]# jinfo -flag SurvivorRatio=7 15525
- Exception in thread "main" com.sun.tools.attach.AttachOperationFailedException: flag 'SurvivorRatio' cannot be changed
最后,对于运行时的修改,jinfo命令好像存在一个bug,如下图所示,我们明明设置了HeapDumpPath=/java/dump.hprof,但是这里显示的却是null:
但是直接指定查看HeapDumpPath这个flag时,返回的又是我们设置的值。