1. 概述
1.1. 工具概述
jinfo(JVM configuration info for java),用于实时查看和调整虚拟机的各项参数(可显示未被显式指定的系统默认参数);
该命令在JDK 1.6时期已经随着Linux版的JDK发布,当时只提供参数信息的查询功能,而在JDK1.6之后,该命令在Linux和Windows平台均有提供,并且加入了运行期修改参数的内容,可使用-flag[+|-]
或者-flag name=value
修改一部分运行期可写的虚拟机参数(注意:jinfo在Windows平台的使用仍然有很大的限制);
1.2. 命令帮助
wanghui@Mokalas-MacBook-Pro ~ $ jinfo --help
Usage:
jinfo [option] <pid>
(to connect to running process)
jinfo [option] <executable <core>
(to connect to a core file)
jinfo [option] [server_id@]<remote server IP or hostname>
(to connect to remote debug server)
where <option> is one of:
-flag <name> to print the value of the named VM flag
-flag [+|-]<name> to enable or disable the named VM flag
-flag <name>=<value> to set the named VM flag to the given value
-flags to print VM flags
-sysprops to print Java system properties
<no option> to print both of the above
-h | -help to print this help message
2. jinfo常用选项
先写一个简单的Java类,并指定JVM运行参数运行之
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.TimeUnit;
/**
* @Author 辉辉大侠
* @Date 2017-03-11 10:23
* @Motto 一生伏首拜阳明
*/
public class JinfoMain {
public static void main(String[] args) throws InterruptedException {
int k = 100;
while (k > 0) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
System.out.println(sdf.format(new Date()));
TimeUnit.SECONDS.sleep(10);
k--;
}
}
}
指定一些JVM参数运行该类:
java JinfoMain -XX:MaxPermSize=128m
通过jps
命令查找到该类的进程id:
wanghui@Mokalas-MacBook-Pro ~ $ jps -l
46603 JinfoMain
46859 sun.tools.jps.Jps
进程id为46603
2.1. 不带任何参数
wanghui@Mokalas-MacBook-Pro ~ $ jinfo 46603
Attaching to process ID 46603, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.101-b13
Java System Properties:
java.runtime.name = Java(TM) SE Runtime Environment
java.vm.version = 25.101-b13
sun.boot.library.path = /Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/jre/lib
user.country.format = CN
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 = US
user.dir = /Users/wanghui/temp/jvm
java.vm.specification.name = Java Virtual Machine Specification
java.runtime.version = 1.8.0_101-b13
java.awt.graphicsenv = sun.awt.CGraphicsEnvironment
os.arch = x86_64
java.endorsed.dirs = /Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/jre/lib/endorsed
line.separator =
java.io.tmpdir = /var/folders/2l/b5hp34t53ys_41q15yx42y280000gn/T/
socksProxyPort = 9742
java.vm.specification.vendor = Oracle Corporation
os.name = Mac OS X
sun.jnu.encoding = UTF-8
java.library.path = /Users/wanghui/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.12.4
http.nonProxyHosts = local|*.local|169.254/16|*.169.254/16
user.home = /Users/wanghui
user.timezone = Asia/Shanghai
java.awt.printerjob = sun.lwawt.macosx.CPrinterJob
file.encoding = UTF-8
java.specification.version = 1.8
user.name = wanghui
java.class.path = .
socksProxyHost = 127.0.0.1
java.vm.specification.version = 1.8
sun.arch.data.model = 64
sun.java.command = JinfoMain -XX:MaxPermSize=128m
java.home = /Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/jre
user.language = en
java.specification.vendor = Oracle Corporation
awt.toolkit = sun.lwawt.macosx.LWCToolkit
java.vm.info = mixed mode
java.version = 1.8.0_101
java.ext.dirs = /Users/wanghui/Library/Java/Extensions:/Library/Java/JavaVirtualMachines/jdk1.8.0_101.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_101.jdk/Contents/Home/jre/lib/resources.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/jre/lib/rt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/jre/lib/sunrsasign.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/jre/lib/jsse.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/jre/lib/jce.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/jre/lib/jfr.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_101.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 =
VM Flags:
Non-default VM flags: -XX:CICompilerCount=3 -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:
输出进程相关的所有信息
2.2. -flags参数
wanghui@Mokalas-MacBook-Pro ~ $ jinfo -flags 46603
Attaching to process ID 46603, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.101-b13
Non-default VM flags: -XX:CICompilerCount=3 -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:
显示运行时JVM参数信息
2.3. -sysprops参数
wanghui@Mokalas-MacBook-Pro ~ $ jinfo -sysprops 47927
Attaching to process ID 47927, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.101-b13
java.runtime.name = Java(TM) SE Runtime Environment
java.vm.version = 25.101-b13
sun.boot.library.path = /Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/jre/lib
user.country.format = CN
gopherProxySet = false
java.vendor.url = http://java.oracle.com/
java.vm.vendor = Oracle Corporation
...
获取运行时系统参数,与system.getProperties()类似