PermGen leak

David Holmes david.holmes at oracle.com
Tue Jul 9 06:28:36 UTC 2013


On 8/07/2013 4:35 PM, feng l.liu wrote:
> Hello Experts,
>
> I am building up a test tool with ant, but I encountered so many
> DelegatingClassLoaders that put pressures on PermGen. I know that
> DelegatingClassLoaders are caused by java reflection.
>
> Google search show some posts indicating generation of
> DelegatingClassLoader will be depressed if
> sun.reflect.inflationThreshold to zero , I tried it and found that this
> idea did not work at all. I dived into the code and found the snippets
> as below:
>
> It looks that the DelegatingClassLoader will go away if I set
> sun.reflect.noInflation = true and sun.reflect.inflationThreshold to
> Integer.MAX_VALUE.  I tried it again but this idea did not work as well.

Inflation is the process by which we start with a native accessor and 
then "inflate" it to a MethodAccessorGenerator when we reach the 
inflation threshold. It is the MethodAccessorGenerator that will cause 
the DelegatingClassLoader to be used.

If inflation is disabled by noInflation=true then you got straight to 
using the MethodAccessorGenerator - not what you want.

You want to remain with the native accessor, in which case you only want 
to set sun.reflect.inflationThreshold to Integer.MAX_VALUE.

HTH

David
-----

> can you please give me some advices on this leak?
>
> thank you in advance
>
> ReflectionFactory.java
>
>                      String val =
> System.getProperty("sun.reflect.noInflation");
>                      if (val != null && val.equals("true")) {
>                          noInflation = true;
>                      }
>
>                      val =
> System.getProperty("sun.reflect.inflationThreshold");
>                      if (val != null) {
>                          try {
>                              inflationThreshold = Integer.parseInt(val);
>                          } catch (NumberFormatException e) {
>                              throw (RuntimeException)
>                                  new RuntimeException("Unable to parse
> property sun.reflect.inflationThreshold").
>                                      initCause(e);
>                          }
>                      }
>
>                      initted = true;
>                      return null;
>                  }
>
>
> NativeMethodAccessorImpl.java
>
>      public Object invoke(Object obj, Object[] args)
>          throws IllegalArgumentException, InvocationTargetException
>      {
>          if (++numInvocations > ReflectionFactory.inflationThreshold()) {
>              MethodAccessorImpl acc = (MethodAccessorImpl)
>                  new MethodAccessorGenerator().
>                      generateMethod(method.getDeclaringClass(),
>                                     method.getName(),
>                                     method.getParameterTypes(),
>                                     method.getReturnType(),
>                                     method.getExceptionTypes(),
>                                     method.getModifiers());
>              parent.setDelegate(acc);
>          }
>
>          return invoke0(method, obj, args);
>      }
>
>
> Best regards
>



More information about the core-libs-dev mailing list