Package org.aspectj.apache.bcel.generic

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


    insert(il, where);
    return ret;
  }

  void insert(InstructionList freshIl, Where where) {
    InstructionHandle h;
    if (where == InsideBefore || where == OutsideBefore) {
      h = getStart();
    } else {
      h = getEnd();
    }
    if (where == InsideBefore || where == OutsideAfter) {
      body.append(h, freshIl);
    } else {
      InstructionHandle newStart = body.insert(h, freshIl);
      if (where == OutsideBefore) {
        // XXX this is slow. There's a better design than this. We should
        // never have to retarget branches apart from the creation of ranges.
        // basically, we should never weave OutsideBefore.
        BcelShadow.retargetAllBranches(h, newStart);
View Full Code Here


      Utility.setSourceLine(ih, lineNumber);
    }
  }

  static InstructionHandle genStart(InstructionList body) {
    InstructionHandle ih = body.insert(Range.RANGEINSTRUCTION);
    setLineNumberFromNext(ih);
    return ih;
  }
View Full Code Here

  static InstructionHandle genStart(InstructionList body, InstructionHandle ih) {
    if (ih == null) {
      return genStart(body);
    }
    InstructionHandle freshIh = body.insert(ih, Range.RANGEINSTRUCTION);
    setLineNumberFromNext(freshIh);
    return freshIh;
  }
View Full Code Here

      // 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);
        }
      }
      // System.err.println("JUST COPIED: " +
      // oldIh.getInstruction().toString(freshMethod.getEnclosingClass().getConstantPoolGen().getConstantPool())
      // + " INTO " +
      // freshIh.getInstruction().toString(freshMethod.getEnclosingClass().getConstantPoolGen().getConstantPool()));
    }

    // now go through again and update variable slots that have been altered as a result
    // of remapping...
    for (InstructionHandle newIh = freshBody.getStart(); newIh != freshBody.getEnd(); newIh = newIh.getNext()) {
      Iterator<InstructionTargeter> tIter = newIh.getTargeters().iterator();
      while (tIter.hasNext()) {
        InstructionTargeter source = tIter.next();
        if (source instanceof LocalVariableTag) {
          LocalVariableTag lvt = (LocalVariableTag) source;
          if (!lvt.isRemapped() && remap.hasKey(lvt.getSlot())) {
            lvt.updateSlot(remap.get(lvt.getSlot()));
          }
        }
      }
    }

    // we've now copied out all the instructions.
    // now delete the instructions... we've already taken care of the damn
    // targets, but since TargetLostException is checked, we have to do this stuff.
    try {
      for (InstructionHandle oldIh = start.getNext(); oldIh != end;) {
        InstructionHandle next = oldIh.getNext();
        body.delete(oldIh);
        oldIh = next;
      }
    } catch (TargetLostException e) {
      throw new BCException("shouldn't have gotten a target lost");
    }

    // now add the return, if one is warranted.
    InstructionHandle ret = null;
    if (addReturn) {
      // we really should pull this out somewhere...
      ret = freshBody.append(InstructionFactory.createReturn(freshMethod.getReturnType()));
    }
    // and remap all the old targeters of the end handle of the range to the return.
View Full Code Here

   * @return true if managed to remove them
   */
  private boolean deleteNewAndDup() {
    final ConstantPool cpool = getEnclosingClass().getConstantPool();
    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) {
          break;
        }
        // need a testcase to show this can really happen in a modern compiler - removed due to 315398 - moved this out to
        // comment proceeding this method:

      }
      ih = ih.getPrev();
    }
    if (ih == null) {
      return false;
    }
    // now IH points to the NEW. We're followed by the DUP, and that is followed
    // by the actual instruction we care about.
    InstructionHandle newHandle = ih;
    InstructionHandle endHandle = newHandle.getNext();
    InstructionHandle nextHandle;
    if (endHandle.getInstruction().opcode == Constants.DUP) {
      nextHandle = endHandle.getNext();
      retargetFrom(newHandle, nextHandle);
      retargetFrom(endHandle, nextHandle);
    } else if (endHandle.getInstruction().opcode == Constants.DUP_X1) {
      InstructionHandle dupHandle = endHandle;
      endHandle = endHandle.getNext();
      nextHandle = endHandle.getNext();
      boolean skipEndRepositioning = false;
      if (endHandle.getInstruction().opcode == Constants.SWAP) {
      } else if (endHandle.getInstruction().opcode == Constants.IMPDEP1) {
View Full Code Here

      range.insert(InstructionConstants.NOP, Range.InsideAfter);
    } else if (getKind() == ExceptionHandler) {

      ShadowRange range = getRange();
      InstructionList body = range.getBody();
      InstructionHandle start = range.getStart();

      // Create a store instruction to put the value from the top of the
      // stack into a local variable slot. This is a trimmed version of
      // what is in initializeArgVars() (since there is only one argument
      // at a handler jp and only before advice is supported) (pr46298)
      argVars = new BcelVar[1];
      // int positionOffset = (hasTarget() ? 1 : 0) + ((hasThis() && !getKind().isTargetSameAsThis()) ? 1 : 0);
      UnresolvedType tx = getArgType(0);
      argVars[0] = genTempVar(tx, "ajc$arg0");
      InstructionHandle insertedInstruction = range.insert(argVars[0].createStore(getFactory()), Range.OutsideBefore);

      // Now the exception range starts just after our new instruction.
      // The next bit of code changes the exception range to point at
      // the store instruction
      for (InstructionTargeter t : start.getTargetersCopy()) {
View Full Code Here

  }

  public static BcelShadow makeStaticInitialization(BcelWorld world, LazyMethodGen enclosingMethod) {
    InstructionList body = enclosingMethod.getBody();
    // move the start past ajc$preClinit
    InstructionHandle clinitStart = body.getStart();
    if (clinitStart.getInstruction() instanceof InvokeInstruction) {
      InvokeInstruction ii = (InvokeInstruction) clinitStart.getInstruction();
      if (ii.getName(enclosingMethod.getEnclosingClass().getConstantPool()).equals(NameMangler.AJC_PRE_CLINIT_NAME)) {
        clinitStart = clinitStart.getNext();
      }
    }

    InstructionHandle clinitEnd = body.getEnd();

    // XXX should move the end before the postClinit, but the return is then tricky...
    // if (clinitEnd.getInstruction() instanceof InvokeInstruction) {
    // InvokeInstruction ii = (InvokeInstruction)clinitEnd.getInstruction();
    // if (ii.getName(enclosingMethod.getEnclosingClass().getConstantPool()).equals(NameMangler.AJC_POST_CLINIT_NAME)) {
View Full Code Here

    sig.setParameterNames(new String[] { findHandlerParamName(startOfHandler) });

    BcelShadow s = new BcelShadow(world, ExceptionHandler, sig, enclosingMethod, enclosingShadow);
    ShadowRange r = new ShadowRange(body);
    r.associateWithShadow(s);
    InstructionHandle start = Range.genStart(body, startOfHandler);
    InstructionHandle end = Range.genEnd(body, start);

    r.associateWithTargets(start, end);
    exceptionRange.updateTarget(startOfHandler, start, body);
    return s;
  }
View Full Code Here

  public void initIfaceInitializer(InstructionHandle end) {
    final InstructionList body = enclosingMethod.getBody();
    ShadowRange r = new ShadowRange(body);
    r.associateWithShadow(this);
    InstructionHandle nop = body.insert(end, InstructionConstants.NOP);

    r.associateWithTargets(Range.genStart(body, nop), Range.genEnd(body, nop));
  }
View Full Code Here

      // Does someone else need it? If so, store it for later retrieval
      if (lazyTjpConsumers > 1) {
        il.append(thisJoinPointVar.createStore(fact));

        InstructionHandle end = il.append(thisJoinPointVar.createLoad(fact));

        il.insert(InstructionFactory.createBranchInstruction(Constants.IFNONNULL, end));
        il.insert(thisJoinPointVar.createLoad(fact));
      }
    } else {
View Full Code Here

TOP

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

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.