标签: jinfo

JVM内存分析命令

jinfo:

[bash]查看Java进程的栈空间大小:sudo -u tomcat /home/java/default/bin/jinfo -flag ThreadStackSize 14750
查看是否使用了压缩指针:sudo -u tomcat /home/java/default/bin/jinfo -flag UseCompressedOops 14750
查看系统属性:sudo -u tomcat /home/java/default/bin/jinfo -sysprops 14750 [/bash]

jstack:

[bash]查看一个指定的Java进程中的线程的状态:sudo -u tomcat /home/java/default/bin/jstack 14750 [/bash]

jstat:

[bash]查看gc的信息:sudo -u tomcat /home/java/default/bin/jstat -gcutil 14750[/bash]

jmap&mat

[bash]sudo -u tomcat /home/java/default/bin/jmap -histo:live 14750

堆空间中各个年龄段的空间的使用情况:sudo -u tomcat /home/java/default/bin/jmap -heap 14750
[/bash]

jmap指定的dump文件一定要是tomcat用户可写,比如可以新创建一个文件夹
sudo mkdir /home/memdump
sudo chown tomcat:tomcat /home/memdump
sudo -u tomcat /home/java/default/bin/jmap -dump:live,format=b,file=/home/memdump/memMap.20131125.hprof 14750

jmap、jstack、jinfo在ubuntu下不起作用的解决方法

1、问题:用jmap查看jvm heap信息时无法连接

[java]
javaranger@ubuntu:~/Downloads$ jmap -heap 3991
Attaching to process ID 3991, please wait…
Error attaching to process: sun.jvm.hotspot.debugger.DebuggerException: Can’t attach to the process
[/java]

2、解决方法:
1)修改/etc/sysctl.d/10-ptrace.conf文件如下:
kernel.yama.ptrace_scope = 1   ==>  kernel.yama.ptrace_scope = 0 (将1改成0)
2)重启
3、结果

[java]
Attaching to process ID 1793, please wait…
Debugger attached successfully.
Client compiler detected.
JVM version is 20.0-b12

using thread-local object allocation.
Mark Sweep Compact GC

Heap Configuration:
MinHeapFreeRatio = 40
MaxHeapFreeRatio = 70
MaxHeapSize = 536870912 (512.0MB)
NewSize = 1048576 (1.0MB)
MaxNewSize = 4294901760 (4095.9375MB)
OldSize = 4194304 (4.0MB)
NewRatio = 2
SurvivorRatio = 8
PermSize = 12582912 (12.0MB)
MaxPermSize = 67108864 (64.0MB)

Heap Usage:
New Generation (Eden + 1 Survivor Space):
capacity = 5046272 (4.8125MB)
used = 2888704 (2.7548828125MB)
free = 2157568 (2.0576171875MB)
57.24431818181818% used
Eden Space:
capacity = 4521984 (4.3125MB)
used = 2707016 (2.5816116333007812MB)
free = 1814968 (1.7308883666992188MB)
59.863458163496375% used
From Space:
capacity = 524288 (0.5MB)
used = 181688 (0.17327117919921875MB)
free = 342600 (0.32672882080078125MB)
34.65423583984375% used
To Space:
capacity = 524288 (0.5MB)
used = 0 (0.0MB)
free = 524288 (0.5MB)
0.0% used
tenured generation:
capacity = 11206656 (10.6875MB)
used = 2532152 (2.4148483276367188MB)
free = 8674504 (8.272651672363281MB)
22.595072071454677% used
Perm Generation:
capacity = 12582912 (12.0MB)
used = 7467776 (7.121826171875MB)
free = 5115136 (4.878173828125MB)
59.348551432291664% used
[/java]

4、参考http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7050524