Package org.aspectj.apache.bcel.generic

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


  }

  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

    Member msig = getSignature();
    if (msig.getArity() == 0 && getKind() == MethodCall && msig.getName().charAt(0) == 'c' && tx.equals(ResolvedType.OBJECT)
        && msig.getReturnType().equals(ResolvedType.OBJECT) && msig.getName().equals("clone")) {

      // Lets go back through the code from the start of the shadow
      InstructionHandle searchPtr = range.getStart().getPrev();
      while (Range.isRangeHandle(searchPtr) || searchPtr.getInstruction().isStoreInstruction()) { // ignore this instruction -
        // it doesnt give us the
        // info we want
        searchPtr = searchPtr.getPrev();
      }

      // A load instruction may tell us the real type of what the clone() call is on
      if (searchPtr.getInstruction().isLoadInstruction()) {
        LocalVariableTag lvt = LazyMethodGen.getLocalVariableTag(searchPtr, searchPtr.getInstruction().getIndex());
        if (lvt != null) {
          return UnresolvedType.forSignature(lvt.getType());
        }
      }
      // A field access instruction may tell us the real type of what the clone() call is on
      if (searchPtr.getInstruction() instanceof FieldInstruction) {
        FieldInstruction si = (FieldInstruction) searchPtr.getInstruction();
        Type t = si.getFieldType(getEnclosingClass().getConstantPool());
        return BcelWorld.fromBcel(t);
      }
      // A new array instruction obviously tells us it is an array type !
      if (searchPtr.getInstruction().opcode == Constants.ANEWARRAY) {
        // ANEWARRAY ana = (ANEWARRAY)searchPoint.getInstruction();
        // Type t = ana.getType(getEnclosingClass().getConstantPool());
        // Just use a standard java.lang.object array - that will work fine
        return BcelWorld.fromBcel(new ArrayType(Type.OBJECT, 1));
      }
      // A multi new array instruction obviously tells us it is an array type !
      if (searchPtr.getInstruction() instanceof MULTIANEWARRAY) {
        MULTIANEWARRAY ana = (MULTIANEWARRAY) searchPtr.getInstruction();
        // Type t = ana.getType(getEnclosingClass().getConstantPool());
        // t = new ArrayType(t,ana.getDimensions());
        // Just use a standard java.lang.object array - that will work fine
        return BcelWorld.fromBcel(new ArrayType(Type.OBJECT, ana.getDimensions()));
      }
      throw new BCException("Can't determine real target of clone() when processing instruction "
          + searchPtr.getInstruction() + ".  Perhaps avoid selecting clone with your pointcut?");
    }
    return tx;
  }
View Full Code Here

    // list of instructions for dispatching to the advice itself
    InstructionList advice = getAfterReturningAdviceDispatchInstructions(munger, retList.getStart());

    if (hasReturnInstructions) {
      InstructionHandle gotoTarget = advice.getStart();
      for (Iterator<InstructionHandle> i = returns.iterator(); i.hasNext();) {
        InstructionHandle ih = i.next();
        retargetReturnInstruction(munger.hasExtraParameter(), returnValueVar, gotoTarget, ih);
      }
    }

    range.append(advice);
View Full Code Here

      // 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

    InstructionList endHandler = new InstructionList(exceptionVar.createLoad(fact));
    handler.append(munger.getAdviceInstructions(this, exceptionVar, endHandler.getStart()));
    handler.append(endHandler);
    handler.append(InstructionConstants.ATHROW);
    InstructionHandle handlerStart = handler.getStart();

    if (isFallsThrough()) {
      InstructionHandle jumpTarget = handler.append(InstructionConstants.NOP);
      handler.insert(InstructionFactory.createBranchInstruction(Constants.GOTO, jumpTarget));
    }
    InstructionHandle protectedEnd = handler.getStart();
    range.insert(handler, Range.InsideAfter);

    enclosingMethod.addExceptionHandler(range.getStart().getNext(), protectedEnd.getPrev(), handlerStart,
        (ObjectType) BcelWorld.makeBcelType(catchType), // ???Type.THROWABLE,
        // high priority if our args are on the stack
        getKind().hasHighPriorityExceptions());
  }
View Full Code Here

    // aload_1
    rtExHandler.append(exceptionVar.createLoad(fact));
    // athrow
    rtExHandler.append(InstructionFactory.ATHROW);

    InstructionHandle handlerStart = rtExHandler.getStart();

    if (isFallsThrough()) {
      InstructionHandle jumpTarget = range.getEnd();// handler.append(fact.NOP);
      rtExHandler.insert(InstructionFactory.createBranchInstruction(Constants.GOTO, jumpTarget));
    }

    rtExHandler.append(handler);

    InstructionHandle protectedEnd = rtExHandler.getStart();
    range.insert(rtExHandler, Range.InsideAfter);

    enclosingMethod.addExceptionHandler(range.getStart().getNext(), protectedEnd.getPrev(), handlerStart,
        (ObjectType) BcelWorld.makeBcelType(catchType),
        // high priority if our args are on the stack
        getKind().hasHighPriorityExceptions());
  }
View Full Code Here

    // inlining support for code style aspects
    if (!munger.getDeclaringType().isAnnotationStyleAspect()) {
      String proceedName = NameMangler.proceedMethodName(munger.getSignature().getName());

      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;
          } else {
            isProceedWithArgs = false;
          }
          InstructionList insteadProceedIl = getRedoneProceedCallForAnnotationStyle(fact, extractedShadowMethod, munger,
              localAdviceMethod, proceedVarList, isProceedWithArgs);
          localAdviceMethod.getBody().append(curr, insteadProceedIl);
          Utility.deleteInstruction(curr, localAdviceMethod);
        }
        curr = next;
      }
    }

    // if (parameterNames.size() == 0) {
    // On return we have inserted the advice body into the local advice method. We have remapped all the local variables
    // that were referenced in the advice as we did the copy, and so the local variable table for localAdviceMethod is
    // now lacking any information about all the initial variables.
    InstructionHandle start = localAdviceMethod.getBody().getStart();
    InstructionHandle end = localAdviceMethod.getBody().getEnd();

    // Find the real start and end
    while (start.getInstruction().opcode == Constants.IMPDEP1) {
      start = start.getNext();
    }
    while (end.getInstruction().opcode == Constants.IMPDEP1) {
      end = end.getPrev();
    }
    Type[] args = localAdviceMethod.getArgumentTypes();
    int argNumber = 0;
    for (int slot = 0; slot < extraParamOffset; argNumber++) { // slot will increase by the argument size each time
      String argumentName = null;
      if (argNumber >= args.length || parameterNames.size() == 0 || argNumber >= parameterNames.size()) {
        // this should be unnecessary as I think all known joinpoints and helper methods
        // propagate the parameter names around correctly - but just in case let us do this
        // rather than fail. If a bug is raised reporting unknown as a local variable name
        // then investigate the joinpoint giving rise to the ResolvedMember and why it has
        // no parameter names specified
        argumentName = new StringBuffer("unknown").append(argNumber).toString();
      } else {
        argumentName = parameterNames.get(argNumber);
      }
      String argumentSignature = args[argNumber].getSignature();
      LocalVariableTag lvt = new LocalVariableTag(argumentSignature, argumentName, slot, 0);
      start.addTargeter(lvt);
      end.addTargeter(lvt);
      slot += args[argNumber].getSize();
    }
  }
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.