Size of Huge Objects directly allocated to Old Generation

前端 未结 3 1513
轮回少年
轮回少年 2020-11-28 06:09

Recently I\'ve been reading about object allocations in different generations in Java. Most of the times new objects are allocated in Eden (part of Young Generation) and the

3条回答
  •  孤街浪徒
    2020-11-28 06:22

    JVM flags:

    -Xms1G -Xmx1G -Xmn500m -XX:PretenureSizeThreshold=100000000 -XX:+PrintGCDetails

    By fixing the young generation size to 500MB, eden comes around 384MB, So any object greater than 384MB goes directly into OldGen and object less than 384MB is allocated in Eden itself. You can find the generation usages below

    byte[] array = new byte[400*1024*1024];

    PSYoungGen      total 448000K, used 30720K  
        eden space 384000K, 8% used  
        from space 64000K, 0% used  
        to   space 64000K, 0% used      
     ParOldGen       total 536576K, used 409600K  
       object space 536576K, 76% used 
    

    byte[] array = new byte[300*1024*1024];

     PSYoungGen      total 448000K, used 337920K  
      eden space 384000K, 88% used  
      from space 64000K, 0% used  
      to   space 64000K, 0% used  
     ParOldGen       total 536576K, used 0K 
      object space 536576K, **0% used** 
    

    For 400MB allocation, eden usage is 8% where as old gen usage is 76% For 300MB allocation, eden usage is 88% where as old gen usage is 0% So its clear that all the objects whose size is greater than the eden will be allocated directly into old gen.

    Thanks apangin & Jigar for your valuable insights :)
    I think -XX:PretenureSizeThreshold is not considered at all.

提交回复
热议问题