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, UnresolvedType.VOID, "<init>", new 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] = INT;
      }
      retval = MemberImpl.method(ut, Modifier.PUBLIC, UnresolvedType.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, UnresolvedType.VOID, "<init>", new 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 = aspectGen.getWorld().resolve(UnresolvedType.forName(invoke.getClassName(cpg)));
View Full Code Here

    freshMethod.assertGoodBody();
    InstructionList freshBody = freshMethod.getBody();

    for (InstructionHandle oldIh = start.getNext(); oldIh != end; oldIh = oldIh.getNext()) {
      // first we copy the instruction itself.
      Instruction oldI = oldIh.getInstruction();
      Instruction freshI = (oldI == RANGEINSTRUCTION) ? oldI : Utility.copyInstruction(oldI);

      // Now we add it to the new instruction list.
      InstructionHandle freshIh;
      if (freshI instanceof InstructionBranch) {
        // If it's a targeting instruction,
        // update the target(s) to point to the new copy instead of the old copy.
        InstructionBranch oldBranch = (InstructionBranch) oldI;
        InstructionBranch freshBranch = (InstructionBranch) freshI;
        InstructionHandle oldTarget = oldBranch.getTarget();
        oldTarget.removeTargeter(oldBranch);
        oldTarget.addTargeter(freshBranch);
        if (freshBranch instanceof InstructionSelect) {
          InstructionSelect oldSelect = (InstructionSelect) oldI;
          InstructionSelect freshSelect = (InstructionSelect) freshI;
          InstructionHandle[] oldTargets = freshSelect.getTargets();
          for (int k = oldTargets.length - 1; k >= 0; k--) {
            oldTargets[k].removeTargeter(oldSelect);
            oldTargets[k].addTargeter(freshSelect);
          }
        }
        freshIh = freshBody.append(freshBranch);
      } else {
        freshIh = freshBody.append(freshI);
      }

      // if source comes before target:
      // source <--> target
      // --> [process: target.removeTargeter(source); target.addTargeter(sourcecopy)]
      // source ---------\
      // v
      // sourcecopy <--> target
      // --> [ process: sourcecopy.updateTarget(target, targetcopy) ]
      // source ----> target
      // sourcecopy <--> targetcopy

      // if target comes before source

      // target <--> source
      // --> [process: source.updateTarget(target, targetcopy) ]
      // target
      // targetcopy <--> source
      // --> [process: targetcopy.removeTargeter(source); targetcopy.addTargeter(sourcecopy)]
      // target source
      // v
      // targetcopy <--> sourcecopy

      // now deal with the old instruction's targeters. Update them all to point to us
      // instead of the old instruction. We use updateTarget to do this. One goal is
      // to make sure we remove all targeters from the old guy, so we can successfully
      // delete it.
      for (InstructionTargeter source : oldIh.getTargetersCopy()) {
        if (source instanceof LocalVariableTag) {
          Shadow.Kind kind = getKind();
          if (kind == Shadow.AdviceExecution || kind == Shadow.ConstructorExecution || kind == Shadow.MethodExecution
              || kind == Shadow.PreInitialization || kind == Shadow.Initialization
              || kind == Shadow.StaticInitialization) {
            LocalVariableTag sourceLocalVariableTag = (LocalVariableTag) source;
            if (sourceLocalVariableTag.getSlot() == 0) {
              // might be 'this' so should be renamed if being dumped in a static method 277616
              if (sourceLocalVariableTag.getName().equals("this")) {
                sourceLocalVariableTag.setName("ajc$this");
              }
            }
            // if we're extracting a whole block we can do this...
            source.updateTarget(oldIh, freshIh);
          } else {
            // XXX destroying local variable info
            // but only for a call or get join point, so no big deal
            source.updateTarget(oldIh, null);
          }
        } else if (source instanceof Range) {
          // exceptions and shadows are just moved
          ((Range) source).updateTarget(oldIh, freshIh, freshBody);
        } else {
          // line numbers can be shared,
          // branches will be copied along with us.
          source.updateTarget(oldIh, freshIh);
        }
      }
      // we're now done with the old instruction entirely, and will ignore them through
      // the rest of this loop. The only time we'll see them again is a second pass to
      // delete them.

      // now deal with local variable instructions. If this points to a remapped
      // frame location, update the instruction's index. If this doesn't,
      // do compaction/expansion: allocate a new local variable, and modify the remap
      // to handle it. XXX We're doing the safe thing and allocating ALL these local variables
      // as double-wides, in case the location is found to hold a double-wide later.
      if (freshI.isLocalVariableInstruction() || freshI instanceof RET) {
        // IndexedInstruction indexedI = (IndexedInstruction) freshI;
        int oldIndex = freshI.getIndex();
        int freshIndex;
        if (!remap.hasKey(oldIndex)) {
          freshIndex = freshMethod.allocateLocal(2);
          remap.put(oldIndex, freshIndex);
        } else {
          freshIndex = remap.get(oldIndex);
        }
        if (freshI instanceof RET) {
          freshI.setIndex(freshIndex);
        } else {
          freshI = ((InstructionLV) freshI).setIndexAndCopyIfNecessary(freshIndex);
          freshIh.setInstruction(freshI);
        }
      }
View Full Code Here

    int depth = 1;
    InstructionHandle ih = range.getStart();

    // Go back from where we are looking for 'NEW' that takes us to a stack depth of 0. INVOKESPECIAL <init>
    while (ih != null) {
      Instruction inst = ih.getInstruction();
      if (inst.opcode == Constants.INVOKESPECIAL && ((InvokeInstruction) inst).getName(cpool).equals("<init>")) {
        depth++;
      } else if (inst.opcode == Constants.NEW) {
        depth--;
        if (depth == 0) {
View Full Code Here

  private BcelVar generateReturnInstructions(List<InstructionHandle> returns, InstructionList returnInstructions) {
    BcelVar returnValueVar = null;
    if (this.hasANonVoidReturnType()) {
      // Find the last *correct* return - this is a method with a non-void return type
      // so ignore RETURN
      Instruction newReturnInstruction = null;
      int i = returns.size() - 1;
      while (newReturnInstruction == null && i >= 0) {
        InstructionHandle ih = returns.get(i);
        if (ih.getInstruction().opcode != Constants.RETURN) {
          newReturnInstruction = Utility.copyInstruction(ih.getInstruction());
        }
        i--;
      }
      returnValueVar = genTempVar(this.getReturnType());
      returnValueVar.appendLoad(returnInstructions, getFactory());
      returnInstructions.append(newReturnInstruction);
    } else {
      InstructionHandle lastReturnHandle = returns.get(returns.size() - 1);
      Instruction newReturnInstruction = Utility.copyInstruction(lastReturnHandle.getInstruction());
      returnInstructions.append(newReturnInstruction);
    }
    return returnValueVar;
  }
View Full Code Here

      InstructionHandle curr = localAdviceMethod.getBody().getStart();
      InstructionHandle end = localAdviceMethod.getBody().getEnd();
      ConstantPool cpg = localAdviceMethod.getEnclosingClass().getConstantPool();
      while (curr != end) {
        InstructionHandle next = curr.getNext();
        Instruction inst = curr.getInstruction();
        if ((inst.opcode == Constants.INVOKESTATIC) && proceedName.equals(((InvokeInstruction) inst).getMethodName(cpg))) {

          localAdviceMethod.getBody().append(curr,
              getRedoneProceedCall(fact, extractedShadowMethod, munger, localAdviceMethod, proceedVarList));
          Utility.deleteInstruction(curr, localAdviceMethod);
        }
        curr = next;
      }
      // and that's it.
    } else {
      // ATAJ inlining support for @AJ aspects
      // [TODO document @AJ code rule: don't manipulate 2 jps proceed at the same time.. in an advice body]
      InstructionHandle curr = localAdviceMethod.getBody().getStart();
      InstructionHandle end = localAdviceMethod.getBody().getEnd();
      ConstantPool cpg = localAdviceMethod.getEnclosingClass().getConstantPool();
      while (curr != end) {
        InstructionHandle next = curr.getNext();
        Instruction inst = curr.getInstruction();
        if ((inst instanceof INVOKEINTERFACE) && "proceed".equals(((INVOKEINTERFACE) inst).getMethodName(cpg))) {
          final boolean isProceedWithArgs;
          if (((INVOKEINTERFACE) inst).getArgumentTypes(cpg).length == 1) {
            // proceed with args as a boxed Object[]
            isProceedWithArgs = true;
View Full Code Here

      InstructionHandle curr = adviceMethod.getBody().getStart();
      InstructionHandle end = adviceMethod.getBody().getEnd();
      ConstantPool cpg = adviceMethod.getEnclosingClass().getConstantPool();
      while (curr != end) {
        InstructionHandle next = curr.getNext();
        Instruction inst = curr.getInstruction();
        if ((inst instanceof InvokeInstruction)
            && ((InvokeInstruction) inst).getSignature(cpg).indexOf("Lorg/aspectj/lang/ProceedingJoinPoint;") > 0) {
          // we may want to refine to exclude stuff returning jp ?
          // does code style skip inline if i write dump(thisJoinPoint) ?
          canSeeProceedPassedToOther = true;// we see one pjp passed around - dangerous
View Full Code Here

    Type jlClass = BcelWorld.makeBcelType(UnresolvedType.JL_CLASS);
    Type jlString = BcelWorld.makeBcelType(UnresolvedType.JL_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

    } else if (fromType.isPrimitiveType()) {
      // assert toType.isPrimitive()
      Type from = BcelWorld.makeBcelType(fromType);
      Type to = BcelWorld.makeBcelType(toType);
      try {
        Instruction i = fact.createCast(from, to);
        if (i != null) {
          il.append(i);
        } else {
          il.append(fact.createCast(from, Type.INT));
          il.append(fact.createCast(Type.INT, to));
View Full Code Here

    il.append(fact.createCast(fromType, toType));
    return il;
  }

  public static Instruction createConstant(InstructionFactory fact, int value) {
    Instruction inst;
    switch (value) {
    case -1:
      inst = InstructionConstants.ICONST_M1;
      break;
    case 0:
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.