Example usage for org.objectweb.asm Opcodes DUP

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

Introduction

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

Prototype

int DUP

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

Click Source Link

Usage

From source file:de.sanandrew.core.manpack.transformer.TransformHorseArmor.java

License:Creative Commons License

private static void transformArmorTexture(MethodNode method) {
    InsnList needle = new InsnList();
    needle.add(new VarInsnNode(Opcodes.ALOAD, 0));
    needle.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_HORSE_FUNC110241CB, false));
    needle.add(new VarInsnNode(Opcodes.ISTORE, 3));

    AbstractInsnNode node = ASMHelper.findLastNodeFromNeedle(method.instructions, needle);

    InsnList newInstr = new InsnList();
    LabelNode l17 = new LabelNode();
    newInstr.add(l17);//  w ww .  j a v  a  2 s . c o m
    newInstr.add(new VarInsnNode(Opcodes.ALOAD, 0));
    newInstr.add(
            ASMHelper.getMethodInsnNode(Opcodes.INVOKESPECIAL, ASMNames.MD_SAP_GET_CUSTOM_ARMOR_ITEM, false));
    newInstr.add(new VarInsnNode(Opcodes.ASTORE, 4));
    LabelNode l18 = new LabelNode();
    newInstr.add(l18);
    newInstr.add(new VarInsnNode(Opcodes.ALOAD, 4));
    newInstr.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_ITEMSTACK_GET_ITEM, false));
    newInstr.add(new TypeInsnNode(Opcodes.INSTANCEOF, ASMNames.CL_ITEM_HORSE_ARMOR));
    LabelNode l19 = new LabelNode();
    newInstr.add(new JumpInsnNode(Opcodes.IFEQ, l19));
    LabelNode l20 = new LabelNode();
    newInstr.add(l20);
    newInstr.add(new VarInsnNode(Opcodes.ALOAD, 0));
    newInstr.add(ASMHelper.getFieldInsnNode(Opcodes.GETFIELD, ASMNames.FD_HORSE_FIELD110280BR));
    newInstr.add(new InsnNode(Opcodes.ICONST_2));
    newInstr.add(new VarInsnNode(Opcodes.ALOAD, 4));
    newInstr.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_ITEMSTACK_GET_ITEM, false));
    newInstr.add(new TypeInsnNode(Opcodes.CHECKCAST, ASMNames.CL_ITEM_HORSE_ARMOR));
    newInstr.add(new VarInsnNode(Opcodes.ALOAD, 0));
    newInstr.add(new VarInsnNode(Opcodes.ALOAD, 4));
    newInstr.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_SAP_GET_ARMOR_TEXTURE, false));
    newInstr.add(new InsnNode(Opcodes.AASTORE));
    LabelNode l21 = new LabelNode();
    newInstr.add(l21);
    newInstr.add(new VarInsnNode(Opcodes.ALOAD, 0));
    newInstr.add(new TypeInsnNode(Opcodes.NEW, ASMNames.CL_STRING_BUILDER));
    newInstr.add(new InsnNode(Opcodes.DUP));
    newInstr.add(new VarInsnNode(Opcodes.ALOAD, 0));
    newInstr.add(ASMHelper.getFieldInsnNode(Opcodes.GETFIELD, ASMNames.FD_HORSE_FIELD110286BQ));
    newInstr.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKESTATIC, ASMNames.MD_STRING_VALUE_OF, false));
    newInstr.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKESPECIAL, ASMNames.MD_STRINGBUILDER_INIT, false));
    newInstr.add(new LdcInsnNode("cst-"));
    newInstr.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_STRINGBUILDER_APPEND, false));
    newInstr.add(new VarInsnNode(Opcodes.ALOAD, 4));
    newInstr.add(
            ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_ITEMSTACK_GET_UNLOC_NAME, false));
    newInstr.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_STRINGBUILDER_APPEND, false));
    newInstr.add(
            ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_STRINGBUILDER_TO_STRING, false));
    newInstr.add(ASMHelper.getFieldInsnNode(Opcodes.PUTFIELD, ASMNames.FD_HORSE_FIELD110286BQ));
    newInstr.add(new InsnNode(Opcodes.RETURN));
    newInstr.add(l19);

    method.instructions.insert(node, newInstr);
}

From source file:de.sanandrew.core.manpack.transformer.TransformHorseArmor.java

License:Creative Commons License

private static void transformEntityInit(MethodNode method) {
    InsnList needle = new InsnList();
    needle.add(new VarInsnNode(Opcodes.ALOAD, 0));
    needle.add(ASMHelper.getFieldInsnNode(Opcodes.GETFIELD, ASMNames.FD_HORSE_DATAWATCHER));
    needle.add(new IntInsnNode(Opcodes.BIPUSH, 22));
    needle.add(new InsnNode(Opcodes.ICONST_0));
    needle.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKESTATIC, ASMNames.MD_INTEGER_VALUE_OF, false));
    needle.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_DATAWATCHER_ADD_OBJECT, false));

    AbstractInsnNode pointer = ASMHelper.findLastNodeFromNeedle(method.instructions, needle);

    InsnList newInstr = new InsnList();
    newInstr.add(new LabelNode());
    newInstr.add(new VarInsnNode(Opcodes.ALOAD, 0));
    newInstr.add(ASMHelper.getFieldInsnNode(Opcodes.GETFIELD, ASMNames.FD_HORSE_DATAWATCHER));
    newInstr.add(new IntInsnNode(Opcodes.BIPUSH, 23));
    newInstr.add(new TypeInsnNode(Opcodes.NEW, ASMNames.CL_ITEM_STACK));
    newInstr.add(new InsnNode(Opcodes.DUP));
    newInstr.add(ASMHelper.getFieldInsnNode(Opcodes.GETSTATIC, ASMNames.FD_ITEMS_IRON_SHOVEL));
    newInstr.add(new InsnNode(Opcodes.ICONST_0));
    newInstr.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKESPECIAL, ASMNames.MD_ITEMSTACK_INIT, false));
    newInstr.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_DATAWATCHER_ADD_OBJECT, false));

    method.instructions.insert(pointer, newInstr);
}

From source file:de.unisb.cs.st.javalanche.coverage.CoverageMethodAdapter.java

License:Open Source License

private void callLogPrototype(String traceMethod, PDType type) {
    if (type != PDType.LONG && type != PDType.DOUBLE) {
        this.visitInsn(Opcodes.DUP);
        if (type == PDType.FLOAT) {
            this.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Float", "floatToRawIntBits", "(F)I");
        }/*from ww  w .  jav  a2 s. co  m*/
    } else {
        this.visitInsn(Opcodes.DUP2);
        if (type == PDType.DOUBLE) {
            this.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Double", "doubleToRawLongBits", "(D)J");
        }
        this.visitInsn(Opcodes.DUP2);
        this.visitIntInsn(Opcodes.BIPUSH, 32);
        this.visitInsn(Opcodes.LSHR);
        this.visitInsn(Opcodes.LXOR);
        this.visitInsn(Opcodes.L2I);
    }

    this.visitMethodInsn(Opcodes.INVOKESTATIC, CoverageProperties.TRACER_CLASS_NAME, "getInstance",
            "()L" + CoverageProperties.TRACER_CLASS_NAME + ";");
    this.visitInsn(Opcodes.SWAP);
    this.visitLdcInsn(className);
    this.visitLdcInsn(methodName);
    this.visitMethodInsn(Opcodes.INVOKEVIRTUAL, CoverageProperties.TRACER_CLASS_NAME, traceMethod,
            "(ILjava/lang/String;Ljava/lang/String;)V");
}

From source file:de.unisb.cs.st.javalanche.coverage.CoverageMethodAdapter.java

License:Open Source License

private void callLogAReturn() {
    this.visitInsn(Opcodes.DUP);
    this.visitMethodInsn(Opcodes.INVOKESTATIC, CoverageProperties.TRACER_CLASS_NAME, "getInstance",
            "()L" + CoverageProperties.TRACER_CLASS_NAME + ";");
    this.visitInsn(Opcodes.SWAP);
    this.visitLdcInsn(className);
    this.visitLdcInsn(methodName);
    this.visitMethodInsn(Opcodes.INVOKEVIRTUAL, CoverageProperties.TRACER_CLASS_NAME, "logAReturn",
            "(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;)V");
}

From source file:de.unisb.cs.st.javalanche.mutation.bytecodeMutations.removeSystemExit.RemoveSystemExitMethodAdapter.java

License:Open Source License

@Override
public void visitMethodInsn(int opcode, String owner, String name, String desc) {
    if (name.equals("exita") && owner.equals("java/lang/System")) {
        logger.info("Replacing System.exit ");

        Label mutationStartLabel = new Label();
        mutationStartLabel.info = new MutationMarker(true);
        mv.visitLabel(mutationStartLabel);

        mv.visitInsn(Opcodes.POP);//from  w  w w  .  j a v  a  2 s . co  m
        mv.visitTypeInsn(Opcodes.NEW, "java/lang/RuntimeException");
        mv.visitInsn(Opcodes.DUP);
        mv.visitLdcInsn("Replaced System Exit");
        mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/RuntimeException", "<init>",
                "(Ljava/lang/String;)V");
        mv.visitInsn(Opcodes.ATHROW);

        Label mutationEndLabel = new Label();
        mutationEndLabel.info = new MutationMarker(false);
        mv.visitLabel(mutationEndLabel);

    } else {
        super.visitMethodInsn(opcode, owner, name, desc);
    }
}

From source file:de.unisb.cs.st.javalanche.mutation.bytecodeMutations.removeSystemExit.RemoveSystemExitMethodNode.java

License:Open Source License

@SuppressWarnings("unchecked")
// Call to pre-1.5 Code
@Override//w ww  .j  a v  a 2  s.  c  o m
public void visitEnd() {
    MethodNode mn = (MethodNode) mv;
    InsnList insns = mn.instructions;
    Iterator i = insns.iterator();
    AbstractInsnNode prev = null;
    InsnList newInstrucionList = new InsnList();
    while (i.hasNext()) {
        boolean addInstruction = true;
        AbstractInsnNode i1 = (AbstractInsnNode) i.next();
        if (i1 instanceof MethodInsnNode) {
            MethodInsnNode methotInsnNode = (MethodInsnNode) i1;
            if (methotInsnNode.name.equals("exit") && methotInsnNode.owner.equals("java/lang/System")) {
                logger.info("Replacing System.exit ");
                newInstrucionList.remove(prev);
                // insns.remove(i1);
                InsnList il = new InsnList();
                Label mutationStartLabel = new Label();
                mutationStartLabel.info = new MutationMarker(true);

                il.add(new LabelNode(mutationStartLabel));
                il.add(new TypeInsnNode(Opcodes.NEW, "java/lang/RuntimeException"));
                il.add(new InsnNode(Opcodes.DUP));
                il.add(new LdcInsnNode("Replaced System.exit()"));
                il.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, "java/lang/RuntimeException", "<init>",
                        "(Ljava/lang/String;)V"));
                il.add(new InsnNode(Opcodes.ATHROW));

                Label mutationEndLabel = new Label();
                mutationEndLabel.info = new MutationMarker(false);
                il.add(new LabelNode(mutationEndLabel));
                newInstrucionList.add(il);
                addInstruction = false;
            }
        }
        if (addInstruction) {
            try {
                insns.remove(i1);
                newInstrucionList.add(i1);
            } catch (Exception e) {
                logger.error(e);
            }

        }
        prev = i1;
    }
    mn.instructions = newInstrucionList;
    mn.accept(next);
}

From source file:de.unisb.cs.st.javaslicer.common.classRepresentation.instructions.SimpleInstruction.java

License:Open Source License

@Override
public String toString() {
    switch (getOpcode()) {
    // the not interesting ones:
    case Opcodes.NOP:
        return "NOP";
    // constants:
    case Opcodes.ACONST_NULL:
        return "ACONST_NULL";
    case Opcodes.ICONST_M1:
        return "ICONST_M1";
    case Opcodes.ICONST_0:
        return "ICONST_0";
    case Opcodes.ICONST_1:
        return "ICONST_1";
    case Opcodes.ICONST_2:
        return "ICONST_2";
    case Opcodes.ICONST_3:
        return "ICONST_3";
    case Opcodes.ICONST_4:
        return "ICONST_4";
    case Opcodes.ICONST_5:
        return "ICONST_5";
    case Opcodes.LCONST_0:
        return "LCONST_0";
    case Opcodes.LCONST_1:
        return "LCONST_1";
    case Opcodes.FCONST_0:
        return "FCONST_0";
    case Opcodes.FCONST_1:
        return "FCONST_1";
    case Opcodes.FCONST_2:
        return "FCONST_2";
    case Opcodes.DCONST_0:
        return "DCONST_0";
    case Opcodes.DCONST_1:
        return "DCONST_1";

    // array load:
    case Opcodes.IALOAD:
        return "IALOAD";
    case Opcodes.LALOAD:
        return "LALOAD";
    case Opcodes.FALOAD:
        return "FALOAD";
    case Opcodes.DALOAD:
        return "DALOAD";
    case Opcodes.AALOAD:
        return "AALOAD";
    case Opcodes.BALOAD:
        return "BALOAD";
    case Opcodes.CALOAD:
        return "CALOAD";
    case Opcodes.SALOAD:
        return "SALOAD";

    // array store:
    case Opcodes.IASTORE:
        return "IASTORE";
    case Opcodes.LASTORE:
        return "LASTORE";
    case Opcodes.FASTORE:
        return "FASTORE";
    case Opcodes.DASTORE:
        return "DASTORE";
    case Opcodes.AASTORE:
        return "AASTORE";
    case Opcodes.BASTORE:
        return "BASTORE";
    case Opcodes.CASTORE:
        return "CASTORE";
    case Opcodes.SASTORE:
        return "SASTORE";

    // stack manipulation:
    case Opcodes.POP:
        return "POP";
    case Opcodes.POP2:
        return "POP2";
    case Opcodes.DUP:
        return "DUP";
    case Opcodes.DUP_X1:
        return "DUP_X1";
    case Opcodes.DUP_X2:
        return "DUP_X2";
    case Opcodes.DUP2:
        return "DUP2";
    case Opcodes.DUP2_X1:
        return "DUP2_X1";
    case Opcodes.DUP2_X2:
        return "DUP2_X2";
    case Opcodes.SWAP:
        return "SWAP";

    // arithmetic:
    case Opcodes.IADD:
        return "IADD";
    case Opcodes.LADD:
        return "LADD";
    case Opcodes.FADD:
        return "FADD";
    case Opcodes.DADD:
        return "DADD";
    case Opcodes.ISUB:
        return "ISUB";
    case Opcodes.LSUB:
        return "LSUB";
    case Opcodes.FSUB:
        return "FSUB";
    case Opcodes.DSUB:
        return "DSUB";
    case Opcodes.IMUL:
        return "IMUL";
    case Opcodes.LMUL:
        return "LMUL";
    case Opcodes.FMUL:
        return "FMUL";
    case Opcodes.DMUL:
        return "DMUL";
    case Opcodes.IDIV:
        return "IDIV";
    case Opcodes.LDIV:
        return "LDIV";
    case Opcodes.FDIV:
        return "FDIV";
    case Opcodes.DDIV:
        return "DDIV";
    case Opcodes.IREM:
        return "IREM";
    case Opcodes.LREM:
        return "LREM";
    case Opcodes.FREM:
        return "FREM";
    case Opcodes.DREM:
        return "DREM";
    case Opcodes.INEG:
        return "INEG";
    case Opcodes.LNEG:
        return "LNEG";
    case Opcodes.FNEG:
        return "FNEG";
    case Opcodes.DNEG:
        return "DNEG";
    case Opcodes.ISHL:
        return "ISHL";
    case Opcodes.LSHL:
        return "LSHL";
    case Opcodes.ISHR:
        return "ISHR";
    case Opcodes.LSHR:
        return "LSHR";
    case Opcodes.IUSHR:
        return "IUSHR";
    case Opcodes.LUSHR:
        return "LUSHR";
    case Opcodes.IAND:
        return "IAND";
    case Opcodes.LAND:
        return "LAND";
    case Opcodes.IOR:
        return "IOR";
    case Opcodes.LOR:
        return "LOR";
    case Opcodes.IXOR:
        return "IXOR";
    case Opcodes.LXOR:
        return "LXOR";

    // type conversions:
    case Opcodes.I2L:
        return "I2L";
    case Opcodes.I2F:
        return "I2F";
    case Opcodes.I2D:
        return "I2D";
    case Opcodes.L2I:
        return "L2I";
    case Opcodes.L2F:
        return "L2F";
    case Opcodes.L2D:
        return "L2D";
    case Opcodes.F2I:
        return "F2I";
    case Opcodes.F2L:
        return "F2L";
    case Opcodes.F2D:
        return "F2D";
    case Opcodes.D2I:
        return "D2I";
    case Opcodes.D2L:
        return "D2L";
    case Opcodes.D2F:
        return "D2F";
    case Opcodes.I2B:
        return "I2B";
    case Opcodes.I2C:
        return "I2C";
    case Opcodes.I2S:
        return "I2S";

    // comparison:
    case Opcodes.LCMP:
        return "LCMP";
    case Opcodes.FCMPL:
        return "FCMPL";
    case Opcodes.FCMPG:
        return "FCMPG";
    case Opcodes.DCMPL:
        return "DCMPL";
    case Opcodes.DCMPG:
        return "DCMPG";

    // control-flow statements:
    case Opcodes.IRETURN:
        return "IRETURN";
    case Opcodes.LRETURN:
        return "LRETURN";
    case Opcodes.FRETURN:
        return "FRETURN";
    case Opcodes.DRETURN:
        return "DRETURN";
    case Opcodes.ARETURN:
        return "ARETURN";
    case Opcodes.RETURN:
        return "RETURN";

    // special things
    case Opcodes.ARRAYLENGTH:
        return "ARRAYLENGTH";
    case Opcodes.ATHROW:
        return "ATHROW";
    case Opcodes.MONITORENTER:
        return "MONITORENTER";
    case Opcodes.MONITOREXIT:
        return "MONITOREXIT";

    default:/*from w w w  . j a  v a 2 s  .  c o  m*/
        assert false;
        return "--ERROR--";
    }
}

From source file:dodola.anole.lib.InstantRunTransform.java

License:Apache License

/**
 * Use asm to generate a concrete subclass of the AppPathLoaderImpl class.
 * It only implements one method :/*ww  w .j a  v  a 2 s  .c o m*/
 * String[] getPatchedClasses();
 * <p>
 * The method is supposed to return the list of classes that were patched in this iteration.
 * This will be used by the InstantRun runtime to load all patched classes and register them
 * as overrides on the original classes.2 class files.
 *
 * @param patchFileContents list of patched class names.
 * @param outputDir         output directory where to generate the .class file in.
 * @return the generated .class files
 */
public static File writePatchFileContents(List<String> patchFileContents, File outputDir) {

    ClassWriter cw = new ClassWriter(0);
    MethodVisitor mv;

    cw.visit(Opcodes.V1_6, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, IncrementalVisitor.APP_PATCHES_LOADER_IMPL,
            null, IncrementalVisitor.ABSTRACT_PATCHES_LOADER_IMPL, null);

    {
        mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null);
        mv.visitCode();
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        mv.visitMethodInsn(Opcodes.INVOKESPECIAL, IncrementalVisitor.ABSTRACT_PATCHES_LOADER_IMPL, "<init>",
                "()V", false);
        mv.visitInsn(Opcodes.RETURN);
        mv.visitMaxs(1, 1);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "getPatchedClasses", "()[Ljava/lang/String;", null, null);
        mv.visitCode();
        mv.visitIntInsn(Opcodes.BIPUSH, patchFileContents.size());
        mv.visitTypeInsn(Opcodes.ANEWARRAY, "java/lang/String");
        for (int index = 0; index < patchFileContents.size(); index++) {
            mv.visitInsn(Opcodes.DUP);
            mv.visitIntInsn(Opcodes.BIPUSH, index);
            mv.visitLdcInsn(patchFileContents.get(index));
            mv.visitInsn(Opcodes.AASTORE);
        }
        mv.visitInsn(Opcodes.ARETURN);
        mv.visitMaxs(4, 1);
        mv.visitEnd();
    }
    cw.visitEnd();

    byte[] classBytes = cw.toByteArray();
    File outputFile = new File(outputDir, IncrementalVisitor.APP_PATCHES_LOADER_IMPL + ".class");
    try {
        Files.createParentDirs(outputFile);
        Files.write(classBytes, outputFile);
        // add the files to the list of files to be processed by subsequent tasks.
        return outputFile;
    } catch (IOException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}

From source file:dyco4j.instrumentation.internals.InitTracingMethodVisitor.java

License:BSD License

@Override
public void visitInsn(final int opcode) {
    super.visitInsn(opcode);
    switch (opcode) {
    case Opcodes.IRETURN: // 1 before n/a after
    case Opcodes.FRETURN: // 1 before n/a after
    case Opcodes.ARETURN: // 1 before n/a after
    case Opcodes.ATHROW: // 1 before n/a after
        this.stackFrame.pop();
        break;// ww w .ja  va 2  s .  c om
    case Opcodes.LRETURN: // 2 before n/a after
    case Opcodes.DRETURN: // 2 before n/a after
        this.stackFrame.pop();
        this.stackFrame.pop();
        break;
    case Opcodes.NOP:
    case Opcodes.LALOAD: // remove 2 add 2
    case Opcodes.DALOAD: // remove 2 add 2
    case Opcodes.LNEG:
    case Opcodes.DNEG:
    case Opcodes.FNEG:
    case Opcodes.INEG:
    case Opcodes.L2D:
    case Opcodes.D2L:
    case Opcodes.F2I:
    case Opcodes.I2B:
    case Opcodes.I2C:
    case Opcodes.I2S:
    case Opcodes.I2F:
    case Opcodes.ARRAYLENGTH:
        break;
    case Opcodes.ACONST_NULL:
    case Opcodes.ICONST_M1:
    case Opcodes.ICONST_0:
    case Opcodes.ICONST_1:
    case Opcodes.ICONST_2:
    case Opcodes.ICONST_3:
    case Opcodes.ICONST_4:
    case Opcodes.ICONST_5:
    case Opcodes.FCONST_0:
    case Opcodes.FCONST_1:
    case Opcodes.FCONST_2:
    case Opcodes.F2L: // 1 before 2 after
    case Opcodes.F2D:
    case Opcodes.I2L:
    case Opcodes.I2D:
        this.stackFrame.push(OTHER);
        break;
    case Opcodes.LCONST_0:
    case Opcodes.LCONST_1:
    case Opcodes.DCONST_0:
    case Opcodes.DCONST_1:
        this.stackFrame.push(OTHER);
        this.stackFrame.push(OTHER);
        break;
    case Opcodes.IALOAD: // remove 2 add 1
    case Opcodes.FALOAD: // remove 2 add 1
    case Opcodes.AALOAD: // remove 2 add 1
    case Opcodes.BALOAD: // remove 2 add 1
    case Opcodes.CALOAD: // remove 2 add 1
    case Opcodes.SALOAD: // remove 2 add 1
    case Opcodes.POP:
    case Opcodes.IADD:
    case Opcodes.FADD:
    case Opcodes.ISUB:
    case Opcodes.LSHL: // 3 before 2 after
    case Opcodes.LSHR: // 3 before 2 after
    case Opcodes.LUSHR: // 3 before 2 after
    case Opcodes.L2I: // 2 before 1 after
    case Opcodes.L2F: // 2 before 1 after
    case Opcodes.D2I: // 2 before 1 after
    case Opcodes.D2F: // 2 before 1 after
    case Opcodes.FSUB:
    case Opcodes.FMUL:
    case Opcodes.FDIV:
    case Opcodes.FREM:
    case Opcodes.FCMPL: // 2 before 1 after
    case Opcodes.FCMPG: // 2 before 1 after
    case Opcodes.IMUL:
    case Opcodes.IDIV:
    case Opcodes.IREM:
    case Opcodes.ISHL:
    case Opcodes.ISHR:
    case Opcodes.IUSHR:
    case Opcodes.IAND:
    case Opcodes.IOR:
    case Opcodes.IXOR:
    case Opcodes.MONITORENTER:
    case Opcodes.MONITOREXIT:
        this.stackFrame.pop();
        break;
    case Opcodes.POP2:
    case Opcodes.LSUB:
    case Opcodes.LMUL:
    case Opcodes.LDIV:
    case Opcodes.LREM:
    case Opcodes.LADD:
    case Opcodes.LAND:
    case Opcodes.LOR:
    case Opcodes.LXOR:
    case Opcodes.DADD:
    case Opcodes.DMUL:
    case Opcodes.DSUB:
    case Opcodes.DDIV:
    case Opcodes.DREM:
        this.stackFrame.pop();
        this.stackFrame.pop();
        break;
    case Opcodes.IASTORE:
    case Opcodes.FASTORE:
    case Opcodes.AASTORE:
    case Opcodes.BASTORE:
    case Opcodes.CASTORE:
    case Opcodes.SASTORE:
    case Opcodes.LCMP: // 4 before 1 after
    case Opcodes.DCMPL:
    case Opcodes.DCMPG:
        this.stackFrame.pop();
        this.stackFrame.pop();
        this.stackFrame.pop();
        break;
    case Opcodes.LASTORE:
    case Opcodes.DASTORE:
        this.stackFrame.pop();
        this.stackFrame.pop();
        this.stackFrame.pop();
        this.stackFrame.pop();
        break;
    case Opcodes.DUP:
        this.stackFrame.push(this.stackFrame.peek());
        break;
    case Opcodes.DUP_X1: {
        final int _s = stackFrame.size();
        stackFrame.add(_s - 2, stackFrame.get(_s - 1));
        break;
    }
    case Opcodes.DUP_X2: {
        final int _s = stackFrame.size();
        stackFrame.add(_s - 3, stackFrame.get(_s - 1));
        break;
    }
    case Opcodes.DUP2: {
        final int _s = stackFrame.size();
        stackFrame.add(_s - 2, stackFrame.get(_s - 1));
        stackFrame.add(_s - 2, stackFrame.get(_s - 1));
        break;
    }
    case Opcodes.DUP2_X1: {
        final int _s = stackFrame.size();
        stackFrame.add(_s - 3, stackFrame.get(_s - 1));
        stackFrame.add(_s - 3, stackFrame.get(_s - 1));
        break;
    }
    case Opcodes.DUP2_X2: {
        final int _s = stackFrame.size();
        stackFrame.add(_s - 4, stackFrame.get(_s - 1));
        stackFrame.add(_s - 4, stackFrame.get(_s - 1));
        break;
    }
    case Opcodes.SWAP: {
        final int _s = stackFrame.size();
        stackFrame.add(_s - 2, stackFrame.get(_s - 1));
        stackFrame.remove(_s);
        break;
    }
    }
}

From source file:dyco4j.instrumentation.internals.TracingMethodVisitor.java

License:BSD License

@Override
public final void visitFieldInsn(final int opcode, final String owner, final String name, final String desc) {
    if (this.cv.cmdLineOptions.traceFieldAccess) {
        final Type _fieldType = Type.getType(desc);
        final String _fieldId = this.cv.getFieldId(name, owner, desc);
        final boolean _isFieldStatic = opcode == Opcodes.GETSTATIC || opcode == Opcodes.PUTSTATIC;
        if (opcode == Opcodes.GETSTATIC || opcode == Opcodes.GETFIELD) {
            if (_isFieldStatic)
                super.visitInsn(Opcodes.ACONST_NULL);
            else if (this.thisInitialized)
                super.visitInsn(Opcodes.DUP);
            else {
                super.visitLdcInsn(LoggingHelper.UNINITIALIZED_THIS);
                super.visitInsn(Opcodes.SWAP);
            }//w w  w.j a v a 2 s  . co  m

            super.visitFieldInsn(opcode, owner, name, desc);
            LoggingHelper.emitLogField(this.mv, _fieldId, _fieldType, Logger.FieldAction.GETF);
        } else if (opcode == Opcodes.PUTSTATIC || opcode == Opcodes.PUTFIELD) {
            if (_isFieldStatic) {
                super.visitInsn(Opcodes.ACONST_NULL);
            } else if (this.thisInitialized) {
                LoggingHelper.emitSwapTwoWordsAndOneWord(this.mv, _fieldType);
                final int _fieldSort = _fieldType.getSort();
                if (_fieldSort == Type.LONG || _fieldSort == Type.DOUBLE)
                    super.visitInsn(Opcodes.DUP_X2);
                else
                    super.visitInsn(Opcodes.DUP_X1);
            } else {
                super.visitLdcInsn(LoggingHelper.UNINITIALIZED_THIS);
            }

            LoggingHelper.emitSwapOneWordAndTwoWords(this.mv, _fieldType);
            LoggingHelper.emitLogField(this.mv, _fieldId, _fieldType, Logger.FieldAction.PUTF);
            super.visitFieldInsn(opcode, owner, name, desc);
        }
    } else
        super.visitFieldInsn(opcode, owner, name, desc);
}