Le 30/07/2010 08:40, Chanwit Kaewkasi a écrit :
Hi Rémi,

I did freshly build mlvm and run Eric's test.
Here's my result:

Duration invokedynamic: 103
Duration reflection: 1463

The patch seems to be working for me as InvokeDynamic is clearly
faster than Reflection on my machine.

Cheers,

Chanwit

Hi Chanwit,
It seems I'm not able to get a mlvm build right :)

Can you test with this snippet ?

java -server ... -XX:+PrintCompilation Fib4

and report if you see lot of lines like "blob made no re-entrant"
indicating too much deopt.

cheers,
Rémi
//import groovy.lang.MissingMethodException;

import java.dyn.CallSite;
import java.dyn.InvokeDynamic;
import java.dyn.Linkage;
import java.dyn.MethodHandle;
import java.dyn.MethodHandles;
import java.dyn.MethodType;
/*
import org.codehaus.groovy.runtime.ScriptBytecodeAdapter;
import org.codehaus.groovy.runtime.typehandling.IntegerMath;
*/


public class Fib4 {
        private static final MethodType ii = 
MethodType.methodType(int.class,int.class);
        //private static final MethodHandle fib = 
MethodHandles.lookup().findVirtual(Fib4.class, "fib2", ii);
        private static final MethodType boo = 
MethodType.methodType(boolean.class, Object.class, Object.class);
//      private static final MethodHandle compareTo = 
MethodHandles.lookup().findStatic(ScriptBytecodeAdapter.class, 
"compareLessThan", boo);
        private static final MethodType nnn = 
MethodType.methodType(Number.class, Number.class, Number.class);
//      private static final MethodHandle plus = 
MethodHandles.lookup().findVirtual(IntegerMath.class, "addImpl", nnn);
//      private static final MethodHandle minus = 
MethodHandles.lookup().findVirtual(IntegerMath.class, "subtractImpl", nnn);

        
        public static void main(String[] args) throws Throwable{
                Fib4 fib = new Fib4();
                for (int i=0; i<10; i++) {
                        long time = System.nanoTime();
                        fib.fib2(42);
                        long end = System.nanoTime();
                        System.out.println("time = "+((end-time)/1000000)+" 
ms");
                }
        }
        
        /*public int fib(int n) throws Throwable {
                if ((Boolean) compareTo.invokeVarargs(n,2)) return 1;
                Object n_1 =  minus.invokeVarargs(IntegerMath.INSTANCE,n,1);
                Object fib_n_1 = fib.invokeVarargs(this,n_1);
                Object n_2 = (Integer) 
minus.invokeVarargs(IntegerMath.INSTANCE,n,2);
                Object fib_n_2 = fib.invokeVarargs(this,n_2);
                return (Integer) 
plus.invokeVarargs(IntegerMath.INSTANCE,fib_n_1,fib_n_2);
        }*/
        
        static {
                Linkage.registerBootstrapMethod("bootstrap");
        }
        private static final MethodType bii = 
MethodType.methodType(boolean.class, int.class, int.class);
        private static final MethodType ooo = 
MethodType.methodType(Object.class, Object.class, Object.class);
        private static final MethodType oii = 
MethodType.methodType(Object.class, int.class, int.class);
        private static final MethodType ioo = MethodType.methodType(int.class, 
Object.class, Object.class);

        private static boolean compareLessThan(int a, int b) {
                return a<b;
        }
        
        private static int minus(int a, int b) {
                return a-b;
        }
        
        private static int plus(int a, int b) {
                return a+b;
        }
        
        private static CallSite bootstrap(Class caller, String name, MethodType 
type) throws Throwable {
                CallSite site = new CallSite();
                MethodHandle target=null;
                if (name.equals("compareLessThan") && type.equals(bii)) {
                        target = 
MethodHandles.lookup().findStatic(Fib4.class,"compareLessThan",bii);
                } else if (name.equals("plus") && type.equals(ioo)) {
                        target = MethodHandles.lookup().findStatic(Fib4.class, 
"plus", 
                                        MethodType.methodType(int.class, 
int.class, int.class));
                        target = MethodHandles.convertArguments(target, type);
                } else if (name.equals("minus") && type.equals(oii)) {
                        target = MethodHandles.lookup().findStatic(Fib4.class, 
"minus", 
                                        MethodType.methodType(int.class, 
int.class, int.class));
                        target = MethodHandles.convertArguments(target, type);
                } else if (name.equals("fib2")) {
                        target = MethodHandles.lookup().findVirtual(Fib4.class, 
"fib2", 
                                        MethodType.methodType(int.class, 
int.class));
                        target = MethodHandles.convertArguments(target, type);  
                
                } else {
                        throw new RuntimeException("missing method "+name+type);
                }
                site.setTarget(target);
                return site;
        }
        
        public int fib2(int n) throws Throwable {
                if (InvokeDynamic.<boolean>compareLessThan(n,2)) return 1;
                Object n_2 = InvokeDynamic.minus(n,2);
                Object fib_n_2 = InvokeDynamic.fib2(this,n_2);
                Object n_1 = InvokeDynamic.minus(n,1);
                Object fib_n_1 = InvokeDynamic.fib2(this,n_1);
                return InvokeDynamic.<int>plus(fib_n_1,fib_n_2);
        }

}
_______________________________________________
mlvm-dev mailing list
[email protected]
http://mail.openjdk.java.net/mailman/listinfo/mlvm-dev

Reply via email to