首页 文章

GroovyClassLoader和permgen

提问于
浏览
2

不幸的是我们得到了PermgenError . jmap -permstat返回如下内容:

0x00000006c17f8520  1   1968    0x00000006ad000000  dead    sun/reflect/DelegatingClassLoader@0x00000007e00686e0
0x00000006babab308  3   19920   0x00000006b6874f88  dead    groovy/lang/GroovyClassLoader$InnerLoader@0x00000007e975bb80
0x00000006bca26800  3   15776   0x00000006b6874f88  dead    groovy/lang/GroovyClassLoader$InnerLoader@0x00000007e975bb80
0x00000006bb84db80  3   16176   0x00000006b6874f88  dead    groovy/lang/GroovyClassLoader$InnerLoader@0x00000007e975bb80
0x00000006b71dffd0  3   19272   0x00000006b6874f88  dead    groovy/lang/GroovyClassLoader$InnerLoader@0x00000007e975bb80

2小时后jmap -permstat返回:

0x00000006c17f8520  1   1968    0x00000006ad000000  dead    sun/reflect/DelegatingClassLoader@0x00000007e00686e0
0x00000006babab308  3   19920   0x00000006b6874f88  dead    groovy/lang/GroovyClassLoader$InnerLoader@0x00000007e975bb80
0x00000006bca26800  43  437232 0x00000006b6874f88   dead    groovy/lang/GroovyClassLoader$InnerLoader@0x00000007e975bb80
0x00000006bb84db80  3   16176   0x00000006b6874f88  dead    groovy/lang/GroovyClassLoader$InnerLoader@0x00000007e975bb80
0x00000006b71dffd0  7   16176 0x00000006b6874f88    dead    groovy/lang/GroovyClassLoader$InnerLoader@0x00000007e975bb80

正如您所看到的,classLoader加载的类数量增加,例如从3增加到43.这只是permstat的短片段 - (total = 4676 53521 436264528 alive = 1,dead = 4675) . 我们用参数运行java:

-XX:+DisableExplicitGC -server -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:MaxGCPauseMillis=800 -XX:+CMSParallelRemarkEnabled -XX:CMSFullGCsBeforeCompaction=1 -XX:+CMSClassUnloadingEnabled

但是在permstat中,所有的clasloader都死了 . 我们的代码解析了groovy类:

class GroovyInvoker {

    private static GroovyClassLoader gcl = new GroovyClassLoader(Thread.currentThread()
            .getContextClassLoader());

    protected static GroovyInvoker getInstance(String fileName, String className)
            throws BaseScriptingException {

        GroovyInvoker instance = new GroovyInvoker();
        instance.setFileName(fileName);
        instance.setClassName(className);
        Class clazz;
        clazz = GroovyInvoker.gcl.parseClass(instance.getFile(fileName));
        Script aScript = (Script) clazz.newInstance();
        instance.setScript(aScript);

        return instance;
    }           
}

我读了这个主题:Locating code that is filling PermGen with dead Groovy code并回答了metaClassRegistry问题,但我们可以't test it now on prod server. My questions is: why number of classes loaded by GroovyClassLoader is increasing when Groovy is using cache? Shouldn'这个数字是不变的吗?为什么gc没有收集死亡的类加载器?

Java版本1.6.0_26 . Groovy版本1.5.8 .

1 回答

相关问题