JVM小工具在实际中的应用

318 阅读2分钟

本文的工具环境是 1.8.0_191-8u191

1.jinfo

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

jinfo -flags pid 查看全部启动参数

jinfo -flags 13874

Attaching to process ID 13874, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.191-b12
Non-default VM flags: -XX:CICompilerCount=3 -XX:+IgnoreUnrecognizedVMOptions -XX:InitialHeapSize=163577856 -XX:MaxHeapSize=2606759936 -XX:MaxNewSize=868745216 -XX:MinHeapDeltaBytes=524288 -XX:NewSize=54525952 -XX:OldSize=109051904 -XX:+PrintHeapAtGC -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseParallelGC
Command line:  -Xlog:gc* -Xlog:safepoint -XX:+IgnoreUnrecognizedVMOptions -XX:+PrintHeapAtGC -Xlog:gc:/home/tmp/heap_trace.txt -Djava.security.egd=file:/dev/./urandom
其它用法

jinfo -sysprops pid 查看系统参数

jinfo -flag +/- key [value] pid 开启/关闭某个参数

2. jstack

jstack主要用来追踪Java的堆栈信息。

  • 针对活着的进程做本地的或远程的线程dump;
  • 针对core文件做线程dump。

Usage:
    jstack [-l] <pid>
        (to connect to running process)
    jstack -F [-m] [-l] <pid>
        (to connect to a hung process)
    jstack [-m] [-l] <executable> <core>
        (to connect to a core file)
    jstack [-m] [-l] [server_id@]<remote server IP or hostname>
        (to connect to a remote debug server)

Options:
    -F  to force a thread dump. Use when jstack <pid> does not respond (process is hung)
    -m  to print both java and native frames (mixed mode)
    -l  long listing. Prints additional information about locks
    -h or -help to print this help message

  • -l 长列表. 打印关于锁的附加信息,例如属于java.util.concurrent 的 ownable synchronizers列表.
  • -F 当jstack [-l] pid没有相应的时候强制打印栈信息
  • -m 打印java和native c/c++框架的所有栈信息.