Package org.aspectj.apache.bcel.generic

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


    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

    if (munger.getConcreteAspect().isAnnotationStyleAspect()) {
      // if we can't find one proceed() we suspect that the call
      // is happening in an inner class so we don't inline it.
      // Note: for code style, this is done at Aspect compilation time.
      boolean canSeeProceedPassedToOther = false;
      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) ?
View Full Code Here

    body.append(InstructionConstants.ARETURN);
  }

  private Type[] getSuperConstructorParameterTypes() {
    // assert getKind() == PreInitialization
    InstructionHandle superCallHandle = getRange().getEnd().getNext();
    InvokeInstruction superCallInstruction = (InvokeInstruction) superCallHandle.getInstruction();
    return superCallInstruction.getArgumentTypes(getEnclosingClass().getConstantPool());
  }
View Full Code Here

        il.append(pushConstant);// fact.createConstant(new ObjectType(toType.getName())));
        il.append(fact.createInvoke("java/lang/reflect/Method", "getAnnotation", jlaAnnotation, new Type[] { jlClass },
            Constants.INVOKEVIRTUAL));
        il.append(InstructionConstants.DUP);
        il.append(fact.createPutStatic(shadow.getEnclosingClass().getName(), annotationCachingField.getName(), jlAnnotation));
        InstructionHandle ifNullElse = il.append(InstructionConstants.NOP);
        ifNonNull.setTarget(ifNullElse);

      } else { // init/preinit/ctor-call/ctor-exec
        il.append(fact.createConstant(BcelWorld.makeBcelType(containingType)));
        buildArray(il, fact, jlClass, paramTypes, 1);
View Full Code Here

    il.append(pushConstantAnnotationType);
    il.append(fact.createInvoke("java/lang/reflect/Field", "getAnnotation", jlaAnnotation, new Type[] { jlClass },
        Constants.INVOKEVIRTUAL));
    il.appendDUP();
    il.append(fact.createPutStatic(shadowEnclosingClass.getName(), annotationCachingFieldName, jlaAnnotation));
    InstructionHandle ifNullElse = il.appendNOP();
    ifNonNull.setTarget(ifNullElse);
  }
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.