java - jinfo jvm配置信息工具

文章目录

    • 命令说明
    • 语法
    • 示例说明
      • jinfo -flag pid:打印所有的jvm标志信息
      • jinfo -flag [+|-] name pid :启用或者禁用指定的jvm参数
      • info -flag name=value pid:给指定的jvm参数设置值
      • jinfo -sysprops pid:打印系统参数信息
      • jinfo pid:打印以上所有配置信息

命令说明

jinfo[Configguration Info for Java] 的作用是实时地查看和调整虚拟机的各项参数。

使用jps -v 可以查看虚拟机启动时显示指定的参数列表,但是如果想知道未被显示指定的参数的系统默认值,除了去找资料外,就只能使用jinfo的-flag选项进行查询了。

语法

[root@localhost ~]# jinfo
Usage:
    jinfo [option] 
        (to connect to running process)
    jinfo [option] 
        (to connect to a core file)
    jinfo [option] [server_id@]
        (to connect to remote debug server)

where 

示例说明

jinfo -flag pid:打印所有的jvm标志信息

java - jinfo jvm配置信息工具_第1张图片

C:\Users\Think>jps -l
44748 com.jvm.Test

C:\Users\Think>jinfo -flags 123
Attaching to process ID 123, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.121-b13
Non-default VM flags: -XX:CICompilerCount=4 -XX:InitialHeapSize=10485760 -XX:MaxHeapSize=1048576000 -XX:MaxNewSize=349175808 -XX:MinHeapDeltaBytes=524288 -XX:NewSize=3145728 -XX:OldSize=7340032 -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseFastUnorderedTimeStamps -XX:-UseLargePagesIndividualAllocation -XX:+UseParallelGC
Command line:  -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:64223,suspend=y,server=n -Xms10m -Xmx1000m -Dfile.encoding=UTF-8
  1. Non-default VM flags: 非默认VM标志
  2. Command line: 命令行中指定的jvm参数
  • jinfo -flag name pid: 打印指定的jvm参数信息
[root@localhost ~]# jinfo -flag InitialHeapSize 2345
-XX:InitialHeapSize=522190848

jinfo -flag [+|-] name pid :启用或者禁用指定的jvm参数

我们运行一段程序,下面这段程序vm参数设置为:-Xms5m -Xmx5m,运行过程中会参数OOM,在运行过程中,我们添加vm参数:+HeapDumpOnOutOfMemoryError:发生OOM的时候,让程序打印堆dump文件

public class Test7 {
    private static final int _1M = 1024 * 1024;
    public static void main(String[] args) throws InterruptedException {
        List list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            TimeUnit.SECONDS.sleep(3);
            list.add(new byte[_1M]);
        }
    }
}
 
  

运行过程中添加参数

C:\Users\Think>jps -l
44520 com.jvm.test7.Test7

C:\Users\Think>jinfo -flag +HeapDumpOnOutOfMemoryError 44520

C:\Users\Think>jinfo -flags 44520
Attaching to process ID 44520, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.121-b13
Non-default VM flags: -XX:CICompilerCount=4 -XX:+HeapDumpOnOutOfMemoryError -XX:InitialHeapSize=6291456 -XX:MaxHeapSize=6291456 -XX:MaxNewSize=2097152 -XX:MinHeapDeltaBytes=524288 -XX:NewSize=2097152 -XX:OldSize=4194304 -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseFastUnorderedTimeStamps -XX:-UseLargePagesIndividualAllocation -XX:+UseParallelGC
Command line:  -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:53193,suspend=y,server=n -Xms5m -Xmx5m -Dfile.encoding=UTF-8

程序运行结果:

Connected to the target VM, address: '127.0.0.1:53193', transport: 'socket'
java.lang.OutOfMemoryError: Java heap space
Dumping heap to java_pid44520.hprof ...
Disconnected from the target VM, address: '127.0.0.1:53193', transport: 'socket'
Heap dump file created [4535342 bytes in 0.009 secs]
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
    at com.jvm.test7.Test7.main(Test7.java:18)

info -flag name=value pid:给指定的jvm参数设置值

jinfo -sysprops pid:打印系统参数信息

打印的信息和System.getProperties()一样。

C:\Users\Think>jinfo -sysprops 44748
Attaching to process ID 44748, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.121-b13
java.runtime.name = Java(TM) SE Runtime Environment
java.vm.version = 25.121-b13
sun.boot.library.path = D:\installsoft\Java\jdk1.8.0_121\jre\bin
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 =
sun.java.launcher = SUN_STANDARD
user.script =
user.country = CN
user.dir = D:\code\IdeaProjects\spring-aop-demo
java.vm.specification.name = Java Virtual Machine Specification
java.runtime.version = 1.8.0_121-b13
java.awt.graphicsenv = sun.awt.Win32GraphicsEnvironment
os.arch = amd64
java.endorsed.dirs = D:\installsoft\Java\jdk1.8.0_121\jre\lib\endorsed
line.separator =

java.io.tmpdir = C:\Users\Think\AppData\Local\Temp\
java.vm.specification.vendor = Oracle Corporation
user.variant =
os.name = Windows 10
sun.jnu.encoding = GBK
java.library.path = D:\installsoft\Java\jdk1.8.0_121\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\ProgramData\DockerDesktop\version-bin;
java.class.path = D:\installsoft\Java\jdk1.8.0_121\jre\lib\charsets.jar;D:\installsoft\Java\jdk1.8.0_121\jre\lib\deploy.jar;
java.specification.vendor = Oracle Corporation
awt.toolkit = sun.awt.windows.WToolkit
java.vm.info = mixed mode
java.version = 1.8.0_121
java.ext.dirs = D:\installsoft\Java\jdk1.8.0_121\jre\lib\ext;C:\Windows\Sun\Java\lib\ext
......

jinfo pid:打印以上所有配置信息

C:\Users\Think>jinfo 44748
Attaching to process ID 44748, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.121-b13
Java System Properties:

java.runtime.name = Java(TM) SE Runtime Environment
java.vm.version = 25.121-b13
sun.boot.library.path = D:\installsoft\Java\jdk1.8.0_121\jre\bin
java.vendor.url = http://java.oracle.com/
java.vm.vendor = Oracle Corporation
path.separator = ;
......

VM Flags:
Non-default VM flags: -XX:CICompilerCount=4 -XX:InitialHeapSize=10485760 -XX:MaxHeapSize=1048576000 -XX:MaxNewSize=349175808 -XX:MinHeapDeltaBytes=524288 -XX:NewSize=3145728 -XX:OldSize=7340032 -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseFastUnorderedTimeStamps -XX:-UseLargePagesIndividualAllocation -XX:+UseParallelGC
Command line:  -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:64223,suspend=y,server=n -Xms10m -Xmx1000m -Dfile.encoding=UTF-8

你可能感兴趣的:(java命令,java,java)