Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jmap可快速查jvm中最大对象 #1

Open
oldratlee opened this issue Mar 13, 2013 · 1 comment
Open

jmap可快速查jvm中最大对象 #1

oldratlee opened this issue Mar 13, 2013 · 1 comment
Assignees
Labels

Comments

@oldratlee
Copy link
Owner

海豹归来提的:
http://weibo.com/1611407701/zncH07tOW

@oldratlee
Copy link
Owner Author

oldratlee commented Mar 20, 2013

Java内存问题,可以的检查操作有:
# 下面的这些都不方便做成脚本直接得出jvm中最大对象。谁有方法脚本化 欢迎提供或是实现。 👍

查看不同类型占用的内存

$ jmap -histo <进程号> | head -n 20 
 num     #instances         #bytes  class name  
----------------------------------------------  
   1:         13352       60321384  [B  
   2:        108823       13516768  <constMethodKlass>  
   3:         89912        9476704  [C  
   4:        108823        8710200  <methodKlass>  
   5:        152780        6715552  <symbolKlass>  
   6:          8796        5325984  <constantPoolKlass>  
   7:          8796        4219536  <instanceKlassKlass>  
   8:         16753        3896104  [I  
   9:          7026        2782816  <constantPoolCacheKlass>  
  10:        109717        2633208  java.lang.String  
  11:         40391         969384  java.util.HashMap$Entry  
  12:         13806         932104  [Ljava.lang.Object;  
  13:          9400         902400  java.lang.Class  
  14:          8076         854312  [Ljava.util.HashMap$Entry;  
  15:         11426         794936  [S  
  16:         13935         685408  [[I  

查看JVM内存消耗和GC情况

$ jstat -gcutil 17708 1000
  S0     S1     E      O      P     YGC     YGCT    FGC    FGCT     GCT   
 35.93   0.00  22.05   2.01  38.92      4    0.156     0    0.000    0.156
 35.93   0.00  22.05   2.01  38.92      4    0.156     0    0.000    0.156
 35.93   0.00  22.05   2.01  38.92      4    0.156     0    0.000    0.156
 35.93   0.00  22.05   2.01  38.92      4    0.156     0    0.000    0.156
 35.93   0.00  22.05   2.01  38.92      4    0.156     0    0.000    0.156

Dump内存,查看对象消耗

这个是 最直接准确的,当然操作也繁琐些。

$ jmap -dump:file=heap.bin <进程号> 
Dumping heap to /path/to/heap.bin ...  
Heap dump file created  

然后用工具分析Dump文件,可以用工具MAT。一般很容易就看到内存泄漏对象。

通过查看对象引用关系,可以分析出内存泄漏的原因。

oldratlee pushed a commit that referenced this issue Oct 22, 2013
@ghost ghost assigned oldratlee Dec 15, 2013
@oldratlee oldratlee assigned oldratlee and unassigned oldratlee Dec 26, 2014
oldratlee added a commit that referenced this issue Mar 31, 2021
COMMAND column of top -H output can be thread name not process name

top output sample and env info:

```
$ uname -a
Linux 33e449b39f66 4.19.121-linuxkit #1 SMP Thu Jan 21 15:36:34 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
$ java -version
openjdk version "11.0.9.1" 2020-11-04
OpenJDK Runtime Environment (build 11.0.9.1+1-Ubuntu-0ubuntu1.18.04)
OpenJDK 64-Bit Server VM (build 11.0.9.1+1-Ubuntu-0ubuntu1.18.04, mixed mode, sharing)
$ top -v
  procps-ng 3.3.12
Usage:
  top -hv | -bcHiOSs -d secs -n max -u|U user -p pid(s) -o field -w [cols]
$ top -H
  PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND
 7012 jerry     20   0 3492604  79492  27096 S  0.0  3.9   0:00.00 java
 7014 jerry     20   0 3492604  79492  27096 S  0.0  3.9   0:00.62 GC Thread#0
 7015 jerry     20   0 3492604  79492  27096 S  0.0  3.9   0:00.00 G1 Main Marker
 7017 jerry     20   0 3492604  79492  27096 S  0.0  3.9   0:00.00 G1 Refine#0
 7018 jerry     20   0 3492604  79492  27096 S  0.0  3.9   0:00.06 G1 Young RemSet
 7019 jerry     20   0 3492604  79492  27096 S  0.0  3.9   0:00.67 VM Thread
 7020 jerry     20   0 3492604  79492  27096 S  0.0  3.9   0:00.00 Reference Handl
 7021 jerry     20   0 3492604  79492  27096 S  0.0  3.9   0:00.00 Finalizer
 7022 jerry     20   0 3492604  79492  27096 S  0.0  3.9   0:00.00 Signal Dispatch
 7023 jerry     20   0 3492604  79492  27096 S  0.0  3.9   0:00.34 C2 CompilerThre
 7024 jerry     20   0 3492604  79492  27096 S  0.0  3.9   0:00.03 C1 CompilerThre
 7025 jerry     20   0 3492604  79492  27096 S  0.0  3.9   0:00.00 Sweeper thread
 7026 jerry     20   0 3492604  79492  27096 S  0.0  3.9   0:00.00 Service Thread
 7027 jerry     20   0 3492604  79492  27096 S  0.0  3.9   0:00.26 VM Periodic Tas
 7032 jerry     20   0 3492604  79492  27096 S  0.0  3.9   0:00.52 GC Thread#1
 ...
```
oldratlee added a commit that referenced this issue Mar 31, 2021
COMMAND column of top -H output can be thread name not process name

top output sample and env info:

```
$ uname -a
Linux 33e449b39f66 4.19.121-linuxkit #1 SMP Thu Jan 21 15:36:34 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
$ java -version
openjdk version "11.0.9.1" 2020-11-04
OpenJDK Runtime Environment (build 11.0.9.1+1-Ubuntu-0ubuntu1.18.04)
OpenJDK 64-Bit Server VM (build 11.0.9.1+1-Ubuntu-0ubuntu1.18.04, mixed mode, sharing)
$ top -v
  procps-ng 3.3.12
Usage:
  top -hv | -bcHiOSs -d secs -n max -u|U user -p pid(s) -o field -w [cols]
$ top -H
  PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND
 7012 jerry     20   0 3492604  79492  27096 S  0.0  3.9   0:00.00 java
 7014 jerry     20   0 3492604  79492  27096 S  0.0  3.9   0:00.62 GC Thread#0
 7015 jerry     20   0 3492604  79492  27096 S  0.0  3.9   0:00.00 G1 Main Marker
 7017 jerry     20   0 3492604  79492  27096 S  0.0  3.9   0:00.00 G1 Refine#0
 7018 jerry     20   0 3492604  79492  27096 S  0.0  3.9   0:00.06 G1 Young RemSet
 7019 jerry     20   0 3492604  79492  27096 S  0.0  3.9   0:00.67 VM Thread
 7020 jerry     20   0 3492604  79492  27096 S  0.0  3.9   0:00.00 Reference Handl
 7021 jerry     20   0 3492604  79492  27096 S  0.0  3.9   0:00.00 Finalizer
 7022 jerry     20   0 3492604  79492  27096 S  0.0  3.9   0:00.00 Signal Dispatch
 7023 jerry     20   0 3492604  79492  27096 S  0.0  3.9   0:00.34 C2 CompilerThre
 7024 jerry     20   0 3492604  79492  27096 S  0.0  3.9   0:00.03 C1 CompilerThre
 7025 jerry     20   0 3492604  79492  27096 S  0.0  3.9   0:00.00 Sweeper thread
 7026 jerry     20   0 3492604  79492  27096 S  0.0  3.9   0:00.00 Service Thread
 7027 jerry     20   0 3492604  79492  27096 S  0.0  3.9   0:00.26 VM Periodic Tas
 7032 jerry     20   0 3492604  79492  27096 S  0.0  3.9   0:00.52 GC Thread#1
 ...
```
oldratlee added a commit that referenced this issue Mar 31, 2021
COMMAND column of top -H output can be thread name not process name

top output sample and env info:

```
$ uname -a
Linux 33e449b39f66 4.19.121-linuxkit #1 SMP Thu Jan 21 15:36:34 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
$ java -version
openjdk version "11.0.9.1" 2020-11-04
OpenJDK Runtime Environment (build 11.0.9.1+1-Ubuntu-0ubuntu1.18.04)
OpenJDK 64-Bit Server VM (build 11.0.9.1+1-Ubuntu-0ubuntu1.18.04, mixed mode, sharing)
$ top -v
  procps-ng 3.3.12
Usage:
  top -hv | -bcHiOSs -d secs -n max -u|U user -p pid(s) -o field -w [cols]
$ top -H
  PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND
 7012 jerry     20   0 3492604  79492  27096 S  0.0  3.9   0:00.00 java
 7014 jerry     20   0 3492604  79492  27096 S  0.0  3.9   0:00.62 GC Thread#0
 7015 jerry     20   0 3492604  79492  27096 S  0.0  3.9   0:00.00 G1 Main Marker
 7017 jerry     20   0 3492604  79492  27096 S  0.0  3.9   0:00.00 G1 Refine#0
 7018 jerry     20   0 3492604  79492  27096 S  0.0  3.9   0:00.06 G1 Young RemSet
 7019 jerry     20   0 3492604  79492  27096 S  0.0  3.9   0:00.67 VM Thread
 7020 jerry     20   0 3492604  79492  27096 S  0.0  3.9   0:00.00 Reference Handl
 7021 jerry     20   0 3492604  79492  27096 S  0.0  3.9   0:00.00 Finalizer
 7022 jerry     20   0 3492604  79492  27096 S  0.0  3.9   0:00.00 Signal Dispatch
 7023 jerry     20   0 3492604  79492  27096 S  0.0  3.9   0:00.34 C2 CompilerThre
 7024 jerry     20   0 3492604  79492  27096 S  0.0  3.9   0:00.03 C1 CompilerThre
 7025 jerry     20   0 3492604  79492  27096 S  0.0  3.9   0:00.00 Sweeper thread
 7026 jerry     20   0 3492604  79492  27096 S  0.0  3.9   0:00.00 Service Thread
 7027 jerry     20   0 3492604  79492  27096 S  0.0  3.9   0:00.26 VM Periodic Tas
 7032 jerry     20   0 3492604  79492  27096 S  0.0  3.9   0:00.52 GC Thread#1
 ...
```
oldratlee added a commit that referenced this issue Nov 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant