JVM调优小工具之jinfo

简介

jinfo 全称Java Configuration Info,是JDK自带的用于查看和修改虚拟机参数的命令行工具。根据官方文档可知,jinfo可以查看给定java进程 或远程调试服务器 或Core文件的Java配置信息。其中配置信息包括Java系统属性、JVM参数。除此以外,它还可以在Java程序运行过程中修改部分JVM参数。

使用方法(使用过程中出现异常,请参考这里解决)

jinfo [option] :连接到特定进程执行option操作
jinfo [option] :连接到特定Core文件执行option操作
jinfo [option] [server_id@] :连接到远程DebugServer执行option操作

options:

options 作用
同时输出Java系统属性和JVM参数
-flag name 输出name以及name所对应的JVM参数值
-flag [+|-]name 修改JVM参数(仅针对Boolean类型)
-flag name=value 修改JVM参数(Boolean类型和非Boolean类型都可以)
-flags 输出传入JVM的命令行标志(参数)
-sysprops 以键值对方式输出Java系统属性
使用示例(以本地虚拟机进程为例)
  1. 先 jinfo 18989查询Java系统参数及JVM参数
david@UX501:~/Desktop$ jps
19079 Jps
18989 Test
david@UX501:~/Desktop$ jinfo 18989
Attaching to process ID 18989, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.212-b01
Java System Properties:

java.runtime.name = OpenJDK Runtime Environment
java.vm.version = 25.212-b01

#此处省略100+行

VM Flags:
Non-default VM flags: -XX:CICompilerCount=4 -XX:InitialHeapSize=20971520 -XX:MaxHeapSize=20971520 -XX:MaxNewSize=6815744 -XX:MinHeapDeltaBytes=524288 -XX:NewSize=6815744 -XX:OldSize=14155776 -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseParallelGC 
Command line:  -Xms20m -Xmx20m -javaagent:/home/david/SoftWare/IDEA/lib/idea_rt.jar=34207:/home/david/SoftWare/IDEA/bin -Dfile.encoding=UTF-8

david@UX501:~/Desktop$ 

  1. 查看Java系统属性
david@UX501:~/Desktop$ jinfo -sysprops 18989
Attaching to process ID 18989, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.212-b01
java.runtime.name = OpenJDK Runtime Environment
java.vm.version = 25.212-b01

#此处省略好多行
  1. 查看传入JVM的参数
david@UX501:~/Desktop$ jinfo -flags 18989
Attaching to process ID 18989, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.212-b01
Non-default VM flags: -XX:CICompilerCount=4 -XX:HeapDumpPath=null -XX:InitialHeapSize=20971520 -XX:MaxHeapSize=20971520 -XX:MaxNewSize=6815744 -XX:MinHeapDeltaBytes=524288 -XX:NewSize=6815744 -XX:OldSize=14155776 -XX:-PrintGCTimeStamps -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseParallelGC 
Command line:  -Xms20m -Xmx20m -javaagent:/home/david/SoftWare/IDEA/lib/idea_rt.jar=34207:/home/david/SoftWare/IDEA/bin -Dfile.encoding=UTF-8
david@UX501:~/Desktop$ 
  1. 查看单个JVM参数
david@UX501:~/Desktop$ jinfo -flag MaxHeapSize 18989
-XX:MaxHeapSize=20971520
  1. 修改某个Boolean类型参数(两种办法。只有中间一句是有用的,前后输出操作仅为了对比)
david@UX501:~/Desktop$ jinfo -flag PrintGCTimeStamps 18989
-XX:+PrintGCTimeStamps

david@UX501:~/Desktop$ jinfo -flag -PrintGCTimeStamps 18989

david@UX501:~/Desktop$ jinfo -flag PrintGCTimeStamps 18989
-XX:-PrintGCTimeStamps
david@UX501:~/Desktop$ 
david@UX501:~/Desktop$ jinfo -flag PrintGCTimeStamps 18989
-XX:+PrintGCTimeStamps

david@UX501:~/Desktop$ jinfo -flag PrintGCTimeStamps=0 18989

david@UX501:~/Desktop$ jinfo -flag PrintGCTimeStamps 18989
-XX:-PrintGCTimeStamps
david@UX501:~/Desktop$ 

  1. 修改非Boolean类型的JVM参数值(前后输出操作仅为作对比)
david@UX501:~/Desktop$ jinfo -flag HeapDumpPath 18989
-XX:HeapDumpPath=

david@UX501:~/Desktop$ jinfo -flag HeapDumpPath=/home/david/dump.hprof 18989

david@UX501:~/Desktop$ jinfo -flag HeapDumpPath 18989
-XX:HeapDumpPath=/home/david/dump.hprof
david@UX501:~/Desktop$ 

参考资料

Oracle官方文档–jinfo


注: 未经授权,禁止转载

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