实践JDK内置命令之jmap

jmap命令用来查看跟JVM内存相关信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
$ jmap -help
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(汇总信息)
    -permstat            to print permanent generation 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

例如:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
$ jmap -heap 3703
Attaching to process ID 8800, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 20.13-b02

using thread-local object allocation.
Parallel GC with 2 thread(s)

Heap Configuration:
   MinHeapFreeRatio = 40
   MaxHeapFreeRatio = 70
   MaxHeapSize      = 2147483648 (2048.0MB)
   NewSize          = 1310720 (1.25MB)
   MaxNewSize       = 17592186044415 MB
   OldSize          = 5439488 (5.1875MB)
   NewRatio         = 2
   SurvivorRatio    = 8
   PermSize         = 21757952 (20.75MB)
   MaxPermSize      = 268435456 (256.0MB)

Heap Usage:
PS Young Generation
Eden Space:
   capacity = 680132608 (648.625MB)
   used     = 55850040 (53.26274871826172MB)
   free     = 624282568 (595.3622512817383MB)
   8.211639810100092% used
From Space:
   capacity = 17498112 (16.6875MB)
   used     = 13733808 (13.097579956054688MB)
   free     = 3764304 (3.5899200439453125MB)
   78.48737052317416% used
To Space:
   capacity = 17825792 (17.0MB)
   used     = 0 (0.0MB)
   free     = 17825792 (17.0MB)
   0.0% used
PS Old Generation
   capacity = 1431699456 (1365.375MB)
   used     = 1176661240 (1122.1516036987305MB)
   free     = 255038216 (243.22339630126953MB)
   82.1863300337805% used
PS Perm Generation
   capacity = 138805248 (132.375MB)
   used     = 124377184 (118.61532592773438MB)
   free     = 14428064 (13.759674072265625MB)
   89.6055342230288% used
1
2
3
$ jmap -dump:format=b,file=outfile.bin 31361
Dumping heap to /tmp/outfile.bin ...
Heap dump file created