JVM学习-监控工具(一)

使用数据说明问题,使用知识分析问题,使用工具处理问题

无监控,不调优!

命令行工具

在JDK安装目录下,可以查看到相应的命令行工具,如下图

jps(Java Process Status)

显示指定系统内所有的Hotpot虚拟机进程,可用于查询正在运行的虚拟机进程,对于本地虚拟机进程来说,进程的本地虚拟机ID与操作系统的进程ID是一致的,是唯一的

基本语法
  • jps [options] [hostid]
  • 【options】
  • -q:仅显示LVMID(local virtual machine id),即本地虚拟机唯一ID,不显示主类的名称
  • -l:输出应用程序主类的全类名或如果进程执行的是jar包,则输出jar完整路径
  • -m:输出虚拟机进程启动时传递给主类main()的参数
  • -v:列出虚拟机进程启动时的JVM参数,比如:-Xms20m -Xmx50m是启动程序指定的JVM参数
  • 补充:如果某Java进程关闭了默认开启的UsePerfData参数(即使用参数-XX:-UsePerfData),那么jps命令将无法探知该Java进程
java 复制代码
//测试代码
public class ScannerTest {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String info = scanner.next();
    }
}
//通过jps查看Java进程
C:\Users\Administrator\IdeaProjects\jvm>jps
14000 ScannerTest          //---查看到运行的程序
5936 Jps
8640 Launcher              //虚拟机启动的进程
2856
7496 RemoteMavenServer36
//只显示pid
C:\Users\Administrator\IdeaProjects\jvm>jps -q
14000
8640
9920
2856
7496
//完整全类名
C:\Users\Administrator\IdeaProjects\jvm>jps -l
10224 sun.tools.jps.Jps
14000 com.chapter12.ScannerTest
8640 org.jetbrains.jps.cmdline.Launcher
2856
7496 org.jetbrains.idea.maven.server.RemoteMavenServer36
C:\Users\Administrator\IdeaProjects\jvm>jps -m
14000 ScannerTest
8640 Launcher D:/Program Files/JetBrains/IntelliJ IDEA 2019.3.5/lib/guava-27.1-jre.jar;D:/Program Files/JetBrains/IntelliJ IDEA 2019.3.5/lib/httpcore-4.4.12
.jar;D:/Program Files/JetBrains/IntelliJ IDEA 2019.3.5/lib/resources_en.jar;D:/Program Files/JetBrains/IntelliJ IDEA 2019.3.5/plugins/java/lib/aether-depend
ency-resolver.jar;D:/Program Files/JetBrains/IntelliJ IDEA 2019.3.5/lib/protobuf-java-3.5.1.jar;D:/Program Files/JetBrains/IntelliJ IDEA 2019.3.5/lib/netty-
codec-4.1.41.Final.jar;D:/Program Files/JetBrains/IntelliJ IDEA 2019.3.5/lib/netty-buffer-4.1.41.Final.jar;D:/Program Files/JetBrains/IntelliJ IDEA 2019.3.5
/lib/qdox-2.0-M10.jar;D:/Program Files/JetBrains/IntelliJ IDEA 2019.3.5/lib/jdom.jar;D:/Program Files/JetBrains/IntelliJ IDEA 2019.3.5/plugins/java/lib/aeth
er-util-1.1.0.jar;D:/Program Files/JetBrains/IntelliJ IDEA 2019.3.5/lib/idea_rt.jar;D:/Program Files/JetBrains/IntelliJ IDEA 2019.3.5/lib/netty-transport-4.
1.41.Final.jar;D:/Program Files/JetBrains/IntelliJ IDEA 2019.3.5/pl
2856
7496 RemoteMavenServer36
9084 Jps -m
C:\Users\Administrator\IdeaProjects\jvm>jps -v
14000 ScannerTest -javaagent:D:\Program Files\JetBrains\IntelliJ IDEA 2019.3.5\lib\idea_rt.jar=65018:D:\Program Files\JetBrains\IntelliJ IDEA 2019.3.5\bin -
Dfile.encoding=UTF-8
8640 Launcher -Xmx700m -Djava.awt.headless=true -Djava.endorsed.dirs="" -Djdt.compiler.useSingleThread=true -Dpreload.project.path=C:/Users/Administrator/Id
eaProjects/jvm -Dpreload.config.path=C:/Users/Administrator/.IntelliJIdea2019.3/config/options -Dexternal.project.config=C:\Users\Administrator\.IntelliJIde
a2019.3\system\external_build_system\jvm.f468d1e -Dcompile.parallel=false -Drebuild.on.dependency.change=true -Djava.net.preferIPv4Stack=true -Dio.netty.ini
tialSeedUniquifier=-7130423394365373067 -Dfile.encoding=GBK -Duser.language=zh -Duser.country=CN -Didea.paths.selector=IntelliJIdea2019.3 -Didea.home.path=D
:\Program Files\JetBrains\IntelliJ IDEA 2019.3.5 -Didea.config.path=C:\Users\Administrator/.IntelliJIdea2019.3/config -Didea.plugins.path=C:\Users\Administr
ator/.IntelliJIdea2019.3/config/plugins -Djps.log.dir=C:/Users/Administrator/.IntelliJIdea2019.3/system/log/build-log -Djps.fallback.jdk.home=D:/Program Fil
es/JetBrains/IntelliJ IDEA 2019.3.5/jbr -Djps.fallback.jdk.version=11.0.6 -Dio.netty.noUnsafe=true -Dj
2856  exit -Xms128m -Xmx2048m -XX:ReservedCodeCacheSize=240m -XX:+UseConcMarkSweepGC -XX:SoftRefLRUPolicyMSPerMB=50 -ea -XX:CICompilerCount=2 -Dsun.io.useCa
nonPrefixCache=false -Djava.net.preferIPv4Stack=true -Djdk.http.auth.tunneling.disabledSchemes="" -XX:+HeapDumpOnOutOfMemoryError -XX:-OmitStackTraceInFastT
hrow -Djdk.attach.allowAttachSelf=true -Dkotlinx.coroutines.debug=off -Djdk.module.illegalAccess.silent=true -javaagent:C:\Users\Public\.jetbrains\jetbrains
-agent-v3.2.0.de72.619 -Djb.vmOptionsFile=C:\Users\Administrator\.IntelliJIdea2019.3\config\idea64.exe.vmoptions -Djava.library.path=D:\Program Files\JetBra
ins\IntelliJ IDEA 2019.3.5\jbr\\bin;D:\Program Files\JetBrains\IntelliJ IDEA 2019.3.5\jbr\\bin\server -Didea.jre.check=true -Dide.native.launcher=true -Dide
a.paths.selector=IntelliJIdea2019.3 -XX:ErrorFile=C:\Users\Administrator\java_error_in_idea_%p.log -XX:HeapDumpPath=C:\Users\Administrator\java_error_in_ide
a.hprof
6360 Jps -Dapplication.home=D:\Program Files\Java\jdk1.8.0_131 -Xms8m
7496 RemoteMavenServer36 -Djava.awt.headless=true -Dmaven.defaultProjectBuilder.disableGlobalModelCache=true -Xmx768m -Didea.maven.embedder.version=3.8.4 -D
maven.ext.class.path=D:\Program Files\JetBrains\IntelliJ IDEA 2019.3.5\plugins\maven\lib\maven-event-listener.jar -Dfile.encoding=GBK

//如果在程序运行时添加-XX:-UsePerfData,则通过jps无法查看
C:\Users\Administrator\IdeaProjects\jvm>jps
3268 Jps
2856
6776 Launcher
7496 RemoteMavenServer36
jstat-查看JVM编译信息

jstat(JVM statistics Monitoring Tool):用于监视虚拟机各种运行状态信息的命令行工具,它可以显示本地或远程进程中的类装载、内存、垃圾收集、JIT编译等运行数据,在没有GUI图形界面下,jstat是性能问题的首选工具,用于检测垃圾回收问题以及内存泄漏问题

  • 基本语法
    jstat - [-t] [-h] [ []]
  • [options]- 类装载相关
  • 类装载相关 -class:显示ClassLoader的相关信息:类装载,卸载数量,总空间,类装载所消耗时间
java 复制代码
//查询1次
C:\Users\Administrator\IdeaProjects\jvm>jstat -class 5752
Loaded  Bytes  Unloaded  Bytes     Time
   728  1447.3        0     0.0       0.08
  • [options]-垃圾回收相关
    • 垃圾回收相关-gc:显示与GC相关的堆信息,包括Eden区,两个Survivor区,老年代、永久代等的容量,已用空间,GC时间合计等信息
java 复制代码
C:\Users\Administrator\IdeaProjects\jvm>jstat -gc 10988
 S0C    S1C    S0U    S1U      EC       EU        OC         OU       MC     MU    CCSC   CCSU   YGC     YGCT    FGC    FGCT     GCT
21504.0 21504.0  0.0    0.0   131072.0 10485.8   348160.0     0.0     4480.0 770.4  384.0   75.9       0    0.000   0      0.000    0.000
//S0C:表示Survivor0区capacity(容量)
//S0U:表示Survivor0区Use
//EC:eden区Capacity
//EU:eden区Use
//OC:Old区capacity
//OU:Old区use
//MC:Method区capacity
//MU:Method区Use
//YGC:Young Gabage Collection次数
//YGCT:Young Gabage Collection时间
//FGC:Full Gabage Collection次数
//FGCT:Full Gabage Collection时间
//GCT:总Gabage Collection Time时间
//CCSC:Compact Class Space Capacity压缩类空间大小
//CCSU:Compact Class Space Use
public class GCTest {
    public static void main(String[] args) {
        ArrayList<byte[]> list = new ArrayList<>();

        for (int i = 0; i < 1000; i++) {
            byte[] arr = new byte[1024 * 1024];
            list.add(arr);
            try {
                Thread.sleep(1200);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}

C:\Users\Administrator\IdeaProjects\jvm>jstat -gc 1196 1000 10
 S0C    S1C    S0U    S1U      EC       EU        OC         OU       MC     MU    CCSC   CCSU   YGC     YGCT    FGC    FGCT     GCT
2048.0 2048.0  0.0   2024.0 16384.0   1024.0   40960.0    11400.2   4864.0 3993.6 512.0  446.8       1    0.007   0      0.000    0.007
2048.0 2048.0  0.0   2024.0 16384.0   2355.2   40960.0    11400.2   4864.0 3993.6 512.0  446.8       1    0.007   0      0.000    0.007
2048.0 2048.0  0.0   2024.0 16384.0   3379.2   40960.0    11400.2   4864.0 3993.6 512.0  446.8       1    0.007   0      0.000    0.007
2048.0 2048.0  0.0   2024.0 16384.0   3379.2   40960.0    11400.2   4864.0 3993.6 512.0  446.8       1    0.007   0      0.000    0.007
2048.0 2048.0  0.0   2024.0 16384.0   4403.2   40960.0    11400.2   4864.0 3993.6 512.0  446.8       1    0.007   0      0.000    0.007
2048.0 2048.0  0.0   2024.0 16384.0   5427.3   40960.0    11400.2   4864.0 3993.6 512.0  446.8       1    0.007   0      0.000    0.007
2048.0 2048.0  0.0   2024.0 16384.0   6451.3   40960.0    11400.2   4864.0 3993.6 512.0  446.8       1    0.007   0      0.000    0.007
2048.0 2048.0  0.0   2024.0 16384.0   7475.3   40960.0    11400.2   4864.0 3993.6 512.0  446.8       1    0.007   0      0.000    0.007
2048.0 2048.0  0.0   2024.0 16384.0   8499.3   40960.0    11400.2   4864.0 3993.6 512.0  446.8       1    0.007   0      0.000    0.007
2048.0 2048.0  0.0   2024.0 16384.0   8499.3   40960.0    11400.2   4864.0 3993.6 512.0  446.8       1    0.007   0      0.000    0.007
  • -gccapacity:显示内容与-gc基本相同,但输出主要关注Java堆各个区域使用最大、最小空间
  • -gcutil:显示内容与-gc基本相同,但输出关注已使用空间占总空间百分比
java 复制代码
C:\Users\Administrator\IdeaProjects\jvm>jstat -gcutil 5752 1000 10
  S0     S1     E      O      M     CCS    YGC     YGCT    FGC    FGCT     GCT
  0.00   0.00  91.36  69.94  82.19  87.27      2    0.013     1    0.007    0.021
  0.00   0.00  97.61  69.94  82.19  87.27      2    0.013     1    0.007    0.021
  0.00   0.00  97.61  69.94  82.19  87.27      2    0.013     1    0.007    0.021
  0.00   0.00  25.00  99.81  82.19  87.27      2    0.013     2    0.016    0.029
  0.00   0.00  33.09  99.81  82.19  87.27      2    0.013     2    0.016    0.029
  0.00   0.00  39.34  99.81  82.19  87.27      2    0.013     2    0.016    0.029
  0.00   0.00  45.59  99.81  82.19  87.27      2    0.013     2    0.016    0.029
  0.00   0.00  51.84  99.81  82.19  87.27      2    0.013     2    0.016    0.029
  0.00   0.00  51.84  99.81  82.19  87.27      2    0.013     2    0.016    0.029
  0.00   0.00  58.09  99.81  82.19  87.27      2    0.013     2    0.016    0.029
  • -gccause:与-gcutil功能一样,但是会额外输出导致最后一次或当前正在发生的GC产生的原因
java 复制代码
C:\Users\Administrator\IdeaProjects\jvm>jstat -gccause 3788 1000 100
  S0     S1     E      O      M     CCS    YGC     YGCT    FGC    FGCT     GCT    LGCC                 GCC
  0.00   0.00  47.61  69.94  82.16  87.27      2    0.012     1    0.008    0.020 Allocation Failure   No GC
  0.00   0.00  53.86  69.94  82.16  87.27      2    0.012     1    0.008    0.020 Allocation Failure   No GC
  0.00   0.00  53.86  69.94  82.16  87.27      2    0.012     1    0.008    0.020 Allocation Failure   No GC
  • -gcnew:显示新生代GC状况
  • -gcnewcapacity:显示内容与-gcnew基本相同,输出主要关注使用到的最大、最小空间
  • -gcold:显示老年代GC状况
  • interval参数:用于指定输出统计数据的周期,单位为毫秒,即查询间隔
java 复制代码
//打印每1秒1次
C:\Users\Administrator\IdeaProjects\jvm>jstat -class 10988 1000
Loaded  Bytes  Unloaded  Bytes     Time
   728  1447.3        0     0.0       0.23
   728  1447.3        0     0.0       0.23
   728  1447.3        0     0.0       0.23
   728  1447.3        0     0.0       0.23
   728  1447.3        0     0.0       0.23
   728  1447.3        0     0.0       0.23
   728  1447.3        0     0.0       0.23
  • count参数:用于指定查询的总次数
java 复制代码
//打印每1秒1次,打印10次
C:\Users\Administrator\IdeaProjects\jvm>jstat -class 10988 1000 10
Loaded  Bytes  Unloaded  Bytes     Time
   728  1447.3        0     0.0       0.23
   728  1447.3        0     0.0       0.23
   728  1447.3        0     0.0       0.23
   728  1447.3        0     0.0       0.23
   728  1447.3        0     0.0       0.23
   728  1447.3        0     0.0       0.23
   728  1447.3        0     0.0       0.23
   728  1447.3        0     0.0       0.23
   728  1447.3        0     0.0       0.23
   728  1447.3        0     0.0       0.23
  • -t参数:可以在输出信息前加上一个Timestamp列,显示程序的运行时间,单位:秒
  • 经验:比较Java进程的启动时间以及总GC时间(GCT),或者两次测量的间隔时间以及总GC时间的增量,来得出GC时间占运行时间的比例
  • 如果该比例超过20%,则说明目前堆的压力较大,如果该比例超过90%,则说明堆里几乎没有可用空间,随时都可能抛出OOM异常
java 复制代码
C:\Users\Administrator\IdeaProjects\jvm>jstat -class -t 10988 1000 10
Timestamp       Loaded  Bytes  Unloaded  Bytes     Time
          233.1    728  1447.3        0     0.0       0.23
          234.1    728  1447.3        0     0.0       0.23
          235.1    728  1447.3        0     0.0       0.23
          236.1    728  1447.3        0     0.0       0.23
          237.1    728  1447.3        0     0.0       0.23
          238.1    728  1447.3        0     0.0       0.23
          239.1    728  1447.3        0     0.0       0.23
          240.1    728  1447.3        0     0.0       0.23
          241.2    728  1447.3        0     0.0       0.23
          242.2    728  1447.3        0     0.0       0.23
  • -h参数:可以在周期性数据输出时,输出多少行数据后输出一个表头信息
java 复制代码
//h3表示输出3行后输出一个表头
C:\Users\Administrator\IdeaProjects\jvm>jstat -class -t -h3 10988 1000 10
Timestamp       Loaded  Bytes  Unloaded  Bytes     Time
          288.5    728  1447.3        0     0.0       0.23
          289.5    728  1447.3        0     0.0       0.23
          290.6    728  1447.3        0     0.0       0.23
Timestamp       Loaded  Bytes  Unloaded  Bytes     Time
          291.6    728  1447.3        0     0.0       0.23
          292.6    728  1447.3        0     0.0       0.23
          293.6    728  1447.3        0     0.0       0.23
Timestamp       Loaded  Bytes  Unloaded  Bytes     Time
          294.6    728  1447.3        0     0.0       0.23
          295.6    728  1447.3        0     0.0       0.23
          296.6    728  1447.3        0     0.0       0.23
Timestamp       Loaded  Bytes  Unloaded  Bytes     Time
          297.6    728  1447.3        0     0.0       0.23
  • JIT相关的
    • compiler:显示JIT编译器编译过的方法和耗时等信息
java 复制代码
C:\Users\Administrator\IdeaProjects\jvm>jstat -compiler 10988
Compiled Failed Invalid   Time   FailedType FailedMethod
      95      0       0     0.03          0
  • -printcompilation:输出已经被JIT编译的方法
java 复制代码
C:\Users\Administrator\IdeaProjects\jvm>jstat -printcompilation 10988
Compiled  Size  Type Method
      95    138    1 java/lang/StringBuffer append
  • jstat如何判断内存泄漏
  • ①在长时间运行的Java程序中,可以运行jstat命令连续获取多行性能数据,并取这几行数据中OU列的最小值
  • ②每隔一段较长时间重复一次上述操作,来获得多组OU(Old Use)最小值,如果这些值呈上涨趋势,则说明该Java程序的老年代内存使用量不断上涨,这意味着无法回收的对象在不断增加,因此有可能存在内存泄漏
jifo(Configuration Info for Java)
  • 查看虚拟机配置参数信息,也可用于调整虚拟机的配置参数
  • 很多情况下,Java应用程序不会指定所有的Java虚拟机参数,而此时,开发人员可能不知道某一个具体的Java虚拟机参数的默认值,在这情况下,可能需要通过查找文档获取某个参数的默认值
  • 查看
java 复制代码
//查看由System.getProperties()取得的参数------------jinfo -flags PID
C:\Users\Administrator\IdeaProjects\jvm>jinfo -sysprops 14272
Attaching to process ID 14272, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.131-b11
Java System Properties:

java.runtime.name = Java(TM) SE Runtime Environment
java.vm.version = 25.131-b11
sun.boot.library.path = D:\Program Files\Java\jdk1.8.0_131\jre\bin
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 =
sun.java.launcher = SUN_STANDARD
user.script =
user.country = CN
user.dir = C:\Users\Administrator\IdeaProjects\jvm
java.vm.specification.name = Java Virtual Machine Specification
java.runtime.version = 1.8.0_131-b11
java.awt.graphicsenv = sun.awt.Win32GraphicsEnvironment
os.arch = amd64
java.endorsed.dirs = D:\Program Files\Java\jdk1.8.0_131\jre\lib\endorsed
line.separator =

java.io.tmpdir = C:\Users\ADMINI~1\AppData\Local\Temp\
java.vm.specification.vendor = Oracle Corporation
user.variant =
os.name = Windows 10
sun.jnu.encoding = GBK
java.library.path = D:\Program Files\Java\jdk1.8.0_131\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Program Files\Common Files\Oracle\Java\
javapath;D:\Program Files (x86)\VMware\VMware Workstation\bin\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell
\v1.0\;C:\Windows\System32\OpenSSH\;D:\Program Files (x86)\NetSarang\Xshell 7\;D:\Program Files (x86)\NetSarang\Xftp 7\;D:\SoftWare\Linux\hadoop\hadoop-3.1.
0\bin;C:\Program Files\Docker\Docker\resources\bin;D:\Program Files\Java\jdk1.8.0_131\bin;D:\SoftWare\apache-maven-3.8.4\bin;C:\Users\Administrator\AppData\
Local\Microsoft\WindowsApps;C:\Users\Administrator\AppData\Local\Programs\Microsoft VS Code\bin;D:\Program Files\Java\jdk1.8.0_131\bin;;.
java.specification.name = Java Platform API Specification
java.class.version = 52.0
sun.management.compiler = HotSpot 64-Bit Tiered Compilers
os.version = 10.0
user.home = C:\Users\Administrator
user.timezone = Asia/Shanghai
java.awt.printerjob = sun.awt.windows.WPrinterJob
file.encoding = UTF-8
java.specification.version = 1.8
user.name = Administrator
java.class.path = D:\Program Files\Java\jdk1.8.0_131\jre\lib\charsets.jar;D:\Program Files\Java\jdk1.8.0_131\jre\lib\deploy.jar;D:\Program Files\Java\jdk1.8
.0_131\jre\lib\ext\access-bridge-64.jar;D:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\cldrdata.jar;D:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\dnsns.jar
;D:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\jaccess.jar;D:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\jfxrt.jar;D:\Program Files\Java\jdk1.8.0_131\jre\
lib\ext\localedata.jar;D:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\nashorn.jar;D:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\sunec.jar;D:\Program Files\
Java\jdk1.8.0_131\jre\lib\ext\sunjce_provider.jar;D:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\sunmscapi.jar;D:\Program Files\Java\jdk1.8.0_131\jre\lib\ex
t\sunpkcs11.jar;D:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\zipfs.jar;D:\Program Files\Java\jdk1.8.0_131\jre\lib\javaws.jar;D:\Program Files\Java\jdk1.8.
0_131\jre\lib\jce.jar;D:\Program Files\Java\jdk1.8.0_131\jre\lib\jfr.jar;D:\Program Files\Java\jdk1.8.0_131\jre\lib\jfxswt.jar;D:\Program Files\Java\jdk1.8.
0_131\jre\lib\jsse.jar;D:\Program Files\Java\jdk1.8.0_131\jre\lib\management-agent.jar;D:\Program Files\Java\jdk1.8.0_131\jre\lib\plugin.jar;D:\Program File
s\Java\jdk1.8.0_131\jre\lib\resources.jar;D:\Program Files\Java\jdk1.8.0_131\jre\lib\rt.jar;C:\Users\Administrator\IdeaProjects\jvm\target\classes;C:\Users\
Administrator\.m2\repository\junit\junit\4.12\junit-4.12.jar;C:\Users\Administrator\.m2\repository\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar;D:\P
rogram Files\JetBrains\IntelliJ IDEA 2019.3.5\lib\idea_rt.jar
java.vm.specification.version = 1.8
sun.arch.data.model = 64
sun.java.command = com.chapter12.GCTest
java.home = D:\Program Files\Java\jdk1.8.0_131\jre
user.language = zh
java.specification.vendor = Oracle Corporation
awt.toolkit = sun.awt.windows.WToolkit
java.vm.info = mixed mode
java.version = 1.8.0_131
java.ext.dirs = D:\Program Files\Java\jdk1.8.0_131\jre\lib\ext;C:\Windows\Sun\Java\lib\ext
sun.boot.class.path = D:\Program Files\Java\jdk1.8.0_131\jre\lib\resources.jar;D:\Program Files\Java\jdk1.8.0_131\jre\lib\rt.jar;D:\Program Files\Java\jdk1.
8.0_131\jre\lib\sunrsasign.jar;D:\Program Files\Java\jdk1.8.0_131\jre\lib\jsse.jar;D:\Program Files\Java\jdk1.8.0_131\jre\lib\jce.jar;D:\Program Files\Java\
jdk1.8.0_131\jre\lib\charsets.jar;D:\Program Files\Java\jdk1.8.0_131\jre\lib\jfr.jar;D:\Program Files\Java\jdk1.8.0_131\jre\classes
java.vendor = Oracle Corporation
file.separator = \
java.vendor.url.bug = http://bugreport.sun.com/bugreport/
sun.io.unicode.encoding = UnicodeLittle
sun.cpu.endian = little
sun.desktop = windows
sun.cpu.isalist = amd64

VM Flags:
Non-default VM flags: -XX:CICompilerCount=3 -XX:InitialHeapSize=62914560 -XX:MaxHeapSize=62914560 -XX:MaxNewSize=20971520 -XX:MinHeapDeltaBytes=524288 -XX:N
ewSize=20971520 -XX:OldSize=41943040 -XX:SurvivorRatio=8 -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseFastUnorderedTimeStamps -XX:-UseLarg
ePagesIndividualAllocation -XX:+UseParallelGC
Command line:  -Xms60m -Xmx60m -XX:SurvivorRatio=8 -javaagent:D:\Program Files\JetBrains\IntelliJ IDEA 2019.3.5\lib\idea_rt.jar=51523:D:\Program Files\JetBr
ains\IntelliJ IDEA 2019.3.5\bin -Dfile.encoding=UTF-8
//-flags:查看赋过值的参数------------jinfo -flags PID
C:\Users\Administrator\IdeaProjects\jvm>jinfo -flags 8828
Attaching to process ID 8828, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.131-b11
Non-default VM flags: -XX:CICompilerCount=3 -XX:InitialHeapSize=62914560 -XX:MaxHeapSize=62914560 -XX:MaxNewSize=20971520 -XX:MinHeapDeltaBytes=524288 -XX:N
ewSize=20971520 -XX:OldSize=41943040 -XX:SurvivorRatio=8 -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseFastUnorderedTimeStamps -XX:-UseLarg
ePagesIndividualAllocation -XX:+UseParallelGC
Command line:  -Xms60m -Xmx60m -XX:SurvivorRatio=8 -javaagent:D:\Program Files\JetBrains\IntelliJ IDEA 2019.3.5\lib\idea_rt.jar=51584:D:\Program Files\JetBr
ains\IntelliJ IDEA 2019.3.5\bin -Dfile.encoding=UTF-8
//jinfo -flag 具体参数PID------------jinfo -flag 具体参数 PID
C:\Users\Administrator\IdeaProjects\jvm>jinfo -flag SurvivorRatio 13940
-XX:SurvivorRatio=8
//+UseParrelGC(+表示使用,-表示未使用)
C:\Users\Administrator\IdeaProjects\jvm>jinfo -flag UseParallelGC 5764
-XX:+UseParallelGC
  • 修改
  • jinfo不仅可以查看运行时某一个Java虚拟机参数的实际取值,甚至可以在运行时修改部分参数,使之立即生效
  • 并非所有参数都支持动态修改。参数没有被标记为manageable的flag可以被实时修改,其实这个修改能力是极其有限的
  • 查看被标记为manageable的参数
java 复制代码
C:\Users\Administrator\IdeaProjects\jvm>java -XX:+PrintFlagsFinal -version > a.txt
java version "17.0.11" 2024-04-16 LTS
Java(TM) SE Runtime Environment (build 17.0.11+7-LTS-207)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.11+7-LTS-207, mixed mode, sharing)

//在windows下可以使用Linux Shell的工具,否则使用grep会报错
DESKTOP-BEU2U68:/mnt/host/c/Users/Administrator/IdeaProjects/jvm# cat a.txt | grep manageable
    uintx G1PeriodicGCInterval                     = 0                                      {manageable} {default}
   double G1PeriodicGCSystemLoadThreshold          = 0.000000                               {manageable} {default}
     bool HeapDumpAfterFullGC                      = false                                  {manageable} {default}
     bool HeapDumpBeforeFullGC                     = false                                  {manageable} {default}
     intx HeapDumpGzipLevel                        = 0                                      {manageable} {default}
     bool HeapDumpOnOutOfMemoryError               = false                                  {manageable} {default}
    ccstr HeapDumpPath                             =                                        {manageable} {default}
    uintx MaxHeapFreeRatio                         = 70                                     {manageable} {default}
    uintx MinHeapFreeRatio                         = 40                                     {manageable} {default}
     bool PrintClassHistogram                      = false                                  {manageable} {default}
     bool PrintConcurrentLocks                     = false                                  {manageable} {default}
     bool ShowCodeDetailsInExceptionMessages       = true                                   {manageable} {default}
   size_t SoftMaxHeapSize                          = 8547991552                             {manageable} {ergonomic}
java 复制代码
//修改相应的参数
C:\Users\Administrator\IdeaProjects\jvm>jinfo -flag PrintGCDetails 13716
-XX:-PrintGCDetails
C:\Users\Administrator\IdeaProjects\jvm>jinfo -flag +PrintGCDetails 13716
C:\Users\Administrator\IdeaProjects\jvm>jinfo -flag PrintGCDetails 13716
-XX:+PrintGCDetails
//------------------------------------------------------------------------
C:\Users\Administrator\IdeaProjects\jvm>jinfo -flag MaxHeapFreeRatio 5588
-XX:MaxHeapFreeRatio=100
C:\Users\Administrator\IdeaProjects\jvm>jinfo -flag MaxHeapFreeRatio=90 5588

C:\Users\Administrator\IdeaProjects\jvm>jinfo -flag MaxHeapFreeRatio 5588
-XX:MaxHeapFreeRatio=90
  • 拓展
  • java -XX:+PrintFlagsIntial:查看所有JVM参数启动的初始值
  • java -XX:+PrintFlagsFinal:查看所有JVM参数启动的最终值
  • java -XX:+PrintCommandLineFlags:查看那些已经被用户或JVM设置过的详细的XX参数的名称和值
java 复制代码
//+PrintCommandLineFlags
-XX:ConcGCThreads=2 -XX:G1ConcRefinementThreads=6 -XX:GCDrainStackTargetSize=64 -XX:InitialHeapSize=534181568 -XX:MarkStackSize=4194304 -XX:MaxHeapSize=8546905088 -XX:MinHeapSize=6815736 -XX:+PrintCommandLineFlags -XX:ReservedCodeCacheSize=251658240 -XX:+SegmentedCodeCache -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseG1GC -XX:-UseLargePagesIndividualAllocation 
java 复制代码
//-XX:+PrintFlagsInitial参数,会显示以下信息
[Global flags]
    uintx AdaptiveSizeDecrementScaleFactor          = 4                                   {product}
    uintx AdaptiveSizeMajorGCDecayTimeScale         = 10                                  {product}
    uintx AdaptiveSizePausePolicy                   = 0                                   {product}
    uintx AdaptiveSizePolicyCollectionCostMargin    = 50                                  {product}
    uintx AdaptiveSizePolicyInitializingSteps       = 20                                  {product}
    uintx AdaptiveSizePolicyOutputInterval          = 0                                   {product}
    uintx AdaptiveSizePolicyWeight                  = 10                                  {product}
    uintx AdaptiveSizeThroughPutPolicy              = 0                                   {product}
    uintx AdaptiveTimeWeight                        = 25                                  {product}
     bool AdjustConcurrency                         = false                               {product}
     bool AggressiveOpts                            = false                               {product}
    ... ...
相关推荐
Daniel 大东13 分钟前
idea 解决缓存损坏问题
java·缓存·intellij-idea
wind瑞20 分钟前
IntelliJ IDEA插件开发-代码补全插件入门开发
java·ide·intellij-idea
HappyAcmen20 分钟前
IDEA部署AI代写插件
java·人工智能·intellij-idea
马剑威(威哥爱编程)25 分钟前
读写锁分离设计模式详解
java·设计模式·java-ee
鸽鸽程序猿26 分钟前
【算法】【优选算法】前缀和(上)
java·算法·前缀和
修道-032327 分钟前
【JAVA】二、设计模式之策略模式
java·设计模式·策略模式
九圣残炎32 分钟前
【从零开始的LeetCode-算法】2559. 统计范围内的元音字符串数
java·算法·leetcode
当归10241 小时前
若依项目-结构解读
java
hlsd#1 小时前
关于 SpringBoot 时间处理的总结
java·spring boot·后端
iiiiiankor1 小时前
C/C++内存管理 | new的机制 | 重载自己的operator new
java·c语言·c++