Package org.objectweb.asm.tree

Examples of org.objectweb.asm.tree.VarInsnNode


  public void test() throws AnalyzerException {
    MethodNode mn = new MethodNode(ACC_PUBLIC, "checkAndSetF", "(I)V",
        null, null);
    InsnList il = mn.instructions;
    il.add(new VarInsnNode(ILOAD, 1));
    LabelNode label = new LabelNode();
    il.add(new JumpInsnNode(IFLT, label));
    il.add(new VarInsnNode(ALOAD, 0));
    il.add(new VarInsnNode(ILOAD, 1));
    il.add(new FieldInsnNode(PUTFIELD, "pkg/Bean", "f", "I"));
    LabelNode end = new LabelNode();
    il.add(new JumpInsnNode(GOTO, end));
    il.add(label);
    il.add(new FrameNode(F_SAME, 0, null, 0, null));
View Full Code Here


    InsnList insns = mn.instructions;
    Iterator i = insns.iterator();
    while (i.hasNext()) {
      AbstractInsnNode i1 = (AbstractInsnNode) i.next();
      if (i1 instanceof VarInsnNode) {
        VarInsnNode v1 = (VarInsnNode) i1;
        int op1 = v1.getOpcode();
        if (op1 >= ILOAD && op1 <= ALOAD) {
          AbstractInsnNode i2 = getNext(i);
          if (i2 instanceof VarInsnNode) {
            VarInsnNode v2 = (VarInsnNode) i2;
            int op2 = v2.getOpcode();
            if (op2 - ISTORE == op1 - ILOAD && v2.var == v1.var) {
              insns.remove(i1);
              insns.remove(i2);
            }
          }
View Full Code Here

    {
      MethodNode mn = new MethodNode(ACC_PUBLIC, "<init>", "()V", null,
          null);
      cn.methods.add(mn);
      InsnList il = mn.instructions;
      il.add(new VarInsnNode(ALOAD, 0));
      il.add(new MethodInsnNode(INVOKESPECIAL, "java/lang/Object",
          "<init>", "()V"));
      il.add(new InsnNode(RETURN));
      mn.maxStack = 1;
      mn.maxLocals = 1;
    }
    {
      MethodNode mn = new MethodNode(ACC_PUBLIC, "getF", "()I", null,
          null);
      cn.methods.add(mn);
      InsnList il = mn.instructions;
      il.add(new VarInsnNode(ALOAD, 0));
      il.add(new FieldInsnNode(GETFIELD, "pkg/Bean", "f", "I"));
      il.add(new InsnNode(IRETURN));
      mn.maxStack = 1;
      mn.maxLocals = 1;
    }
    {
      MethodNode mn = new MethodNode(ACC_PUBLIC, "setF", "(I)V", null,
          null);
      cn.methods.add(mn);
      InsnList il = mn.instructions;
      il.add(new VarInsnNode(ALOAD, 0));
      il.add(new VarInsnNode(ILOAD, 1));
      il.add(new FieldInsnNode(PUTFIELD, "pkg/Bean", "f", "I"));
      il.add(new InsnNode(RETURN));
      mn.maxStack = 2;
      mn.maxLocals = 2;
    }
    MethodNode mn = new MethodNode(ACC_PUBLIC, "checkAndSetF", "(I)V",
        null, null);
    cn.methods.add(mn);
    InsnList il = mn.instructions;
    il.add(new VarInsnNode(ILOAD, 1));
    LabelNode label = new LabelNode();
    il.add(new JumpInsnNode(IFLT, label));
    il.add(new VarInsnNode(ALOAD, 0));
    il.add(new VarInsnNode(ILOAD, 1));
    il.add(new FieldInsnNode(PUTFIELD, "pkg/Bean", "f", "I"));
    LabelNode end = new LabelNode();
    il.add(new JumpInsnNode(GOTO, end));
    il.add(label);
    il.add(new FrameNode(F_SAME, 0, null, 0, null));
View Full Code Here

          il.add(getLabel(((IInteger)((IConstructor)v).get(0)).intValue()));
        } else if (((IConstructor)v).getName().equals("lineNumber")) {
          il.add(new LineNumberNode(((IInteger)((IConstructor)v).get(0)).intValue(),
                        getLabel(((IInteger)((IConstructor)v).get(1)).intValue())));
        } else if (((IConstructor)v).getName().equals("localVariable")) {
          il.add(new VarInsnNode(((IInteger)((IConstructor)v).get(0)).intValue(),
                       ((IInteger)((IConstructor)v).get(1)).intValue()));
        } else if (((IConstructor)v).getName().equals("loadConstantString")) {
          il.add(new LdcInsnNode(((IString)((IConstructor)v).get(0)).getValue()));
        } else if (((IConstructor)v).getName().equals("loadConstantInteger")) {
          il.add(new LdcInsnNode(((IInteger)((IConstructor)v).get(0)).intValue()));
View Full Code Here

        writer.write("\n\t\t\t\tlabel(" + getLabelIndex(n) + ")");
      } else if (ai instanceof LineNumberNode) {
        LineNumberNode n = ((LineNumberNode)ai);
        writer.write("\n\t\t\t\tlineNumber(" + n.line + ", " + getLabelIndex(n.start) + ")");
      } else if (ai instanceof VarInsnNode) {
        VarInsnNode n = ((VarInsnNode)ai);
        writer.write("\n\t\t\t\tlocalVariable(" + n.getOpcode() + ", " + n.var + ")");
      } else if (ai instanceof LdcInsnNode) {
        LdcInsnNode n = ((LdcInsnNode)ai);
        if (n.cst instanceof String) {
          writer.write("\n\t\t\t\tloadConstantString(\"" + escape((String)n.cst) + "\")");
        } else if (n.cst instanceof Integer) {
          writer.write("\n\t\t\t\tloadConstantInteger(" + n.cst + ")");
        } else if (n.cst instanceof Long) {
          writer.write("\n\t\t\t\tloadConstantLong(" + n.cst + ")");
        } else if (n.cst instanceof Float) {
          writer.write("\n\t\t\t\tloadConstantFloat(" + n.cst + ")");
        } else if (n.cst instanceof Double) {
          writer.write("\n\t\t\t\tloadConstantDouble(" + n.cst + ")");
        }
      } else if (ai instanceof LookupSwitchInsnNode) {
        LookupSwitchInsnNode n = ((LookupSwitchInsnNode)ai);
        writer.write("\n\t\t\t\tlookupSwitch(" + getLabelIndex(n.dflt) + ", [");
        boolean firstKey = true;
        for (Integer k : (List<Integer>)n.keys) {
          if (firstKey) { firstKey = false; } else { writer.write(", "); }
          writer.write(k);
        }
        writer.write("], [");
        boolean firstCase = true;
        for (LabelNode l : (List<LabelNode>)n.labels) {
          if (firstCase) { firstCase = false; } else { writer.write(", "); }
          writer.write("" + getLabelIndex(l));
        }
        writer.write("])");
      } else if (ai instanceof MethodInsnNode) {
        MethodInsnNode n = ((MethodInsnNode)ai);
        writer.write("\n\t\t\t\tmethod(" + n.getOpcode() + ", \"" + escape(n.owner) + "\", \"" + escape(n.name) + "\", \"" + escape(n.desc) + "\")");
      } else if (ai instanceof MultiANewArrayInsnNode) {
        MultiANewArrayInsnNode n = ((MultiANewArrayInsnNode)ai);
        writer.write("\n\t\t\t\tmultiANewArray(\"" + escape(n.desc) + "\", " + n.dims + ")");
      } else if (ai instanceof TableSwitchInsnNode) {
        TableSwitchInsnNode n = ((TableSwitchInsnNode)ai);
        writer.write("\n\t\t\t\ttableSwitch(" + n.min + ", " + n.max + ", " + getLabelIndex(n.dflt) + ", [");
        boolean firstCase = true;
        for (LabelNode l : (List<LabelNode>)n.labels) {
          if (firstCase) { firstCase = false; } else { writer.write(", "); }
          writer.write("" + getLabelIndex(l));
        }
        writer.write("])");
      } else if (ai instanceof TypeInsnNode) {
        TypeInsnNode n = ((TypeInsnNode)ai);
        writer.write("\n\t\t\t\t\\type(" + n.getOpcode() + ", \"" + escape(n.desc) + "\")");
      } else {
        if (!(ai instanceof FrameNode)) {
          throw new RuntimeException("Error: Unsupported instruction encountered (" + ai.getClass() + ").");
        }
        first = true;
View Full Code Here

          FieldInsnNode f = (FieldInsnNode)node;
          if (shouldDoSetter && isSettingFieldWithPrimitive(f)) {
            if (LOG) System.out.println(">> SETTING FIELD index=" + i);
            i = on(instructions, f)
              .insertAtOffset(2,
                new VarInsnNode(ALOAD, 0),
                new FieldInsnNode(GETFIELD, owner, "$data", BYTEBUFFER_DESC))
              .insertAtOffset(1,
                new FieldInsnNode(GETFIELD, owner, "$stride", "I"),
                fieldOffsetInstruction(f.name),
                new InsnNode(IADD))
              .insertAtOffset(0,
                bufferHelper.invokePutter(f.name),
                new InsnNode(POP))
              .delete(0)
              .transform();
          } else if (!shouldDoSetter && isSettingFieldWithPrimitive(f)) {
            if (LOG) System.out.println(">> SETTING FIELD index=" + i);
            i = on(instructions, f)
              .insertAtOffset(0,
                bufferHelper.invokePutter(f.name),
                new InsnNode(POP))
              .delete(0)
              .transform();
          } else if (isSettingFieldWithObject(f)) {
            if (LOG) System.out.println(">> SETTING FIELD FROM OBJECT index=" + i);
            i = on(instructions, f)
              .insertAtOffset(3,
                new VarInsnNode(ALOAD, 0),
                new FieldInsnNode(GETFIELD, owner, "$data", BYTEBUFFER_DESC))
              .insertAtOffset(2,
                new FieldInsnNode(GETFIELD, owner, "$stride", "I"),
                fieldOffsetInstruction(f.name),
                new InsnNode(IADD))
              .insertAtOffset(0,
                bufferHelper.invokePutter(f.name),
                new InsnNode(POP))
              .delete(0)
              .transform();
          } else if (isModifyingFieldWithObject(f)) {
            if (LOG) System.out.println(">> SETTING-MODIFYING FIELD FROM OBJECT index=" + i);
            i = on(instructions, f)
              .insertAtOffset(6,
                new VarInsnNode(ALOAD, 0),
                new FieldInsnNode(GETFIELD, owner, "$data", BYTEBUFFER_DESC))
              .insertAtOffset(5,
                new FieldInsnNode(GETFIELD, owner, "$stride", "I"),
                fieldOffsetInstruction(f.name),
                new InsnNode(IADD),
                new InsnNode(DUP2),
                bufferHelper.invokeGetter(f.name))
              .insertAtOffset(0,
                bufferHelper.invokePutter(f.name),
                new InsnNode(POP))
              .delete(5)
              .delete(4)
              .delete(0)
              .transform();
          } else if (isLoadingFromField(f)) {
            if (LOG) System.out.println("<< LOAD FIELD index=" + i);
            i = on(instructions, f)
              .insertAtOffset(2,
                new VarInsnNode(ALOAD, 0),
                new FieldInsnNode(GETFIELD, owner, "$data", BYTEBUFFER_DESC))
              .insertAtOffset(0,
                new FieldInsnNode(GETFIELD, owner, "$stride", "I"),
                fieldOffsetInstruction(f.name),
                new InsnNode(IADD),
                new InsnNode(DUP2),
                bufferHelper.invokeGetter(f.name))
              .delete(1)
              .delete(0)
              .transform();
            shouldDoSetter = false;
          } else if (isGettingField(f)) {
            if (LOG) System.out.println("<< GETTING FIELD index=" + i);
            i = on(instructions, f)
              .insertAtOffset(1,
                new VarInsnNode(ALOAD, 0),
                new FieldInsnNode(GETFIELD, owner, "$data", BYTEBUFFER_DESC))
              .insertAtOffset(0,
                new FieldInsnNode(GETFIELD, owner, "$stride", "I"),
                fieldOffsetInstruction(f.name),
                new InsnNode(IADD),
View Full Code Here

        labels.add(catchNode.handler.getLabel());
       
        LabelNode labelNode = catchNode.handler;
        AbstractInsnNode lineNumberNode = labelNode.getNext() instanceof LineNumberNode ? labelNode.getNext() : labelNode;
        FrameNode frameNode = (FrameNode) lineNumberNode.getNext();
        VarInsnNode varInsnNode = (VarInsnNode) frameNode.getNext();
        AbstractInsnNode insertPoint = varInsnNode;
       
        if (catchNode.type == null) {
          // this is probably a finally block;
          if (insertPoint.getNext() != null && insertPoint.getNext() instanceof LabelNode) {
            insertPoint = insertPoint.getNext();
          }
        }
       
        LabelNode labelNode4ifeg = new LabelNode();
        InsnList newCode = new InsnList();
        newCode.add(new VarInsnNode(Opcodes.ALOAD, varInsnNode.var));
        newCode.add(new TypeInsnNode(Opcodes.INSTANCEOF, INTERRUPT_EXCEPTION_NAME));
        newCode.add(new JumpInsnNode(Opcodes.IFEQ, labelNode4ifeg));
        newCode.add(new VarInsnNode(Opcodes.ALOAD, varInsnNode.var));
        newCode.add(new TypeInsnNode(Opcodes.CHECKCAST, INTERRUPT_EXCEPTION_NAME));
        newCode.add(new InsnNode(Opcodes.ATHROW));
        newCode.add(labelNode4ifeg);
        m.instructions.insert(insertPoint, newCode);
      }
View Full Code Here

        {
            AbstractInsnNode node = (AbstractInsnNode) li.next();

            if (node.getOpcode() == ALOAD)
            {
                VarInsnNode varNode = (VarInsnNode) node;

                assert varNode.var == 0;

                // Remove the ALOAD
                li.remove();
View Full Code Here

        mn.maxLocals += 1;

        for (Iterator<?> i = mn.instructions.iterator(); i.hasNext();) {
            Object current = i.next();
            if (current instanceof VarInsnNode) {
                VarInsnNode vin = (VarInsnNode) current;
                if (vin.var >= purrSecretIndex) {
                    vin.var = vin.var + 1;
                }
            }
            if (current instanceof IincInsnNode) {
                IincInsnNode iin = (IincInsnNode) current;
                iin.var = iin.var + 1;
                log("Incremented iinc var to " + iin.var);
            }
        }

        InsnList pre = new InsnList();
        // pre.add(vStart);
        if (isStatic) {
            pre.add(new LdcInsnNode(cn.name));
        } else {
            pre.add(new VarInsnNode(ALOAD, 0)); // "this" is index 0 locvar.
        }

        pre.add(new MethodInsnNode(INVOKESTATIC, classDesc, BEFORE,
                ONE_OBJECT_PARAM + OBJECT_DESC));
        pre.add(new VarInsnNode(ASTORE, purrSecretIndex));
        pre.add(fStart);
        mn.instructions.insert(mStart, pre);

        List<AbstractInsnNode> terminalNodes = new ArrayList<AbstractInsnNode>();
        for (int i = 0; i < mn.instructions.size(); i++) {
View Full Code Here

        InsnList post = new InsnList();
        if ( (mn.access & ACC_STATIC) != 0 ) {
            post.add( new LdcInsnNode( cn.name ));
        }
        else {
            post.add( new VarInsnNode( ALOAD, 0 ));
        }
        post.add( new VarInsnNode( ALOAD, varIndex ));
        post.add( new MethodInsnNode( INVOKESTATIC, classDesc, "after", TWO_OBJECT_PARAM +"V"));
        return post;
    }
View Full Code Here

TOP

Related Classes of org.objectweb.asm.tree.VarInsnNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.