Package org.aspectj.apache.bcel.generic

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


  private boolean isInitFailureHandler(InstructionHandle ih) {
    // Skip the astore_0 and aload_0 at the start of the handler and
    // then check if the instruction following these is
    // 'putstatic ajc$initFailureCause'. If it is then we are
    // in the handler we created in AspectClinit.generatePostSyntheticCode()
    InstructionHandle twoInstructionsAway = ih.getNext().getNext();
    if (twoInstructionsAway.getInstruction().opcode == Constants.PUTSTATIC) {
      String name = ((FieldInstruction) twoInstructionsAway.getInstruction()).getFieldName(cpg);
      if (name.equals(NameMangler.INITFAILURECAUSE_FIELD_NAME)) {
        return true;
      }
    }
    return false;
View Full Code Here


      // if (len > 0) hasExceptionHandlers = true;
      int priority = len - 1;
      for (int i = 0; i < len; i++, priority--) {
        CodeExceptionGen exn = exns[i];

        InstructionHandle start = Range.genStart(body, getOutermostExceptionStart(exn.getStartPC()));
        InstructionHandle end = Range.genEnd(body, getOutermostExceptionEnd(exn.getEndPC()));
        // this doesn't necessarily handle overlapping correctly!!!
        ExceptionRange er = new ExceptionRange(body, exn.getCatchType() == null ? null : BcelWorld.fromBcel(exn
            .getCatchType()), priority);
        er.associateWithTargets(start, end, exn.getHandlerPC());
        exn.setStartPC(null); // also removes from target
View Full Code Here

  }

  public void addExceptionHandler(InstructionHandle start, InstructionHandle end, InstructionHandle handlerStart,
      ObjectType catchType, boolean highPriority) {

    InstructionHandle start1 = Range.genStart(body, start);
    InstructionHandle end1 = Range.genEnd(body, end);

    ExceptionRange er = new ExceptionRange(body, (catchType == null ? null : BcelWorld.fromBcel(catchType)), highPriority);
    er.associateWithTargets(start1, end1, handlerStart);
  }
View Full Code Here

    /*
     * Update branch targets and insert various attributes. Insert our exceptionHandlers into a sorted list, so they can be
     * added in order later.
     */
    InstructionHandle oldInstructionHandle = getBody().getStart();
    InstructionHandle newInstructionHandle = fresh.getStart();
    LinkedList<ExceptionRange> exceptionList = new LinkedList<ExceptionRange>();

    Map<LocalVariableTag, LVPosition> localVariables = new HashMap<LocalVariableTag, LVPosition>();

    int currLine = -1;
    int lineNumberOffset = (fromFilename == null) ? 0 : getEnclosingClass().getSourceDebugExtensionOffset(fromFilename);

    while (oldInstructionHandle != null) {
      if (map.get(oldInstructionHandle) == null) {
        // must be a range instruction since they're the only things we
        // didn't copy across
        handleRangeInstruction(oldInstructionHandle, exceptionList);
        // just increment ih.
        oldInstructionHandle = oldInstructionHandle.getNext();
      } else {
        // assert map.get(ih) == jh
        Instruction oldInstruction = oldInstructionHandle.getInstruction();
        Instruction newInstruction = newInstructionHandle.getInstruction();

        if (oldInstruction instanceof InstructionBranch) {
          handleBranchInstruction(map, oldInstruction, newInstruction);
        }

        // now deal with line numbers
        // and store up info for local variables
        for (InstructionTargeter targeter : oldInstructionHandle.getTargeters()) {
          if (targeter instanceof LineNumberTag) {
            int line = ((LineNumberTag) targeter).getLineNumber();
            if (line != currLine) {
              gen.addLineNumber(newInstructionHandle, line + lineNumberOffset);
              currLine = line;
            }
          } else if (targeter instanceof LocalVariableTag) {
            LocalVariableTag lvt = (LocalVariableTag) targeter;
            LVPosition p = localVariables.get(lvt);
            // If we don't know about it, create a new position and
            // store
            // If we do know about it - update its end position
            if (p == null) {
              LVPosition newp = new LVPosition();
              newp.start = newp.end = newInstructionHandle;
              localVariables.put(lvt, newp);
            } else {
              p.end = newInstructionHandle;
            }
          }
        }

        // now continue
        oldInstructionHandle = oldInstructionHandle.getNext();
        newInstructionHandle = newInstructionHandle.getNext();
      }
    }

    addExceptionHandlers(gen, map, exceptionList);
    if (localVariables.size() == 0) {
View Full Code Here

  private void createNewLocalVariables(MethodGen gen) {
    gen.removeLocalVariables();
    // ignore <clinit> or <init> for now
    if (!getName().startsWith("<")) {
      int slot = 0;
      InstructionHandle start = gen.getInstructionList().getStart();
      InstructionHandle end = gen.getInstructionList().getEnd();
      // Add a 'this' if non-static
      if (!isStatic()) {
        String cname = this.enclosingClass.getClassName();
        if (cname == null) {
          return; // give up for now
View Full Code Here

   * Optimized packing that does a 'local packing' of the code rather than building a brand new method and packing into it. Only
   * usable when the packing is going to be done just once.
   */
  public void optimizedPackBody(MethodGen gen) {
    InstructionList theBody = getBody();
    InstructionHandle iHandle = theBody.getStart();

    int currLine = -1;
    int lineNumberOffset = (fromFilename == null) ? 0 : getEnclosingClass().getSourceDebugExtensionOffset(fromFilename);
    Map<LocalVariableTag, LVPosition> localVariables = new HashMap<LocalVariableTag, LVPosition>();
    LinkedList<ExceptionRange> exceptionList = new LinkedList<ExceptionRange>();
    Set<InstructionHandle> forDeletion = new HashSet<InstructionHandle>();
    Set<BranchHandle> branchInstructions = new HashSet<BranchHandle>();
    // OPTIMIZE sort out in here: getRange()/insertHandler() and type of
    // exceptionList
    while (iHandle != null) {
      Instruction inst = iHandle.getInstruction();
      // InstructionHandle nextInst = iHandle.getNext();
      // OPTIMIZE remove this instructionhandle as it now points to
      // nowhere?
      if (inst == Range.RANGEINSTRUCTION) {
        Range r = Range.getRange(iHandle);
        if (r instanceof ExceptionRange) {
          ExceptionRange er = (ExceptionRange) r;
          if (er.getStart() == iHandle) {
            if (!er.isEmpty()) {
              // order is important, insert handlers in order of start
              insertHandler(er, exceptionList);
            }
          }
        }
        forDeletion.add(iHandle);
      } else {
        if (inst instanceof InstructionBranch) {
          branchInstructions.add((BranchHandle) iHandle);
        }

        for (InstructionTargeter targeter : iHandle.getTargetersCopy()) {
          if (targeter instanceof LineNumberTag) {
            int line = ((LineNumberTag) targeter).getLineNumber();
            if (line != currLine) {
              gen.addLineNumber(iHandle, line + lineNumberOffset);
              currLine = line;
            }
          } else if (targeter instanceof LocalVariableTag) {
            LocalVariableTag lvt = (LocalVariableTag) targeter;
            LVPosition p = localVariables.get(lvt);
            // If we don't know about it, create a new position
            // and store
            // If we do know about it - update its end position
            if (p == null) {
              LVPosition newp = new LVPosition();
              newp.start = newp.end = iHandle;
              localVariables.put(lvt, newp);
            } else {
              p.end = iHandle;
            }
          }
        }
      }
      iHandle = iHandle.getNext();
    }
    for (BranchHandle branchHandle : branchInstructions) {
      handleBranchInstruction(branchHandle, forDeletion);
    }
    // now add exception handlers
View Full Code Here

    for (LocalVariableTag tag : localVariables.keySet()) {
      // have we already added one with the same slot number and start
      // location?
      // if so, just continue.
      LVPosition lvpos = localVariables.get(tag);
      InstructionHandle start = lvpos.start;
      Set<Integer> slots = duplicatedLocalMap.get(start);
      if (slots == null) {
        slots = new HashSet<Integer>();
        duplicatedLocalMap.put(start, slots);
      } else if (slots.contains(new Integer(tag.getSlot()))) {
View Full Code Here

    // now add exception handlers
    for (ExceptionRange r : exnList) {
      if (r.isEmpty()) {
        continue;
      }
      InstructionHandle rMappedStart = remap(r.getRealStart(), map);
      InstructionHandle rMappedEnd = remap(r.getRealEnd(), map);
      InstructionHandle rMappedHandler = remap(r.getHandler(), map);
      gen.addExceptionHandler(rMappedStart, rMappedEnd, rMappedHandler, (r.getCatchType() == null) ? null
          : (ObjectType) BcelWorld.makeBcelType(r.getCatchType()));
    }
  }
View Full Code Here

  private void handleBranchInstruction(Map<InstructionHandle, InstructionHandle> map, Instruction oldInstruction,
      Instruction newInstruction) {
    InstructionBranch oldBranchInstruction = (InstructionBranch) oldInstruction;
    InstructionBranch newBranchInstruction = (InstructionBranch) newInstruction;
    InstructionHandle oldTarget = oldBranchInstruction.getTarget(); // old
    // target

    // New target is in hash map
    newBranchInstruction.setTarget(remap(oldTarget, map));
View Full Code Here

      }
    }
  }

  private InstructionHandle jumpForward(InstructionHandle t, Set<InstructionHandle> handlesForDeletion) {
    InstructionHandle target = t;
    if (handlesForDeletion.contains(target)) {
      do {
        target = target.getNext();
      } while (handlesForDeletion.contains(target));
    }
    return target;
  }
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.