public static void main(String[] args) {
byte[] b1=new byte[2*_10m];//分配20mb内存
byte[] b2=new byte[2*_10m];// 分配20mb内存
byte[] b_2=new byte[2*_10m];//分配20mb内存
byte[] b3=new byte[2*_10m];//分配20mb内存
byte[] b5=new byte[2*_10m];//分配20mb内存
byte[] b4=new byte[3*_10m];//分配30mb内存
System.out.println("------------");
byte[] b_6=new byte[4*_10m - 10000];//分配40mb内存
}
-XX:InitialHeapSize=209715200 -XX:MaxHeapSize=209715200 -XX:MaxNewSize=104857600 -XX:NewSize=104857600 -XX:+PrintCommandLineFlags -XX:+PrintGC -XX:+PrintGCDetails -XX:SurvivorRatio=8 -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:-UseLargePagesIndividualAllocation -XX:+UseParallelGC
[GC (Allocation Failure) [PSYoungGen: 68001K->1064K(92160K)] 68001K->62512K(194560K), 0.0429928 secs] [Times: user=0.14 sys=0.03, real=0.04 secs]
[Full GC (Ergonomics) [PSYoungGen: 1064K->0K(92160K)] [ParOldGen: 61448K->62335K(102400K)] 62512K->62335K(194560K), [Metaspace: 3459K->3459K(1056768K)], 0.0150700 secs] [Times: user=0.09 sys=0.00, real=0.02 secs]
------------
[Full GC (Ergonomics) [PSYoungGen: 74897K->51200K(92160K)] [ParOldGen: 62335K->82707K(102400K)] 137233K->133907K(194560K), [Metaspace: 3460K->3460K(1056768K)], 0.0200246 secs] [Times: user=0.08 sys=0.02, real=0.02 secs]
[Full GC (Allocation Failure) Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at com.learn.mq.MqApplicationTests.main(MqApplicationTests.java:40)
[PSYoungGen: 51200K->51200K(92160K)] [ParOldGen: 82707K->82688K(102400K)] 133907K->133889K(194560K), [Metaspace: 3460K->3460K(1056768K)], 0.0101650 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
Heap
PSYoungGen total 92160K, used 53438K [0x00000000f9c00000, 0x0000000100000000, 0x0000000100000000)
eden space 81920K, 65% used [0x00000000f9c00000,0x00000000fd02f930,0x00000000fec00000)
from space 10240K, 0% used [0x00000000fec00000,0x00000000fec00000,0x00000000ff600000)
to space 10240K, 0% used [0x00000000ff600000,0x00000000ff600000,0x0000000100000000)
ParOldGen total 102400K, used 82688K [0x00000000f3800000, 0x00000000f9c00000, 0x00000000f9c00000)
object space 102400K, 80% used [0x00000000f3800000,0x00000000f88c03f0,0x00000000f9c00000)
Metaspace used 3491K, capacity 4500K, committed 4864K, reserved 1056768K
class space used 381K, capacity 388K, committed 512K, reserved 1048576K
伊甸园内存:80 老年代内存:100
------------下面的那一次gc日志 : PSYoungGen: 74897K->51200K(92160K)] [ParOldGen: 62335K->82707K(102400K)
gc之前,伊甸园已使用内存为20+20+30,老年代为20+20+20
gc之后,伊甸园已使用内存为20+30,老年代为20+20+20+20
剩余内存 伊甸园:30 老年代:20 均不足以放下引起这次gc的40大小的对象,而这次gc如果把30移动到老年代,gc之后内存为:
伊甸园已使用内存为20+20,老年代为20+20+20+30
这样伊甸园剩余内存为40,放得下40的对象,也不用报错,为什么收集器没有这么做呢?
或者说收集器对于哪些对象提前进入老年代行为是怎么确定的呢?
大于eden/2的对象一定要
目前看起来是年龄比较大的进去了,可是最大的年龄也挺小啊~~
ps:为了避免其他因素,我把参数改为:-verbose:gc -XX:+PrintGCDetails -Xmn105M -Xmx205M -Xms205M -XX:SurvivorRatio=8 -XX:+PrintCommandLineFlags后,得到了同样的结果