13、JVM实战:内存分配策略:空间分配担保

13–内存分配策略–空间分配担保


1、空间分配担保

只要老年代的连续空间大于新生代对象总大小或者历次晋升的平均大小就会进行Minor GC,否则将进行Full GC。

2、测试

2.1、代码

测试jdk7

public class Test {
    private static final int _1MB = 1024 * 1024;

  //参数
  //-verbose:gc
  //-Xms20M
  //-Xmx20M
  //-Xmn10M
  //-XX:+PrintGCDetails
  //-XX:SurvivorRatio=8
  //-XX:MaxTenuringThreshold=15     
  //-XX:+PrintTenuringDistribution   
  //-XX:+UseSerialGC
    public static void main(String[] args) {
    	 byte[] allocation1, allocation2, allocation3,
    	 allocation4;  
    	 
    	  allocation1 = new byte[2 * _1MB];  
    	  allocation2 = new byte[2 * _1MB];  
    	  allocation3 = new byte[2 * _1MB];  
    	  
    	  allocation4 = new byte[4 * _1MB];  
    	  
      
    }
}

2.1、日志

 
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option HandlePromotionFailure; support was removed in 6.0_24
[GC[DefNew
Desired survivor size 524288 bytes, new threshold 15 (max 15)
- age   1:     478760 bytes,     478760 total
: 6815K->467K(9216K), 0.0091874 secs] 6815K->6611K(19456K), 0.0092695 secs] [Times: user=0.00 sys=0.00, real=0.01 secs] 
Heap
 def new generation   total 9216K, used 5055K [0x00000000f9a00000, 0x00000000fa400000, 0x00000000fa400000)
  eden space 8192K,  56% used [0x00000000f9a00000, 0x00000000f9e7af60, 0x00000000fa200000)
  from space 1024K,  45% used [0x00000000fa300000, 0x00000000fa374e28, 0x00000000fa400000)
  to   space 1024K,   0% used [0x00000000fa200000, 0x00000000fa200000, 0x00000000fa300000)
 tenured generation   total 10240K, used 6144K [0x00000000fa400000, 0x00000000fae00000, 0x00000000fae00000)
   the space 10240K,  60% used [0x00000000fa400000, 0x00000000faa00030, 0x00000000faa00200, 0x00000000fae00000)
 compacting perm gen  total 21248K, used 2540K [0x00000000fae00000, 0x00000000fc2c0000, 0x0000000100000000)
   the space 21248K,  11% used [0x00000000fae00000, 0x00000000fb07b350, 0x00000000fb07b400, 0x00000000fc2c0000)
No shared spaces configured.

3、分析

*
*
*