JVM - jinfo工具

2021/09/29 JVM 共 3145 字,约 9 分钟
Bob.Zhu

jinfo: 实时地查看和调整虚拟机各项参数

jinfo -help

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

查看

jinfo vmid

jinfo vmid:输出当前 jvm 进程的全部参数和系统属性 (第一部分是系统的属性,第二部分是 JVM 的参数)。

Attaching to process ID 32577, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 24.76-b04
Java System Properties:

java.runtime.name = Java(TM) SE Runtime Environment
java.vm.version = 24.76-b04
sun.boot.library.path = /home/jyapp/app/jdk1.7.0_76/jre/lib/amd64
java.protocol.handler.pkgs = org.apache.catalina.webresources
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 = /home/jyapp/app/tomcat-8096/conf/logging.properties
tomcat.util.buf.StringCache.byte.enabled = true
sun.os.patch.level = unknown
sun.java.launcher = SUN_STANDARD
user.country = US
tomcat.util.scan.StandardJarScanFilter.jarsToScan = log4j-web*.jar,log4j-taglib*.jar,log4javascript*.jar,slf4j-taglib*.jar
user.dir = /home/jyapp/app/tomcat-8096
java.vm.specification.name = Java Virtual Machine Specification
java.runtime.version = 1.7.0_76-b13
java.awt.graphicsenv = sun.awt.X11GraphicsEnvironment
os.arch = amd64
java.endorsed.dirs = /home/jyapp/app/jdk1.7.0_76/jre/lib/endorsed

VM Flags:
-Djava.util.logging.config.file=/home/jyapp/app/tomcat-8096/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dignore.endorsed.dirs= -Dcatalina.base=/home/jyapp/app/tomcat-8096 -Dcatalina.home=/home/jyapp/app/tomcat-8096 -Djava.io.tmpdir=/home/jyapp/app/tomcat-8096/temp

jinfo -flag name vmid

jinfo -flag name vmid:输出对应名称的参数的具体值。 比如输出 MaxHeapSize、查看当前 jvm 进程是否开启打印 GC 日志 ( -XX:PrintGCDetails: 详细 GC 日志模式,这两个都是默认关闭的)。

Jps
25259 Jps
19343 Bootstrap
32577 Bootstrap
14029 Bootstrap
jinfo -flag MaxHeapSize 19343
-XX:MaxHeapSize=2051014656
jinfo -flag PrintGC 19343
-XX:-PrintGC

动态调整

jinfo -flag [+|-]name vmid 开启或者关闭对应名称的参数。

jinfo -flag PrintGC 19343
jinfo -flag +PrintGC 19343
jinfo -flag PrintGC 19343

问题

在执行 jinfo pid 的时候,遇到如下问题:

Attaching to process ID 19343, please wait...
Error attaching to process: sun.jvm.hotspot.debugger.DebuggerException: Can't attach to the process

以为是权限问题,切换到root用户之后执行 jps 得到如下信息:

3482 Jps
3413 Application
19343 -- process information unavailable
32577 -- process information unavailable
14029 -- process information unavailable

root账户下,执行jps指令获取pid信息也失败了,搜索后得知,因为新版的Linux系统加入了 ptrace-scope 机制. 这种机制为了防止用户访问当前正在运行的进程的内存和状态, 而一些调试软件本身就是利用 ptrace 来进行获取某进程的内存状态的(包括GDB), 所以在新版本的Linux系统, 默认情况下不允许再访问了. 可以临时开启. 如:

echo 0 > /proc/sys/kernel/yama/ptrace_scope

退出root账号,再次执行 jinof pid 指令就可以看到相关输出信息了。

![image-alter](/image/post/2021/09/29/03/xxx.jpg)

参考资料

文档信息

Search

    Table of Contents