您的位置:首页 > 其它

GC日志分析

2017-08-22 17:18 337 查看
本博客来自:http://blog.csdn.net/yxc135/article/details/12137663 点击打开链接 尊重原创


首先,给出一个日志输出的例子:

package jvm.gc;

import java.util.ArrayList;

import java.util.List;

/**

 * 简单的JAVA虚拟机内存回收,Parallel Scavenge收集器的使用

 * 运行参数,见具体方法,注意:需要开启server模式才能使用

 * @author AB051932

 */

public class EasyParallelScavenge {

       public static final int _64KB = 64 * 1024;     

       public byte[] placeHolder = new byte[_64KB]; //占位符

       public static void  main(String[] args) throws Exception{

              outOfMemoryByExpansionSize();

       }

       /**

        * JAVA虚拟机的大小适当可扩展,其中Xms30m,Xmx400m

        * Args:-server -Xms30m -Xmx100m -XX:+UseParallelGC -XX:+PrintGCDetails

        * 参数说明:-server  服务器模式运行   -Xms30m  最小JAVA虚拟机内存30M  -Xmx100m最大JAVA虚拟机内存100M

        * -XX:+UseParallelGC 明确指定使用Parallel Scavenge收集器  -XX:+PrintGCDetails 打印回收情况

        * @author AB051932

        */

       private static void outOfMemoryByExpansionSize() throws Exception{

              List<EasyParallelScavenge>list = new ArrayList<EasyParallelScavenge>();

              while(true){

                     EasyParallelScavenge serial = new EasyParallelScavenge();

                     list.add(serial);

                     Thread.sleep(10);//停顿10毫秒

              }

       }

}

默认垃圾收集器为:Parallel
Scavenge 

运行结果:

[GC [PSYoungGen: 7621K->1264K(8960K)] 7621K->7557K(29440K), 0.0066958 secs] [Times: user=0.03 sys=0.02, real=0.01 secs] 

[GC [PSYoungGen: 8923K->1264K(8960K)] 15217K->15051K(29440K), 0.0070636 secs] [Times: user=0.00 sys=0.00, real=0.01 secs] 

[Full GC [PSYoungGen: 1264K->0K(8960K)] [PSOldGen: 13787K->15021K(30528K)] 15051K->15021K(39488K) [PSPermGen: 2072K->2072K(12288K)], 0.0078038 secs] [Times: user=0.02 sys=0.00, real=0.01 secs] 

[GC [PSYoungGen: 7670K->1216K(8960K)] 22691K->22702K(39488K), 0.0054962 secs] [Times: user=0.00 sys=0.00, real=0.01 secs] 

[GC [PSYoungGen: 8868K->1216K(8960K)] 30355K->30320K(39488K), 0.0064028 secs] [Times: user=0.00 sys=0.00, real=0.01 secs] 

[Full GC [PSYoungGen: 1216K->0K(8960K)] [PSOldGen: 29104K->30263K(46080K)] 30320K->30263K(55040K) [PSPermGen: 2072K->2072K(12288K)], 0.0107713 secs] [Times: user=0.01 sys=0.00, real=0.01 secs] 

[GC [PSYoungGen: 7640K->1216K(8832K)] 37903K->37945K(54912K), 0.0061826 secs] [Times: user=0.00 sys=0.06, real=0.01 secs] 

[GC [PSYoungGen: 8720K->8706K(18112K)] 45449K->45434K(64192K), 0.0074070 secs] [Times: user=0.02 sys=0.02, real=0.01 secs] 

[GC [PSYoungGen: 15820K->11266K(18496K)] 52549K->52540K(64576K), 0.0118328 secs] [Times: user=0.01 sys=0.05, real=0.01 secs] 

[Full GC [PSYoungGen: 11266K->6465K(18496K)] [PSOldGen: 41273K->46020K(62528K)] 52540K->52485K(81024K) [PSPermGen: 2072K->2072K(12288K)], 0.0152228 secs] [Times: user=0.00 sys=0.02, real=0.02 secs] 

[GC [PSYoungGen: 7111K->7153K(22784K)] 53132K->53174K(85312K), 0.0050284 secs] [Times: user=0.00 sys=0.06, real=0.00 secs] 

[GC [PSYoungGen: 18554K->11266K(22784K)] 64575K->64584K(85312K), 0.0095008 secs] [Times: user=0.02 sys=0.05, real=0.01 secs] 

[GC [PSYoungGen: 22675K->11314K(22784K)] 75993K->75971K(87616K), 0.0090107 secs] [Times: user=0.05 sys=0.00, real=0.01 secs] 

[Full GC [PSYoungGen: 11314K->11077K(22784K)] [PSOldGen: 64656K->64817K(68288K)] 75971K->75895K(91072K) [PSPermGen: 2072K->2066K(12288K)], 0.0229330 secs] [Times: user=0.02 sys=0.00, real=0.02 secs] 

[Full GC [PSYoungGen: 11400K->7938K(22784K)] [PSOldGen: 64817K->68277K(68288K)] 76218K->76215K(91072K) [PSPermGen: 2066K->2066K(12288K)], 0.0091107 secs] [Times: user=0.00 sys=0.00, real=0.01 secs] 

[Full GC [PSYoungGen: 11396K->11396K(22784K)] [PSOldGen: 68277K->68277K(68288K)] 79674K->79674K(91072K) [PSPermGen: 2066K->2066K(12288K)], 0.0088315 secs] [Times: user=0.01 sys=0.00, real=0.01 secs] 

[Full GC [PSYoungGen: 11396K->11395K(22784K)] [PSOldGen: 68277K->68277K(68288K)] 79674K->79673K(91072K) [PSPermGen: 2066K->2066K(12288K)], 0.0100152 secs] [Times: user=0.00 sys=0.00, real=0.01 secs] 

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at jvm.gc.EasyParallelScavenge.<init>(EasyParallelScavenge.java:19)
at jvm.gc.EasyParallelScavenge.outOfMemoryByExpansionSize(EasyParallelScavenge.java:45)
at jvm.gc.EasyParallelScavenge.main(EasyParallelScavenge.java:23)

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Heap

 PSYoungGen      total 22784K, used 11456K [0x0c5c0000, 0x0e710000, 0x0e710000)

  eden space 11456K, 100% used [0x0c5c0000,0x0d0f0000,0x0d0f0000)

  from space 11328K, 0% used [0x0dc00000,0x0dc00000,0x0e710000)

  to   space 11328K, 0% used [0x0d0f0000,0x0d0f0000,0x0dc00000)

 PSOldGen        total 68288K, used 68277K [0x08310000, 0x0c5c0000, 0x0c5c0000)

  object space 68288K, 99% used [0x08310000,0x0c5bd558,0x0c5c0000)

 PSPermGen       total 12288K, used 2072K [0x04310000, 0x04f10000, 0x08310000)

  object space 12288K, 16% used [0x04310000,0x045162f0,0x04f10000)

-------------------------------------------------------------------------

前半段分析:

GC (minor )日志:


后半段分析:

     首先需要了解虚拟机内存结构图



相关参数说明:

     JVM内存区分为 年轻代、老年代和永久代三大部分

     1、 年轻代:(Eden、From、To) -XX:MaxNewSize 设置年轻代最大值, -XX:NewSize设置年轻代的值

     2、 堆内存: 年轻代+老年代  -Xmx 设置可用堆内存,-Xms设置最大堆内存

     3、 永久代: -XX:MaxPermSize 设置永久代最大值,-XX:PermSize设置永久代值



  参数:

  1、SurvivorRatio 设置 Eden/From Space 的比率

  2、 NewRatio 设置 老年代/年轻代 的比率

GC日志中的PSYoungGen(PS是指Parallel
Scavenge)为Eden+FromSpace,而整个YoungGeneration为Eden+FromSpace+ToSpace

更详细描述参见官方文档:http://www.oracle.com/technetwork/java/javase/gc-tuning-6-140523.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: