Detailed explanation of Jinfo command in Java

Time:2022-8-2

Introduction to Jinfo command

Jinfo (Java virtual machine configuration information) is a command line tool provided by JDK that can view various configuration parameters and system properties of Java virtual machine in real time. Use the -v parameter of the JPS command to view the configuration parameters that are explicitly specified when the Java virtual machine starts. If you want to view the configuration parameters that are not explicitly specified, you can use the Jinfo command to view them. In addition, the Jinfo command can also query theSystem.getProperties()Content of.

Nodbgeng.dllIn the windows system of, the debugging tool for windows must be installed to make the Jinfo command work normally. The path environment variable should contain the location of jvm.dll.

Jinfo command parameters

Command syntax:

jinfo [option] pid

Description of command parameters:

  • option: optional parameters of Jinfo command. If this parameter is not specified, the Jinfo command will display all configuration parameters and system properties.
  • pid: the process ID of the Java virtual machine to print configuration information.

To get the list of running Java virtual machine processes, you can use PS command (in Linux system) or tasklist command (in Windows system). If Java virtual machine processes are not running in a separate docker instance, you can use JPS command.

optionWhat are the parameters? Let’s have a look.

-flag name

Display the configuration parameters corresponding to the specified name. For example, check whether the simple GC log mode (printgc) is enabled:

# jinfo -flag PrintGC 15729
-XX:-PrintGC

-flag [+|-]name

Enable or disable the parameter with the specified name, which must beBooleanType. For example, turn on the simple GC log mode:

# jinfo -flag +PrintGC 15729
# jinfo -flag PrintGC 15729
-XX:+PrintGC

For example, disable simple GC logging mode:

# jinfo -flag -PrintGC 15729
# jinfo -flag PrintGC 15729
-XX:-PrintGC

-flag name=value

There is no need to restart the Java virtual machine, and modify the parameter with the specified name to the specified value. For example, modify the minimum percentage of free heap space (minheapfreeratio) to 30%:

# jinfo -flag MinHeapFreeRatio 15729
-XX:MinHeapFreeRatio=40
# jinfo -flag MinHeapFreeRatio=30 15729
# jinfo -flag MinHeapFreeRatio 15729
-XX:MinHeapFreeRatio=30

Of course, not all parameters can be modified in this way, such as the number of threads that the concurrent garbage collector will use (concgcthreads):

# jinfo -flag ConcGCThreads=5 15729
Exception in thread "main" com.sun.tools.attach.AttachOperationFailedException: flag 'ConcGCThreads' cannot be changed

        at sun.tools.attach.LinuxVirtualMachine.execute(LinuxVirtualMachine.java:229)
        at sun.tools.attach.HotSpotVirtualMachine.executeCommand(HotSpotVirtualMachine.java:261)
        at sun.tools.attach.HotSpotVirtualMachine.setFlag(HotSpotVirtualMachine.java:234)
        at sun.tools.jinfo.JInfo.flag(JInfo.java:134)
        at sun.tools.jinfo.JInfo.main(JInfo.java:81)

So, which configuration parameters support dynamic modification? We can passjava -XX:+PrintFlagsInitialCommand found marked asmanageableThe running results of the configuration parameters of are shown in the following figure:

万猫学社.png

-flags

Display all configuration parameters, such as:

# jinfo -flags 15729
Attaching to process ID 15729, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.251-b08
Non-default VM flags: -XX:CICompilerCount=4 -XX:ConcGCThreads=2 -XX:G1HeapRegionSize=1048576 -XX:InitialHeapSize=1073741824 -XX:MarkStackSize=4194304 -XX:MaxHeapSize=1073741824 -XX:MaxNewSize=536870912 -XX:MetaspaceSize=268435456 -XX:MinHeapDeltaBytes=1048576 -XX:MinHeapFreeRatio=30 -XX:NewSize=536870912 -XX:-PrintGC -XX:SurvivorRatio=4 -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseFastUnorderedTimeStamps -XX:+UseG1GC 
Command line:  -Xmx1g -Xms1g -Xmn512m -XX:SurvivorRatio=4 -XX:MetaspaceSize=256m -XX:+UseG1GC

-sysprops

Display all the system properties of the current Java virtual machine in the form of key value pairs, such as:

# jinfo -sysprops 15729
Attaching to process ID 15729, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.251-b08
java.runtime.name = Java(TM) SE Runtime Environment
java.vm.version = 25.251-b08
sun.boot.library.path = /usr/local/java/jdk1.8.0_251/jre/lib/amd64
java.protocol.handler.pkgs = org.springframework.boot.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
sun.os.patch.level = unknown
sun.java.launcher = SUN_STANDARD
user.country = CN
java.vm.specification.name = Java Virtual Machine Specification
PID = 15729
java.runtime.version = 1.8.0_251-b08
java.awt.graphicsenv = sun.awt.X11GraphicsEnvironment
os.arch = amd64
java.endorsed.dirs = /usr/local/java/jdk1.8.0_251/jre/lib/endorsed
line.separator = 
......

-H and -help

Displays help information for the Jinfo command.

ending

Although Jinfo command has been launched for a long time and is used frequently, it is still an “experimental and unsupported” tool, which may be confirmed in the future or disappear silently in a JDK version. So, use and cherish it.

Finally, thank you for being so handsome. Give it back to megive the thumbs-upandfollow

Wechat official account: wanmao Society

Wechat scanning QR code

Reply to “e-book” after following

Get 12 Java required technical books

Detailed explanation of Jinfo command in Java