Package org.aspectj.apache.bcel.generic

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


    Type jlClass = BcelWorld.makeBcelType(UnresolvedType.JAVA_LANG_CLASS);
    Type jlString = BcelWorld.makeBcelType(UnresolvedType.JAVA_LANG_STRING);
    Type jlClassArray = BcelWorld.makeBcelType(UnresolvedType.JAVA_LANG_CLASS_ARRAY);
    Type jlaAnnotation = BcelWorld.makeBcelType(UnresolvedType.JAVA_LANG_ANNOTATION);

    Instruction pushConstant = fact.createConstant(new ObjectType(toType.getName()));

    if (kind == Shadow.MethodCall || kind == Shadow.MethodExecution || kind == Shadow.PreInitialization
        || kind == Shadow.Initialization || kind == Shadow.ConstructorCall || kind == Shadow.ConstructorExecution
        || kind == Shadow.AdviceExecution ||
        // annotations for fieldset/fieldget when an ITD is involved are stored against a METHOD
View Full Code Here


  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

    // fix frame instructions
    for (InstructionHandle src = sourceList.getStart();
      src != null;
      src = src.getNext())
    {
      Instruction fresh = Utility.copyInstruction(src.getInstruction());
      InstructionHandle dest;
      if (fresh instanceof CPInstruction) {
        // 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) {
          CPInstruction cpi = (CPInstruction) fresh;
          cpi.setIndex(
            recipientCpg.addConstant(
              donorCpg.getConstant(cpi.getIndex()),
              donorCpg));
        }
      }
      if (src.getInstruction() == Range.RANGEINSTRUCTION) {
        dest = ret.append(Range.RANGEINSTRUCTION);
      } else if (fresh instanceof ReturnInstruction) {
        if (keepReturns) {
          dest = ret.append(fresh);
        } else {
          dest =
            ret.append(InstructionFactory.createBranchInstruction(Constants.GOTO, end));
        }
      } else if (fresh instanceof BranchInstruction) {
        dest = ret.append((BranchInstruction) fresh);
      } else if (
        fresh instanceof LocalVariableInstruction || fresh instanceof RET) {
        IndexedInstruction indexed = (IndexedInstruction) fresh;
        int oldIndex = indexed.getIndex();
        int freshIndex;
        if (!frameEnv.hasKey(oldIndex)) {
          freshIndex = recipient.allocateLocal(2);
          frameEnv.put(oldIndex, freshIndex);
        } else {
          freshIndex = frameEnv.get(oldIndex);
        }
        indexed.setIndex(freshIndex);
        dest = ret.append(fresh);
      } else {
        dest = ret.append(fresh);
      }
      srcToDest.put(src, dest);
    }
   
    // second pass: retarget branch instructions, copy ranges and tags
    Map tagMap = new HashMap();
    Map shadowMap = new HashMap();   
    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 BranchInstruction) {
        BranchInstruction branch = (BranchInstruction) inst;
        InstructionHandle oldTarget = branch.getTarget();
View Full Code Here

    int depth = 1;
    InstructionHandle start = mg.getBody().getStart();
    while (true) {
      if (start == null) return null;
     
      Instruction inst = start.getInstruction();
      if (inst instanceof INVOKESPECIAL
        && ((INVOKESPECIAL) inst).getName(cpg).equals("<init>")) {
        depth--;
        if (depth == 0) return start;
      } else if (inst instanceof NEW) {
View Full Code Here

    LazyMethodGen mg,
    InstructionHandle ih,
    BcelShadow enclosingShadow,
    List shadowAccumulator)
  {
    Instruction i = ih.getInstruction();
    if ((i instanceof FieldInstruction) &&
      (canMatch(Shadow.FieldGet) || canMatch(Shadow.FieldSet))
    ) {
      FieldInstruction fi = (FieldInstruction) i;
           
      if (fi instanceof PUTFIELD || fi instanceof 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

    // TODO: Check how BCEL handles (and will handle) instructions like IMPDEP1, IMPDEP2,
    //       BREAKPOINT... that BCEL knows about but which are illegal anyway.
    //       We currently go the safe way here.
    InstructionHandle ih = instructionList.getStart();
    while (ih != null){
      Instruction i = ih.getInstruction();
      if (i instanceof IMPDEP1){
        throw new StaticCodeInstructionConstraintException("IMPDEP1 must not be in the code, it is an illegal instruction for _internal_ JVM use!");
      }
      if (i instanceof IMPDEP2){
        throw new StaticCodeInstructionConstraintException("IMPDEP2 must not be in the code, it is an illegal instruction for _internal_ JVM use!");
      }
      if (i instanceof BREAKPOINT){
        throw new StaticCodeInstructionConstraintException("BREAKPOINT must not be in the code, it is an illegal instruction for _internal_ JVM use!");
      }
      ih = ih.getNext();
    }
   
    // The original verifier seems to do this check here, too.
    // An unreachable last instruction may also not fall through the
    // end of the code, which is stupid -- but with the original
    // verifier's subroutine semantics one cannot predict reachability.
    Instruction last = instructionList.getEnd().getInstruction();
    if (! ((last instanceof ReturnInstruction||
          (last instanceof RET)                  ||
          (last instanceof GotoInstruction)      ||
          (last instanceof ATHROW) )) // JSR / JSR_W would possibly RETurn and then fall off the code!
      throw new StaticCodeInstructionConstraintException("Execution must not fall off the bottom of the code array. This constraint is enforced statically as some existing verifiers do - so it may be a false alarm if the last instruction is not reachable.");
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.