解决方案 »

  1.   

    你确定在Eclipse下正确设置了VM参数没有?我试了没问题啊,虽然我用的是JDK8下的1.7环境,但JDK7也不应该有问题啊第一个测试
    [GC (Allocation Failure) [DefNew: 6809K->464K(9216K), 0.0042200 secs] 6809K->6608K(19456K), 0.0042709 secs] [Times: user=0.00 sys=0.00, real=0.01 secs] 
    Heap
     def new generation   total 9216K, used 5912K [0x03a00000, 0x04400000, 0x04400000)
      eden space 8192K,  66% used [0x03a00000, 0x03f520a0, 0x04200000)
      from space 1024K,  45% used [0x04300000, 0x043741d8, 0x04400000)
      to   space 1024K,   0% used [0x04200000, 0x04200000, 0x04300000)
     tenured generation   total 10240K, used 6144K [0x04400000, 0x04e00000, 0x04e00000)
       the space 10240K,  60% used [0x04400000, 0x04a00030, 0x04a00200, 0x04e00000)
     Metaspace       used 79K, capacity 2242K, committed 2368K, reserved 4480K第二个测试
    Heap
     def new generation   total 9216K, used 829K [0x03800000, 0x04200000, 0x04200000)
      eden space 8192K,  10% used [0x03800000, 0x038cf5a8, 0x04000000)
      from space 1024K,   0% used [0x04000000, 0x04000000, 0x04100000)
      to   space 1024K,   0% used [0x04100000, 0x04100000, 0x04200000)
     tenured generation   total 10240K, used 4096K [0x04200000, 0x04c00000, 0x04c00000)
       the space 10240K,  40% used [0x04200000, 0x04600010, 0x04600200, 0x04c00000)
     Metaspace       used 79K, capacity 2242K, committed 2368K, reserved 4480K
      

  2.   

    我确定没有将参数弄反,但是现在我可以得到正确答案了,但是我加上了-verbose:gc -Xms20M -Xmx20M -Xmn10M -XX:+PrintGCDetails -XX:SurvivorRatio=8 -XX:+UseSerialGC 
    我想问下+UseSerialGC加上这个串行化就可以得到正确答案?那本身默认的是什么?我看还有2种是并行和并发,那默认的是哪一种,为什么其他的就得不到正确的结果呢
      

  3.   

    原来不同机器默认GC还不同
    我换了一台多核CPU的电脑发现和你一样,默认是Parallel Scavenge GC,而单核机器上默认是Serial GC这个PS GC确实比较奇葩,Serial GC和ParNew GC都没问题,但PS GC好像无视PretenureSizeThreshold这个参数,而且当Eden区放不下的时候,是马上进行Minor GC还是直接放入Tenured区也不是确定的,要根据Eden区有多满以及新创建的数据有多大来决定我翻了各种资料,中文英文搜索搜了半天,也没找到一篇讲PS GC具体工作机制的文章,几乎全是概念性的泛泛而谈毫无价值,所以也不太清楚PS GC到底是什么策略