Loopy CallSite
Charles Oliver Nutter
headius at headius.com
Sat Jul 12 18:08:58 UTC 2014
I played with this some years ago. Doesn't it just become recursive,
because it won't inline through the dynamicInvoker?
- Charlie (mobile)
On Jul 12, 2014 9:36 AM, "Remi Forax" <forax at univ-mlv.fr> 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 core-libs-dev
mailing list