jinfo 用法
$ 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
參數說明
- pid 對應jvm的進程id
- executable core 產生core dump文件
- [server-id@]remote server IP or hostname 遠程的ip或者hostname,server-id標記服務的唯一性id
option
- no option 輸出全部的參數和系統屬性
- -flag name 輸出對應名稱的參數
- -flag [+|-]name 開啓或者關閉對應名稱的參數
- -flag name=value 設定對應名稱的參數
- -flags 輸出全部的參數
- -sysprops 輸出系統屬性
Javacore 概述
Javacore,也可以稱爲“threaddump”或是“javadump”,它是 Java 提供的一種診斷特性,能夠提供一份可讀的當前運行的 JVM 中線程使用情況的快照。即在某個特定時刻,JVM 中有哪些線程在運行,每個線程執行到哪一個類,哪一個方法。
應用程序如果出現不可恢復的錯誤或是內存泄露,就會自動觸發 Javacore 的生成。
示例一:no option
命令:jinfo <pid>
描述:輸出當前 jvm 進程的全部參數和系統屬性
$ jinfo 22912
Attaching to process ID 22912, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.161-b12
Java System Properties:
java.vendor = Oracle Corporation
preload.project.path = D:/WorkSpace/hqev/rbac
sun.java.launcher = SUN_STANDARD
idea.config.path = D:/Program Files/JetBrains/IntelliJIdeaConfig/config
sun.management.compiler = HotSpot 64-Bit Tiered Compilers
sun.nio.ch.bugLevel =
idea.paths.selector = IntelliJIdea2018.1
kotlin.daemon.client.alive.path = "C:\Users\Victor.Zxy\AppData\Local\Temp\kotlin-idea-3229673183181290493-is-running"
os.name = Windows 10
示例二:-flag name
命令:jinfo -flag name <pid>
描述:輸出對應名稱的參數
$ jinfo -flag PrintGC 22912
-XX:-PrintGC
$ jinfo -flag PrintGCDetails 22912
-XX:-PrintGCDetails
$ jinfo -flag PrintGCTimeStamps 22912
-XX:-PrintGCTimeStamps
使用該命令,可以查看指定的 jvm 參數的值。如:查看當前 jvm 進程是否開啓打印 GC 日誌。
示例三:-flag [+|-]name
命令:jinfo -flag [+|-]name <pid>
描述:開啓或者關閉對應名稱的參數
$ jinfo -flag +PrintGC 22912
$ jinfo -flag PrintGC 22912
-XX:+PrintGC
$ jinfo -flag -PrintGC 22912
$ jinfo -flag PrintGC 22912
-XX:-PrintGC
使用 jinfo 可以在不重啓虛擬機的情況下,可以動態的修改 jvm 的參數。尤其在線上的環境特別有用。
示例四:-flag name=value
命令:jinfo -flag name=value <pid>
描述:修改指定參數的值(同示例三,但示例三主要是針對 boolean 值的參數設置的。如果是設置 value值,則需要使用 name=value 的形式)。
$ jinfo -flag HeapDumpPath 22912
-XX:HeapDumpPath=
$ jinfo -flag HeapDumpPath=C:\Users\Victor.Zxy\error.hprof 22912
$ jinfo -flag HeapDumpPath 22912
-XX:HeapDumpPath=C:\Users\Victor.Zxy\error.hprof
jinfo雖然可以在java程序運行時動態地修改虛擬機參數,但並不是所有的參數都支持動態修改。
示例五:-flags
命令:jinfo -flags <pid>
描述:輸出全部的參數
$ jinfo -flags 22912
Attaching to process ID 22912, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.161-b12
Non-default VM flags: -XX:CICompilerCount=3 -XX:HeapDumpPath=null -XX:InitialHeapSize=335544320 -XX:MaxHeapSize=734003200 -XX:MaxNewSize=244318208 -XX:MinHeapDeltaBytes=524288 -XX:NewSize=111673344 -XX:OldSize=223870976 -XX:-PrintGC -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseFastUnorderedTimeStamps -XX:-UseLargePagesIndividualAllocation -XX:+UseParallelGC
Command line: -Xmx700m -Djava.awt.headless=true -Djava.endorsed.dirs="" -Djdt.compiler.useSingleThread=true -Dpreload.project.path=D:/WorkSpace/hqev/rbac -Dpreload.config.path=D:/Program Files/JetBrains/IntelliJIdeaConfig/config/options -Dcompile.parallel=false -Drebuild.on.dependency.change=true -Djava.net.preferIPv4Stack=true -Dio.netty.initialSeedUniquifier=8246017585702392224 -Dfile.encoding=UTF-8 -Duser.language=zh -Duser.country=CN -Didea.paths.selector=IntelliJIdea2018.1 -Didea.home.path=D:\Program Files\JetBrains\IntelliJ IDEA 2018.1 -Didea.config.path=D:/Program Files/JetBrains/IntelliJIdeaConfig/config -Didea.plugins.path=D:/Program Files/JetBrains/IntelliJIdeaConfig/config/plugins -Djps.log.dir=D:/Program Files/JetBrains/IntelliJIdeaConfig/system/log/build-log -Djps.fallback.jdk.home=D:/Program Files/JetBrains/IntelliJ IDEA 2018.1/jre64 -Djps.fallback.jdk.version=1.8.0_152-release -Dio.netty.noUnsafe=true -Djava.io.tmpdir=D:/Program Files/JetBrains/IntelliJIdeaConfig/system/compile-server/rbac_aca57a50/_temp_ -Djps.backward.ref.index.builder=true -Dkotlin.incremental.compilation=true -Dkotlin.daemon.enabled -Dkotlin.daemon.client.alive.path="C:\Users\Victor.Zxy\AppData\Local\Temp\kotlin-idea-3229673183181290493-is-running"
示例六:-sysprops
命令:jinfo -sysprops <pid>
描述:輸出當前 jvm 進行的全部的系統屬性
$ jinfo -sysprops 22912
Attaching to process ID 22912, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.161-b12
java.vendor = Oracle Corporation
preload.project.path = D:/WorkSpace/hqev/rbac
sun.java.launcher = SUN_STANDARD
idea.config.path = D:/Program Files/JetBrains/IntelliJIdeaConfig/config
sun.management.compiler = HotSpot 64-Bit Tiered Compilers
sun.nio.ch.bugLevel =
idea.paths.selector = IntelliJIdea2018.1
kotlin.daemon.client.alive.path = "C:\Users\Victor.Zxy\AppData\Local\Temp\kotlin-idea-3229673183181290493-is-running"
os.name = Windows 10
sun.boot.class.path = D:\Program Files\Java\jdk1.8.0_161\jre\lib\resources.jar;D:\Program Files\Java\jdk1.8.0_161\jre\lib\rt.jar;D:\Program Files\Java\jdk1.8.0_161\jre\lib\sunrsasign.jar;D:\Program Files\Java\jdk1.8.0_161\jre\lib\jsse.jar;D:\Program Files\Java\jdk1.8.0_161\jre\lib\jce.jar;D:\Program Files\Java\jdk1.8.0_161\jre\lib\charsets.jar;D:\Program Files\Java\jdk1.8.0_161\jre\lib\jfr.jar;D:\Program Files\Java\jdk1.8.0_161\jre\classes
sun.desktop = windows
idea.plugins.path = D:/Program Files/JetBrains/IntelliJIdeaConfig/config/plugins
java.vm.specification.vendor = Oracle Corporation
java.runtime.version = 1.8.0_161-b12