Package org.objectweb.asm.tree

Examples of org.objectweb.asm.tree.FieldInsnNode


    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"));
View Full Code Here


        while (j.hasNext()) {
          AbstractInsnNode in = (AbstractInsnNode) j.next();
          int op = in.getOpcode();
          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;
      }
      int acc = ACC_PUBLIC + ACC_STATIC;
View Full Code Here

      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"));
View Full Code Here

 
    InsnList buildInstructions(IList iList) {
      InsnList il = new InsnList();
      for (IValue v : iList) {
        if (((IConstructor)v).getName().equals("fieldRef")) {
          il.add(new FieldInsnNode(((IInteger)((IConstructor)v).get(0)).intValue(),
                       ((IString)((IConstructor)v).get(1)).getValue(),
                       ((IString)((IConstructor)v).get(2)).getValue(),
                       ((IString)((IConstructor)v).get(3)).getValue()));
        } else if (((IConstructor)v).getName().equals("increment")) {
          il.add(new IincInsnNode(((IInteger)((IConstructor)v).get(0)).intValue(),
View Full Code Here

    writer.write("[");
    boolean first = true;
    for (AbstractInsnNode ai : mn.instructions.toArray()) {
      if (first) { first = false; } else { writer.write(","); }
      if (ai instanceof FieldInsnNode) {
        FieldInsnNode n = ((FieldInsnNode)ai);
        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

      case IF_ACMPNE:
        expected1 = BasicValue.REFERENCE_VALUE;
        expected2 = BasicValue.REFERENCE_VALUE;
        break;
      case PUTFIELD:
        FieldInsnNode fin = (FieldInsnNode)insn;
        expected1 = newValue(Type.getType("L" + fin.owner + ";"));
        expected2 = newValue(Type.getType(fin.desc));
        break;
      default:
        throw new RuntimeException("Internal error.");
View Full Code Here

    boolean shouldDoSetter = true;
    for (int i = 0; instructions.size() > i; i++) {
      AbstractInsnNode node = instructions.get(i);
      switch(node.getType()) {
        case AbstractInsnNode.FIELD_INSN:
          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),
                bufferHelper.invokeGetter(f.name))
              .delete(0)
              .transform();
View Full Code Here

    for (int i = 0; instructions.size() > i; i++) {
      AbstractInsnNode node = instructions.get(i);
      if (AbstractInsnNode.FIELD_INSN != node.getType())
        continue;
     
      FieldInsnNode fn = (FieldInsnNode)node;
      if (className.equals(fn.owner))
        continue;
     
      if (PUTFIELD == fn.getOpcode() && components.containsKey(fn.owner)) {
        changed = true;
        i = InstructionMutator.on(instructions, fn)
          .insertAtOffset(0,
            new MethodInsnNode(INVOKEVIRTUAL, fn.owner, fn.name, param(fn)))
          .delete(0)
          .transform();
      } else if (GETFIELD == fn.getOpcode() && components.containsKey(fn.owner)) {
        changed = true;
       
        i = on(instructions, fn)
          .insertAtOffset(0,
            new MethodInsnNode(INVOKEVIRTUAL, fn.owner, fn.name, "()" + fn.desc))
View Full Code Here

                continue;

            // Make sure we're talking about access to a field of this class, not some other
            // visible field of another class.

            FieldInsnNode fnode = (FieldInsnNode) node;

            if (!fnode.owner.equals(classNode.name))
                continue;

            Map<String, String> fieldToMethod = opcode == GETFIELD ? fieldToReadMethod : fieldToWriteMethod;
View Full Code Here

    private void verifyAccess(InstructionGraphNode node) {
        switch (node.getInstruction().getOpcode()) {
            case GETFIELD:
            case GETSTATIC:
                FieldInsnNode field = (FieldInsnNode) node.getInstruction();
                Checks.ensure(!isPrivateField(field.owner, field.name),
                        "Rule method '%s' contains an illegal access to private field '%s'.\n" +
                                "Mark the field protected or package-private if you want to prevent public access!",
                        method.name, field.name);
                break;
View Full Code Here

TOP

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

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.