1 23 24 package protoactive.core.body.future; 25 26 import org.objectweb.fractal.julia.asm.AbstractClassGenerator; 27 28 import org.objectweb.asm.CodeVisitor; 29 import org.objectweb.asm.Type; 30 31 import java.lang.reflect.Method ; 32 33 63 64 public class FutureClassGenerator extends AbstractClassGenerator { 65 66 protected void generateMethod (final Method m) { 67 String itf = m.getDeclaringClass().getName().replace('.', '/'); 69 String mName = m.getName(); 70 String mDesc = Type.getMethodDescriptor(m); 71 Class [] params = m.getParameterTypes(); 72 Class result = m.getReturnType(); 73 Class [] exceptions = m.getExceptionTypes(); 74 String [] excepts = new String [exceptions.length]; 75 for (int i = 0; i < exceptions.length; ++i) { 76 excepts[i] = exceptions[i].getName().replace('.', '/'); 77 } 78 CodeVisitor mv = cw.visitMethod(ACC_PUBLIC, mName, mDesc, excepts, null); 79 80 mv.visitVarInsn(ALOAD, 0); 82 mv.visitMethodInsn(INVOKEVIRTUAL, name, "waitReply", "()V"); 83 84 mv.visitVarInsn(ALOAD, 0); 86 mv.visitFieldInsn(GETFIELD, name, "reply", "Ljava/lang/Object;"); 87 mv.visitTypeInsn(CHECKCAST, itf); 88 89 int offset = 1; 91 for (int i = 0; i < params.length; ++i) { 92 mv.visitVarInsn(ILOAD + getOpcodeOffset(params[i]), offset); 93 offset += getSize(params[i]); 94 } 95 96 mv.visitMethodInsn(INVOKEINTERFACE, itf, mName, mDesc); 98 99 if (result == Void.TYPE) { 101 mv.visitInsn(RETURN); 102 } else { 103 mv.visitInsn(IRETURN + getOpcodeOffset(result)); 104 } 105 106 mv.visitMaxs(Math.max(offset, getSize(result)), offset); 108 } 109 } 110 | Popular Tags |