重金求解!JVM GC机制问题

fengyvn 2016-04-14 07:25:44
加精
编写了段代码跟踪GC,不明白为什么最后连续调用了两次FULLGC

代码
class Test{
public static void main(String []args){
Test1();
}

static void Test1(){
byte[] b1,b2,b3,b4;
System.out.println("b1");
b1=new byte[1024*1024];
System.out.println("b2");
b2=new byte[4*1024*1024];;
System.out.println("b3");
b3=new byte[6*1024*1024];
System.out.println("b4");
b4=new byte[2*1024*1024];; //这里为什么连续进行了两次FULLGC
}
}

指mx=ms=16M,mn=10M
日志

E:\JAVA\Test>java -verbose:gc -Xms16M -Xmx16M -Xmn10M -XX:SurvivorRatio=8 -XX:+
PrintGCDetails -XX:+PrintHeapAtGC -XX:+UseParallelGC Test

b1
b2
b3
{Heap before GC invocations=1 (full 0):
PSYoungGen total 9216K, used 5791K [0x00000000ff600000, 0x0000000100000000
, 0x0000000100000000)
eden space 8192K, 70% used [0x00000000ff600000,0x00000000ffba7fc0,0x00000000ff
e00000)
from space 1024K, 0% used [0x00000000fff00000,0x00000000fff00000,0x00000001000
00000)
to space 1024K, 0% used [0x00000000ffe00000,0x00000000ffe00000,0x00000000fff
00000)
ParOldGen total 6144K, used 0K [0x00000000ff000000, 0x00000000ff600000, 0
x00000000ff600000)
object space 6144K, 0% used [0x00000000ff000000,0x00000000ff000000,0x00000000f
f600000)
PSPermGen total 21504K, used 2461K [0x00000000f9e00000, 0x00000000fb30000
0, 0x00000000ff000000)
object space 21504K, 11% used [0x00000000f9e00000,0x00000000fa067718,0x0000000
0fb300000)
[GC [PSYoungGen: 5791K->600K(9216K)] 5791K->5720K(15360K), 0.0041053 secs] [Time
s: user=0.00 sys=0.00, real=0.00 secs]
Heap after GC invocations=1 (full 0):
PSYoungGen total 9216K, used 600K [0x00000000ff600000, 0x0000000100000000,
0x0000000100000000)
eden space 8192K, 0% used [0x00000000ff600000,0x00000000ff600000,0x00000000ffe
00000)
from space 1024K, 58% used [0x00000000ffe00000,0x00000000ffe96010,0x00000000ff
f00000)
to space 1024K, 0% used [0x00000000fff00000,0x00000000fff00000,0x00000001000
00000)
ParOldGen total 6144K, used 5120K [0x00000000ff000000, 0x00000000ff600000
, 0x00000000ff600000)
object space 6144K, 83% used [0x00000000ff000000,0x00000000ff500020,0x00000000
ff600000)
PSPermGen total 21504K, used 2461K [0x00000000f9e00000, 0x00000000fb30000
0, 0x00000000ff000000)
object space 21504K, 11% used [0x00000000f9e00000,0x00000000fa067718,0x0000000
0fb300000)
}
{Heap before GC invocations=2 (full 1):
PSYoungGen total 9216K, used 600K [0x00000000ff600000, 0x0000000100000000,
0x0000000100000000)
eden space 8192K, 0% used [0x00000000ff600000,0x00000000ff600000,0x00000000ffe
00000)
from space 1024K, 58% used [0x00000000ffe00000,0x00000000ffe96010,0x00000000ff
f00000)
to space 1024K, 0% used [0x00000000fff00000,0x00000000fff00000,0x00000001000
00000)
ParOldGen total 6144K, used 5120K [0x00000000ff000000, 0x00000000ff600000
, 0x00000000ff600000)
object space 6144K, 83% used [0x00000000ff000000,0x00000000ff500020,0x00000000
ff600000)
PSPermGen total 21504K, used 2461K [0x00000000f9e00000, 0x00000000fb30000
0, 0x00000000ff000000)
object space 21504K, 11% used [0x00000000f9e00000,0x00000000fa067718,0x0000000
0fb300000)
[Full GC [PSYoungGen: 600K->0K(9216K)] [ParOldGen: 5120K->5589K(6144K)] 5720K->5
589K(15360K) [PSPermGen: 2461K->2460K(21504K)], 0.0148748 secs] [Times: user=0.0
0 sys=0.00, real=0.01 secs]
Heap after GC invocations=2 (full 1):
PSYoungGen total 9216K, used 0K [0x00000000ff600000, 0x0000000100000000, 0
x0000000100000000)
eden space 8192K, 0% used [0x00000000ff600000,0x00000000ff600000,0x00000000ffe
00000)
from space 1024K, 0% used [0x00000000ffe00000,0x00000000ffe00000,0x00000000fff
00000)
to space 1024K, 0% used [0x00000000fff00000,0x00000000fff00000,0x00000001000
00000)
ParOldGen total 6144K, used 5589K [0x00000000ff000000, 0x00000000ff600000
, 0x00000000ff600000)
object space 6144K, 90% used [0x00000000ff000000,0x00000000ff575528,0x00000000
ff600000)
PSPermGen total 21504K, used 2460K [0x00000000f9e00000, 0x00000000fb30000
0, 0x00000000ff000000)
object space 21504K, 11% used [0x00000000f9e00000,0x00000000fa067390,0x0000000
0fb300000)
}
b4
{Heap before GC invocations=3 (full 2): //1次FULLgc
PSYoungGen total 9216K, used 6563K [0x00000000ff600000, 0x0000000100000000
, 0x0000000100000000)
eden space 8192K, 80% used [0x00000000ff600000,0x00000000ffc68c70,0x00000000ff
e00000)
from space 1024K, 0% used [0x00000000ffe00000,0x00000000ffe00000,0x00000000fff
00000)
to space 1024K, 0% used [0x00000000fff00000,0x00000000fff00000,0x00000001000
00000)
ParOldGen total 6144K, used 5589K [0x00000000ff000000, 0x00000000ff600000
, 0x00000000ff600000)
object space 6144K, 90% used [0x00000000ff000000,0x00000000ff575528,0x00000000
ff600000)
PSPermGen total 21504K, used 2463K [0x00000000f9e00000, 0x00000000fb30000
0, 0x00000000ff000000)
object space 21504K, 11% used [0x00000000f9e00000,0x00000000fa067eb8,0x0000000
0fb300000)
[Full GC [PSYoungGen: 6563K->6144K(9216K)] [ParOldGen: 5589K->5588K(6144K)] 1215
2K->11733K(15360K) [PSPermGen: 2463K->2463K(21504K)], 0.0118234 secs] [Times: us
er=0.05 sys=0.00, real=0.01 secs]
Heap after GC invocations=3 (full 2):
PSYoungGen total 9216K, used 6144K [0x00000000ff600000, 0x0000000100000000
, 0x0000000100000000)
eden space 8192K, 75% used [0x00000000ff600000,0x00000000ffc00140,0x00000000ff
e00000)
from space 1024K, 0% used [0x00000000ffe00000,0x00000000ffe00000,0x00000000fff
00000)
to space 1024K, 0% used [0x00000000fff00000,0x00000000fff00000,0x00000001000
00000)
ParOldGen total 6144K, used 5588K [0x00000000ff000000, 0x00000000ff600000
, 0x00000000ff600000)
object space 6144K, 90% used [0x00000000ff000000,0x00000000ff575338,0x00000000
ff600000)
PSPermGen total 21504K, used 2463K [0x00000000f9e00000, 0x00000000fb30000
0, 0x00000000ff000000)
object space 21504K, 11% used [0x00000000f9e00000,0x00000000fa067eb8,0x0000000
0fb300000)
}
{Heap before GC invocations=4 (full 3): //第二次FULLGC
PSYoungGen total 9216K, used 6144K [0x00000000ff600000, 0x0000000100000000
, 0x0000000100000000)
eden space 8192K, 75% used [0x00000000ff600000,0x00000000ffc00140,0x00000000ff
e00000)
from space 1024K, 0% used [0x00000000ffe00000,0x00000000ffe00000,0x00000000fff
00000)
to space 1024K, 0% used [0x00000000fff00000,0x00000000fff00000,0x00000001000
00000)
ParOldGen total 6144K, used 5588K [0x00000000ff000000, 0x00000000ff600000
, 0x00000000ff600000)
object space 6144K, 90% used [0x00000000ff000000,0x00000000ff575338,0x00000000
ff600000)
PSPermGen total 21504K, used 2463K [0x00000000f9e00000, 0x00000000fb30000
0, 0x00000000ff000000)
object space 21504K, 11% used [0x00000000f9e00000,0x00000000fa067eb8,0x0000000
0fb300000)
[Full GC [PSYoungGen: 6144K->6144K(9216K)] [ParOldGen: 5588K->5578K(6144K)] 1173
3K->11722K(15360K) [PSPermGen: 2463K->2463K(21504K)], 0.0121387 secs] [Times: us
er=0.00 sys=0.00, real=0.01 secs]
Heap after GC invocations=4 (full 3):
PSYoungGen total 9216K, used 6144K [0x00000000ff600000, 0x0000000100000000
, 0x0000000100000000)
eden space 8192K, 75% used [0x00000000ff600000,0x00000000ffc00140,0x00000000ff
e00000)
from space 1024K, 0% used [0x00000000ffe00000,0x00000000ffe00000,0x00000000fff
00000)
to space 1024K, 0% used [0x00000000fff00000,0x00000000fff00000,0x00000001000
00000)
ParOldGen total 6144K, used 5578K [0x00000000ff000000, 0x00000000ff600000
, 0x00000000ff600000)
object space 6144K, 90% used [0x00000000ff000000,0x00000000ff572888,0x00000000
ff600000)
PSPermGen total 21504K, used 2463K [0x00000000f9e00000, 0x00000000fb30000
0, 0x00000000ff000000)
object space 21504K, 11% used [0x00000000f9e00000,0x00000000fa067eb8,0x0000000
0fb300000)
}
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at Test.Test1(Test.java:15)
at Test.main(Test.java:3)
Heap
PSYoungGen total 9216K, used 6286K [0x00000000ff600000, 0x0000000100000000
, 0x0000000100000000)
eden space 8192K, 76% used [0x00000000ff600000,0x00000000ffc239a8,0x00000000ff
e00000)
from space 1024K, 0% used [0x00000000ffe00000,0x00000000ffe00000,0x00000000fff
00000)
to space 1024K, 0% used [0x00000000fff00000,0x00000000fff00000,0x00000001000
00000)
ParOldGen total 6144K, used 5578K [0x00000000ff000000, 0x00000000ff600000
, 0x00000000ff600000)
object space 6144K, 90% used [0x00000000ff000000,0x00000000ff572888,0x00000000
ff600000)
PSPermGen total 21504K, used 2494K [0x00000000f9e00000, 0x00000000fb30000
0, 0x00000000ff000000)
object space 21504K, 11% used [0x00000000f9e00000,0x00000000fa06f838,0x0000000
0fb300000)

为什么是两次不是一次?为什么是两次不是一次?为什么是两次不是一次?为什么是两次不是一次?为什么是两次不是一次?
...全文
2272 21 打赏 收藏 转发到动态 举报
写回复
用AI写文章
21 条回复
切换为时间正序
请发表友善的回复…
发表回复
家里敷泥呀 2016-04-25
  • 打赏
  • 举报
回复
对比两个full gc Full GC (Ergonomics) // Ergonomics表明是通过某种规则触发的; Full GC (Allocation Failure) // Allocation Failure表明是由于内存分配失败照成的。 这里的规则可能是下文中情况1或4照成的,待确认。 触发Full GC执行的情况_Teaey_新浪博客 http://blog.sina.com.cn/s/blog_7a351012010163a1.html
家里敷泥呀 2016-04-25
  • 打赏
  • 举报
回复
我做了三组测试,情况如下: 测试一:使用Serial (+UseSerialGC) b1 b2 b3 GC (Allocation Failure) b4 GC (Allocation Failure) Full GC (Allocation Failure) 测试一:使用ParNew (+UseParallelGC) b1 b2 b3 GC (Allocation Failure) Full GC (Ergonomics) // 注1:多一个full gc b4 Full GC (Ergonomics) // 注2:Serial采用的是GC, ParNew采用的是Full GC Full GC (Allocation Failure) 测试三:使用ParNew且修改b4大小 (+UseParallelGC && b4 = new byte[2 * 1024 * 1020];) // b4的值适当缩小(小于2M),确保不出现OOM b1 b2 b3 GC (Allocation Failure) Full GC (Ergonomics) b4 Full GC (Ergonomics) // 注3:对比上一个测试,这里少一个 Full GC (Allocation Failure) 综上: 1)测试二、三的对比表明(注3处):最后一个Full GC是由于分配失败照成的(Allocation Failure的中文意思就是分配失败,二有OOM,三没有)。 2)ParNew 比 Serial 更容易触发Full GC(注1,注2处),触发原因的话,暂时没查到准确的资料。 你可以阅读下这个:触发Full GC执行的情况_Teaey_新浪博客 http://blog.sina.com.cn/s/blog_7a351012010163a1.html
SoulRed 2016-04-22
  • 打赏
  • 举报
回复
你换个电脑试试,或者换个系统,换个编译软件,看看结果是否一样
fengyvn 2016-04-21
  • 打赏
  • 举报
回复
to u011878699 前半部分你说得很对,但是第2次full gc是在打印出b4之后进行的,就是说第2,3次FULLGC都是new b4触发的。我的问题是“FULLGC为什么会触发两次“
qq_34740107 2016-04-21
  • 打赏
  • 举报
回复
不明觉厉,大神
ljheee 2016-04-19
  • 打赏
  • 举报
回复
不明觉厉,大神
okkk 2016-04-18
  • 打赏
  • 举报
回复
看不懂这些日志哈。 GC好像要分代,堆栈上是一代, 对象上有对其他对象的引用,释放对象的同时,该对象对其他对象的引用可能也需要释放。 估计这个多次GC调用,不是调用了多次,而是一个递归操作,递归调用导致了这个现象。
潜行攻城狮 2016-04-18
  • 打赏
  • 举报
回复
不对啊,,是在b3后就死了,,,b4还没有开始,,,那么就是在第二步死循环了,,一直回收不了的节奏
潜行攻城狮 2016-04-18
  • 打赏
  • 举报
回复
主要步骤是这样的 1:b1,b2打印过后.有5M在yang,刚好需要GC(jvm自己判断).. so...GC [GC [PSYoungGen: 5955K->600K(9216K)] 5955K->5720K(15360K), 0.0033181 secs] [Time s: user=0.03 sys=0.02, real=0.01 secs] 最终,yang 600kb,old 5120kb,(yang没有清理干净) -------------------- 2:现在b1和b2都在old,jvm发现old是真的要满了,FULLGC, [Full GC [PSYoungGen: 600K->0K(9216K)] [ParOldGen: 5120K->5589K(6144K)] 5720K->5 589K(15360K) [PSPermGen: 2461K->2460K(21504K)], 0.0152989 secs] [Times: user=0.0 1 sys=0.00, real=0.01 secs] 最终,yang 0kb,old 5589kb,(yang清理干净,old=5120+600-可清理部分) -------------- 3:又放了6M到yang而且发现在第二步过后old还是快满了,,,,so full gc再来一次 [Full GC [PSYoungGen: 6483K->6144K(9216K)] [ParOldGen: 5589K->5588K(6144K)] 1207 2K->11733K(15360K) [PSPermGen: 2463K->2463K(21504K)], 0.0141060 secs] [Times: us er=0.00 sys=0.00, real=0.01 secs] 重点来了,,,yang 6144kb,old 5588kb, 这次gc其实没有回收什么东西,也就是说b1,b2,b3,都还在内存里面,并没有被回收 ---------------- 4:从复第3步,,,, [Full GC [PSYoungGen: 6483K->6144K(9216K)] [ParOldGen: 5589K->5588K(6144K)] 1207 2K->11733K(15360K) [PSPermGen: 2463K->2463K(21504K)], 0.0141060 secs] [Times: us er=0.00 sys=0.00, real=0.01 secs] yang 6144kb,old 5588kb, --------------- 现在你再把b4放进来,,你说爆不爆?
liuxiaopingsdfsdf 2016-04-16
  • 打赏
  • 举报
回复
sdfsdfdsf
liuxiaopingsdfsdf 2016-04-16
  • 打赏
  • 举报
回复
sdfdsfd
liuxiaopingsdfsdf 2016-04-16
  • 打赏
  • 举报
回复
scmod 2016-04-15
  • 打赏
  • 举报
回复
话说Heap before GC invocations=2 (full 1)第一次full gc是为啥触发的
Stluny 2016-04-15
  • 打赏
  • 举报
回复
前一阵被一个大图像问题整的头都裂了。。 就是一直内存溢出 查了下 java GC机制不是说掉就掉了 好像是个一定时间或者到那个情况下 自己调用GC。。
skgary 2016-04-15
  • 打赏
  • 举报
回复
补充一句,JVM可没说对像一旦不用就马上GC或full gc,只是对应那一代内存不够了,才会GC
skgary 2016-04-15
  • 打赏
  • 举报
回复
1,你的代码跑太快了而且运行时间太短,根本不足以去理解GC,这里只需要知道这些对像何时能被回收就可以了。 2,JVM是执行的中间代码。也就是说,JVM本身也是有开销的,本身也是要被GC的,所以会有超出你代码本身的东西存在。 3. 异常的代码Java heap space at Test.test5(Test.java:66) at Test.main(Test.java:10) 和你贴里的代码对的起来? 日志这么多,看的累死也看不出个所以然来。
  • 打赏
  • 举报
回复
好吧,我承认我看不懂
h2plus0 2016-04-15
  • 打赏
  • 举报
回复
如果只从表现来看, 执行4次full gc 有可能是因为使用了 UseParallelGC, 如果换成 UseSerialGC 就只执行3此了。 估计是因为parallel gc 执行的太快了,来不及刹车啊
fengyvn 2016-04-15
  • 打赏
  • 举报
回复
代码刻意写得很短,结合xm,xs,xn三个值也算比较典型的alloc空间不够的问题,就是希望在应用层面明显出现空间不够的情况下触发GC,这时对JVM本身的GC应该可以忽略。测试代码和运行日志基本是一样的,只有报异常的行数有点差异。重贴下代码和日志,大家再帮忙分析一下 代码 class Test{ public static void main(String []args){ Test1(); /*try{ Thread.sleep(1000*60); }catch(InterruptedException e){ e.printStackTrace(); }*/ } static void Test1(){ byte[] b1,b2,b3,b4; System.out.println("b1"); b1=new byte[1024*1024]; System.out.println("b2"); b2=new byte[4*1024*1024];; System.out.println("b3"); b3=new byte[6*1024*1024]; System.out.println("b4"); b4=new byte[2*1024*1024]; //空间不够抛出异常 } } 运行 java -verbose:gc -Xms16M -Xmx16M -Xmn10M -XX:SurvivorRatio=8 -XX:+ PrintGCDetails -XX:+PrintHeapAtGC -XX:+UseParallelGC Test 日志 b1 b2 b3 {Heap before GC invocations=1 (full 0): //GC1 PSYoungGen total 9216K, used 5955K [0x00000000ff600000, 0x0000000100000000 , 0x0000000100000000) eden space 8192K, 72% used [0x00000000ff600000,0x00000000ffbd0fb8,0x00000000ff e00000) from space 1024K, 0% used [0x00000000fff00000,0x00000000fff00000,0x00000001000 00000) to space 1024K, 0% used [0x00000000ffe00000,0x00000000ffe00000,0x00000000fff 00000) ParOldGen total 6144K, used 0K [0x00000000ff000000, 0x00000000ff600000, 0 x00000000ff600000) object space 6144K, 0% used [0x00000000ff000000,0x00000000ff000000,0x00000000f f600000) PSPermGen total 21504K, used 2461K [0x00000000f9e00000, 0x00000000fb30000 0, 0x00000000ff000000) object space 21504K, 11% used [0x00000000f9e00000,0x00000000fa067718,0x0000000 0fb300000) [GC [PSYoungGen: 5955K->600K(9216K)] 5955K->5720K(15360K), 0.0033181 secs] [Time s: user=0.03 sys=0.02, real=0.01 secs] Heap after GC invocations=1 (full 0): PSYoungGen total 9216K, used 600K [0x00000000ff600000, 0x0000000100000000, 0x0000000100000000) eden space 8192K, 0% used [0x00000000ff600000,0x00000000ff600000,0x00000000ffe 00000) from space 1024K, 58% used [0x00000000ffe00000,0x00000000ffe96010,0x00000000ff f00000) to space 1024K, 0% used [0x00000000fff00000,0x00000000fff00000,0x00000001000 00000) ParOldGen total 6144K, used 5120K [0x00000000ff000000, 0x00000000ff600000 , 0x00000000ff600000) object space 6144K, 83% used [0x00000000ff000000,0x00000000ff500020,0x00000000 ff600000) PSPermGen total 21504K, used 2461K [0x00000000f9e00000, 0x00000000fb30000 0, 0x00000000ff000000) object space 21504K, 11% used [0x00000000f9e00000,0x00000000fa067718,0x0000000 0fb300000) } {Heap before GC invocations=2 (full 1)://GC2 PSYoungGen total 9216K, used 600K [0x00000000ff600000, 0x0000000100000000, 0x0000000100000000) eden space 8192K, 0% used [0x00000000ff600000,0x00000000ff600000,0x00000000ffe 00000) from space 1024K, 58% used [0x00000000ffe00000,0x00000000ffe96010,0x00000000ff f00000) to space 1024K, 0% used [0x00000000fff00000,0x00000000fff00000,0x00000001000 00000) ParOldGen total 6144K, used 5120K [0x00000000ff000000, 0x00000000ff600000 , 0x00000000ff600000) object space 6144K, 83% used [0x00000000ff000000,0x00000000ff500020,0x00000000 ff600000) PSPermGen total 21504K, used 2461K [0x00000000f9e00000, 0x00000000fb30000 0, 0x00000000ff000000) object space 21504K, 11% used [0x00000000f9e00000,0x00000000fa067718,0x0000000 0fb300000) [Full GC [PSYoungGen: 600K->0K(9216K)] [ParOldGen: 5120K->5589K(6144K)] 5720K->5 589K(15360K) [PSPermGen: 2461K->2460K(21504K)], 0.0152989 secs] [Times: user=0.0 1 sys=0.00, real=0.01 secs] Heap after GC invocations=2 (full 1): PSYoungGen total 9216K, used 0K [0x00000000ff600000, 0x0000000100000000, 0 x0000000100000000) eden space 8192K, 0% used [0x00000000ff600000,0x00000000ff600000,0x00000000ffe 00000) from space 1024K, 0% used [0x00000000ffe00000,0x00000000ffe00000,0x00000000fff 00000) to space 1024K, 0% used [0x00000000fff00000,0x00000000fff00000,0x00000001000 00000) ParOldGen total 6144K, used 5589K [0x00000000ff000000, 0x00000000ff600000 , 0x00000000ff600000) object space 6144K, 90% used [0x00000000ff000000,0x00000000ff575528,0x00000000 ff600000) PSPermGen total 21504K, used 2460K [0x00000000f9e00000, 0x00000000fb30000 0, 0x00000000ff000000) object space 21504K, 11% used [0x00000000f9e00000,0x00000000fa067390,0x0000000 0fb300000) } b4 {Heap before GC invocations=3 (full 2): // b4触发的第一次FULLGC PSYoungGen total 9216K, used 6483K [0x00000000ff600000, 0x0000000100000000 , 0x0000000100000000) eden space 8192K, 79% used [0x00000000ff600000,0x00000000ffc54cc0,0x00000000ff e00000) from space 1024K, 0% used [0x00000000ffe00000,0x00000000ffe00000,0x00000000fff 00000) to space 1024K, 0% used [0x00000000fff00000,0x00000000fff00000,0x00000001000 00000) ParOldGen total 6144K, used 5589K [0x00000000ff000000, 0x00000000ff600000 , 0x00000000ff600000) object space 6144K, 90% used [0x00000000ff000000,0x00000000ff575528,0x00000000 ff600000) PSPermGen total 21504K, used 2463K [0x00000000f9e00000, 0x00000000fb30000 0, 0x00000000ff000000) object space 21504K, 11% used [0x00000000f9e00000,0x00000000fa067eb8,0x0000000 0fb300000) [Full GC [PSYoungGen: 6483K->6144K(9216K)] [ParOldGen: 5589K->5588K(6144K)] 1207 2K->11733K(15360K) [PSPermGen: 2463K->2463K(21504K)], 0.0141060 secs] [Times: us er=0.00 sys=0.00, real=0.01 secs] Heap after GC invocations=3 (full 2): PSYoungGen total 9216K, used 6144K [0x00000000ff600000, 0x0000000100000000 , 0x0000000100000000) eden space 8192K, 75% used [0x00000000ff600000,0x00000000ffc00140,0x00000000ff e00000) from space 1024K, 0% used [0x00000000ffe00000,0x00000000ffe00000,0x00000000fff 00000) to space 1024K, 0% used [0x00000000fff00000,0x00000000fff00000,0x00000001000 00000) ParOldGen total 6144K, used 5588K [0x00000000ff000000, 0x00000000ff600000 , 0x00000000ff600000) object space 6144K, 90% used [0x00000000ff000000,0x00000000ff575338,0x00000000 ff600000) PSPermGen total 21504K, used 2463K [0x00000000f9e00000, 0x00000000fb30000 0, 0x00000000ff000000) object space 21504K, 11% used [0x00000000f9e00000,0x00000000fa067eb8,0x0000000 0fb300000) } {Heap before GC invocations=4 (full 3)://b4触发的第二次FULLGC PSYoungGen total 9216K, used 6144K [0x00000000ff600000, 0x0000000100000000 , 0x0000000100000000) eden space 8192K, 75% used [0x00000000ff600000,0x00000000ffc00140,0x00000000ff e00000) from space 1024K, 0% used [0x00000000ffe00000,0x00000000ffe00000,0x00000000fff 00000) to space 1024K, 0% used [0x00000000fff00000,0x00000000fff00000,0x00000001000 00000) ParOldGen total 6144K, used 5588K [0x00000000ff000000, 0x00000000ff600000 , 0x00000000ff600000) object space 6144K, 90% used [0x00000000ff000000,0x00000000ff575338,0x00000000 ff600000) PSPermGen total 21504K, used 2463K [0x00000000f9e00000, 0x00000000fb30000 0, 0x00000000ff000000) object space 21504K, 11% used [0x00000000f9e00000,0x00000000fa067eb8,0x0000000 0fb300000) [Full GC [PSYoungGen: 6144K->6144K(9216K)] [ParOldGen: 5588K->5578K(6144K)] 1173 3K->11722K(15360K) [PSPermGen: 2463K->2463K(21504K)], 0.0119514 secs] [Times: us er=0.05 sys=0.00, real=0.01 secs] Heap after GC invocations=4 (full 3): PSYoungGen total 9216K, used 6144K [0x00000000ff600000, 0x0000000100000000 , 0x0000000100000000) eden space 8192K, 75% used [0x00000000ff600000,0x00000000ffc00140,0x00000000ff e00000) from space 1024K, 0% used [0x00000000ffe00000,0x00000000ffe00000,0x00000000fff 00000) to space 1024K, 0% used [0x00000000fff00000,0x00000000fff00000,0x00000001000 00000) ParOldGen total 6144K, used 5578K [0x00000000ff000000, 0x00000000ff600000 , 0x00000000ff600000) object space 6144K, 90% used [0x00000000ff000000,0x00000000ff572888,0x00000000 ff600000) PSPermGen total 21504K, used 2463K [0x00000000f9e00000, 0x00000000fb30000 0, 0x00000000ff000000) object space 21504K, 11% used [0x00000000f9e00000,0x00000000fa067eb8,0x0000000 0fb300000) } Exception in thread "main" java.lang.OutOfMemoryError: Java heap space at Test.Test1(Test.java:20) at Test.main(Test.java:3) Heap PSYoungGen total 9216K, used 6286K [0x00000000ff600000, 0x0000000100000000 , 0x0000000100000000) eden space 8192K, 76% used [0x00000000ff600000,0x00000000ffc23908,0x00000000ff e00000) from space 1024K, 0% used [0x00000000ffe00000,0x00000000ffe00000,0x00000000fff 00000) to space 1024K, 0% used [0x00000000fff00000,0x00000000fff00000,0x00000001000 00000) ParOldGen total 6144K, used 5578K [0x00000000ff000000, 0x00000000ff600000 , 0x00000000ff600000) object space 6144K, 90% used [0x00000000ff000000,0x00000000ff572888,0x00000000 ff600000) PSPermGen total 21504K, used 2494K [0x00000000f9e00000, 0x00000000fb30000 0, 0x00000000ff000000) object space 21504K, 11% used [0x00000000f9e00000,0x00000000fa06f838,0x0000000 0fb300000) GC后空间还是不够抛出了异常,大家再分析一下,谢谢
fengyvn 2016-04-14
  • 打赏
  • 举报
回复
改一下代码,b2变成5M,输出日志又不一样了 System.out.println("read b1"); alloc1 = new byte[1024*1024]; System.out.println("read b2"); alloc2 = new byte[5*1024*1024]; //变成5M System.out.println("read b3"); alloc3 = new byte[6*1024*1024]; System.out.println("read b4"); alloc4 = new byte[2*1024*1024]; java -verbose:gc -Xms16M -Xmx16M -Xmn10M -XX:SurvivorRatio=8 -XX:+ PrintGCDetails -XX:+PrintHeapAtGC -XX:+UseParallelGC Test read b1 read b2 read b3 {Heap before GC invocations=1 (full 0): PSYoungGen total 9216K, used 6816K [0x00000000ff600000, 0x0000000100000000, 0x0000000100000000) eden space 8192K, 83% used [0x00000000ff600000,0x00000000ffca80e0,0x00000000ffe00000) from space 1024K, 0% used [0x00000000fff00000,0x00000000fff00000,0x0000000100000000) to space 1024K, 0% used [0x00000000ffe00000,0x00000000ffe00000,0x00000000fff00000) ParOldGen total 6144K, used 0K [0x00000000ff000000, 0x00000000ff600000, 0x00000000ff600000) object space 6144K, 0% used [0x00000000ff000000,0x00000000ff000000,0x00000000ff600000) PSPermGen total 21504K, used 2835K [0x00000000f4a00000, 0x00000000f5f00000, 0x00000000ff000000) object space 21504K, 13% used [0x00000000f4a00000,0x00000000f4cc4c70,0x00000000f5f00000) [GC-- [PSYoungGen: 6816K->6816K(9216K)] 6816K->7840K(15360K), 1.7616370 secs] [Times: user=0.18 sys=1.47, real=1.76 secs] Heap after GC invocations=1 (full 0): PSYoungGen total 9216K, used 6816K [0x00000000ff600000, 0x0000000100000000, 0x0000000100000000) eden space 8192K, 83% used [0x00000000ff600000,0x00000000ffca80e0,0x00000000ffe00000) from space 1024K, 0% used [0x00000000fff00000,0x00000000fff00000,0x0000000100000000) to space 1024K, 53% used [0x00000000ffe00000,0x00000000ffe8a020,0x00000000fff00000) ParOldGen total 6144K, used 1024K [0x00000000ff000000, 0x00000000ff600000, 0x00000000ff600000) object space 6144K, 16% used [0x00000000ff000000,0x00000000ff100010,0x00000000ff600000) PSPermGen total 21504K, used 2835K [0x00000000f4a00000, 0x00000000f5f00000, 0x00000000ff000000) object space 21504K, 13% used [0x00000000f4a00000,0x00000000f4cc4c70,0x00000000f5f00000) } {Heap before GC invocations=2 (full 1): PSYoungGen total 9216K, used 6816K [0x00000000ff600000, 0x0000000100000000, 0x0000000100000000) eden space 8192K, 83% used [0x00000000ff600000,0x00000000ffca80e0,0x00000000ffe00000) from space 1024K, 0% used [0x00000000fff00000,0x00000000fff00000,0x0000000100000000) to space 1024K, 53% used [0x00000000ffe00000,0x00000000ffe8a020,0x00000000fff00000) ParOldGen total 6144K, used 1024K [0x00000000ff000000, 0x00000000ff600000, 0x00000000ff600000) object space 6144K, 16% used [0x00000000ff000000,0x00000000ff100010,0x00000000ff600000) PSPermGen total 21504K, used 2835K [0x00000000f4a00000, 0x00000000f5f00000, 0x00000000ff000000) object space 21504K, 13% used [0x00000000f4a00000,0x00000000f4cc4c70,0x00000000f5f00000) [Full GC [PSYoungGen: 6816K->5600K(9216K)] [ParOldGen: 1024K->1024K(6144K)] 7840K->6624K(15360K) [PSPermGen: 2835K->2834K(21504K)], 1.5682240 secs] [Times: user=0.04 sys=1.49, real=1.56 secs] Heap after GC invocations=2 (full 1): //eden 中由6M变成了5M,还有1M去哪里了。 PSYoungGen total 9216K, used 5600K [0x00000000ff600000, 0x0000000100000000, 0x0000000100000000) eden space 8192K, 68% used [0x00000000ff600000,0x00000000ffb78238,0x00000000ffe00000) from space 1024K, 0% used [0x00000000fff00000,0x00000000fff00000,0x0000000100000000) to space 1024K, 0% used [0x00000000ffe00000,0x00000000ffe00000,0x00000000fff00000) ParOldGen total 6144K, used 1024K [0x00000000ff000000, 0x00000000ff600000, 0x00000000ff600000) //old gen容量无变化,new gen中还有1M去哪里了 object space 6144K, 16% used [0x00000000ff000000,0x00000000ff100010,0x00000000ff600000) PSPermGen total 21504K, used 2834K [0x00000000f4a00000, 0x00000000f5f00000, 0x00000000ff000000) object space 21504K, 13% used [0x00000000f4a00000,0x00000000f4cc48b8,0x00000000f5f00000) } {Heap before GC invocations=3 (full 1)://FULL GC 为什么又触发一次YGC? PSYoungGen total 9216K, used 5600K [0x00000000ff600000, 0x0000000100000000, 0x0000000100000000) eden space 8192K, 68% used [0x00000000ff600000,0x00000000ffb78238,0x00000000ffe00000) from space 1024K, 0% used [0x00000000fff00000,0x00000000fff00000,0x0000000100000000) to space 1024K, 0% used [0x00000000ffe00000,0x00000000ffe00000,0x00000000fff00000) ParOldGen total 6144K, used 1024K [0x00000000ff000000, 0x00000000ff600000, 0x00000000ff600000) object space 6144K, 16% used [0x00000000ff000000,0x00000000ff100010,0x00000000ff600000) PSPermGen total 21504K, used 2834K [0x00000000f4a00000, 0x00000000f5f00000, 0x00000000ff000000) object space 21504K, 13% used [0x00000000f4a00000,0x00000000f4cc48b8,0x00000000f5f00000) [GC-- [PSYoungGen: 5600K->5600K(9216K)] 6624K->6624K(15360K), 0.0017920 secs] [Times: user=0.01 sys=0.00, real=0.01 secs] Heap after GC invocations=3 (full 1): PSYoungGen total 9216K, used 5600K [0x00000000ff600000, 0x0000000100000000, 0x0000000100000000) eden space 8192K, 68% used [0x00000000ff600000,0x00000000ffb78238,0x00000000ffe00000) from space 1024K, 0% used [0x00000000fff00000,0x00000000fff00000,0x0000000100000000) to space 1024K, 49% used [0x00000000ffe00000,0x00000000ffe7e030,0x00000000fff00000) ParOldGen total 6144K, used 1024K [0x00000000ff000000, 0x00000000ff600000, 0x00000000ff600000) object space 6144K, 16% used [0x00000000ff000000,0x00000000ff100010,0x00000000ff600000) PSPermGen total 21504K, used 2834K [0x00000000f4a00000, 0x00000000f5f00000, 0x00000000ff000000) object space 21504K, 13% used [0x00000000f4a00000,0x00000000f4cc48b8,0x00000000f5f00000) } {Heap before GC invocations=4 (full 2)://又一次触发了FULLGC,是谁触发的 PSYoungGen total 9216K, used 5600K [0x00000000ff600000, 0x0000000100000000, 0x0000000100000000) eden space 8192K, 68% used [0x00000000ff600000,0x00000000ffb78238,0x00000000ffe00000) from space 1024K, 0% used [0x00000000fff00000,0x00000000fff00000,0x0000000100000000) to space 1024K, 49% used [0x00000000ffe00000,0x00000000ffe7e030,0x00000000fff00000) ParOldGen total 6144K, used 1024K [0x00000000ff000000, 0x00000000ff600000, 0x00000000ff600000) object space 6144K, 16% used [0x00000000ff000000,0x00000000ff100010,0x00000000ff600000) PSPermGen total 21504K, used 2834K [0x00000000f4a00000, 0x00000000f5f00000, 0x00000000ff000000) object space 21504K, 13% used [0x00000000f4a00000,0x00000000f4cc48b8,0x00000000f5f00000) [Full GC [PSYoungGen: 5600K->5589K(9216K)] [ParOldGen: 1024K->1024K(6144K)] 6624K->6613K(15360K) [PSPermGen: 2834K->2834K(21504K)], 0.0059670 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] Heap after GC invocations=4 (full 2): PSYoungGen total 9216K, used 5589K [0x00000000ff600000, 0x0000000100000000, 0x0000000100000000) eden space 8192K, 68% used [0x00000000ff600000,0x00000000ffb75440,0x00000000ffe00000) from space 1024K, 0% used [0x00000000fff00000,0x00000000fff00000,0x0000000100000000) to space 1024K, 0% used [0x00000000ffe00000,0x00000000ffe00000,0x00000000fff00000) ParOldGen total 6144K, used 1024K [0x00000000ff000000, 0x00000000ff600000, 0x00000000ff600000) object space 6144K, 16% used [0x00000000ff000000,0x00000000ff100010,0x00000000ff600000) PSPermGen total 21504K, used 2834K [0x00000000f4a00000, 0x00000000f5f00000, 0x00000000ff000000) object space 21504K, 13% used [0x00000000f4a00000,0x00000000f4cc48b8,0x00000000f5f00000) } Exception in thread "main" java.lang.OutOfMemoryError: Java heap space at Test.test5(Test.java:66) at Test.main(Test.java:10) Heap PSYoungGen total 9216K, used 6170K [0x00000000ff600000, 0x0000000100000000, 0x0000000100000000) eden space 8192K, 75% used [0x00000000ff600000,0x00000000ffc06ad0,0x00000000ffe00000) from space 1024K, 0% used [0x00000000fff00000,0x00000000fff00000,0x0000000100000000) to space 1024K, 0% used [0x00000000ffe00000,0x00000000ffe00000,0x00000000fff00000) ParOldGen total 6144K, used 1024K [0x00000000ff000000, 0x00000000ff600000, 0x00000000ff600000) object space 6144K, 16% used [0x00000000ff000000,0x00000000ff100010,0x00000000ff600000) PSPermGen total 21504K, used 2874K [0x00000000f4a00000, 0x00000000f5f00000, 0x00000000ff000000) object space 21504K, 13% used [0x00000000f4a00000,0x00000000f4cce978,0x00000000f5f00000) 实在想不通了
加载更多回复(1)

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧