Package org.aspectj.apache.bcel.generic

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


    return il;
  }

  InstructionList createThisJoinPoint() {
    InstructionFactory fact = getFactory();
    InstructionList il = new InstructionList();

    BcelVar staticPart = getThisJoinPointStaticPartBcelVar();
    staticPart.appendLoad(il, fact);
    if (hasThis()) {
      ((BcelVar) getThisVar()).appendLoad(il, fact);
    } else {
      il.append(InstructionConstants.ACONST_NULL);
    }
    if (hasTarget()) {
      ((BcelVar) getTargetVar()).appendLoad(il, fact);
    } else {
      il.append(InstructionConstants.ACONST_NULL);
    }

    switch (getArgCount()) {
    case 0:
      il.append(fact.createInvoke("org.aspectj.runtime.reflect.Factory", "makeJP", LazyClassGen.tjpType, new Type[] {
          LazyClassGen.staticTjpType, Type.OBJECT, Type.OBJECT }, Constants.INVOKESTATIC));
      break;
    case 1:
      ((BcelVar) getArgVar(0)).appendLoadAndConvert(il, fact, world.getCoreType(ResolvedType.OBJECT));
      il.append(fact.createInvoke("org.aspectj.runtime.reflect.Factory", "makeJP", LazyClassGen.tjpType, new Type[] {
          LazyClassGen.staticTjpType, Type.OBJECT, Type.OBJECT, Type.OBJECT }, Constants.INVOKESTATIC));
      break;
    case 2:
      ((BcelVar) getArgVar(0)).appendLoadAndConvert(il, fact, world.getCoreType(ResolvedType.OBJECT));
      ((BcelVar) getArgVar(1)).appendLoadAndConvert(il, fact, world.getCoreType(ResolvedType.OBJECT));
      il.append(fact.createInvoke("org.aspectj.runtime.reflect.Factory", "makeJP", LazyClassGen.tjpType, new Type[] {
          LazyClassGen.staticTjpType, Type.OBJECT, Type.OBJECT, Type.OBJECT, Type.OBJECT }, Constants.INVOKESTATIC));
      break;
    default:
      il.append(makeArgsObjectArray());
      il.append(fact.createInvoke("org.aspectj.runtime.reflect.Factory", "makeJP", LazyClassGen.tjpType, new Type[] {
          LazyClassGen.staticTjpType, Type.OBJECT, Type.OBJECT, new ArrayType(Type.OBJECT, 1) }, Constants.INVOKESTATIC));
      break;
    }

    return il;
View Full Code Here


  // }

  private InstructionList makeArgsObjectArray() {
    InstructionFactory fact = getFactory();
    BcelVar arrayVar = genTempVar(UnresolvedType.OBJECTARRAY);
    final InstructionList il = new InstructionList();
    int alen = getArgCount();
    il.append(Utility.createConstant(fact, alen));
    il.append(fact.createNewArray(Type.OBJECT, (short) 1));
    arrayVar.appendStore(il, fact);

    int stateIndex = 0;
    for (int i = 0, len = getArgCount(); i < len; i++) {
      arrayVar.appendConvertableArrayStore(il, fact, stateIndex, (BcelVar) getArgVar(i));
View Full Code Here

  public void weaveAfterReturning(BcelAdvice munger) {
    List<InstructionHandle> returns = findReturnInstructions();
    boolean hasReturnInstructions = !returns.isEmpty();

    // list of instructions that handle the actual return from the join point
    InstructionList retList = new InstructionList();

    // variable that holds the return value
    BcelVar returnValueVar = null;

    if (hasReturnInstructions) {
      returnValueVar = generateReturnInstructions(returns, retList);
    } else {
      // we need at least one instruction, as the target for jumps
      retList.append(InstructionConstants.NOP);
    }

    // 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);
      }
    }
View Full Code Here

   * @param firstInstructionInReturnSequence
   * @return
   */
  private InstructionList getAfterReturningAdviceDispatchInstructions(BcelAdvice munger,
      InstructionHandle firstInstructionInReturnSequence) {
    InstructionList advice = new InstructionList();

    BcelVar tempVar = null;
    if (munger.hasExtraParameter()) {
      tempVar = insertAdviceInstructionsForBindingReturningParameter(advice);
    }
    advice.append(munger.getAdviceInstructions(this, tempVar, firstInstructionInReturnSequence));
    return advice;
  }
View Full Code Here

  private void retargetReturnInstruction(boolean hasReturningParameter, BcelVar returnValueVar, InstructionHandle gotoTarget,
      InstructionHandle returnHandle) {
    // pr148007, work around JRockit bug
    // replace ret with store into returnValueVar, followed by goto if not
    // at the end of the instruction list...
    InstructionList newInstructions = new InstructionList();
    if (returnValueVar != null) {
      if (hasReturningParameter) {
        // we have to dup the return val before consuming it...
        newInstructions.append(InstructionFactory.createDup(this.getReturnType().getSize()));
      }
      // store the return value into this var
      returnValueVar.appendStore(newInstructions, getFactory());
    }
    if (!isLastInstructionInRange(returnHandle, range)) {
      newInstructions.append(InstructionFactory.createBranchInstruction(Constants.GOTO, gotoTarget));
    }
    if (newInstructions.isEmpty()) {
      newInstructions.append(InstructionConstants.NOP);
    }
    Utility.replaceInstruction(returnHandle, newInstructions, enclosingMethod);
  }
View Full Code Here

    // a shadow, inside me).
    if (getRange().getStart().getNext() == getRange().getEnd()) {
      return;
    }
    InstructionFactory fact = getFactory();
    InstructionList handler = new InstructionList();
    BcelVar exceptionVar = genTempVar(catchType);
    exceptionVar.appendStore(handler, fact);

    // pr62642
    // I will now jump through some firey BCEL hoops to generate a trivial bit of code:
    // if (exc instanceof ExceptionInInitializerError)
    // throw (ExceptionInInitializerError)exc;
    if (this.getEnclosingMethod().getName().equals("<clinit>")) {
      ResolvedType eiieType = world.resolve("java.lang.ExceptionInInitializerError");
      ObjectType eiieBcelType = (ObjectType) BcelWorld.makeBcelType(eiieType);
      InstructionList ih = new InstructionList(InstructionConstants.NOP);
      handler.append(exceptionVar.createLoad(fact));
      handler.append(fact.createInstanceOf(eiieBcelType));
      InstructionBranch bi = InstructionFactory.createBranchInstruction(Constants.IFEQ, ih.getStart());
      handler.append(bi);
      handler.append(exceptionVar.createLoad(fact));
      handler.append(fact.createCheckCast(eiieBcelType));
      handler.append(InstructionConstants.ATHROW);
      handler.append(ih);
    }

    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()) {
View Full Code Here

    if (getRange().getStart().getNext() == getRange().getEnd()) {
      return;
    }

    InstructionFactory fact = getFactory();
    InstructionList handler = new InstructionList();
    InstructionList rtExHandler = new InstructionList();
    BcelVar exceptionVar = genTempVar(catchType);

    handler.append(fact.createNew(NameMangler.SOFT_EXCEPTION_TYPE));
    handler.append(InstructionFactory.createDup(1));
    handler.append(exceptionVar.createLoad(fact));
    handler.append(fact.createInvoke(NameMangler.SOFT_EXCEPTION_TYPE, "<init>", Type.VOID, new Type[] { Type.THROWABLE },
        Constants.INVOKESPECIAL)); // ??? special
    handler.append(InstructionConstants.ATHROW);

    // ENH 42737
    exceptionVar.appendStore(rtExHandler, fact);
    // aload_1
    rtExHandler.append(exceptionVar.createLoad(fact));
    // instanceof class java/lang/RuntimeException
    rtExHandler.append(fact.createInstanceOf(new ObjectType("java.lang.RuntimeException")));
    // ifeq go to new SOFT_EXCEPTION_TYPE instruction
    rtExHandler.append(InstructionFactory.createBranchInstruction(Constants.IFEQ, handler.getStart()));
    // 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
View Full Code Here

  }

  public void weavePerObjectEntry(final BcelAdvice munger, final BcelVar onVar) {
    final InstructionFactory fact = getFactory();

    InstructionList entryInstructions = new InstructionList();
    InstructionList entrySuccessInstructions = new InstructionList();
    onVar.appendLoad(entrySuccessInstructions, fact);

    entrySuccessInstructions
        .append(Utility.createInvoke(fact, world, AjcMemberMaker.perObjectBind(munger.getConcreteAspect())));

    InstructionList testInstructions = munger.getTestInstructions(this, entrySuccessInstructions.getStart(), range
        .getRealStart(), entrySuccessInstructions.getStart());

    entryInstructions.append(testInstructions);
    entryInstructions.append(entrySuccessInstructions);
View Full Code Here

    if (t.resolve(world).isInterface()) {
      return; // Don't initialize statics in
    }
    final InstructionFactory fact = getFactory();

    InstructionList entryInstructions = new InstructionList();
    InstructionList entrySuccessInstructions = new InstructionList();

    BcelWorld.getBcelObjectType(munger.getConcreteAspect());
    String aspectname = munger.getConcreteAspect().getName();

    String ptwField = NameMangler.perTypeWithinFieldForTarget(munger.getConcreteAspect());
    entrySuccessInstructions.append(InstructionFactory.PUSH(fact.getConstantPool(), t.getName()));

    entrySuccessInstructions.append(fact.createInvoke(aspectname, "ajc$createAspectInstance", new ObjectType(aspectname),
        new Type[] { new ObjectType("java.lang.String") }, Constants.INVOKESTATIC));
    entrySuccessInstructions.append(fact.createPutStatic(t.getName(), ptwField, new ObjectType(aspectname)));

    entryInstructions.append(entrySuccessInstructions);

    range.insert(entryInstructions, Range.InsideBefore);
  }
View Full Code Here

      il = initializeAllTjps();
    }

    if (serialVersionUIDRequiresInitialization) {
      InstructionList[] ilSVUID = new InstructionList[1];
      ilSVUID[0] = new InstructionList();
      ilSVUID[0].append(InstructionFactory.PUSH(getConstantPool(), calculatedSerialVersionUID));
      ilSVUID[0].append(getFactory().createFieldAccess(getClassName(), "serialVersionUID", BasicType.LONG,
          Constants.PUTSTATIC));
      if (il == null) {
        il = ilSVUID;
View Full Code Here

TOP

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

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.