Package org.aspectj.apache.bcel.generic

Examples of org.aspectj.apache.bcel.generic.InstructionFactory$MethodObject


   */
  public void initializeArgVars() {
    if (allArgVarsInitialized) {
      return;
    }
    InstructionFactory fact = getFactory();
    int len = getArgCount();
    if (argVars == null) {
      argVars = new BcelVar[len];
    }
    int positionOffset = (hasTarget() ? 1 : 0) + ((hasThis() && !getKind().isTargetSameAsThis()) ? 1 : 0);
View Full Code Here


    // if the shadow is GUARANTEED empty (i.e., there's NOTHING, not even
    // 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));
View Full Code Here

    // a shadow, inside me).
    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
View Full Code Here

        // high priority if our args are on the stack
        getKind().hasHighPriorityExceptions());
  }

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

  public void weavePerTypeWithinAspectInitialization(final BcelAdvice munger, UnresolvedType t) {

    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

  public void weaveCflowEntry(final BcelAdvice munger, final Member cflowField) {
    final boolean isPer = munger.getKind() == AdviceKind.PerCflowBelowEntry || munger.getKind() == AdviceKind.PerCflowEntry;

    final Type objectArrayType = new ArrayType(Type.OBJECT, 1);
    final InstructionFactory fact = getFactory();

    final BcelVar testResult = genTempVar(UnresolvedType.BOOLEAN);

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

      if (munger.hasDynamicTests()) {
        entryInstructions.append(Utility.createConstant(fact, 0));
        testResult.appendStore(entryInstructions, fact);

        entrySuccessInstructions.append(Utility.createConstant(fact, 1));
        testResult.appendStore(entrySuccessInstructions, fact);
      }

      if (isPer) {
        entrySuccessInstructions.append(fact.createInvoke(munger.getConcreteAspect().getName(),
            NameMangler.PERCFLOW_PUSH_METHOD, Type.VOID, new Type[] {}, Constants.INVOKESTATIC));
      } else {
        BcelVar[] cflowStateVars = munger.getExposedStateAsBcelVars(false);

        if (cflowStateVars.length == 0) {
          // This should be getting managed by a counter - lets make sure.
          if (!cflowField.getType().getName().endsWith("CFlowCounter")) {
            throw new RuntimeException("Incorrectly attempting counter operation on stacked cflow");
          }
          entrySuccessInstructions.append(Utility.createGet(fact, cflowField));
          // arrayVar.appendLoad(entrySuccessInstructions, fact);
          entrySuccessInstructions.append(fact.createInvoke(NameMangler.CFLOW_COUNTER_TYPE, "inc", Type.VOID,
              new Type[] {}, Constants.INVOKEVIRTUAL));
        } else {
          BcelVar arrayVar = genTempVar(UnresolvedType.OBJECTARRAY);

          int alen = cflowStateVars.length;
          entrySuccessInstructions.append(Utility.createConstant(fact, alen));
          entrySuccessInstructions.append(fact.createNewArray(Type.OBJECT, (short) 1));
          arrayVar.appendStore(entrySuccessInstructions, fact);

          for (int i = 0; i < alen; i++) {
            arrayVar.appendConvertableArrayStore(entrySuccessInstructions, fact, i, cflowStateVars[i]);
          }

          entrySuccessInstructions.append(Utility.createGet(fact, cflowField));
          arrayVar.appendLoad(entrySuccessInstructions, fact);

          entrySuccessInstructions.append(fact.createInvoke(NameMangler.CFLOW_STACK_TYPE, "push", Type.VOID,
              new Type[] { objectArrayType }, Constants.INVOKEVIRTUAL));
        }
      }

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

    // this is the same for both per and non-per
    weaveAfter(new BcelAdvice(null, null, null, 0, 0, 0, null, munger.getConcreteAspect()) {
      @Override
      public InstructionList getAdviceInstructions(BcelShadow s, BcelVar extraArgVar, InstructionHandle ifNoAdvice) {
        InstructionList exitInstructions = new InstructionList();
        if (munger.hasDynamicTests()) {
          testResult.appendLoad(exitInstructions, fact);
          exitInstructions.append(InstructionFactory.createBranchInstruction(Constants.IFEQ, ifNoAdvice));
        }
        exitInstructions.append(Utility.createGet(fact, cflowField));
        if (munger.getKind() != AdviceKind.PerCflowEntry && munger.getKind() != AdviceKind.PerCflowBelowEntry
            && munger.getExposedStateAsBcelVars(false).length == 0) {
          exitInstructions.append(fact.createInvoke(NameMangler.CFLOW_COUNTER_TYPE, "dec", Type.VOID, new Type[] {},
              Constants.INVOKEVIRTUAL));
        } else {
          exitInstructions.append(fact.createInvoke(NameMangler.CFLOW_STACK_TYPE, "pop", Type.VOID, new Type[] {},
              Constants.INVOKEVIRTUAL));
        }
        return exitInstructions;
      }
    });
View Full Code Here

    IntMap varMap = IntMap.idMap(nVars);
    for (int i = extraParamOffset; i < nVars; i++) {
      varMap.put(i - extraParamOffset, i);
    }

    final InstructionFactory fact = getFactory();

    localAdviceMethod.getBody().insert(
        BcelClassWeaver.genInlineInstructions(adviceMethod, localAdviceMethod, varMap, fact, true));

    localAdviceMethod.setMaxLocals(nVars);
View Full Code Here

      return node;
    }
  }

  public void weaveAroundClosure(BcelAdvice munger, boolean hasDynamicTest) {
    InstructionFactory fact = getFactory();

    enclosingMethod.setCanInline(false);

    int linenumber = getSourceLine();
    // MOVE OUT ALL THE INSTRUCTIONS IN MY SHADOW INTO ANOTHER METHOD!
    LazyMethodGen callbackMethod = extractShadowInstructionsIntoNewMethod(
        NameMangler.aroundShadowMethodName(getSignature(), getEnclosingClass().getNewGeneratedNameTag()), 0,
        munger.getSourceLocation(), new ArrayList<String>());

    BcelVar[] adviceVars = munger.getExposedStateAsBcelVars(true);

    String closureClassName = NameMangler.makeClosureClassName(getEnclosingClass().getType(), getEnclosingClass()
        .getNewGeneratedNameTag());

    Member constructorSig = new MemberImpl(Member.CONSTRUCTOR, UnresolvedType.forName(closureClassName), 0, "<init>",
        "([Ljava/lang/Object;)V");

    BcelVar closureHolder = null;

    // This is not being used currently since getKind() == preinitializaiton
    // cannot happen in around advice
    if (getKind() == PreInitialization) {
      closureHolder = genTempVar(AjcMemberMaker.AROUND_CLOSURE_TYPE);
    }

    InstructionList closureInstantiation = makeClosureInstantiation(constructorSig, closureHolder);

    /* LazyMethodGen constructor = */
    makeClosureClassAndReturnConstructor(closureClassName, callbackMethod, makeProceedArgumentMap(adviceVars));

    InstructionList returnConversionCode;
    if (getKind() == PreInitialization) {
      returnConversionCode = new InstructionList();

      BcelVar stateTempVar = genTempVar(UnresolvedType.OBJECTARRAY);
      closureHolder.appendLoad(returnConversionCode, fact);

      returnConversionCode.append(Utility.createInvoke(fact, world, AjcMemberMaker.aroundClosurePreInitializationGetter()));
      stateTempVar.appendStore(returnConversionCode, fact);

      Type[] stateTypes = getSuperConstructorParameterTypes();

      returnConversionCode.append(InstructionConstants.ALOAD_0); // put "this" back on the stack
      for (int i = 0, len = stateTypes.length; i < len; i++) {
        UnresolvedType bcelTX = BcelWorld.fromBcel(stateTypes[i]);
        ResolvedType stateRTX = world.resolve(bcelTX, true);
        if (stateRTX.isMissing()) {
          world.getLint().cantFindType.signal(
              new String[] { WeaverMessages.format(WeaverMessages.CANT_FIND_TYPE_DURING_AROUND_WEAVE_PREINIT,
                  bcelTX.getClassName()) }, getSourceLocation(),
              new ISourceLocation[] { munger.getSourceLocation() });
          // IMessage msg = new Message(
          // WeaverMessages.format(WeaverMessages.CANT_FIND_TYPE_DURING_AROUND_WEAVE_PREINIT,bcelTX.getClassName()),
          // "",IMessage.ERROR,getSourceLocation(),null,
          // new ISourceLocation[]{ munger.getSourceLocation()});
          // world.getMessageHandler().handleMessage(msg);
        }
        stateTempVar.appendConvertableArrayLoad(returnConversionCode, fact, i, stateRTX);
      }
    } else {
      // pr226201
      Member mungerSignature = munger.getSignature();
      if (munger.getSignature() instanceof ResolvedMember) {
        if (((ResolvedMember) mungerSignature).hasBackingGenericMember()) {
          mungerSignature = ((ResolvedMember) mungerSignature).getBackingGenericMember();
        }
      }
      UnresolvedType returnType = mungerSignature.getReturnType();
      returnConversionCode = Utility.createConversion(getFactory(), BcelWorld.makeBcelType(returnType),
          callbackMethod.getReturnType(), world.isInJava5Mode());
      if (!isFallsThrough()) {
        returnConversionCode.append(InstructionFactory.createReturn(callbackMethod.getReturnType()));
      }
    }

    // initialize the bit flags for this shadow
    int bitflags = 0x000000;
    if (getKind().isTargetSameAsThis()) {
      bitflags |= 0x010000;
    }
    if (hasThis()) {
      bitflags |= 0x001000;
    }
    if (bindsThis(munger)) {
      bitflags |= 0x000100;
    }
    if (hasTarget()) {
      bitflags |= 0x000010;
    }
    if (bindsTarget(munger)) {
      bitflags |= 0x000001;
    }

    // ATAJ for @AJ aspect we need to link the closure with the joinpoint instance
    if (munger.getConcreteAspect() != null && munger.getConcreteAspect().isAnnotationStyleAspect()
        && munger.getDeclaringAspect() != null && munger.getDeclaringAspect().resolve(world).isAnnotationStyleAspect()) {
      // stick the bitflags on the stack and call the variant of linkClosureAndJoinPoint that takes an int
      closureInstantiation.append(fact.createConstant(Integer.valueOf(bitflags)));
      closureInstantiation.append(Utility.createInvoke(getFactory(), getWorld(),
          new MemberImpl(Member.METHOD, UnresolvedType.forName("org.aspectj.runtime.internal.AroundClosure"),
              Modifier.PUBLIC, "linkClosureAndJoinPoint", "(I)Lorg/aspectj/lang/ProceedingJoinPoint;")));
    }

View Full Code Here

    }
  }

  // exposed for testing
  InstructionList makeCallToCallback(LazyMethodGen callbackMethod) {
    InstructionFactory fact = getFactory();
    InstructionList callback = new InstructionList();
    if (thisVar != null) {
      callback.append(InstructionConstants.ALOAD_0);
    }
    if (targetVar != null && targetVar != thisVar) {
View Full Code Here

  /** side-effect-free */
  private InstructionList makeClosureInstantiation(Member constructor, BcelVar holder) {

    // LazyMethodGen constructor) {
    InstructionFactory fact = getFactory();
    BcelVar arrayVar = genTempVar(UnresolvedType.OBJECTARRAY);
    // final Type objectArrayType = new ArrayType(Type.OBJECT, 1);
    final InstructionList il = new InstructionList();
    int alen = getArgCount() + (thisVar == null ? 0 : 1) + ((targetVar != null && targetVar != thisVar) ? 1 : 0)
        + (thisJoinPointVar == null ? 0 : 1);
    il.append(Utility.createConstant(fact, alen));
    il.append(fact.createNewArray(Type.OBJECT, (short) 1));
    arrayVar.appendStore(il, fact);

    int stateIndex = 0;
    if (thisVar != null) {
      arrayVar.appendConvertableArrayStore(il, fact, stateIndex, thisVar);
      thisVar.setPositionInAroundState(stateIndex);
      stateIndex++;
    }
    if (targetVar != null && targetVar != thisVar) {
      arrayVar.appendConvertableArrayStore(il, fact, stateIndex, targetVar);
      targetVar.setPositionInAroundState(stateIndex);
      stateIndex++;
    }
    for (int i = 0, len = getArgCount(); i < len; i++) {
      arrayVar.appendConvertableArrayStore(il, fact, stateIndex, argVars[i]);
      argVars[i].setPositionInAroundState(stateIndex);
      stateIndex++;
    }
    if (thisJoinPointVar != null) {
      arrayVar.appendConvertableArrayStore(il, fact, stateIndex, thisJoinPointVar);
      thisJoinPointVar.setPositionInAroundState(stateIndex);
      stateIndex++;
    }
    il.append(fact.createNew(new ObjectType(constructor.getDeclaringType().getName())));
    il.append(InstructionConstants.DUP);
    arrayVar.appendLoad(il, fact);
    il.append(Utility.createInvoke(fact, world, constructor));
    if (getKind() == PreInitialization) {
      il.append(InstructionConstants.DUP);
View Full Code Here

TOP

Related Classes of org.aspectj.apache.bcel.generic.InstructionFactory$MethodObject

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.