java virtual machine - GC log

When analyzing java memory problems, you need to check the GC log. Here is a brief summary of how to read the GC log.
The GC log can be obtained by setting the -XX:+PrintGCDetails virtual machine parameter. The following is an example of a GC log. The author uses JDK8, HotSpot virtual machine
 
public class T {
public static void main(String[] args ) {
T
t = new T();
 
System.gc();
}
}
 
 
[GC (System.gc()) [PSYoungGen: 2662K->576K(38400K)] 2662K->584K(125952K), 0.0015403 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[Full GC (System.gc()) [PSYoungGen: 576K->0K(38400K)] [ParOldGen: 8K->482K(87552K)] 584K->482K(125952K), [Metaspace: 2778K->2778K(1056768K)], 0.0056851 secs] [Times: user=0.01 sys=0.00, real=0.01 secs]
Heap
 PSYoungGen      total 38400K, used 333K [0x0000000795580000, 0x0000000798000000, 0x00000007c0000000)
  eden space 33280K, 1% used [0x0000000795580000,0x00000007955d34a8,0x0000000797600000)
  from space 5120K, 0% used [0x0000000797600000,0x0000000797600000,0x0000000797b00000)
  to   space 5120K, 0% used [0x0000000797b00000,0x0000000797b00000,0x0000000798000000)
 ParOldGen       total 87552K, used 482K [0x0000000740000000, 0x0000000745580000, 0x0000000795580000)
  object space 87552K, 0% used [0x0000000740000000,0x00000007400788f8,0x0000000745580000)
 Metaspace       used 2785K, capacity 4486K, committed 4864K, reserved 1056768K
  class space    used 301K, capacity 386K, committed 512K, reserved 1048576K
 
 
[GC (System.gc())   [Full GC (System.gc()) Indicates the type of garbage collection and who caused it.
 
[PSYoungGen: 576K->0K(38400K)] indicates that the Parallel Scavenge collector is used to recycle the new generation, the memory usage before GC is 576K -> the memory usage after GC is 0K (the total amount of memory in the new generation is 38400K) )
 
[ParOldGen: 8K->482K(87552K)] indicates that the Parallel Scavenge collector is used to collect the old age, the memory usage before GC is 8K -> the memory usage after GC is 482K (the total amount of memory in the old age is 87552K ) After this GC, some objects in the new generation were moved to the old generation, and they were not directly killed.
 
[Metaspace: 2778K->2778K(1056768K)]  Starting from JDK8, the concept of permanent generation (PermGen) has been abandoned and replaced by a storage space called Metaspace. Metaspace uses local memory instead of heap memory, which means that by default the size of Metaspace is only related to the size of local memory.
 
[Times: user=0.01 sys=0.00, real=0.01 secs] user represents the CPU time consumed by the user state, sys represents the CPU time consumed by the kernel state, and real represents the wall clock time from the start to the end of the operation, and the wall clock time Including the time consumed by various non-operations, including disk IO waiting time, thread blocking waiting time, etc. And CPU time doesn't include those.
 
Heap
 PSYoungGen      total 38400K, used 333K [0x0000000795580000, 0x0000000798000000, 0x00000007c0000000)
  eden space 33280K, 1% used [0x0000000795580000,0x00000007955d34a8,0x0000000797600000)
  from space 5120K, 0% used [0x0000000797600000,0x0000000797600000,0x0000000797b00000)
  to   space 5120K, 0% used [0x0000000797b00000,0x0000000797b00000,0x0000000798000000)
 ParOldGen       total 87552K, used 482K [0x0000000740000000, 0x0000000745580000, 0x0000000795580000)
  object space 87552K, 0% used [0x0000000740000000,0x00000007400788f8,0x0000000745580000)
 Metaspace       used 2785K, capacity 4486K, committed 4864K, reserved 1056768K
  class space    used 301K, capacity 386K, committed 512K, reserved 1048576K
 
这段是堆内存的具体信息,从新生代到老年代,再到方法区的Metaspace,都有详细的描述。其中eden表示新生代中的Eden区,from表示Survivor里的from surviver区,to 表示Survivor里的to Survivor区。新生代中采用复制清理的算法,大概的原理就是把这快内存分为两块,一块用于使用,另一块空着,当要回收的时候就把还活着的对象复制到空闲区,然后对使用区进行全部回收。通常90%对象都是朝生夕死的,所以基本按照9:1的比例划分使用区和空闲区。
其中Eden和from survivor就是在使用区,to survivor就是在空闲区。

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326981169&siteId=291194637