2

Eden是8M,survivor1和survivor2总共是2M,Old area是10M。创建对象alloc4时,触发了第一次Minor GC,并且alloc1/alloc2/alloc3被移动了old area。创建alloc6时,alloc4被移动了old area,alloc5被移动了移动sur​​vivor area。创建alloc7时,Eden不能hold住alloc7,所以它被移动了old area,但是old areahold alloc1/alloc2/alloc3/alloc4,9M,也不能hold alloc7,所以old area应该触发Full GC,回收alloc1,alloc3。但是为什么第3次GC不是full gc而是minor 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)
4

0 回答 0