Under Linux Java program memory analysis (pmap, jmap, jstat)

 

1, pmap view process memory

Run command

Use pmap can see a certain process (non-java may be) of memory usage usage,

Format:

pmap 进程id
  • 1

Example shows

pmap 12358
  • 1

The first column, the start address of the memory block 
in the second column, the size of the memory for 
the third column, the memory permissions 
fourth column, the name of the memory, dynamic memory allocation represents anon, Stack stack memory represents 
the last line, the total memory occupancy size, note here is the virtual memory size, taking up physical memory size can be viewed through the top

Write pictures described here

2, jmap View Java process object usage

Run command

Use jmap can view a Java process in how many instances of each object, how much memory footprint, 
the command format:

jmap -histo 进程id
  • 1

Example shows

jmap -histo  12538
  • 1

The first column, number, no practical significance 
in the second column, the number of the object instance 
in the third column, the total amount of memory occupied by the object instance, unit: bytes 
in the fourth column, the name of the object instance 
the last row, the total number of instances of the total number of occupied memory

Write pictures described here

Write pictures described here

jmap -heap 1024 > jmap-heap-1024.bin
  • 1

Write pictures described here

3, jstat command to view the GC jvm case

jstat command format:

jstat [Options] vmid [interval] [count]
  • 1

Parameter Description:

Options, options, we generally use -gcutil View gc situation 
vmid, VM process ID, java process ID that is currently running 
interval, the interval of time, in seconds or milliseconds 
count, printing times, if the default print numerous times

Example shows

jstat -gc 1024 5000
  • 1

That would be every 5 seconds display case GC process number 1024 into the java into

Write pictures described here

Display content as follows (partial results are displayed by another other parameters, they will not be described):

S0C:年轻代中第一个survivor(幸存区)的容量 (字节) 
S1C:年轻代中第二个survivor(幸存区)的容量 (字节) 
S0U:年轻代中第一个survivor(幸存区)目前已使用空间 (字节) 
S1U:年轻代中第二个survivor(幸存区)目前已使用空间 (字节) 
EC:年轻代中Eden(伊甸园)的容量 (字节) 
EU:年轻代中Eden(伊甸园)目前已使用空间 (字节) 
OC:Old代的容量 (字节) 
OU:Old代目前已使用空间 (字节) 
PC:Perm(持久代)的容量 (字节) 
PU:Perm(持久代)目前已使用空间 (字节) 
YGC:从应用程序启动到采样时年轻代中gc次数 
YGCT:从应用程序启动到采样时年轻代中gc所用时间(s) 
FGC:从应用程序启动到采样时old代(全gc)gc次数 
FGCT:从应用程序启动到采样时old代(全gc)gc所用时间(s) 
GCT:从应用程序启动到采样时gc用的总时间(s) 
NGCMN:年轻代(young)中初始化(最小)的大小 (字节) 
NGCMX:年轻代(young)的最大容量 (字节) 
NGC:年轻代(young)中当前的容量 (字节) 
OGCMN:old代中初始化(最小)的大小 (字节) 
OGCMX:old代的最大容量 (字节) 
OGC:old代当前新生成的容量 (字节) 
PGCMN:perm代中初始化(最小)的大小 (字节) 
PGCMX:perm代的最大容量 (字节) 
PGC:perm代当前新生成的容量 (字节) 
S0:年轻代中第一个survivor(幸存区)已使用的占当前容量百分比 
S1:年轻代中第二个survivor(幸存区)已使用的占当前容量百分比 
E:年轻代中Eden(伊甸园)已使用的占当前容量百分比 
O:old代已使用的占当前容量百分比 
P:perm代已使用的占当前容量百分比 
S0CMX:年轻代中第一个survivor(幸存区)的最大容量 (字节) 
S1CMX :年轻代中第二个survivor(幸存区)的最大容量 (字节) 
ECMX:年轻代中Eden(伊甸园)的最大容量 (字节) 
DSS:当前需要survivor(幸存区)的容量 (字节)(Eden区已满) 
TT: 持有次数限制 
MTT : 最大持有次数限制

Java 堆分为新生代和老年代,新生代一般划分为三块区域,Eden + From Survivor + To Survivor,Eden 和 Survivor 的内存比为8:1,每次只使用一个Eden 和一个 Survivor 区域,另一个 Survivor 用于复制收集算法回收内存。

对象一般尽量分配到新生代中,而对于大对象(长字符串和大数组)直接分配在老年代中,同时“年龄”长的的对象会从新生代自动晋升到老年代中。

Java 方法区称为永久代,只有 HotSpot 虚拟机才存在永久代。

When the Eden area allocation is insufficient, it occurs automatically once Minor GC.

When happen Minor GC, virtual machines are automatically detected (relatively) new generation of memory size objects promoted to the old era and the remaining years old memory size, if promoted> remaining, a Full GC occurs; if promotion <remains, to detect old memory's guarantee HandlePromotionFailure whether to allow a security failure, if not allowed to guarantee failure, a Full GC occurs, if allowed to fail, then conduct a Minor GC.

Print stack information

jmap -dump:format=b,file=/filepath/heap.bin pid

 


jstack  pid 

 

Guess you like

Origin blog.csdn.net/qq_34730511/article/details/80647046