欢迎访问移动开发之家(rcyd.net),关注移动开发教程。移动开发之家  移动开发问答|  每日更新
页面位置 : > > 内容正文

JVM 性能调优工具 jinfo-云栖社区-阿里云,阿里云云栖

来源: 开发者 投稿于  被查看 14677 次 评论:256

JVM 性能调优工具 jinfo-云栖社区-阿里云,阿里云云栖


Jinfo 是 JDK 自带的命令,可以用来查看正在运行的 java 应用程序的扩展参数,包括Java System属性和JVM命令行参数;也可以动态的修改正在运行的 JVM 一些参数。当系统崩溃时,jinfo可以从core文件里面知道崩溃的Java应用程序的配置信息。

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:-UseLargePagesInpidualAllocation -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

相关频道:

用户评论