Unreachable Memory not freed, Nashorn Demo

Jenny Zhang yu.zhang at oracle.com
Tue Feb 28 17:06:32 UTC 2017


Thorsten

Thanks very much for the micro. I have update it to

https://bugs.openjdk.java.net/browse/JDK-8173594

Thanks
Jenny

On 2/28/2017 4:45 AM, Thorsten Goetzke wrote:
> Hello,
>
> Back in January i posted about Unreachable Objects not claimed by the 
> gc, i am finally able to produce a micro, see below. When I run the 
> class below using -Xmx4g and take a memory snaphsot (hprof or yourkit, 
> doesnt matter), I will see 2 LeakImpl Objects. These Objects have no 
> reported path to root, yet they won't be collected. If i lower the 
> heap space to -Xmx2g the Application throws 
> java.lang.OutOfMemoryError: Java heap space.
> @Jenny Zhang should I create a new bugreport, or will you take care of 
> this?
>
> Best Regards,
> Thorsten Goetzke
>
> package de.frei.demo;
>
> import jdk.nashorn.api.scripting.NashornScriptEngine;
> import jdk.nashorn.api.scripting.NashornScriptEngineFactory;
>
> import javax.script.CompiledScript;
> import javax.script.ScriptException;
> import javax.script.SimpleBindings;
> import java.util.function.Function;
>
>
> public final class LeakDemo {
>
>     private static  NashornScriptEngine ENGINE = 
> getNashornScriptEngine();
>     private static CompiledScript SCRIPT;
>
>     public static void main(String[] args) throws Exception {
>         simulateLoad();
>         simulateLoad();
>         System.gc();
>         Thread.sleep(1000000);
>
>     }
>
>     private static void simulateLoad() throws ScriptException {
>         final CompiledScript compiledScript = getCompiledScript(ENGINE);
>         compiledScript.eval(new SimplestBindings(new LeakImpl()));
>     }
>
>     private static NashornScriptEngine getNashornScriptEngine() {
>         final NashornScriptEngineFactory factory = new 
> NashornScriptEngineFactory();
>         final NashornScriptEngine scriptEngine = (NashornScriptEngine) 
> factory.getScriptEngine();
>         return scriptEngine;
>     }
>
>
>
>     private static CompiledScript getCompiledScript(final 
> NashornScriptEngine scriptEngine) throws ScriptException {
>         if (SCRIPT == null) {
>             SCRIPT = scriptEngine.compile("    var pivot = 
> getItem(\"pivot\");");
>         }
>         return SCRIPT;
>     }
>
>     public  interface Leak {
>
>         LiveItem getItem(String id);
>     }
>
>
>     public static final class LeakImpl implements Leak {
>         private final byte[] payload = new byte[1024 * 1024 * 1024];
>
>
>         @Override
>         public LiveItem getItem(final String id) {
>             return new LiveItem() {
>             };
>         }
>
>
>     }
>
>     public interface LiveItem {
>     }
>
>     public static final class SimplestBindings extends SimpleBindings {
>         public SimplestBindings(Leak leak) {
>
>             put("getItem",(Function< String, LiveItem>) leak::getItem);
>         }
>     }
> }
>
> _______________________________________________
> hotspot-gc-use mailing list
> hotspot-gc-use at openjdk.java.net
> http://mail.openjdk.java.net/mailman/listinfo/hotspot-gc-use



More information about the hotspot-gc-use mailing list