JavaJava学习笔记

Java 内存查看及分析

2016-12-28  本文已影响469人  专职跑龙套

首先使用 jps -l 查找当前所有的 Java 进程。

jstat 命令

jstat -gc pid 1000 或者 jstat -gc pid 1000 > out.txt: 每隔1000号码打印一次或导出 GC 的状态。

 S0C    S1C    S0U    S1U      EC       EU        OC         OU       MC     MU    CCSC   CCSU   YGC     YGCT    FGC    FGCT     GCT   
10752.0 10752.0  0.0    0.0   65536.0   3932.2   175104.0     0.0     4480.0 769.8  384.0   75.8       0    0.000   0      0.000    0.000
10752.0 10752.0  0.0    0.0   65536.0   3932.2   175104.0     0.0     4480.0 769.8  384.0   75.8       0    0.000   0      0.000    0.000
10752.0 10752.0  0.0    0.0   65536.0   3932.2   175104.0     0.0     4480.0 769.8  384.0   75.8       0    0.000   0      0.000    0.000
10752.0 10752.0  0.0    0.0   65536.0   3932.2   175104.0     0.0     4480.0 769.8  384.0   75.8       0    0.000   0      0.000    0.000
10752.0 10752.0  0.0    0.0   65536.0   3932.2   175104.0     0.0     4480.0 769.8  384.0   75.8       0    0.000   0      0.000    0.000
10752.0 10752.0  0.0    0.0   65536.0   3932.2   175104.0     0.0     4480.0 769.8  384.0   75.8       0    0.000   0      0.000    0.000

jmap -heap 命令

jmap -heap pid 或者 jmap -heap pid > out.txt:打印或导出堆内存使用情况。
例如:
可以查看:

Attaching to process ID 20128, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.92-b14

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

Heap Configuration:
   MinHeapFreeRatio         = 0
   MaxHeapFreeRatio         = 100
   MaxHeapSize              = 4271898624 (4074.0MB)
   NewSize                  = 89128960 (85.0MB)
   MaxNewSize               = 1423966208 (1358.0MB)
   OldSize                  = 179306496 (171.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 = 67108864 (64.0MB)
   used     = 4026592 (3.840057373046875MB)
   free     = 63082272 (60.159942626953125MB)
   6.000089645385742% used
From Space:
   capacity = 11010048 (10.5MB)
   used     = 0 (0.0MB)
   free     = 11010048 (10.5MB)
   0.0% used
To Space:
   capacity = 11010048 (10.5MB)
   used     = 0 (0.0MB)
   free     = 11010048 (10.5MB)
   0.0% used
PS Old Generation
   capacity = 179306496 (171.0MB)
   used     = 0 (0.0MB)
   free     = 179306496 (171.0MB)
   0.0% used

873 interned Strings occupying 59320 bytes.

jmap -histo 命令

jmap -histo pid 或者 jmap -histo pid > out.txt:打印或导出堆内存中对象的数量及大小。
例如:
可以查看:

 num     #instances         #bytes  class name
----------------------------------------------
   1:           522        3248552  [I
   2:          3282         416008  [C
   3:           217          78016  [B
   4:           581          66208  java.lang.Class
   5:          2292          55008  java.lang.String
   6:           618          32144  [Ljava.lang.Object;
   7:           152          10944  java.lang.reflect.Field
   8:           262           6288  java.lang.StringBuilder
   9:           178           5696  java.io.File
  10:           173           5536  java.util.HashMap$Node
  11:            61           5368  java.lang.reflect.Method
  12:            82           5248  java.net.URL
  13:           110           4400  java.lang.ref.SoftReference
  14:            26           4256  [Ljava.util.HashMap$Node;
  15:           259           4144  java.lang.Integer
  16:           101           4040  java.util.TreeMap$Entry
上一篇下一篇

猜你喜欢

热点阅读