Am 26.01.2011 16:04, schrieb Rémi Forax:
On 01/26/2011 03:17 PM, Jochen Theodorou wrote:
Am 26.01.2011 15:04, schrieb Rémi Forax:
[...]
It's optimized for 64bits.
But if you enable invokedynamic, you disable escape analysis*.
For small benchmarks with a dynamic language, it severely impact
performance.

* there is a partial fix in hotspot repository that enables escape
analysis when
invokedynamic is used. But EA analysis in not yet able to look through
invokedynamic.

I am not sure I would call that optimized if an essential feature for
accelerating the code is not available anymore. True, it is one of
those stupid microbenchmark examples and inlining isn't going to help
at all for the fibonacci problem but I had at least expected it to be
as fast as reflection.

Could you send your code ?
With my tests, it's faster than reflection.

Class creation:

            ClassWriter cw = new 
ClassWriter(ClassWriter.COMPUTE_MAXS+ClassWriter.COMPUTE_FRAMES);
            cw.visit(V1_7, ACC_PUBLIC, "FTest", null, "java/lang/Object", null);
        
            MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", 
null, null);
            mv.visitCode();
            mv.visitIntInsn(ALOAD, 0);
            mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", 
"()V");
            mv.visitInsn(RETURN);
            mv.visitMaxs(0, 0);
            mv.visitEnd();

            mv = cw.visitMethod(ACC_PUBLIC, "fib", "(I)I", null, null);
            mv.visitIntInsn(ILOAD, 1);
            mv.visitInsn(ICONST_1);
            Label l1 = new Label();
            mv.visitJumpInsn(IF_ICMPGT, l1);
            mv.visitInsn(ICONST_1);
            mv.visitInsn(IRETURN);
        
            mv.visitLabel(l1);
            mv.visitIntInsn(ALOAD, 0);
        mv.visitIntInsn(ILOAD, 1);
        mv.visitInsn(ICONST_1);
        mv.visitInsn(ISUB);
        mv.visitMethodInsn(INVOKEDYNAMIC, null, "fib", "(LFTest;I)I");
        mv.visitIntInsn(ALOAD, 0);
        mv.visitIntInsn(ILOAD, 1);
        mv.visitInsn(ICONST_2);
        mv.visitInsn(ISUB);
        mv.visitMethodInsn(INVOKEDYNAMIC, null, "fib", "(LFTest;I)I");
        mv.visitInsn(IADD);
        mv.visitInsn(IRETURN);
        mv.visitMaxs(0, 0);
        mv.visitEnd();

bootstrap register:

MethodHandle bootStrap = MethodHandles.lookup().findStatic(Test.class, 
"bootstrapMethod", 
MethodType.methodType(CallSite.class,Lookup.class,String.class,MethodType.class,Object[].class));
Linkage.registerBootstrapMethod(c, bootStrap);

bootstrap method:
        public static CallSite bootstrapMethod(Lookup caller, String name, 
MethodType type, Object... args) throws NoAccessException {
            MethodHandle mh = caller.findVirtual(caller.lookupClass(), name, 
type.dropParameterTypes(0, 1));
            CallSite c = new ConstantCallSite(mh);
            return c;
        }

The test itself (c is class FTest I created):
            MethodHandle fib = MethodHandles.lookup().findVirtual(c, "fib", 
MethodType.methodType(int.class,int.class));
        
            Object instance = c.newInstance();

            for (int i=0; i<10; i++) {
            fib.invokeWithArguments(instance,33);
          }
        
            for (int j=0; j<10; j++) {
            long t1 = System.nanoTime();
            for (int i=0; i<10; i++) {
                fib.invokeWithArguments(instance,33);
            }
            long t2 = System.nanoTime();
            System.out.println("took "+((t2-t1)/1000000)+"ms");
            }

 bye Jochen

--
Jochen "blackdrag" Theodorou
The Groovy Project Tech Lead
http://blackdragsview.blogspot.com/
For Groovy programming sources visit http://groovy.codehaus.org

--
You received this message because you are subscribed to the Google Groups "JVM 
Languages" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/jvm-languages?hl=en.

Reply via email to