jvm 性能调优之 jmap

编程入门 行业动态 更新时间:2024-10-28 02:36:13

jvm <a href=https://www.elefans.com/category/jswz/34/1771266.html style=性能调优之 jmap"/>

jvm 性能调优之 jmap

概述

Java Memory Map,打印出某个java进程内存中所有‘对象’的情况(如:产生那些对象,及其数量),可以输出所有内存中对象的工具,甚至可以将JVM 中的heap,以二进制输出成文本。

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 formatdump-options:live         dump only live objects; if not specified,all objects in the heap are dumped.format=b     binary formatfile=<file>  dump heap to <file>Example: jmap -dump:live,format=b,file=heap.bin <pid>-F                   force. Use with -dump:<dump-options> <pid> or -histoto force a heap dump or histogram when <pid> does notrespond. The "live" suboption is not supportedin this mode.-h | -help           to print this help message-J<flag>             to pass <flag> directly to the runtime system

使用说明

options

显示JVM版本信息

(base) ➜  ~ jmap 10375
Attaching to process ID 10375, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.77-b03

heap

打印jvm线程各个分区的摘要

(base) ➜  ~ jmap -heap 10375
Attaching to process ID 10375, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.77-b03using thread-local object allocation.
Parallel GC with 4 thread(s)Heap Configuration:MinHeapFreeRatio         = 0MaxHeapFreeRatio         = 100 # 空余空间百分比,超过这个值堆会减小,直到 minsizeMaxHeapSize              = 4294967296 (4096.0MB)NewSize                  = 89128960 (85.0MB)MaxNewSize               = 1431306240 (1365.0MB)OldSize                  = 179306496 (171.0MB)NewRatio                 = 2  # 老年代和年轻代比例是2:1SurvivorRatio            = 8  # eden 区和单个survivor区的比例是8:1MetaspaceSize            = 21807104 (20.796875MB)CompressedClassSpaceSize = 1073741824 (1024.0MB)MaxMetaspaceSize         = 17592186044415 MBG1HeapRegionSize         = 0 (0.0MB)Heap Usage:
PS Young Generation
Eden Space:capacity = 304611328 (290.5MB)used     = 71829624 (68.50206756591797MB)free     = 232781704 (221.99793243408203MB)23.58074615005782% used
From Space:capacity = 10485760 (10.0MB)used     = 10252080 (9.777145385742188MB)free     = 233680 (0.2228546142578125MB)97.77145385742188% used
To Space:capacity = 17301504 (16.5MB)used     = 0 (0.0MB)free     = 17301504 (16.5MB)0.0% used
PS Old Generationcapacity = 161480704 (154.0MB)used     = 34655000 (33.049583435058594MB)free     = 126825704 (120.9504165649414MB)21.460768464323763% used17424 interned Strings occupying 1782392 bytes.

histo[:live]

打印内存中对象直方图

 num     #instances         #bytes  class name
----------------------------------------------1:        150075       19363864  [C2:         29583       13819960  [B3:        100510        2412240  java.lang.String4:          3878        2052664  [I5:         36845        1813272  [Ljava.lang.Object;6:         28568         914176  java.util.AbstractList$Itr7:          9883         632512  java.util.stream.ReferencePipeline$28:         15161         606440  org.jdom.Attribute9:          9885         553560  java.util.stream.ReferencePipeline$Head10:          4910         546088  java.lang.Class11:         10206         489888  gnu.trove.THashMap12:         11834         473360  java.util.LinkedHashMap$Entry13:          9883         395320  java.util.HashMap$EntrySpliterator14:         11728         375296  java.io.File15:         14090         338160  java.lang.StringBuilder16:         19908         318528  java.lang.Object17:          9883         316256  java.util.stream.FindOps$FindOp18:          9799         313568  java.util.HashMap$Node19:          9744         311808  java.util.concurrent.ConcurrentHashMap$Node20:          1184         297480  [Ljava.util.HashMap$Node;21:          9125         292000  java.util.ArrayList$Itr22:         10211         245064  java.util.ArrayList

class name对应的就是Class文件里的class的标识
B代表byte
C代表char
D代表double
F代表float
I代表int
J代表long
Z代表boolean
前边有[代表数组,[I 就相当于int[], 对象用[L+类名表示

clstats

(base) ➜  ~ jmap -clstats 30559
Attaching to process ID 30559, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.77-b03
finding class loader instances ..done.
computing per loader stat ..done.
please wait.. computing liveness..................liveness analysis may be inaccurate ...
class_loader	classes	bytes	parent_loader	alive?	type<bootstrap>	1883	3292097	  null  	live	<internal>
0x000000079460d2e0	1	1471	  null  	dead	sun/reflect/DelegatingClassLoader@0x00000007c0009df8
0x000000079460dd20	1	1471	  null  	dead	sun/reflect/DelegatingClassLoader@0x00000007c0009df8
0x000000079460eda0	1	1472	0x0000000794424050	dead	sun/reflect/DelegatingClassLoader@0x00000007c0009df8
0x000000079460d3a8	1	1471	  null  	dead	sun/reflect/DelegatingClassLoader@0x00000007c0009df8
0x000000079460dde8	2	4839	  null  	dead	javax/management/remote/rmi/NoCallStackClassLoader@0x00000007c021d838
0x00000007b599d9d0	1	1472	0x0000000794424050	dead	sun/reflect/DelegatingClassLoader@0x00000007c0009df8
0x0000000794456608	17	44376	  null  	live	sun/misc/Launcher$ExtClassLoader@0x00000007c000fa30
0x000000079460d470	1	1471	  null  	dead	sun/reflect/DelegatingClassLoader@0x00000007c0009df8
0x000000079460e8b0	1	1471	0x0000000794424050	dead	sun/reflect/DelegatingClassLoader@0x00000007c0009df8
0x00000007b599d908	1	1472	  null  	dead	sun/reflect/DelegatingClassLoader@0x00000007c0009df8
0x0000000794424050	2793	4890978	0x00000007944565a8	live	java/net/URLClassLoader@0x00000007c000ecb8
0x000000079460d538	1	1471	  null  	dead	sun/reflect/DelegatingClassLoader@0x00000007c0009df8
0x000000079460e9f8	1	1472	0x0000000794424050	dead	sun/reflect/DelegatingClassLoader@0x00000007c0009df8
0x00000007b3502e08	1	881	  null  	dead	sun/reflect/DelegatingClassLoader@0x00000007c0009df8
0x00000007b599d840	1	1471	0x0000000794424050	dead	sun/reflect/DelegatingClassLoader@0x00000007c0009df8
0x000000079460d600	1	1471	  null  	dead	sun/reflect/DelegatingClassLoader@0x00000007c0009df8
0x000000079460dec0	4	4029	  null  	dead	javax/management/remote/rmi/NoCallStackClassLoader@0x00000007c021d838
0x00000007b599d778	1	1471	0x0000000794424050	dead	sun/reflect/DelegatingClassLoader@0x00000007c0009df8
0x00000007b599ee78	1	1471	  null  	dead	sun/reflect/DelegatingClassLoader@0x00000007c0009df8
0x000000079460d6c8	1	1471	  null  	dead	sun/reflect/DelegatingClassLoader@0x00000007c0009df8
0x00000007b599c130	11	36886	0x00000007944565a8	dead	sun/reflect/misc/MethodUtil@0x00000007c025b228
0x00000007b599d6b0	1	1471	0x0000000794424050	dead	sun/reflect/DelegatingClassLoader@0x00000007c0009df8
0x00000007944565a8	31	118741	0x0000000794456608	live	sun/misc/Launcher$AppClassLoader@0x00000007c000f688
0x000000079460db90	1	1471	  null  	dead	sun/reflect/DelegatingClassLoader@0x00000007c0009df8
0x00000007949dfb68	0	0	0x00000007944565a8	dead	java/util/ResourceBundle$RBClassLoader@0x00000007c00a8318
0x000000079460d218	1	1471	  null  	dead	sun/reflect/DelegatingClassLoader@0x00000007c0009df8
0x000000079460dc58	1	1471	  null  	dead	sun/reflect/DelegatingClassLoader@0x00000007c0009df8
0x000000079460ecd8	1	1472	0x0000000794424050	dead	sun/reflect/DelegatingClassLoader@0x00000007c0009df8
0x00000007945f1620	0	0	0x00000007944565a8	live	javax/management/remote/rmi/RMIConnectionImpl$CombinedClassLoader@0x00000007c0258430
0x00000007945f1860	0	0	0x00000007944565a8	live	javax/management/remote/rmi/RMIConnectionImpl$CombinedClassLoader$ClassLoaderWrapper@0x00000007c0258748
0x00000007945f1aa0	0	0	0x00000007944565a8	live	com/sun/jmx/remote/util/ClassLoaderWithRepository@0x00000007c0257ef8total = 32	4762	8422252	    N/A    	alive=7, dead=25	    N/A

dump

导出堆栈内存快照,以供分析。

 dump-options:live         dump only live objects; if not specified,all objects in the heap are dumped.format=b     binary formatfile=<file>  dump heap to <file>Example: jmap -dump:live,format=b,file=heap.bin <pid>

总共有三种方式导出内存快照

  1. 如上
  2. oom 自动导出
-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=filename.hprof 
  1. gcore

setp 1 使用gdb生成core.4990的core文件

# sudo gdb -q --pid=4990
(gdb) generate-core-file 
(gdb) detach 
(gdb) quit

step 2 使用jmap 生成 dump文件

sudo jmap -dump:format=b,file=heap.hprof /usr/xxx/jdk1.6.0_29/bin/java core.4990

更多推荐

jvm 性能调优之 jmap

本文发布于:2023-07-03 16:27:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1008939.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:性能   jvm   jmap

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!