Topic
IC4NOTICE: developerWorks Community will be offline May 29-30, 2015 while we upgrade to the latest version of IBM Connections. For more information, read our upgrade FAQ.
2 replies Latest Post - ‏2013-02-07T11:43:27Z by SystemAdmin
SystemAdmin
SystemAdmin
2736 Posts
ACCEPTED ANSWER

Pinned topic Memory leak caused by Groovy executed from Java on IBM J9 JVM

‏2013-01-19T11:44:43Z |
Hi all,

I'm experiencing memory leak somehow related to Groovy and IBM JVM.
I execute custom groovy code from Java using GroovyShell like this:

Script s = (new GroovyShell(new Binding())).parse("int a=0; int b=0; int c=a+b; return null");
s.run();

If the simple code above is executed many times (depending on memory limit), it eventually fails with OOM.
However only on IBM JVM. It works perfectly on Oracle JVM.

I've found this thread: http://groovy.329449.n5.nabble.com/Memory-Leak-org-codehaus-groovy-reflection-tt363571.html
but suggested settings "-Xgcpolicy:optthruput -Xsoftrefthreshold0 -Xalwaysclassgc"
didn't help at all.

Until it fails, num of loaded classes keeps growing as well as Non-heap "classes memory". GC can't (or doesn't want) to release anything from "classes memory". Also heap memory grows, however GC activity is clearly visible, heap memory is eventually filled anyway.

Environments I tested:
  • Groovy 2.0.0 and 1.6.3 - no difference
  • Windows and Linux - no difference
  • Oracle JVM works, IBM J9 JVM fails
  • Simple example above fails after cca 7000 executions with 128MB mem limit.

I believe I'm not the only one who needed to execute Groovy from IBM JVM,
so please does anyone know how to configure JVM or modify code?

Example app and full stack trace follows:

import groovy.lang.Binding;
import groovy.lang.GroovyShell;
import groovy.lang.Script;
import java.util.Date;

/** with -Xmx128m takes 5 minutes (cca 7000 execs) until it fails */
public class GroovyGcTest {
public static void main(String[] args) {
int i=0;
do {
execute();
if ((i % 100)==0){
System.out.println(""(new Date())" i: "+i);
}
i++;
} while (i<3000000);
}
public static void execute() {
Script s = (new GroovyShell(new Binding())).parse("int a=0; int b=0; int c=a+b; return null");
s.run();
}
}
JVMDUMP013I Processed dump event "systhrow", detail "java/lang/OutOfMemoryError".
Exception in thread "main" java.lang.OutOfMemoryError
at java.lang.Class.getVirtualMethodsImpl(Native Method)
at java.lang.Class.getMethods(Class.java:925)
at java.beans.StandardBeanInfo.introspectMethods(StandardBeanInfo.java:535)
at java.beans.StandardBeanInfo.introspectMethods(StandardBeanInfo.java:528)
at java.beans.StandardBeanInfo.introspectProperties(StandardBeanInfo.java:620)
at java.beans.StandardBeanInfo.<init>(StandardBeanInfo.java:158)
at java.beans.Introspector.getBeanInfoImpl(Introspector.java:271)
at java.beans.Introspector.getBeanInfoImpl(Introspector.java:290)
at java.beans.Introspector.getBeanInfoImpl(Introspector.java:290)
at java.beans.Introspector.getBeanInfoImpl(Introspector.java:290)
at java.beans.Introspector.getBeanInfoImplAndInit(Introspector.java:367)
at java.beans.Introspector.getBeanInfo(Introspector.java:170)
at groovy.lang.MetaClassImpl$15.run(MetaClassImpl.java:2942)
at java.security.AccessController.doPrivileged(AccessController.java:251)
at groovy.lang.MetaClassImpl.addProperties(MetaClassImpl.java:2940)
at groovy.lang.MetaClassImpl.initialize(MetaClassImpl.java:2923)
at org.codehaus.groovy.reflection.ClassInfo.getMetaClassUnderLock(ClassInfo.java:166)
at org.codehaus.groovy.reflection.ClassInfo.getMetaClass(ClassInfo.java:182)
at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.getMetaClass(MetaClassRegistryImpl.java:302)
at org.codehaus.groovy.runtime.InvokerHelper.getMetaClass(InvokerHelper.java:767)
at groovy.lang.GroovyObjectSupport.<init>(GroovyObjectSupport.java:32)
at groovy.lang.Script.<init>(Script.java:40)
at groovy.lang.Script.<init>(Script.java:37)
at Script1.<init>(Script1.groovy)
at java.lang.J9VMInternals.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1325)
at org.codehaus.groovy.runtime.InvokerHelper.createScript(InvokerHelper.java:420)
at groovy.lang.GroovyShell.parse(GroovyShell.java:625)
at groovy.lang.GroovyShell.parse(GroovyShell.java:652)
at groovy.lang.GroovyShell.parse(GroovyShell.java:643)
at GroovyGcTest.execute(GroovyGcTest.java:25)
at GroovyGcTest.main(GroovyGcTest.java:14)

Martin
Updated on 2013-02-07T11:43:27Z at 2013-02-07T11:43:27Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    2736 Posts
    ACCEPTED ANSWER

    Re: Memory leak caused by Groovy executed from Java on IBM J9 JVM

    ‏2013-01-22T05:39:32Z  in response to SystemAdmin
    Our J9 VM Team is aware of this issue. We have identified the solution & in the process of integrating the solution. I will update this discussion with fix release details once we confirmed everything.
    • SystemAdmin
      SystemAdmin
      2736 Posts
      ACCEPTED ANSWER

      Re: Memory leak caused by Groovy executed from Java on IBM J9 JVM

      ‏2013-02-07T11:43:27Z  in response to SystemAdmin
      The issue is resolved. You find more details here http://www-01.ibm.com/support/docview.wss?uid=swg1IV36441

      The fix will be available as part of
      6.0.1 SR6
      7.0.0 SR5
      6.0.0 SR14

      Release date is not confirmed. Once SR GAed it will be available here http://www.ibm.com/developerworks/java/jdk/linux/download.html