Package org.aspectj.apache.bcel.generic

Examples of org.aspectj.apache.bcel.generic.Instruction


  public Member makeJoinPointSignatureForMonitorExit(LazyClassGen cg, InstructionHandle h) {
    return MemberImpl.monitorExit();
  }

  public Member makeJoinPointSignatureForArrayConstruction(LazyClassGen cg, InstructionHandle handle) {
    Instruction i = handle.getInstruction();
    ConstantPool cpg = cg.getConstantPool();
    Member retval = null;

    if (i.opcode == Constants.ANEWARRAY) {
      // ANEWARRAY arrayInstruction = (ANEWARRAY)i;
      Type ot = i.getType(cpg);
      UnresolvedType ut = fromBcel(ot);
      ut = UnresolvedType.makeArray(ut, 1);
      retval = MemberImpl.method(ut, Modifier.PUBLIC, ResolvedType.VOID, "<init>", new ResolvedType[] { ResolvedType.INT });
    } else if (i instanceof MULTIANEWARRAY) {
      MULTIANEWARRAY arrayInstruction = (MULTIANEWARRAY) i;
      UnresolvedType ut = null;
      short dimensions = arrayInstruction.getDimensions();
      ObjectType ot = arrayInstruction.getLoadClassType(cpg);
      if (ot != null) {
        ut = fromBcel(ot);
        ut = UnresolvedType.makeArray(ut, dimensions);
      } else {
        Type t = arrayInstruction.getType(cpg);
        ut = fromBcel(t);
      }
      ResolvedType[] parms = new ResolvedType[dimensions];
      for (int ii = 0; ii < dimensions; ii++) {
        parms[ii] = ResolvedType.INT;
      }
      retval = MemberImpl.method(ut, Modifier.PUBLIC, ResolvedType.VOID, "<init>", parms);

    } else if (i.opcode == Constants.NEWARRAY) {
      // NEWARRAY arrayInstruction = (NEWARRAY)i;
      Type ot = i.getType();
      UnresolvedType ut = fromBcel(ot);
      retval = MemberImpl.method(ut, Modifier.PUBLIC, ResolvedType.VOID, "<init>", new ResolvedType[] { ResolvedType.INT });
    } else {
      throw new BCException("Cannot create array construction signature for this non-array instruction:" + i);
    }
View Full Code Here


      if (realizedCannotInline) {
        // we know we cannot inline this advice so no need for futher handling
        break;
      }
      InstructionHandle next = curr.getNext();
      Instruction inst = curr.getInstruction();

      // open-up method call
      if ((inst instanceof InvokeInstruction)) {
        InvokeInstruction invoke = (InvokeInstruction) inst;
        ResolvedType callee = m_aspectGen.getWorld().resolve(UnresolvedType.forName(invoke.getClassName(cpg)));
View Full Code Here

    // first pass: copy the instructions directly, populate the srcToDest
    // map,
    // fix frame instructions
    for (InstructionHandle src = sourceList.getStart(); src != null; src = src.getNext()) {
      Instruction fresh = Utility.copyInstruction(src.getInstruction());
      InstructionHandle dest;

      // OPTIMIZE optimize this stuff?
      if (fresh.isConstantPoolInstruction()) {
        // need to reset index to go to new constant pool. This is
        // totally
        // a computation leak... we're testing this LOTS of times. Sigh.
        if (isAcrossClass) {
          InstructionCP cpi = (InstructionCP) fresh;
          cpi.setIndex(recipientCpg.addConstant(donorCpg.getConstant(cpi.getIndex()), donorCpg));
        }
      }
      if (src.getInstruction() == Range.RANGEINSTRUCTION) {
        dest = ret.append(Range.RANGEINSTRUCTION);
      } else if (fresh.isReturnInstruction()) {
        if (keepReturns) {
          dest = ret.append(fresh);
        } else {
          dest = ret.append(InstructionFactory.createBranchInstruction(Constants.GOTO, end));
        }
      } else if (fresh instanceof InstructionBranch) {
        dest = ret.append((InstructionBranch) fresh);
      } else if (fresh.isLocalVariableInstruction() || fresh instanceof RET) {

        // IndexedInstruction indexed = (IndexedInstruction) fresh;
        int oldIndex = fresh.getIndex();
        int freshIndex;
        if (!frameEnv.hasKey(oldIndex)) {
          freshIndex = recipient.allocateLocal(2);
          frameEnv.put(oldIndex, freshIndex);
        } else {
          freshIndex = frameEnv.get(oldIndex);
        }
        if (fresh instanceof RET) {
          fresh.setIndex(freshIndex);
        } else {
          fresh = ((InstructionLV) fresh).setIndexAndCopyIfNecessary(freshIndex);
        }
        dest = ret.append(fresh);
      } else {
        dest = ret.append(fresh);
      }
      srcToDest.put(src, dest);
    }

    // second pass: retarget branch instructions, copy ranges and tags
    Map<Tag, Tag> tagMap = new HashMap<Tag, Tag>();
    Map<BcelShadow, BcelShadow> shadowMap = new HashMap<BcelShadow, BcelShadow>();
    for (InstructionHandle dest = ret.getStart(), src = sourceList.getStart(); dest != null; dest = dest.getNext(), src = src
        .getNext()) {
      Instruction inst = dest.getInstruction();

      // retarget branches
      if (inst instanceof InstructionBranch) {
        InstructionBranch branch = (InstructionBranch) inst;
        InstructionHandle oldTarget = branch.getTarget();
View Full Code Here

    while (true) {
      if (start == null) {
        return null;
      }

      Instruction inst = start.getInstruction();
      if (inst.opcode == Constants.INVOKESPECIAL && ((InvokeInstruction) inst).getName(cpg).equals("<init>")) {
        depth--;
        if (depth == 0) {
          return start;
        }
View Full Code Here

    }
    return ret;
  }

  private void match(LazyMethodGen mg, InstructionHandle ih, BcelShadow enclosingShadow, List<BcelShadow> shadowAccumulator) {
    Instruction i = ih.getInstruction();

    // Exception handlers (pr230817)
    if (canMatch(Shadow.ExceptionHandler) && !Range.isRangeHandle(ih)) {
      Set<InstructionTargeter> targeters = ih.getTargetersCopy();
      for (InstructionTargeter t : targeters) {
        if (t instanceof ExceptionRange) {
          // assert t.getHandler() == ih
          ExceptionRange er = (ExceptionRange) t;
          if (er.getCatchType() == null) {
            continue;
          }
          if (isInitFailureHandler(ih)) {
            return;
          }

          if (!ih.getInstruction().isStoreInstruction() && ih.getInstruction().getOpcode() != Constants.NOP) {
            // If using cobertura, the catch block stats with
            // INVOKESTATIC rather than ASTORE, in order that
            // the
            // ranges
            // for the methodcall and exceptionhandler shadows
            // that occur at this same
            // line, we need to modify the instruction list to
            // split them - adding a
            // NOP before the invokestatic that gets all the
            // targeters
            // that were aimed at the INVOKESTATIC
            mg.getBody().insert(ih, InstructionConstants.NOP);
            InstructionHandle newNOP = ih.getPrev();
            // what about a try..catch that starts at the start
            // of the exception handler? need to only include
            // certain targeters really.
            er.updateTarget(ih, newNOP, mg.getBody());
            for (InstructionTargeter t2 : targeters) {
              newNOP.addTargeter(t2);
            }
            ih.removeAllTargeters();
            match(BcelShadow.makeExceptionHandler(world, er, mg, newNOP, enclosingShadow), shadowAccumulator);
          } else {
            match(BcelShadow.makeExceptionHandler(world, er, mg, ih, enclosingShadow), shadowAccumulator);
          }
        }
      }
    }

    if ((i instanceof FieldInstruction) && (canMatch(Shadow.FieldGet) || canMatch(Shadow.FieldSet))) {
      FieldInstruction fi = (FieldInstruction) i;

      if (fi.opcode == Constants.PUTFIELD || fi.opcode == Constants.PUTSTATIC) {
        // check for sets of constant fields. We first check the
        // previous
        // instruction. If the previous instruction is a LD_WHATEVER
        // (push
        // constant on the stack) then we must resolve the field to
        // determine
        // if it's final. If it is final, then we don't generate a
        // shadow.
        InstructionHandle prevHandle = ih.getPrev();
        Instruction prevI = prevHandle.getInstruction();
        if (Utility.isConstantPushInstruction(prevI)) {
          Member field = BcelWorld.makeFieldJoinPointSignature(clazz, (FieldInstruction) i);
          ResolvedMember resolvedField = field.resolve(world);
          if (resolvedField == null) {
            // we can't find the field, so it's not a join point.
View Full Code Here

      }
    }
  }

  private static void assertGoodHandle(InstructionHandle ih, Set body, Stack<Range> ranges, String from) {
    Instruction inst = ih.getInstruction();
    if ((inst instanceof InstructionBranch) ^ (ih instanceof BranchHandle)) {
      throw new BCException("bad instruction/handle pair in " + from);
    }
    if (Range.isRangeHandle(ih)) {
      assertGoodRangeHandle(ih, body, ranges, from);
View Full Code Here

    void printInstruction(InstructionHandle h, int depth) {
      printDepth(depth);
      printLabel(labelMap.get(h), depth);

      Instruction inst = h.getInstruction();
      if (inst.isConstantPoolInstruction()) {
        out.print(Constants.OPCODE_NAMES[inst.opcode].toUpperCase());
        out.print(" ");
        out.print(pool.constantToString(pool.getConstant(inst.getIndex())));
      } else if (inst instanceof InstructionSelect) {
        InstructionSelect sinst = (InstructionSelect) inst;
        out.println(Constants.OPCODE_NAMES[sinst.opcode].toUpperCase());
        int[] matches = sinst.getMatchs();
        InstructionHandle[] targets = sinst.getTargets();
        InstructionHandle defaultTarget = sinst.getTarget();
        for (int i = 0, len = matches.length; i < len; i++) {
          printDepth(depth);
          printLabel(null, depth);
          out.print("  ");
          out.print(matches[i]);
          out.print(": \t");
          out.println(labelMap.get(targets[i]));
        }
        printDepth(depth);
        printLabel(null, depth);
        out.print("  ");
        out.print("default: \t");
        out.print(labelMap.get(defaultTarget));
      } else if (inst instanceof InstructionBranch) {
        InstructionBranch brinst = (InstructionBranch) inst;
        out.print(Constants.OPCODE_NAMES[brinst.getOpcode()].toUpperCase());
        out.print(" ");
        out.print(labelMap.get(brinst.getTarget()));
      } else if (inst.isLocalVariableInstruction()) {
        // LocalVariableInstruction lvinst = (LocalVariableInstruction)
        // inst;
        out.print(inst.toString(false).toUpperCase());
        int index = inst.getIndex();
        LocalVariableTag tag = getLocalVariableTag(h, index);
        if (tag != null) {
          out.print("     // ");
          out.print(tag.getType());
          out.print(" ");
          out.print(tag.getName());
        }
      } else {
        out.print(inst.toString(false).toUpperCase());
      }
    }
View Full Code Here

    // first pass: copy the instructions directly, populate the srcToDest
    // map,
    // fix frame instructions
    for (InstructionHandle src = sourceList.getStart(); src != null; src = src.getNext()) {
      Instruction fresh = Utility.copyInstruction(src.getInstruction());
      InstructionHandle dest;

      // OPTIMIZE optimize this stuff?
      if (fresh.isConstantPoolInstruction()) {
        // need to reset index to go to new constant pool. This is
        // totally
        // a computation leak... we're testing this LOTS of times. Sigh.
        if (isAcrossClass) {
          InstructionCP cpi = (InstructionCP) fresh;
          cpi.setIndex(recipientCpg.addConstant(donorCpg.getConstant(cpi.getIndex()), donorCpg));
        }
      }
      if (src.getInstruction() == Range.RANGEINSTRUCTION) {
        dest = ret.append(Range.RANGEINSTRUCTION);
      } else if (fresh.isReturnInstruction()) {
        if (keepReturns) {
          dest = ret.append(fresh);
        } else {
          dest = ret.append(InstructionFactory.createBranchInstruction(Constants.GOTO, end));
        }
      } else if (fresh instanceof InstructionBranch) {
        dest = ret.append((InstructionBranch) fresh);
      } else if (fresh.isLocalVariableInstruction() || fresh instanceof RET) {

        // IndexedInstruction indexed = (IndexedInstruction) fresh;
        int oldIndex = fresh.getIndex();
        int freshIndex;
        if (!frameEnv.hasKey(oldIndex)) {
          freshIndex = recipient.allocateLocal(2);
          frameEnv.put(oldIndex, freshIndex);
        } else {
          freshIndex = frameEnv.get(oldIndex);
        }
        if (fresh instanceof RET) {
          fresh.setIndex(freshIndex);
        } else {
          fresh = ((InstructionLV) fresh).setIndexAndCopyIfNecessary(freshIndex);
        }
        dest = ret.append(fresh);
      } else {
        dest = ret.append(fresh);
      }
      srcToDest.put(src, dest);
    }

    // second pass: retarget branch instructions, copy ranges and tags
    Map<Tag, Tag> tagMap = new HashMap<Tag, Tag>();
    Map<BcelShadow, BcelShadow> shadowMap = new HashMap<BcelShadow, BcelShadow>();
    for (InstructionHandle dest = ret.getStart(), src = sourceList.getStart(); dest != null; dest = dest.getNext(), src = src
        .getNext()) {
      Instruction inst = dest.getInstruction();

      // retarget branches
      if (inst instanceof InstructionBranch) {
        InstructionBranch branch = (InstructionBranch) inst;
        InstructionHandle oldTarget = branch.getTarget();
View Full Code Here

    while (true) {
      if (start == null) {
        return null;
      }

      Instruction inst = start.getInstruction();
      if (inst.opcode == Constants.INVOKESPECIAL && ((InvokeInstruction) inst).getName(cpg).equals("<init>")) {
        depth--;
        if (depth == 0) {
          return start;
        }
View Full Code Here

    }
    return ret;
  }

  private void match(LazyMethodGen mg, InstructionHandle ih, BcelShadow enclosingShadow, List<BcelShadow> shadowAccumulator) {
    Instruction i = ih.getInstruction();

    // Exception handlers (pr230817)
    if (canMatch(Shadow.ExceptionHandler) && !Range.isRangeHandle(ih)) {
      Set<InstructionTargeter> targeters = ih.getTargetersCopy();
      for (InstructionTargeter t : targeters) {
        if (t instanceof ExceptionRange) {
          // assert t.getHandler() == ih
          ExceptionRange er = (ExceptionRange) t;
          if (er.getCatchType() == null) {
            continue;
          }
          if (isInitFailureHandler(ih)) {
            return;
          }

          if (!ih.getInstruction().isStoreInstruction() && ih.getInstruction().getOpcode() != Constants.NOP) {
            // If using cobertura, the catch block stats with
            // INVOKESTATIC rather than ASTORE, in order that
            // the
            // ranges
            // for the methodcall and exceptionhandler shadows
            // that occur at this same
            // line, we need to modify the instruction list to
            // split them - adding a
            // NOP before the invokestatic that gets all the
            // targeters
            // that were aimed at the INVOKESTATIC
            mg.getBody().insert(ih, InstructionConstants.NOP);
            InstructionHandle newNOP = ih.getPrev();
            // what about a try..catch that starts at the start
            // of the exception handler? need to only include
            // certain targeters really.
            er.updateTarget(ih, newNOP, mg.getBody());
            for (InstructionTargeter t2 : targeters) {
              newNOP.addTargeter(t2);
            }
            ih.removeAllTargeters();
            match(BcelShadow.makeExceptionHandler(world, er, mg, newNOP, enclosingShadow), shadowAccumulator);
          } else {
            match(BcelShadow.makeExceptionHandler(world, er, mg, ih, enclosingShadow), shadowAccumulator);
          }
        }
      }
    }

    if ((i instanceof FieldInstruction) && (canMatch(Shadow.FieldGet) || canMatch(Shadow.FieldSet))) {
      FieldInstruction fi = (FieldInstruction) i;

      if (fi.opcode == Constants.PUTFIELD || fi.opcode == Constants.PUTSTATIC) {
        // check for sets of constant fields. We first check the
        // previous
        // instruction. If the previous instruction is a LD_WHATEVER
        // (push
        // constant on the stack) then we must resolve the field to
        // determine
        // if it's final. If it is final, then we don't generate a
        // shadow.
        InstructionHandle prevHandle = ih.getPrev();
        Instruction prevI = prevHandle.getInstruction();
        if (Utility.isConstantPushInstruction(prevI)) {
          Member field = BcelWorld.makeFieldJoinPointSignature(clazz, (FieldInstruction) i);
          ResolvedMember resolvedField = field.resolve(world);
          if (resolvedField == null) {
            // we can't find the field, so it's not a join point.
View Full Code Here

TOP

Related Classes of org.aspectj.apache.bcel.generic.Instruction

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.