Search in sources :

Example 81 with MethodVisitor

use of org.objectweb.asm.MethodVisitor in project groovy by apache.

the class InvocationWriter method finnishConstructorCall.

protected void finnishConstructorCall(ConstructorNode cn, String ownerDescriptor, int argsToRemove) {
    String desc = BytecodeHelper.getMethodDescriptor(ClassHelper.VOID_TYPE, cn.getParameters());
    MethodVisitor mv = controller.getMethodVisitor();
    mv.visitMethodInsn(INVOKESPECIAL, ownerDescriptor, "<init>", desc, false);
    controller.getOperandStack().remove(argsToRemove);
    controller.getOperandStack().push(cn.getDeclaringClass());
}
Also used : MethodVisitor(org.objectweb.asm.MethodVisitor)

Example 82 with MethodVisitor

use of org.objectweb.asm.MethodVisitor in project groovy by apache.

the class InvocationWriter method coerce.

public void coerce(ClassNode from, ClassNode target) {
    if (from.isDerivedFrom(target))
        return;
    MethodVisitor mv = controller.getMethodVisitor();
    OperandStack os = controller.getOperandStack();
    os.box();
    (new ClassExpression(target)).visit(controller.getAcg());
    os.remove(1);
    asTypeMethod.call(mv);
    BytecodeHelper.doCast(mv, target);
    os.replace(target);
}
Also used : MethodVisitor(org.objectweb.asm.MethodVisitor)

Example 83 with MethodVisitor

use of org.objectweb.asm.MethodVisitor in project groovy by apache.

the class OperandStack method load.

public void load(ClassNode type, int idx) {
    MethodVisitor mv = controller.getMethodVisitor();
    BytecodeHelper.load(mv, type, idx);
    push(type);
}
Also used : MethodVisitor(org.objectweb.asm.MethodVisitor)

Example 84 with MethodVisitor

use of org.objectweb.asm.MethodVisitor in project groovy by apache.

the class OptimizingStatementWriter method writeFastPathPrelude.

private void writeFastPathPrelude(FastPathData meta) {
    MethodVisitor mv = controller.getMethodVisitor();
    mv.visitJumpInsn(GOTO, meta.afterPath);
    mv.visitLabel(meta.pathStart);
    controller.switchToFastPath();
}
Also used : MethodVisitor(org.objectweb.asm.MethodVisitor)

Example 85 with MethodVisitor

use of org.objectweb.asm.MethodVisitor in project groovy by apache.

the class OptimizingStatementWriter method writeGuards.

private FastPathData writeGuards(StatementMeta meta, Statement statement) {
    if (notEnableFastPath(meta))
        return null;
    controller.getAcg().onLineNumber(statement, null);
    MethodVisitor mv = controller.getMethodVisitor();
    FastPathData fastPathData = new FastPathData();
    Label slowPath = new Label();
    for (int i = 0; i < guards.length; i++) {
        if (meta.involvedTypes[i]) {
            guards[i].call(mv);
            mv.visitJumpInsn(IFEQ, slowPath);
        }
    }
    // meta class check with boolean holder
    String owner = BytecodeHelper.getClassInternalName(controller.getClassNode());
    MethodNode mn = controller.getMethodNode();
    if (mn != null) {
        mv.visitFieldInsn(GETSTATIC, owner, Verifier.STATIC_METACLASS_BOOL, "Z");
        mv.visitJumpInsn(IFNE, slowPath);
    }
    //standard metaclass check
    disabledStandardMetaClass.call(mv);
    mv.visitJumpInsn(IFNE, slowPath);
    // other guards here
    mv.visitJumpInsn(GOTO, fastPathData.pathStart);
    mv.visitLabel(slowPath);
    return fastPathData;
}
Also used : Label(org.objectweb.asm.Label) MethodVisitor(org.objectweb.asm.MethodVisitor)

Aggregations

MethodVisitor (org.objectweb.asm.MethodVisitor)630 Label (org.objectweb.asm.Label)186 ClassWriter (org.objectweb.asm.ClassWriter)116 Type (org.objectweb.asm.Type)59 ClassNode (org.codehaus.groovy.ast.ClassNode)57 FieldVisitor (org.objectweb.asm.FieldVisitor)56 ClassVisitor (org.objectweb.asm.ClassVisitor)47 ClassReader (org.objectweb.asm.ClassReader)43 ArrayList (java.util.ArrayList)32 InnerClassNode (org.codehaus.groovy.ast.InnerClassNode)30 Test (org.junit.Test)29 AnnotationVisitor (org.objectweb.asm.AnnotationVisitor)29 List (java.util.List)23 LinkedList (java.util.LinkedList)22 Parameter (org.codehaus.groovy.ast.Parameter)22 InterfaceHelperClassNode (org.codehaus.groovy.ast.InterfaceHelperClassNode)18 AsmClassGenerator (org.codehaus.groovy.classgen.AsmClassGenerator)18 BytecodeExpression (org.codehaus.groovy.classgen.BytecodeExpression)18 ArgumentListExpression (org.codehaus.groovy.ast.expr.ArgumentListExpression)17 Method (java.lang.reflect.Method)16