美文网首页
JVM的内存调优工具

JVM的内存调优工具

作者: 超越爱迪生 | 来源:发表于2017-04-29 11:34 被阅读98次

    JVM自带了一些比较好用的工具,比如jstat,jmap等。

    jstat -gc pid

    可以查看某个进程的gc次数。每列的含义如下

    字段 含义
    S0 Heap上的 Survivor space 0 区已使用空间的百分比
    S1 Heap上的 Survivor space 1 区已使用空间的百分比
    E Heap上的 Eden space 区已使用空间的百分比
    O Heap上的 Old space 区已使用空间的百分比
    P Perm space 区已使用空间的百分比
    YGC 从应用程序启动到采样时发生 Young GC 的次数
    YGCT 从应用程序启动到采样时 Young GC 所用的时间(单位秒)
    FGC 从应用程序启动到采样时发生 Full GC 的次数
    FGCT 从应用程序启动到采样时 Full GC 所用的时间(单位秒)
    GCT 从应用程序启动到采样时用于垃圾回收的总时间(单位秒)

    jmap -heap pid

    可以查看内存中各个代(新生代,老年代和永久代)的大小配置以及使用情况。比如

    Attaching to process ID 31523, please wait...
    Debugger attached successfully.
    Server compiler detected.
    JVM version is 24.65-b04
    
    using parallel threads in the new generation.
    using thread-local object allocation.
    Concurrent Mark-Sweep GC
    
    Heap Configuration:
       MinHeapFreeRatio = 40
       MaxHeapFreeRatio = 70
       MaxHeapSize      = 2684354560 (2560.0MB)
       NewSize          = 1342177280 (1280.0MB)
       MaxNewSize       = 1342177280 (1280.0MB)
       OldSize          = 5439488 (5.1875MB)
       NewRatio         = 2
       SurvivorRatio    = 4
       PermSize         = 83886080 (80.0MB)
       MaxPermSize      = 167772160 (160.0MB)
       G1HeapRegionSize = 0 (0.0MB)
    
    Heap Usage:
    New Generation (Eden + 1 Survivor Space):
       capacity = 1118502912 (1066.6875MB)
       used     = 1071778952 (1022.128059387207MB)
       free     = 46723960 (44.55944061279297MB)
       95.82263403172972% used
    Eden Space:
       capacity = 894828544 (853.375MB)
       used     = 894828544 (853.375MB)
       free     = 0 (0.0MB)
       100.0% used
    From Space:
       capacity = 223674368 (213.3125MB)
       used     = 176950408 (168.75305938720703MB)
       free     = 46723960 (44.55944061279297MB)
       79.11072224422246% used
    To Space:
       capacity = 223674368 (213.3125MB)
       used     = 0 (0.0MB)
       free     = 223674368 (213.3125MB)
       0.0% used
    concurrent mark-sweep generation:
       capacity = 1342177280 (1280.0MB)
       used     = 1342177128 (1279.999855041504MB)
       free     = 152 (1.4495849609375E-4MB)
       99.99998867511749% used
    Perm Generation:
       capacity = 83886080 (80.0MB)
       used     = 22813536 (21.756683349609375MB)
    

    jmap -histo pid

    统计内存中每个对象占用的大小。
    还可以带上参数live: jmap -histo:live pid,这样就只统计当前依然存活的对象。


    image.png

    [ 表示是一个数组
    C: char
    B: byte
    I: int

    jmap -dump 配合eclipse的memory analyzer tool

    jmap -dump:format=b,file=dump.hprof pid
    这个命令可以把当前的内存dump到文件,然后通过eclipse的memory analyzer tool,可以分析这个dump,检测可能的内存泄漏等。

    如果dump文件过大,mat加载时候会报错

    An internal error occurred during:
    "Parsing heap dump from **\java_pid6564.hprof'".Java heap space
    

    可以把MemoryAnalyzer.ini里面的-Xmx1024m改为更大的数即可解决。

    相关文章

      网友评论

          本文标题:JVM的内存调优工具

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