Package org.objectweb.asm.tree

Examples of org.objectweb.asm.tree.InsnNode


    LabelNode end = new LabelNode();
    il.add(new JumpInsnNode(GOTO, end));
    il.add(label);
    il.add(new FrameNode(F_SAME, 0, null, 0, null));
    il.add(new TypeInsnNode(NEW, "java/lang/IllegalArgumentException"));
    il.add(new InsnNode(DUP));
    il.add(new MethodInsnNode(INVOKESPECIAL,
        "java/lang/IllegalArgumentException", "<init>", "()V"));
    il.add(new InsnNode(ATHROW));
    il.add(end);
    il.add(new FrameNode(F_SAME, 0, null, 0, null));
    il.add(new InsnNode(RETURN));
    mn.maxStack = 2;
    mn.maxLocals = 2;
    CyclomaticComplexity cc = new CyclomaticComplexity();
    assert (cc.getCyclomaticComplexity("pkg/Bean", mn) == 1);
  }
View Full Code Here


          if ((op >= IRETURN && op <= RETURN) || op == ATHROW) {
            InsnList il = new InsnList();
            il.add(new FieldInsnNode(GETSTATIC, cn.name, "timer", "J"));
            il.add(new MethodInsnNode(INVOKESTATIC, "java/lang/System",
                "currentTimeMillis", "()J"));
            il.add(new InsnNode(LADD));
            il.add(new FieldInsnNode(PUTSTATIC, cn.name, "timer", "J"));
            if (in.getPrevious() == null) {
              continue;
            }
            insns.insert(in.getPrevious(), il);
          }
        }
        InsnList il = new InsnList();
        il.add(new FieldInsnNode(GETSTATIC, cn.name, "timer", "J"));
        il.add(new MethodInsnNode(INVOKESTATIC, "java/lang/System",
            "currentTimeMillis", "()J"));
        il.add(new InsnNode(LSUB));
        il.add(new FieldInsnNode(PUTSTATIC, cn.name, "timer", "J"));
        insns.insert(il);

        mn.maxStack += 4;
      }
View Full Code Here

      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));
    il.add(new TypeInsnNode(NEW, "java/lang/IllegalArgumentException"));
    il.add(new InsnNode(DUP));
    il.add(new MethodInsnNode(INVOKESPECIAL,
        "java/lang/IllegalArgumentException", "<init>", "()V"));
    il.add(new InsnNode(ATHROW));
    il.add(end);
    il.add(new FrameNode(F_SAME, 0, null, 0, null));
    il.add(new InsnNode(RETURN));
    mn.maxStack = 2;
    mn.maxLocals = 2;
    ClassWriter cw = new ClassWriter(0);
    cn.accept(cw);
    return cw.toByteArray();
View Full Code Here

                       ((IString)((IConstructor)v).get(3)).getValue()));
        } else if (((IConstructor)v).getName().equals("increment")) {
          il.add(new IincInsnNode(((IInteger)((IConstructor)v).get(0)).intValue(),
                      ((IInteger)((IConstructor)v).get(1)).intValue()));
        } else if (((IConstructor)v).getName().equals("instruction")) {
          il.add(new InsnNode(((IInteger)((IConstructor)v).get(0)).intValue()));
        } else if (((IConstructor)v).getName().equals("integer")) {
          il.add(new IntInsnNode(((IInteger)((IConstructor)v).get(0)).intValue(),
                       ((IInteger)((IConstructor)v).get(1)).intValue()));
        } else if (((IConstructor)v).getName().equals("jump")) {
          il.add(new JumpInsnNode(((IInteger)((IConstructor)v).get(0)).intValue(),
View Full Code Here

        writer.write("\n\t\t\t\tfieldRef(" + n.getOpcode() + ", \"" + escape(n.owner) + "\", \"" + escape(n.name) + "\", \"" + escape(n.desc) + "\")");
      } else if (ai instanceof IincInsnNode) {
        IincInsnNode n = ((IincInsnNode)ai);
        writer.write("\n\t\t\t\tincrement(" + n.var + ", " + n.incr + ")");
      } else if (ai instanceof InsnNode) {
        InsnNode n = ((InsnNode)ai);
        writer.write("\n\t\t\t\tinstruction(" + n.getOpcode() + ")");
      } else if (ai instanceof IntInsnNode) {
        IntInsnNode n = ((IntInsnNode)ai);
        writer.write("\n\t\t\t\tinteger(" + n.getOpcode() + ", " + n.operand + ")");
      } else if (ai instanceof JumpInsnNode) {
        JumpInsnNode n = ((JumpInsnNode)ai);
        writer.write("\n\t\t\t\tjump(" + n.getOpcode() + ", " + getLabelIndex(n.label) + ")");
      } else if (ai instanceof LabelNode) {
        LabelNode n = ((LabelNode)ai);
        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

                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),
                bufferHelper.invokeGetter(f.name))
              .delete(0)
              .transform();
          }
          if (LOG) System.out.println("\tindex=" + i);
View Full Code Here

 
  private AbstractInsnNode fieldOffsetInstruction(String name) {
    int offset = offset(name);
   
    if (offset <= 5)
      return new InsnNode(ICONST_0 + offset);
    else if (offset <= 0xff)
      return new IntInsnNode(BIPUSH, offset);
    else
      return new IntInsnNode(SIPUSH, offset);
  }
View Full Code Here

        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

        }

        InsnList coda = new InsnList();
        coda.add( okReturnLabel );
        coda.add( preExitInsns( cn, mn, purrSecretIndex ));
        coda.add( new InsnNode( returnOpcode ));
        coda.add(fEnd);
//        coda.add( throwReturnLabel );
        coda.add(preExitInsns(cn, mn, purrSecretIndex));
        coda.add(new InsnNode(ATHROW));
        mn.instructions.insertBefore(mEnd, coda);

        for (Object o : mn.tryCatchBlocks) {
            TryCatchBlockNode tcbn = (TryCatchBlockNode) o;
            if (tcbn.start == mStart) {
View Full Code Here

        method.instructions.clear();
        method.instructions.add(new VarInsnNode(ALOAD, 0));
        method.instructions.add(createArgumentLoaders(method.desc));
        method.instructions.add(new MethodInsnNode(INVOKESPECIAL,
                classNode.getParentType().getInternalName(), method.name, method.desc));
        method.instructions.add(new InsnNode(ARETURN));
    }
View Full Code Here

TOP

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

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.