Loopy CallSite
Remi Forax
forax at univ-mlv.fr
Sat Jul 12 18:37:17 UTC 2014
On 07/12/2014 08:08 PM, Charles Oliver Nutter wrote:
>
> I played with this some years ago. Doesn't it just become recursive,
> because it won't inline through the dynamicInvoker?
>
> - Charlie (mobile)
>
It's clearly recursive.
I don't think it's a good idea to try to fully inline it anyway, it will
generate too much assembly code.
The actual problem is that the JIT generate assembly code and then try
again, and again, and again ...
Rémi
> On Jul 12, 2014 9:36 AM, "Remi Forax" <forax at univ-mlv.fr
> <mailto: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 <mailto:mlvm-dev at openjdk.java.net>
> http://mail.openjdk.java.net/mailman/listinfo/mlvm-dev
>
>
>
> _______________________________________________
> mlvm-dev mailing list
> mlvm-dev at openjdk.java.net
> http://mail.openjdk.java.net/mailman/listinfo/mlvm-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/mlvm-dev/attachments/20140712/7c93a45f/attachment.html>
More information about the mlvm-dev
mailing list