Example usage for org.objectweb.asm Opcodes LLOAD

List of usage examples for org.objectweb.asm Opcodes LLOAD

Introduction

In this page you can find the example usage for org.objectweb.asm Opcodes LLOAD.

Prototype

int LLOAD

To view the source code for org.objectweb.asm Opcodes LLOAD.

Click Source Link

Usage

From source file:org.glassfish.pfl.tf.spi.Util.java

License:Open Source License

public int wrapArg(MethodVisitor mv, int argIndex, Type atype) {
    info(2, "Emitting code to wrap argument at " + argIndex + " of type " + atype);

    switch (atype.getSort()) {
    case Type.BOOLEAN:
        mv.visitVarInsn(Opcodes.ILOAD, argIndex);
        mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(Boolean.class), "valueOf",
                "(Z)Ljava/lang/Boolean;");
        break;//from   w  ww  .  j  a v a2 s  . c om
    case Type.BYTE:
        mv.visitVarInsn(Opcodes.ILOAD, argIndex);
        mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(Byte.class), "valueOf",
                "(B)Ljava/lang/Byte;");
        break;
    case Type.CHAR:
        mv.visitVarInsn(Opcodes.ILOAD, argIndex);
        mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(Character.class), "valueOf",
                "(C)Ljava/lang/Character;");
        break;
    case Type.SHORT:
        mv.visitVarInsn(Opcodes.ILOAD, argIndex);
        mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(Short.class), "valueOf",
                "(S)Ljava/lang/Short;");
        break;
    case Type.INT:
        mv.visitVarInsn(Opcodes.ILOAD, argIndex);
        mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(Integer.class), "valueOf",
                "(I)Ljava/lang/Integer;");
        break;
    case Type.LONG:
        mv.visitVarInsn(Opcodes.LLOAD, argIndex);
        mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(Long.class), "valueOf",
                "(J)Ljava/lang/Long;");
        break;
    case Type.DOUBLE:
        mv.visitVarInsn(Opcodes.DLOAD, argIndex);
        mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(Double.class), "valueOf",
                "(D)Ljava/lang/Double;");
        break;
    case Type.FLOAT:
        mv.visitVarInsn(Opcodes.FLOAD, argIndex);
        mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(Float.class), "valueOf",
                "(F)Ljava/lang/Float;");
        break;
    default:
        mv.visitVarInsn(Opcodes.ALOAD, argIndex);
        break;
    }

    return argIndex + atype.getSize();
}

From source file:org.glassfish.pfl.tf.spi.Util.java

License:Open Source License

public void loadFromXReturn(MethodVisitor mv, int returnOpcode, LocalVariableNode holder) {

    switch (returnOpcode) {
    case Opcodes.RETURN:
        // NOP// w w w  . ja  va 2s.c  o  m
        break;
    case Opcodes.ARETURN:
        mv.visitVarInsn(Opcodes.ALOAD, holder.index);
        break;
    case Opcodes.IRETURN:
        mv.visitVarInsn(Opcodes.ILOAD, holder.index);
        break;
    case Opcodes.LRETURN:
        mv.visitVarInsn(Opcodes.LLOAD, holder.index);
        break;
    case Opcodes.FRETURN:
        mv.visitVarInsn(Opcodes.FLOAD, holder.index);
        break;
    case Opcodes.DRETURN:
        mv.visitVarInsn(Opcodes.DLOAD, holder.index);
        break;
    }
}

From source file:org.iobserve.mobile.instrument.bytecode.SensorBytecodeInstrumenter.java

License:Apache License

/**
 * {@inheritDoc}//  www.ja  v a 2  s.c om
 */
@Override
public void onMethodExit(final int opcode, final String owner, final String name, final String desc,
        final AdviceAdapter parent, final MethodVisitor mv) {
    if (opcode == Opcodes.ATHROW) {
        mv.visitInsn(Opcodes.DUP);
        mv.visitVarInsn(Opcodes.LLOAD, index);
        mv.visitMethodInsn(Opcodes.INVOKESTATIC, ANDROIDAGENT_TYPE.getInternalName(),
                exitBodyErrorMethod.getName(), exitBodyErrorType.getDescriptor(), false);
    } else {
        mv.visitVarInsn(Opcodes.LLOAD, index);
        mv.visitMethodInsn(Opcodes.INVOKESTATIC, ANDROIDAGENT_TYPE.getInternalName(), exitBodyMethod.getName(),
                exitBodyType.getDescriptor(), false);
    }
}

From source file:org.jacoco.core.internal.instr.FrameTracker.java

License:Open Source License

@Override
public void visitVarInsn(final int opcode, final int var) {
    final Object t;
    switch (opcode) {
    case Opcodes.ALOAD:
        push(get(var));
        break;// w w  w.  j a v  a2 s .  com
    case Opcodes.ILOAD:
        push(Opcodes.INTEGER);
        break;
    case Opcodes.FLOAD:
        push(Opcodes.FLOAT);
        break;
    case Opcodes.LLOAD:
        push(Opcodes.LONG);
        push(Opcodes.TOP);
        break;
    case Opcodes.DLOAD:
        push(Opcodes.DOUBLE);
        push(Opcodes.TOP);
        break;
    case Opcodes.ASTORE:
    case Opcodes.ISTORE:
    case Opcodes.FSTORE:
        t = pop();
        set(var, t);
        break;
    case Opcodes.LSTORE:
    case Opcodes.DSTORE:
        pop(1);
        t = pop();
        set(var, t);
        set(var + 1, Opcodes.TOP);
        break;
    default:
        throw new IllegalArgumentException();
    }
    mv.visitVarInsn(opcode, var);
}

From source file:org.mbte.groovypp.compiler.bytecode.BytecodeExpr.java

License:Apache License

public static void load(ClassNode type, int idx, MethodVisitor mv) {
    if (type == double_TYPE) {
        mv.visitVarInsn(Opcodes.DLOAD, idx);
    } else if (type == float_TYPE) {
        mv.visitVarInsn(Opcodes.FLOAD, idx);
    } else if (type == long_TYPE) {
        mv.visitVarInsn(Opcodes.LLOAD, idx);
    } else if (type == boolean_TYPE || type == char_TYPE || type == byte_TYPE || type == int_TYPE
            || type == short_TYPE) {
        mv.visitVarInsn(Opcodes.ILOAD, idx);
    } else {//from   ww w  .j ava  2  s  .c o  m
        mv.visitVarInsn(Opcodes.ALOAD, idx);
    }
}

From source file:org.mbte.groovypp.compiler.ClosureUtil.java

License:Apache License

private static void makeOneMethodClass(List<MethodNode> abstractMethods, final ClassNode closureType,
        ClassNode baseType, CompilerTransformer compiler, final MethodNode doCall) {
    boolean traitMethods = false;
    int k = 0;//from  w w w .  j  av  a  2  s. c o  m
    for (final MethodNode missed : abstractMethods) {
        final Parameter[] parameters = eraseParameterTypes(missed.getParameters());
        if (k == 0) {
            closureType.addMethod(missed.getName(), Opcodes.ACC_PUBLIC,
                    getSubstitutedReturnType(doCall, missed, closureType, baseType), parameters,
                    ClassNode.EMPTY_ARRAY, new BytecodeSequence(new BytecodeInstruction() {
                        public void visit(MethodVisitor mv) {
                            mv.visitVarInsn(Opcodes.ALOAD, 0);
                            Parameter pp[] = parameters;
                            for (int i = 0, k = 1; i != pp.length; ++i) {
                                final ClassNode type = pp[i].getType();
                                ClassNode expectedType = doCall.getParameters()[i].getType();
                                if (ClassHelper.isPrimitiveType(type)) {
                                    if (type == ClassHelper.long_TYPE) {
                                        mv.visitVarInsn(Opcodes.LLOAD, k++);
                                        k++;
                                    } else if (type == ClassHelper.double_TYPE) {
                                        mv.visitVarInsn(Opcodes.DLOAD, k++);
                                        k++;
                                    } else if (type == ClassHelper.float_TYPE) {
                                        mv.visitVarInsn(Opcodes.FLOAD, k++);
                                    } else {
                                        mv.visitVarInsn(Opcodes.ILOAD, k++);
                                    }
                                    BytecodeExpr.box(type, mv);
                                    BytecodeExpr.cast(TypeUtil.wrapSafely(type),
                                            TypeUtil.wrapSafely(expectedType), mv);
                                } else {
                                    mv.visitVarInsn(Opcodes.ALOAD, k++);
                                    BytecodeExpr.checkCast(TypeUtil.wrapSafely(expectedType), mv);
                                }
                                BytecodeExpr.unbox(expectedType, mv);
                            }
                            mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                                    BytecodeHelper.getClassInternalName(doCall.getDeclaringClass()),
                                    doCall.getName(), BytecodeHelper.getMethodDescriptor(doCall.getReturnType(),
                                            doCall.getParameters()));

                            if (missed.getReturnType() != ClassHelper.VOID_TYPE
                                    && !missed.getReturnType().equals(doCall.getReturnType())) {
                                BytecodeExpr.box(doCall.getReturnType(), mv);
                                BytecodeExpr.checkCast(TypeUtil.wrapSafely(doCall.getReturnType()), mv);
                                BytecodeExpr.unbox(missed.getReturnType(), mv);
                            }
                            BytecodeExpr.doReturn(mv, missed.getReturnType());
                        }
                    }));
        } else {
            if (traitMethod(missed)) {
                traitMethods = true;
            } else if (likeGetter(missed)) {
                String pname = missed.getName().substring(3);
                pname = Character.toLowerCase(pname.charAt(0)) + pname.substring(1);
                final PropertyNode propertyNode = closureType.addProperty(pname, Opcodes.ACC_PUBLIC,
                        missed.getReturnType(), null, null, null);
                propertyNode.getField().addAnnotation(new AnnotationNode(TypeUtil.NO_EXTERNAL_INITIALIZATION));
            } else {
                if (likeSetter(missed)) {
                    String pname = missed.getName().substring(3);
                    pname = Character.toLowerCase(pname.charAt(0)) + pname.substring(1);
                    final PropertyNode propertyNode = closureType.addProperty(pname, Opcodes.ACC_PUBLIC,
                            parameters[0].getType(), null, null, null);
                    propertyNode.getField()
                            .addAnnotation(new AnnotationNode(TypeUtil.NO_EXTERNAL_INITIALIZATION));
                }
            }
        }
        k++;
    }

    if (traitMethods)
        TraitASTTransformFinal.improveAbstractMethods(closureType);
}

From source file:org.mbte.groovypp.compiler.ClosureUtil.java

License:Apache License

public static void createClosureConstructor(final ClassNode newType, final Parameter[] constrParams,
        Expression superArgs, CompilerTransformer compiler) {

    final ClassNode superClass = newType.getSuperClass();

    final Parameter[] finalConstrParams;
    final ArgumentListExpression superCallArgs = new ArgumentListExpression();
    if (superArgs != null) {
        final ArgumentListExpression args = (ArgumentListExpression) superArgs;
        if (args.getExpressions().size() > 0) {
            Parameter[] newParams = new Parameter[constrParams.length + args.getExpressions().size()];
            System.arraycopy(constrParams, 0, newParams, 0, constrParams.length);
            for (int i = 0; i != args.getExpressions().size(); ++i) {
                final Parameter parameter = new Parameter(args.getExpressions().get(i).getType(),
                        "$super$param$" + i);
                newParams[i + constrParams.length] = parameter;
                superCallArgs.addExpression(new VariableExpression(parameter));
            }/*from   w  w  w . j  a  v a  2 s  . co  m*/
            finalConstrParams = newParams;
        } else
            finalConstrParams = constrParams;
    } else {
        if (superClass == ClassHelper.CLOSURE_TYPE) {
            if (constrParams.length > 0) {
                superCallArgs.addExpression(new VariableExpression(constrParams[0]));
                superCallArgs.addExpression(new VariableExpression(constrParams[0]));
            } else if (compiler.methodNode.isStatic() && !compiler.classNode.getName().endsWith("$TraitImpl")) {
                ClassNode cn = compiler.classNode;
                superCallArgs.addExpression(new ClassExpression(cn));
                superCallArgs.addExpression(new ClassExpression(getOutermostClass(cn)));
            } else {
                superCallArgs.addExpression(ConstantExpression.NULL);
                superCallArgs.addExpression(ConstantExpression.NULL);
            }
        }
        finalConstrParams = constrParams;
    }

    ConstructorCallExpression superCall = new ConstructorCallExpression(ClassNode.SUPER, superCallArgs);

    BytecodeSequence fieldInit = new BytecodeSequence(new BytecodeInstruction() {
        public void visit(MethodVisitor mv) {
            for (int i = 0, k = 1; i != constrParams.length; i++) {
                mv.visitVarInsn(Opcodes.ALOAD, 0);

                final ClassNode type = constrParams[i].getType();
                if (ClassHelper.isPrimitiveType(type)) {
                    if (type == ClassHelper.long_TYPE) {
                        mv.visitVarInsn(Opcodes.LLOAD, k++);
                        k++;
                    } else if (type == ClassHelper.double_TYPE) {
                        mv.visitVarInsn(Opcodes.DLOAD, k++);
                        k++;
                    } else if (type == ClassHelper.float_TYPE) {
                        mv.visitVarInsn(Opcodes.FLOAD, k++);
                    } else {
                        mv.visitVarInsn(Opcodes.ILOAD, k++);
                    }
                } else {
                    mv.visitVarInsn(Opcodes.ALOAD, k++);
                }
                mv.visitFieldInsn(Opcodes.PUTFIELD, BytecodeHelper.getClassInternalName(newType),
                        constrParams[i].getName(), BytecodeHelper.getTypeDescription(type));
            }
            mv.visitInsn(Opcodes.RETURN);
        }
    });

    BlockStatement code = new BlockStatement();
    code.addStatement(new ExpressionStatement(superCall));

    ConstructorNode cn = new ConstructorNode(Opcodes.ACC_PUBLIC, finalConstrParams, ClassNode.EMPTY_ARRAY,
            code);
    newType.addConstructor(cn);

    code.addStatement(fieldInit);

    CleaningVerifier.getCleaningVerifier().visitClass(newType);

    compiler.replaceMethodCode(newType, cn);

    if (newType.getOuterClass() != null && newType.getMethods("methodMissing").isEmpty()) {
        final ClassNode this0Type = (!compiler.methodNode.isStatic()
                || compiler.classNode.getName().endsWith("$TraitImpl")) ? newType.getOuterClass()
                        : ClassHelper.CLASS_Type;
        newType.addMethod("methodMissing", Opcodes.ACC_PUBLIC, ClassHelper.OBJECT_TYPE,
                new Parameter[] { new Parameter(ClassHelper.STRING_TYPE, "name"),
                        new Parameter(ClassHelper.OBJECT_TYPE, "args") },
                ClassNode.EMPTY_ARRAY, new BytecodeSequence(new BytecodeInstruction() {
                    public void visit(MethodVisitor mv) {
                        mv.visitVarInsn(Opcodes.ALOAD, 0);
                        mv.visitFieldInsn(Opcodes.GETFIELD, BytecodeHelper.getClassInternalName(newType),
                                "this$0", BytecodeHelper.getTypeDescription(this0Type));
                        mv.visitVarInsn(Opcodes.ALOAD, 1);
                        mv.visitVarInsn(Opcodes.ALOAD, 2);
                        mv.visitMethodInsn(Opcodes.INVOKESTATIC, "org/codehaus/groovy/runtime/InvokerHelper",
                                "invokeMethod",
                                "(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;");
                        mv.visitInsn(Opcodes.ARETURN);
                    }
                }));
    }
}

From source file:org.mbte.groovypp.compiler.TraitASTTransformFinal.java

License:Apache License

private static void createGetterSetter(final ClassNode classNode, MethodNode method, final ClassNode fieldType,
        Parameter[] parameters, final boolean getter, final String fieldName) {
    classNode.addMethod(method.getName(), ACC_PUBLIC, getter ? fieldType : ClassHelper.VOID_TYPE, parameters,
            ClassNode.EMPTY_ARRAY, new BytecodeSequence(new BytecodeInstruction() {
                public void visit(MethodVisitor mv) {
                    if (getter) {
                        mv.visitVarInsn(ALOAD, 0);
                        mv.visitFieldInsn(GETFIELD, BytecodeHelper.getClassInternalName(classNode), fieldName,
                                BytecodeHelper.getTypeDescription(fieldType));
                        BytecodeExpr.doReturn(mv, fieldType);
                    } else {
                        mv.visitVarInsn(ALOAD, 0);
                        if (fieldType == double_TYPE) {
                            mv.visitVarInsn(Opcodes.DLOAD, 1);
                        } else if (fieldType == float_TYPE) {
                            mv.visitVarInsn(Opcodes.FLOAD, 1);
                        } else if (fieldType == long_TYPE) {
                            mv.visitVarInsn(Opcodes.LLOAD, 1);
                        } else if (fieldType == boolean_TYPE || fieldType == char_TYPE || fieldType == byte_TYPE
                                || fieldType == int_TYPE || fieldType == short_TYPE) {
                            mv.visitVarInsn(Opcodes.ILOAD, 1);
                        } else {
                            mv.visitVarInsn(Opcodes.ALOAD, 1);
                        }//from  ww  w.j a v  a 2  s .  c  o m
                        mv.visitFieldInsn(PUTFIELD, BytecodeHelper.getClassInternalName(classNode), fieldName,
                                BytecodeHelper.getTypeDescription(fieldType));
                        mv.visitInsn(RETURN);
                    }
                }
            }));
}

From source file:org.mutabilitydetector.checkers.settermethod.EffectiveAssignmentInsnVerifier.java

License:Apache License

private static boolean isAliasLoadInstruction(final AbstractInsnNode insn, final int aliasLocalVariable) {
    switch (insn.getOpcode()) {
    case Opcodes.ILOAD:
    case Opcodes.LLOAD:
    case Opcodes.FLOAD:
    case Opcodes.DLOAD:
    case Opcodes.ALOAD:
        final VarInsnNode varInsnNode = (VarInsnNode) insn;
        return aliasLocalVariable == varInsnNode.var;
    default://from   w  ww . j  av  a2s  .  c o m
        return false;
    }
}

From source file:org.openquark.cal.internal.javamodel.AsmJavaBytecodeGenerator.java

License:Open Source License

private static int getLoadOpCode(JavaTypeName varType) {

    //ASM automatically handles replacing ILOAD 0, ILOAD 1, ILOAD 2 and ILOAD 3 by the special
    //0 argument op codes ILOAD_0, ILOAD_1, ILOAD_2, and ILOAD_3 and similarly for the other
    //types./*from w  ww  . j a  v a 2s .c om*/

    switch (varType.getTag()) {

    case JavaTypeName.VOID_TAG:
        throw new IllegalArgumentException("Cannot load a local variable of void type.");

    case JavaTypeName.BOOLEAN_TAG:
    case JavaTypeName.BYTE_TAG:
    case JavaTypeName.SHORT_TAG:
    case JavaTypeName.CHAR_TAG:
    case JavaTypeName.INT_TAG:
        return Opcodes.ILOAD;

    case JavaTypeName.LONG_TAG:
        return Opcodes.LLOAD;

    case JavaTypeName.DOUBLE_TAG:
        return Opcodes.DLOAD;

    case JavaTypeName.FLOAT_TAG:
        return Opcodes.FLOAD;

    case JavaTypeName.ARRAY_TAG:
    case JavaTypeName.OBJECT_TAG:
        return Opcodes.ALOAD;

    default: {
        throw new IllegalArgumentException("Cannot load a local variable of type " + varType);
    }
    }
}