JVM性能调优监控工具之jmap

目录

jmap作用

工具使用

参数说明

heap

histo[:live]

permstat

finalizerinfo

dump:


jmap作用

监控内存内的Java对象

工具使用

在cmd中输入jsp获取当前所有java进程pid

C:\Users\bikong>jps
9316 Jps
13244 org.eclipse.equinox.launcher_1.4.0.v20161219-1356.jar

在cmd中输入jmap -h或jmap -help查看jmap所有可用命令及作用,如下所示:

C:\Users\bikong>jmap -h
Usage:
    jmap [option] <pid>
        (to connect to running process)
    jmap [option] <executable <core>
        (to connect to a core file)
    jmap [option] [server_id@]<remote server IP or hostname>
        (to connect to remote debug server)

where <option> is one of:
    <none>               to print same info as Solaris pmap
    -heap                to print java heap summary
    -histo[:live]        to print histogram of java object heap; if the "live"
                         suboption is specified, only count live objects
    -clstats             to print class loader statistics
    -finalizerinfo       to print information on objects awaiting finalization
    -dump:<dump-options> to dump java heap in hprof binary format
                         dump-options:
                           live         dump only live objects; if not specified,
                                        all objects in the heap are dumped.
                           format=b     binary format
                           file=<file>  dump heap to <file>
                         Example: jmap -dump:live,format=b,file=heap.bin <pid>
    -F                   force. Use with -dump:<dump-options> <pid> or -histo
                         to force a heap dump or histogram when <pid> does not
                         respond. The "live" suboption is not supported
                         in this mode.
    -h | -help           to print this help message
    -J<flag>             to pass <flag> directly to the runtime system

参数说明

语法:jmap [option] <pid>        option:为命令选项,常用选项如下:

heap

命令:jmap -heap pid
描述:打印Java堆概要信息,包括使用的GC算法、堆配置参数和各代中堆内存使用情况

C:\Users\bikong>jmap -heap 13244
Attaching to process ID 13244, please wait...
Debugger attached successfully.
Client compiler detected.
JVM version is 25.131-b11

using thread-local object allocation.
Garbage-First (G1) GC with 4 thread(s)

Heap Configuration:
   MinHeapFreeRatio         = 40
   MaxHeapFreeRatio         = 70
   MaxHeapSize              = 268435456 (256.0MB)
   NewSize                  = 1048576 (1.0MB)
   MaxNewSize               = 160432128 (153.0MB)
   OldSize                  = 4194304 (4.0MB)
   NewRatio                 = 2
   SurvivorRatio            = 8
   MetaspaceSize            = 12582912 (12.0MB)
   CompressedClassSpaceSize = 1073741824 (1024.0MB)
   MaxMetaspaceSize         = 4294901760 (4095.9375MB)
   G1HeapRegionSize         = 1048576 (1.0MB)

Heap Usage:
G1 Heap:
   regions  = 256
   capacity = 268435456 (256.0MB)
   used     = 154699200 (147.53265380859375MB)
   free     = 113736256 (108.46734619140625MB)
   57.629942893981934% used
G1 Young Generation:
Eden Space:
   regions  = 19
   capacity = 92274688 (88.0MB)
   used     = 19922944 (19.0MB)
   free     = 72351744 (69.0MB)
   21.59090909090909% used
Survivor Space:
   regions  = 0
   capacity = 0 (0.0MB)
   used     = 0 (0.0MB)
   free     = 0 (0.0MB)
   0.0% used
G1 Old Generation:
   regions  = 130
   capacity = 176160768 (168.0MB)
   used     = 134776256 (128.53265380859375MB)
   free     = 41384512 (39.46734619140625MB)
   76.50753202892486% used

99802 interned Strings occupying 12773416 bytes.
  •   Heap Configuration:中为堆配置信息
  • Heap Usage: 堆使用情况
  • Young Generation(Eden Space 88+Survivor Space 0)+Old Generation 168=Heap capacity 256

histo[:live]

命令:jmap -histo:live pid
描述:打印Java堆中对象直方图,通过该图可以获取每个class的对象数目占用内存大小和类全名信息,带上:live,则只统计活着的对象,如下命令:


C:\Users\bikong>jmap -histo:live 13244

 num     #instances         #bytes  class name
----------------------------------------------
   1:        214170       24722472  [C
   2:        221774        5322576  java.util.HashMap$Node
   3:        261574        4185184  java.lang.String
   4:         69220        3393552  [Ljava.lang.Object;
   5:         41783        3138616  [Ljava.util.HashMap$Node;
   6:         66698        2550440  [I
   ......
8297:             1              8  sun.util.locale.provider.CalendarNameProviderImpl$LengthBasedComparator
8298:             1              8  sun.util.locale.provider.TimeZoneNameUtility$TimeZoneNameGetter
8299:             1              8  sun.util.resources.LocaleData$LocaleDataResourceBundleControl
Total       1746704       74245720
   

class name列出现了[C、[B、[L等很奇怪的内容,这些属于非自定义类,具体为:

BaseType Character

Type

Interpretation

B

byte

signed byte

C

char

Unicode character

D

double

double-precision floating-point value

F

float

single-precision floating-point value

I

int

integer

J

long

long integer

L

reference

an instance of class

S

short

signed short

Z

boolean

true or false

[

reference

one array dimension

 

permstat

命令:jmap -permstat pid
描述:-permstat 打印永久代统计信息,注意:从JDK8开始,Metaspace(元空间)替代了永久代, 高版本jdk将得不到统计信息,

finalizerinfo

命令:jmap -finalizerinfo pid
描述:-finalizerinfo 打印等待回收的对象信息,如下命令:

C:\Users\bikong>jmap -finalizerinfo 13244
Attaching to process ID 13244, please wait...
Debugger attached successfully.
Client compiler detected.
JVM version is 25.131-b11
Number of objects pending for finalization: 0

Number of objects pending for finalization: 0 说明当前F-QUEUE队列中并没有等待Fializer线程执行finalizer方法的对象。

dump:<dump-options>

命令:jmap -dump:format=b,file=heapdump.phrof pid
描述:-dump:<dump-options> 以hprof二进制格式将Java堆信息输出到文件内,该文件可以用MAT、VisualVMjhat等工具查看

dump-options选项:

  • live 只输出活着的对象;可选,不指定是,则输出堆中所有对象
  • format=b 指定输出格式为二进制
  • file=<file> 指定文件名及文件存储位置,例如:jmap -dump:live,format=b,file=D:\heap.bin <pid>

 

 

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值