Loopy CallSite

Vladimir Ivanov vladimir.x.ivanov at oracle.com
Wed Jul 16 17:38:24 UTC 2014


Remi,

The problem is that for every iteration you create new call site
 >      for(int i=0; i<100_000; i++) {
 >        new LoopyCS().getTarget().invokeExact(1_000);
 >      }

In LoopyCS constructor you instantiates 3 new MethodHandles:
 >        target = MethodHandles.filterArguments(target, 0, FOO);
 >        target = MethodHandles.guardWithTest(ZERO,
 >            target,
 > MethodHandles.dropArguments(MethodHandles.constant(int.class,
 > 0).asType(MethodType.methodType(void.class)), 0, int.class));

Since we don't cache LambdaForms yet for these combinators, 3 new 
LambdaForms are created for each invocation. Then they are compiled to 
bytecode and then JIT kicks in. That's why you see continuous JITing.

If you reuse a call site object, it stabilizes very quickly.

Best regards,
Vladimir Ivanov

On 7/12/14 6:05 PM, Remi Forax wrote:
> It seems that the JIT is lost with whe there is a loopy callsite and
> never stabilize (or the steady state is after the program ends).
>
> import java.lang.invoke.MethodHandle;
> import java.lang.invoke.MethodHandles;
> import java.lang.invoke.MethodType;
> import java.lang.invoke.MutableCallSite;
>
> public class Loop {
>    static class LoopyCS extends MutableCallSite {
>      public LoopyCS() {
>        super(MethodType.methodType(void.class, int.class));
>
>        MethodHandle target = dynamicInvoker();
>        target = MethodHandles.filterArguments(target, 0, FOO);
>        target = MethodHandles.guardWithTest(ZERO,
>            target,
> MethodHandles.dropArguments(MethodHandles.constant(int.class,
> 0).asType(MethodType.methodType(void.class)), 0, int.class));
>        setTarget(target);
>      }
>    }
>
>    static final MethodHandle FOO, ZERO;
>    static {
>      try {
>        FOO = MethodHandles.lookup().findStatic(Loop.class, "foo",
> MethodType.methodType(int.class, int.class));
>        ZERO = MethodHandles.lookup().findStatic(Loop.class, "zero",
> MethodType.methodType(boolean.class, int.class));
>      } catch (NoSuchMethodException | IllegalAccessException e) {
>        throw new AssertionError(e);
>      }
>    }
>
>    private static boolean zero(int i) {
>      return i != 0;
>    }
>
>    private static int foo(int i) {
>      COUNTER++;
>      return i - 1;
>    }
>
>    private static int COUNTER = 0;
>
>    public static void main(String[] args) throws Throwable {
>      for(int i=0; i<100_000; i++) {
>        new LoopyCS().getTarget().invokeExact(1_000);
>      }
>      System.out.println(COUNTER);
>    }
> }
>
> cheers,
> Rémi
>
>
> _______________________________________________
> mlvm-dev mailing list
> mlvm-dev at openjdk.java.net
> http://mail.openjdk.java.net/mailman/listinfo/mlvm-dev


More information about the mlvm-dev mailing list