java进程分析

jmap分析运行内存情况
jstack 分析java运行栈信息,查找问题代码


先找到java进程的进程pid

jmap常用命令

-dump 输出到文件(文件时二进制的需要借助工具分析)

C:\Users\HP\Desktop>jmap -dump:live,format=b,file=dump.hprof 5444
Dumping heap to C:\Users\HP\Desktop\dump.hprof ...
Heap dump file created                                          

-heap 打印heap概要信息到控制台

C:\Users\HP\Desktop>jmap -heap 5444
Attaching to process ID 5444, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.144-b01

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

Heap Configuration:
   MinHeapFreeRatio         = 0
   MaxHeapFreeRatio         = 100
   MaxHeapSize              = 2120220672 (2022.0MB)
   NewSize                  = 44564480 (42.5MB)
   MaxNewSize               = 706740224 (674.0MB)
   OldSize                  = 89653248 (85.5MB)
   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 = 134217728 (128.0MB)
   used     = 582088 (0.5551223754882812MB)
   free     = 133635640 (127.44487762451172MB)
   0.4336893558502197% used
From Space:
   capacity = 7340032 (7.0MB)
   used     = 0 (0.0MB)
   free     = 7340032 (7.0MB)
   0.0% used
To Space:
   capacity = 37224448 (35.5MB)
   used     = 0 (0.0MB)
   free     = 37224448 (35.5MB)
   0.0% used
PS Old Generation
   capacity = 203948032 (194.5MB)
   used     = 31683152 (30.215408325195312MB)
   free     = 172264880 (164.2845916748047MB)
   15.534914306013015% used

16791 interned Strings occupying 1587744 bytes.
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         

-histo

打印对象信息

C:\Users\HP\Desktop>jmap -histo:live 5444 | more


 num     #instances         #bytes  class name
----------------------------------------------
   1:         66746        6509056  [C
   2:         64180        3594080  org.codehaus.groovy.runtime.metaclass.MetaMe
thodIndex$Entry
   3:         47244        1624576  [Ljava.lang.Object;
   4:         65954        1582896  java.lang.String
   5:         37929        1213728  java.lang.ref.WeakReference
   6:         13685        1204280  java.lang.reflect.Method
   7:          3322        1190952  [I
   8:         32865        1051680  java.util.HashMap$Node
   9:         27559         881888  org.codehaus.groovy.util.SingleKeyHashMap$En
try
  10:          4617         769936  [Lorg.codehaus.groovy.util.ComplexKeyHashMap
$Entry;
  11:         29488         707712  org.codehaus.groovy.util.FastArray
  12:          5932         671712  java.lang.Class
  13:         15869         634760  java.lang.ref.SoftReference
  14:           361         543760  [Lorg.codehaus.groovy.runtime.metaclass.Meta
MethodIndex$Entry;
  15:          8963         501928  java.beans.MethodDescriptor
  16:          6722         430208  org.codehaus.groovy.reflection.CachedMethod
  17:         17614         422736  java.util.ArrayList
  18:         12576         402432  groovy.lang.MetaBeanProperty
  19:         11259         360288  java.util.concurrent.ConcurrentHashMap$Node
  20:         14537         348888  java.beans.MethodRef
  21:          4733         340776  java.lang.reflect.Field
  22:         14293         310752  [Ljava.lang.Class;
  23:          1080         307968  [Ljava.util.HashMap$Node;
  24:          1418         295496  [B
  25:          5269         252912  org.codehaus.groovy.util.ReferenceType$SoftR
ef
  26:          9471         228120  [Ljava.lang.String;
  27:          9038         216912  sun.font.TrueTypeFont$DirectoryEntry
  28:          1326         190824  [Ljava.lang.ClassValue$Entry;
  29:          2531         182232  java.beans.PropertyDescriptor
  30:           648         178616  [Ljava.beans.MethodDescriptor;
  31:         10032         160512  java.lang.Object
  32:          4550         145600  java.util.Hashtable$Entry
  33:          6088         132496  [Lorg.codehaus.groovy.reflection.CachedClass
;
  34:          5269         126456  org.codehaus.groovy.util.ManagedReference
  35:          1358         120032  [Ljava.util.WeakHashMap$Entry;
  36:          2921         116840  java.util.WeakHashMap$Entry
  37:          1177          94160  java.lang.reflect.Constructor
  38:          1950          93600  java.util.HashMap
  39:          3894          93456  org.codehaus.groovy.util.SingleKeyHashMap
  40:            79          87616  [Ljava.util.concurrent.ConcurrentHashMap$Nod
e;
  41:          1325          84800  java.lang.ClassValue$ClassValueMap
-- More  --                                                                   is 25.144-b01
                                                                                                                                                                                                                                               


jstack主要用来分析线程运行情况

可以分析哪些方法耗时长、还有进行死锁分析

C:\Users\HP\Desktop>jstack -l 5444
2018-05-16 11:37:48
Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.144-b01 mixed mode):

"Swing-Shell" #25 daemon prio=5 os_prio=0 tid=0x000000001c074800 nid=0x1940 wait
ing on condition [0x00000000229fe000]
   java.lang.Thread.State: WAITING (parking)
        at sun.misc.Unsafe.park(Native Method)
        - parking to wait for  <0x000000008298abd8> (a java.util.concurrent.lock
s.AbstractQueuedSynchronizer$ConditionObject)
        at java.util.concurrent.locks.LockSupport.park(Unknown Source)
        at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject
.await(Unknown Source)
        at java.util.concurrent.LinkedBlockingQueue.take(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor.getTask(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at sun.awt.shell.Win32ShellFolderManager2$ComInvoker$3.run(Unknown Sourc
e)
        at java.lang.Thread.run(Unknown Source)

   Locked ownable synchronizers:
        - None

"TimerQueue" #23 daemon prio=5 os_prio=0 tid=0x000000001c073000 nid=0xe28 waitin
g on condition [0x0000000022e8f000]
   java.lang.Thread.State: WAITING (parking)
        at sun.misc.Unsafe.park(Native Method)
        - parking to wait for  <0x00000000830532b8> (a java.util.concurrent.lock
s.AbstractQueuedSynchronizer$ConditionObject)
        at java.util.concurrent.locks.LockSupport.park(Unknown Source)
        at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject
.await(Unknown Source)
        at java.util.concurrent.DelayQueue.take(Unknown Source)
        at javax.swing.TimerQueue.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)

   Locked ownable synchronizers:
        - <0x00000000830532f0> (a java.util.concurrent.locks.ReentrantLock$Nonfa
irSync)

"pool-2-thread-1" #22 prio=5 os_prio=0 tid=0x000000001b489000 nid=0xc54 waiting
on condition [0x0000000022b1f000]
   java.lang.Thread.State: WAITING (parking)
        at sun.misc.Unsafe.park(Native Method)
        - parking to wait for  <0x0000000082708f80> (a java.util.concurrent.lock
s.AbstractQueuedSynchronizer$ConditionObject)
        at java.util.concurrent.locks.LockSupport.park(Unknown Source)
        at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject
.await(Unknown Source)
        at java.util.concurrent.LinkedBlockingQueue.take(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor.getTask(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)

   Locked ownable synchronizers:
        - None


具体的死锁分析方法与测试实例参考:

https://blog.csdn.net/zhengchao1991/article/details/77507952?locationNum=3&fps=1


阅读更多
个人分类: java技术
上一篇java classloader使用,热部署原理
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭