如何查看JVM采用的是哪种GC

方法一:使用命令行获取

C:\Users\10255880>java -XX:+PrintCommandLineFlags -version
-XX:InitialHeapSize=136306112 -XX:MaxHeapSize=2180897792 -XX:+PrintCommandLineFl
ags -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:-UseLargePagesInd
ividualAllocation -XX:+UseParallelGC
java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)

上述结果中的 -XX:+UseParallelGC 表明选择的垃圾收集器为并行收集器。

方法二:打印进程信息

  • jps:jdk提供的一个查看当前java进程的小工具, 可以看做是JavaVirtual Machine Process Status Tool的缩写
C:\Program Files\Java\jdk1.8.0_161\bin>jps
11328 Bootstrap
2800 RemoteMavenServer36
3424 Launcher
5744
6336 Launcher
5540 LoaderMain
9316 Jps
10600
11672 Launcher
4728 KotlinCompileDaemon
  • jinfo -flags {进程号}:jinfo 命令可以用来查看 Java 进程运行的 JVM 参数,; -flags 可以打印虚拟机标识。
    jinfo 命令具体如下:
C:\Program Files\Java\jdk1.8.0_161\bin>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

使用jinfo -flags查看所有VM标识

C:\Program Files\Java\jdk1.8.0_161\bin>jinfo -flags  11672
Attaching to process ID 11672, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.161-b12
Non-default VM flags: -XX:CICompilerCount=3 -XX:InitialHeapSize=136314880 
-XX:MaxHeapSize=734003200 -XX:MaxNewSize=244318208 -XX:MinHeapDeltaBytes=524288 
-XX:NewSize=45088768 -XX:OldSize=91226112 -XX:+UseCompressedClassPointers 
-XX:+UseCompressedOops -XX:-UseLargePagesIndividualAllocation -XX:+UseParallelGC

可以看到最后打印的就是使用的GC类型。

    原文作者:六月的尾巴
    原文地址: https://blog.csdn.net/zhengdong12345/article/details/114359921
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞