Class.forName cause ClassLoader objects moved to tenured generation

=?gb2312?B?usbD9w==?= liquan.liu at alipay.com
Sun Feb 26 20:50:38 PST 2012


Hi all,

I have seen Class.forName() causes the tenured generation got filled with custom ClassLoader objects. I suspect something JVM done internally will move the ClassLoader objects to tenured generation. For example, the following code:
========================
public class Test  {
   public static void main(String[] args) throws Exception {
     for (int i=0 ;i<30000;i++) {
         test();
     }
   }
   private static void test() throws Exception {
     MyClassLoader mcl = new MyClassLoader();
     Class.forName("java.lang.String", false, mcl);
   }
}

public class MyClassLoader extends ClassLoader {}
=========================
will output gc log:

[GC [DefNew: 512K->64K(576K), 0.0041095 secs] 512K->344K(1984K), 0.0042064 secs]
[GC [DefNew: 576K->64K(576K), 0.0032096 secs] 856K->682K(1984K), 0.0032937 secs]
[GC [DefNew: 575K->63K(576K), 0.0032085 secs] 1194K->1021K(1984K), 0.0033686 secs]
[GC [DefNew: 575K->64K(576K), 0.0025146 secs] 1533K->1359K(1984K), 0.0026305 secs]
[GC [DefNew: 576K->64K(576K), 0.0025942 secs][Tenured: 1634K->166K(1664K), 0.0169541 secs] 1871K->166K(2240K), 0.0197106 secs]
[GC [DefNew: 512K->64K(576K), 0.0019209 secs] 678K->505K(1984K), 0.0020053 secs]
[GC [DefNew: 576K->63K(576K), 0.0022846 secs] 1017K->844K(1984K), 0.0024271 secs]
[GC [DefNew: 575K->63K(576K), 0.0023358 secs] 1356K->1182K(1984K), 0.0024235 secs]
[GC [DefNew: 575K->64K(576K), 0.0025660 secs][Tenured: 1457K->166K(1536K), 0.0136841 secs] 1694K->166K(2112K), 0.0164004 secs]


If change the Class.forName to loadClass:
========================
private static void test() throws Exception {
    MyClassLoader mcl = new MyClassLoader();
    mcl.loadClass("java.lang.String");
}
========================
then gc log will be:

[GC [DefNew: 512K->63K(576K), 0.0028769 secs] 512K->138K(1984K), 0.0029627 secs]
[GC [DefNew: 575K->0K(576K), 0.0009856 secs] 650K->138K(1984K), 0.0010711 secs]
[GC [DefNew: 512K->0K(576K), 0.0006255 secs] 650K->138K(1984K), 0.0007062 secs]
[GC [DefNew: 512K->0K(576K), 0.0002065 secs] 650K->138K(1984K), 0.0002861 secs]
[GC [DefNew: 512K->0K(576K), 0.0001936 secs] 650K->138K(1984K), 0.0002674 secs]
[GC [DefNew: 512K->0K(576K), 0.0002045 secs] 650K->138K(1984K), 0.0002796 secs]
[GC [DefNew: 512K->0K(576K), 0.0001704 secs] 650K->138K(1984K), 0.0002481 secs]
[GC [DefNew: 512K->0K(576K), 0.0002229 secs] 650K->138K(1984K), 0.0003118 secs]

Reproduced in both jdk1.5 and 1.6.

Can someone enlight me what's happening inside jvm (regarding class load and gc) ?

Thanks.

________________________________

This email (including any attachments) is confidential and may be legally privileged. If you received this email in error, please delete it immediately and do not copy it or use it for any purpose or disclose its contents to any other person. Thank you.

±¾µçÓÊ(°üÀ¨Èκθ½¼þ)¿ÉÄܺ¬ÓлúÃÜ×ÊÁϲ¢ÊÜ·¨Âɱ£»¤¡£ÈçÄú²»ÊÇÕýÈ·µÄÊÕ¼þÈË£¬ÇëÄúÁ¢¼´É¾³ý±¾Óʼþ¡£Çë²»Òª½«±¾µçÓʽøÐи´ÖƲ¢ÓÃ×÷ÈκÎÆäËûÓÃ;¡¢»ò͸¶±¾ÓʼþÖ®ÄÚÈÝ¡£Ð»Ð»¡£


More information about the hotspot-gc-use mailing list