Jmap:可以获得运行中的jvm的堆的快照,从而可以离线分析堆,以检查内存泄漏,检查一些严重影响性能的大对象的创建,检查系统中什么对象最多,各种对象所占内存的大小等等
Jmap是一个可以输出所有内存中对象的工具,甚至可以将VM 中的heap,以二进制输出成文本。打印出某个java进程(使用pid)内存内的,所有‘对象’的情况(如:产生那些对象,及其数量)。
使用方法 jmap -histo pid。如果使用SHELL ,可采用jmap -histo pid>a.log日志将其保存到文件 中,在一段时间后,使用文本对比工具,可以对比出GC回收了哪些对象。jmap -dump:format=b,file=outfile 3024可以 将3024进程的内存heap输出出来到outfile文件里,再配合MAT(内存分析工具)。
Code:
D:\Program Files\Java\jdk1.8.0_102\bin $ jmap -heap 47960 Attaching to process ID 47960, please wait... Debugger attached successfully. Server compiler detected. JVM version is 25.102-b14 using thread-local object allocation. Parallel GC with 4 thread(s) Heap Configuration: MinHeapFreeRatio = 0 MaxHeapFreeRatio = 100 MaxHeapSize = 734003200 (700.0MB) NewSize = 42991616 (41.0MB) MaxNewSize = 244318208 (233.0MB) OldSize = 87031808 (83.0MB) NewRatio = 2 SurvivorRatio = 8 MetaspaceSize = 21807104 (20.796875MB) CompressedClassSpaceSize = 1073741824 (1024.0MB) MaxMetaspaceSize = 17592186044415 MB G1HeapRegionSize = 0 (0.0MB) Heap Usage: PS Young Generation Eden Space: capacity = 32505856 (31.0MB) used = 19961640 (19.036903381347656MB) free = 12544216 (11.963096618652344MB) 61.40936574628276% used From Space: capacity = 5242880 (5.0MB) used = 4268096 (4.07037353515625MB) free = 974784 (0.92962646484375MB) 81.407470703125% used To Space: capacity = 5242880 (5.0MB) used = 0 (0.0MB) free = 5242880 (5.0MB) 0.0% used PS Old Generation capacity = 87031808 (83.0MB) used = 16867360 (16.085968017578125MB) free = 70164448 (66.91403198242188MB) 19.380684358527862% used 5691 interned Strings occupying 486856 bytes.
https://www.cnblogs.com/qlqwjy/p/7953491.html
jps:显示当前所有java进程pid的命令,简单实用
D:\Program Files\Java\jdk1.8.0_102\bin $ jps 15856 RemoteMavenServer 17412 Jps 47960 Launcher 5224
jstack: