为什么不是Full GC?

时间:2013-03-26 14:49:46

标签: garbage-collection

Eden是8M,survivor1和survivor2总共是2M,旧区域是10M。当创建对象alloc4时,首先触发Minor GC,并且alloc1 / alloc2 / alloc3被移动旧区域。当创建alloc6时,alloc4被移动旧区域,alloc5被移动幸存区。当创建alloc7时,Eden无法持有alloc7,所以它被移动了旧区域,但旧区域保存alloc1 / alloc2 / alloc3 / alloc4,9M,也无法保存alloc7,所以旧区域应该触发Full GC,回收alloc1,alloc3.But为什么第3个GC不是完全gc而是次要的gc?

    /**
 * VM Args:-Xms20M -Xmx20M -Xmn10M -XX:SurvivorRatio=8 -XX:+PrintGCDetails
 * 
 * @author yikebocai@gmail.com
 * @since 2013-3-26
 * 
 */
public class Testjstat {
    private static final int _1MB = 1024 * 1024;

    public static void main(String[] args) throws InterruptedException {
        byte[] alloc1 = new byte[2 * _1MB];
        byte[] alloc2 = new byte[2 * _1MB];
        byte[] alloc3 = new byte[1 * _1MB];

        // first Minor GC
        byte[] alloc4 = new byte[4 * _1MB];
        byte[] alloc5 = new byte[_1MB / 4];

        // second Minor GC
        byte[] alloc6 = new byte[6 * _1MB];

        alloc1 = null;
        alloc3 = null;

        // first Full GC
        byte[] alloc7 = new byte[3 * _1MB];

    }

     } 

gc的细节是:

[GC [DefNew: 5463K->148K(9216K), 0.0063046 secs] 5463K->5268K(19456K), 0.0063589 secs] [Times: user=0.00 sys=0.00, real=0.01 secs] 
[GC [DefNew: 4587K->404K(9216K), 0.0046368 secs] 9707K->9620K(19456K), 0.0046822 secs] [Times: user=0.02 sys=0.00, real=0.01 secs] 
[GC [DefNew: 6548K->6548K(9216K), 0.0000373 secs][Tenured: 9216K->6144K(10240K), 0.0124560 secs] 15764K->12692K(19456K), [Perm : 369K->369K(12288K)], 0.0126052 secs] [Times: user=0.00 sys=0.02, real=0.01 secs] 
Heap
 def new generation   total 9216K, used 6712K [0x322a0000, 0x32ca0000, 0x32ca0000)
  eden space 8192K,  81% used [0x322a0000, 0x3292e2a8, 0x32aa0000)
  from space 1024K,   0% used [0x32aa0000, 0x32aa0000, 0x32ba0000)
  to   space 1024K,   0% used [0x32ba0000, 0x32ba0000, 0x32ca0000)
 tenured generation   total 10240K, used 9216K [0x32ca0000, 0x336a0000, 0x336a0000)
   the space 10240K,  90% used [0x32ca0000, 0x335a0030, 0x335a0200, 0x336a0000)
 compacting perm gen  total 12288K, used 369K [0x336a0000, 0x342a0000, 0x376a0000)
   the space 12288K,   3% used [0x336a0000, 0x336fc548, 0x336fc600, 0x342a0000)
    ro space 10240K,  51% used [0x376a0000, 0x37bccf58, 0x37bcd000, 0x380a0000)
    rw space 12288K,  54% used [0x380a0000, 0x38738f50, 0x38739000, 0x38ca0000)

0 个答案:

没有答案