Detailed explanation of the use of jinfo command in Java

Introduction to the 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 the Java virtual machine in real time. Use the -v parameter of the jps command to view the configuration parameters 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 System.getProperties()the content of the Java virtual machine process.

On dbgeng.dllWindows systems that don't have it, the debugging tools for Windows must be installed for the jinfo command to work, and the PATH environment variable should contain the location of jvm.dll.

jinfo command parameters

Command syntax:

jinfo [option] pid

Command parameter description:

  • option: Optional argument to the jinfo command. If this parameter is not specified, the jinfo command displays all configuration parameters and system properties.
  • pid: The process ID of the Java virtual machine for which configuration information is to be printed.

To get a list of running Java virtual machine processes, use the ps command (on Linux systems) or the tasklist command (on Windows systems), or if the Java virtual machine processes are not running in a separate docker instance, use the jps command.

optionWhat are the parameters? Let's take 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

Enables or disables the parameter with the specified name, which must be of Booleantype. For example, to enable simple GC logging mode:

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

For example, to disable simple GC logging mode:

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

-flag name=value

It is not necessary 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 like this, such as the number of threads 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, what configuration parameters support dynamic modification? We can java -XX:+PrintFlagsInitialfind the configuration parameters marked as through the command manageable, and the running result is shown in the following figure:

Manneko Gakusha.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 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.

end

Although the jinfo command has been introduced for a long time and is used frequently, it is still an "Experimental and Unsupported" tool, which may be turned into a positive in the future, or it may be silent in a certain JDK version disappeared without a trace. So, use it and cherish it.

Finally, thank you for being so handsome, and for giving me likes and attention .

{{o.name}}
{{m.name}}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324135875&siteId=291194637