美文网首页
JVM 学习笔记记录

JVM 学习笔记记录

作者: 就这样火了 | 来源:发表于2020-05-20 09:52 被阅读0次

    JVM 学习笔记记录

    Sun JDK 监控和故障处理工具

    名称 主要作用
    jps JVM Process Status Tool, 显示指定系统内所有的HotSpot虚拟机进程
    jstat JVM Statistics Moitoring Tool,用于收集HotSpot虚拟机各方面的运行数据
    jinfo Configuration info for java,显示虚拟机配置信息
    jmap Memory Map for java,生成虚拟机的内存转储快照(heapdump文件)
    jhat JVM Heap Dump Browser,用于分析heapdump文件,它会建立一个HTTP/HTML服务器,让用户可以在浏览器上查看分析结果
    jstack Stack Trace for java,显示虚拟机的线程快照

    常用命令:

    1. jps -l 查询LVMID,及主类的名称
    
        C:\Users\Harry>jps -l
        11856 com.ssm.common.jvm.JvmTest
        14368 com.ddc.template.TemplateApplication
        16848
        19664
        6640 org.jetbrains.jps.cmdline.Launcher
        7732 sun.tools.jps.Jps
        2168 org.apache.zookeeper.server.quorum.QuorumPeerMain
    
    2. jps -v 输出虚拟机进程参数
    
        C:\Users\Harry>jps -v
        11856 JvmTest -agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:49232 -verbose:gc -Xms20M -Xmx20M -Xmn10M -XX:+PrintGCDetails -XX:SurvivorRatio=8 -Dfile.encoding=utf8
        
    3. jstat -gc 11856 250 5 每250毫秒查询一次进程11856垃圾收集情况状况,一共查询5次
    
        C:\Users\Harry>jstat -gc 11856 250 20
         S0C    S1C    S0U    S1U      EC       EU        OC         OU       MC     MU    CCSC   CCSU   YGC     YGCT    FGC    FGCT     GCT
        1024.0 1024.0  0.0    0.0    8192.0   7619.8   10240.0      0.0     4480.0 780.5  384.0   75.8       0    0.000   0      0.000    0.000
        1024.0 1024.0  0.0    0.0    8192.0   7619.8   10240.0      0.0     4480.0 780.5  384.0   75.8       0    0.000   0      0.000    0.000
        1024.0 1024.0  0.0    0.0    8192.0   7619.8   10240.0      0.0     4480.0 780.5  384.0   75.8       0    0.000   0      0.000    0.000
        1024.0 1024.0  0.0    0.0    8192.0   7619.8   10240.0      0.0     4480.0 780.5  384.0   75.8       0    0.000   0      0.000    0.000
        1024.0 1024.0  0.0    0.0    8192.0   7619.8   10240.0      0.0     4480.0 780.5  384.0   75.8       0    0.000   0      0.000    0.000
        
    4. jstat -gc 11856 只查询一次
    
        C:\Users\Harry>jstat -gc 11856
         S0C    S1C    S0U    S1U      EC       EU        OC         OU       MC     MU    CCSC   CCSU   YGC     YGCT    FGC    FGCT     GCT
        1024.0 1024.0  0.0    0.0    8192.0   7619.8   10240.0      0.0     4480.0 780.5  384.0   75.8       0    0.000   0      0.000    0.000
    
    5. jstat -gcutil 11856 查询各JVM内存使用百分比
       
        C:\Users\Harry>jstat -gcutil 11856
          S0     S1     E      O      M     CCS    YGC     YGCT    FGC    FGCT     GCT
          0.00   0.00  93.01   0.00  17.42  19.75      0    0.000     0    0.000    0.000
    
    6. jstat -gcnew 11856 查询新生代GC状况
       
        C:\Users\Harry>jstat -gcnew 11856
         S0C    S1C    S0U    S1U   TT MTT  DSS      EC       EU     YGC     YGCT
        1024.0 1024.0    0.0    0.0 15  15    0.0   8192.0   7619.8      0    0.000
    
    7. jstat -gcold 11856 查询老年代GC状况
       
        C:\Users\Harry>jstat -gcold 11856
           MC       MU      CCSC     CCSU       OC          OU       YGC    FGC    FGCT     GCT
          4480.0    780.5    384.0     75.8     10240.0         0.0      0     0    0.000    0.000
    
    8. jinfo -flag CMSInitiatingOccupancyFraction 11856 查询JVM参数的值
        
        C:\Users\Harry>jinfo -flag CMSInitiatingOccupancyFraction 11856
        -XX:CMSInitiatingOccupancyFraction=-1
    
    9. jinfo -sysprops 11856 
    
    可以把System.getProperties()信息打印出来
        C:\Users\Harry>jinfo -sysprops 11856
        Attaching to process ID 11856, please wait...
        Debugger attached successfully.
        Server compiler detected.
        JVM version is 25.92-b14
        java.runtime.name = Java(TM) SE Runtime Environment
        java.vm.version = 25.92-b14
        ......
    
    10. jmap -dump:format=b,file=eclipse.bin 11856 生成java堆转储快照
        
        C:\Users\Harry>jmap -dump:format=b,file=eclipse.bin 11856
        Dumping heap to C:\Users\Harry\eclipse.bin ...
        Heap dump file created
    
    11. jhat eclipse.bin 分析dump文件,浏览器中访问http://localhost:7000
        
        C:\Users\Harry>jhat eclipse.bin
        Reading from eclipse.bin...
        Dump file created Sun Jul 22 11:55:08 CST 2018
        Snapshot read, resolving...
        Resolving 11914 objects...
        Chasing references, expect 2 dots..
        Eliminating duplicate references..
        Snapshot resolved.
        Started HTTP server on port 7000
        Server is ready.
        
    12. jmap -dump:live,format=b,file=heap.hprof 11856
        将heap.hprof传输出来到window电脑上使用mat工具分析。
    
    13. jhat -heap 11856 显示java堆详细信息,如使用哪种回收器、参数配置、分代状况等,只在linux平台才可以测试
    
    14. jstack -l 11856 除堆栈外,显示锁的附加信息
        
        "Finalizer" #3 daemon prio=8 os_prio=1 tid=0x00000000152da800 nid=0x18b4 in Object.wait() [0x000000001664e000]
           java.lang.Thread.State: WAITING (on object monitor)
                at java.lang.Object.wait(Native Method)
                - waiting on <0x00000000ff608ee0> (a java.lang.ref.ReferenceQueue$Lock)
                at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:143)
                - locked <0x00000000ff608ee0> (a java.lang.ref.ReferenceQueue$Lock)
                at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:164)
                at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:209)
        
           Locked ownable synchronizers:
                - None
        
        "Reference Handler" #2 daemon prio=10 os_prio=2 tid=0x00000000152b9000 nid=0x444c in Object.wait() [0x000000001654f000]
           java.lang.Thread.State: WAITING (on object monitor)
                at java.lang.Object.wait(Native Method)
                - waiting on <0x00000000ff606b50> (a java.lang.ref.Reference$Lock)
                at java.lang.Object.wait(Object.java:502)
                at java.lang.ref.Reference.tryHandlePending(Reference.java:191)
                - locked <0x00000000ff606b50> (a java.lang.ref.Reference$Lock)
                at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:153)
        
           Locked ownable synchronizers:
                - None
    
    

    本文由博客一文多发平台 OpenWrite 发布!

    相关文章

      网友评论

          本文标题:JVM 学习笔记记录

          本文链接:https://www.haomeiwen.com/subject/bjhgohtx.html