0%

jinfo命令

本文使用的JDK版本为jdk1.7.0_79。

一、常用用法

1
jinfo [-flag name] JVM进程ID

二、含义与选项

2.1、没有选项

打印两方面内容:1)相应JVM进程运行时环境变量“键-值”列表;2)使用“java”命令运行相应JVM进程时传入的虚拟机参数,有些虚拟机参数并不显示,比如“-classpath”,“-showversion”。可参照《jps命令》

2.2、有“[-flag name]”选项

此处“name”表示“-XX”类型虚拟机参数的名称,表示打印相应JVM进程运行时该参数的参数值。

三、例子

3.1、例子1

有如下一段代码:

1
2
3
4
5
public class Example {
public static void main(String[] args) throws InterruptedException {
Thread.sleep(10 * 60 * 1000L);
}
}

编译后,执行java -showversion -verbose:jni -Dhello=world -classpath ".:$JAVA_HOME/lib/tools.jar" -Xnoclassgc -Xloggc:jvm.log -verbose:gc -XX:+PrintGCTimeStamps -XX:+PrintGCDetails -XX:+PrintGCDateStamps -Xms10M -Xmx20M -XX:SurvivorRatio=8 -XX:PermSize=20M -XX:MaxPermSize=100M Example 10 20命令,在该JVM进程(假设JVM进程ID为15506)还在运行时,执行jinfo 15506命令,得到如下所示结果:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Java System Properties:

java.runtime.name = Java(TM) SE Runtime Environment
java.vm.version = 24.79-b02
sun.boot.library.path = /mnt/bigdisk/apps/jdk1.7.0_79/jre/lib/i386
hello = world
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) Client VM
sun.os.patch.level = unknown
sun.java.launcher = SUN_STANDARD
user.country = CN
user.dir = /mnt/bigdisk/workspace/dslztx/src/main/java
java.vm.specification.name = Java Virtual Machine Specification
java.runtime.version = 1.7.0_79-b15
java.awt.graphicsenv = sun.awt.X11GraphicsEnvironment
os.arch = i386
java.endorsed.dirs = /mnt/bigdisk/apps/jdk1.7.0_79/jre/lib/endorsed
java.io.tmpdir = /tmp
line.separator =

java.vm.specification.vendor = Oracle Corporation
os.name = Linux
sun.jnu.encoding = UTF-8
java.library.path = /usr/java/packages/lib/i386:/lib:/usr/lib
java.specification.name = Java Platform API Specification
java.class.version = 51.0
sun.management.compiler = HotSpot Client Compiler
os.version = 3.16.0-30-generic
user.home = /home/dsl
user.timezone =
java.awt.printerjob = sun.print.PSPrinterJob
file.encoding = UTF-8
java.specification.version = 1.7
user.name = dsl
java.class.path = .:/home/dsl/bigdisk/apps/jdk1.7.0_79/lib/tools.jar
java.vm.specification.version = 1.7
sun.arch.data.model = 32
sun.java.command = Example 10 20
java.home = /mnt/bigdisk/apps/jdk1.7.0_79/jre
user.language = zh
java.specification.vendor = Oracle Corporation
awt.toolkit = sun.awt.X11.XToolkit
java.vm.info = mixed mode
java.version = 1.7.0_79
java.ext.dirs = /mnt/bigdisk/apps/jdk1.7.0_79/jre/lib/ext:/usr/java/packages/lib/ext
sun.boot.class.path = /mnt/bigdisk/apps/jdk1.7.0_79/jre/lib/resources.jar:/mnt/bigdisk/apps/jdk1.7.0_79/jre/lib/rt.jar:/mnt/bigdisk/apps/jdk1.7.0_79/jre/lib/sunrsasign.jar:/mnt/bigdisk/apps/jdk1.7.0_79/jre/lib/jsse.jar:/mnt/bigdisk/apps/jdk1.7.0_79/jre/lib/jce.jar:/mnt/bigdisk/apps/jdk1.7.0_79/jre/lib/charsets.jar:/mnt/bigdisk/apps/jdk1.7.0_79/jre/lib/jfr.jar:/mnt/bigdisk/apps/jdk1.7.0_79/jre/classes
java.vendor = Oracle Corporation
file.separator = /
java.vendor.url.bug = http://bugreport.sun.com/bugreport/
sun.io.unicode.encoding = UnicodeLittle
sun.cpu.endian = little
sun.desktop = gnome
sun.cpu.isalist =

VM Flags:

-verbose:jni -Dhello=world -Xnoclassgc -Xloggc:jvm.log -verbose:gc -XX:+PrintGCTimeStamps -XX:+PrintGCDetails -XX:+PrintGCDateStamps -Xms10M -Xmx20M -XX:SurvivorRatio=8 -XX:PermSize=20M -XX:MaxPermSize=100M

3.2、例子2

使用上一小节的代码,编译后,执行java Example命令,在该JVM进程(假设JVM进程ID为15945)还在运行时,依次执行:

1
2
3
4
5
6
jinfo -flag PrintGCTimeStamps 15945
jinfo -flag PrintGCDetails 15945
jinfo -flag PrintGCDateStamps 15945
jinfo -flag SurvivorRatio 15945
jinfo -flag PermSize 15945
jinfo -flag MaxPermSize 15945

依次执行结果显示如下:

1
2
3
4
5
6
-XX:-PrintGCTimeStamps
-XX:-PrintGCDetails
-XX:-PrintGCDateStamps
-XX:SurvivorRatio=8
-XX:PermSize=12582912
-XX:MaxPermSize=67108864

参考文献: [1]http://docs.oracle.com/javase/7/docs/technotes/tools/share/jinfo.html [2]man jinfo
您的支持将鼓励我继续分享!