重金求解!JVM GC机制问题
编写了段代码跟踪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)
为什么是两次不是一次?为什么是两次不是一次?为什么是两次不是一次?为什么是两次不是一次?为什么是两次不是一次?