Le 29/07/2010 01:26, John Rose a écrit :
On Jul 28, 2010, at 4:26 PM, Rémi Forax wrote:

My question was more, is it enable in mlvm if I use default guards.
Yes.  In the series file, you'll see that it has the same guards (-/meth 
+<hexstuff>) as the other patches:
   http://hg.openjdk.java.net/mlvm/mlvm/hotspot/file/tip/series

So I think the patch doesn't fix the issue.
Excellent.  Can you hand me a small test app.?

-- John

sure !

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