Examples of InstructionList


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

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

    final BcelVar testResult = genTempVar(ResolvedType.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

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

    // to the around advice. This includes both the call (which may involve
    // value conversion of the advice arguments) and the return
    // (which may involve value conversion of the return value). Right now
    // we push a null for the unused closure. It's sad, but there it is.

    InstructionList advice = new InstructionList();
    // InstructionHandle adviceMethodInvocation;
    {
      for (Iterator<BcelVar> i = argsToCallLocalAdviceMethodWith.iterator(); i.hasNext();) {
        BcelVar var = i.next();
        var.appendLoad(advice, fact);
      }
      // ??? we don't actually need to push NULL for the closure if we take care
      boolean isAnnoStyleConcreteAspect = munger.getConcreteAspect().isAnnotationStyleAspect();
      boolean isAnnoStyleDeclaringAspect = munger.getDeclaringAspect() != null ? munger.getDeclaringAspect().resolve(world)
          .isAnnotationStyleAspect() : false;

      InstructionList iList = null;
      if (isAnnoStyleConcreteAspect && isAnnoStyleDeclaringAspect) {
        iList = this.loadThisJoinPoint();
        iList.append(Utility.createConversion(getFactory(), LazyClassGen.tjpType, LazyClassGen.proceedingTjpType));
      } else {
        iList = new InstructionList(InstructionConstants.ACONST_NULL);
      }
      advice.append(munger.getAdviceArgSetup(this, null, iList));
      // adviceMethodInvocation =
      advice.append(Utility.createInvoke(fact, localAdviceMethod)); // (fact, getWorld(), munger.getSignature()));
      advice.append(Utility.createConversion(getFactory(), BcelWorld.makeBcelType(mungerSig.getReturnType()),
          extractedShadowMethod.getReturnType(), world.isInJava5Mode()));
      if (!isFallsThrough()) {
        advice.append(InstructionFactory.createReturn(extractedShadowMethod.getReturnType()));
      }
    }

    // now, situate the call inside the possible dynamic tests,
    // and actually add the whole mess to the shadow
    if (!hasDynamicTest) {
      range.append(advice);
    } else {
      InstructionList afterThingie = new InstructionList(InstructionConstants.NOP);
      InstructionList callback = makeCallToCallback(extractedShadowMethod);
      if (terminatesWithReturn()) {
        callback.append(InstructionFactory.createReturn(extractedShadowMethod.getReturnType()));
      } else {
        // InstructionHandle endNop = range.insert(fact.NOP, Range.InsideAfter);
        advice.append(InstructionFactory.createBranchInstruction(Constants.GOTO, afterThingie.getStart()));
      }
      range.append(munger.getTestInstructions(this, advice.getStart(), callback.getStart(), advice.getStart()));
      range.append(advice);
      range.append(callback);
      range.append(afterThingie);
    }

    // now search through the advice, looking for a call to PROCEED.
    // Then we replace the call to proceed with some argument setup, and a
    // call to the extracted method.

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

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

      cg.addAnnotation(agprec);
    }

    // default constructor
    LazyMethodGen init = new LazyMethodGen(Modifier.PUBLIC, Type.VOID, "<init>", EMPTY_TYPES, EMPTY_STRINGS, cg);
    InstructionList cbody = init.getBody();
    cbody.append(InstructionConstants.ALOAD_0);

    cbody.append(cg.getFactory().createInvoke(parentName, "<init>", Type.VOID, EMPTY_TYPES, Constants.INVOKESPECIAL));
    cbody.append(InstructionConstants.RETURN);
    cg.addMethodGen(init);

    for (Iterator it = concreteAspect.pointcuts.iterator(); it.hasNext();) {
      Definition.Pointcut abstractPc = (Definition.Pointcut) it.next();
      // TODO AV - respect visibility instead of opening up as public?
      LazyMethodGen mg = new LazyMethodGen(Modifier.PUBLIC, Type.VOID, abstractPc.name, EMPTY_TYPES, EMPTY_STRINGS, cg);
      SimpleElementValue svg = new SimpleElementValue(ElementValue.STRING, cg.getConstantPool(), abstractPc.expression);
      List elems = new ArrayList();
      elems.add(new NameValuePair("value", svg, cg.getConstantPool()));
      AnnotationGen mag = new AnnotationGen(new ObjectType("org/aspectj/lang/annotation/Pointcut"), elems, true, cg
          .getConstantPool());
      AnnotationAJ max = new BcelAnnotation(mag, world);
      mg.addAnnotation(max);

      InstructionList body = mg.getBody();
      body.append(InstructionConstants.RETURN);
      cg.addMethodGen(mg);
    }

    if (concreteAspect.deows.size() > 0) {
View Full Code Here

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

    return false;
  }

  private InstructionList getRedoneProceedCall(InstructionFactory fact, LazyMethodGen callbackMethod, BcelAdvice munger,
      LazyMethodGen localAdviceMethod, List<BcelVar> argVarList) {
    InstructionList ret = new InstructionList();
    // we have on stack all the arguments for the ADVICE call.
    // we have in frame somewhere all the arguments for the non-advice call.

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

    // System.out.println(proceedMap + " for " + this);
    // System.out.println(argVarList);

    ResolvedType[] proceedParamTypes = world.resolve(munger.getSignature().getParameterTypes());
    // remove this*JoinPoint* as arguments to proceed
    if (munger.getBaseParameterCount() + 1 < proceedParamTypes.length) {
      int len = munger.getBaseParameterCount() + 1;
      ResolvedType[] newTypes = new ResolvedType[len];
      System.arraycopy(proceedParamTypes, 0, newTypes, 0, len);
      proceedParamTypes = newTypes;
    }

    // System.out.println("stateTypes: " + Arrays.asList(stateTypes));
    BcelVar[] proceedVars = Utility.pushAndReturnArrayOfVars(proceedParamTypes, ret, fact, localAdviceMethod);

    Type[] stateTypes = callbackMethod.getArgumentTypes();
    // System.out.println("stateTypes: " + Arrays.asList(stateTypes));

    for (int i = 0, len = stateTypes.length; i < len; i++) {
      Type stateType = stateTypes[i];
      ResolvedType stateTypeX = BcelWorld.fromBcel(stateType).resolve(world);
      if (proceedMap.hasKey(i)) {
        // throw new RuntimeException("unimplemented");
        proceedVars[proceedMap.get(i)].appendLoadAndConvert(ret, fact, stateTypeX);
      } else {
        argVarList.get(i).appendLoad(ret, fact);
      }
    }

    ret.append(Utility.createInvoke(fact, callbackMethod));
    ret.append(Utility.createConversion(fact, callbackMethod.getReturnType(), BcelWorld.makeBcelType(munger.getSignature()
        .getReturnType())));
    return ret;
  }
View Full Code Here

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

   *
   *
   */
  private InstructionList getRedoneProceedCallForAnnotationStyle(InstructionFactory fact, LazyMethodGen callbackMethod,
      BcelAdvice munger, LazyMethodGen localAdviceMethod, List<BcelVar> argVarList, boolean isProceedWithArgs) {
    InstructionList ret = new InstructionList();

    // store the Object[] array on stack if proceed with args
    if (isProceedWithArgs) {

      // STORE the Object[] into a local variable
      Type objectArrayType = Type.OBJECT_ARRAY;
      int theObjectArrayLocalNumber = localAdviceMethod.allocateLocal(objectArrayType);
      ret.append(InstructionFactory.createStore(objectArrayType, theObjectArrayLocalNumber));

      // STORE the ProceedingJoinPoint instance into a local variable
      Type proceedingJpType = Type.getType("Lorg/aspectj/lang/ProceedingJoinPoint;");
      int pjpLocalNumber = localAdviceMethod.allocateLocal(proceedingJpType);
      ret.append(InstructionFactory.createStore(proceedingJpType, pjpLocalNumber));

      // Aim here initially is to determine whether the user will have provided a new
      // this/target in the object array and consume them if they have, leaving us the rest of
      // the arguments to process as regular arguments to the invocation at the original join point

      boolean pointcutBindsThis = bindsThis(munger);
      boolean pointcutBindsTarget = bindsTarget(munger);
      boolean targetIsSameAsThis = getKind().isTargetSameAsThis();

      int nextArgumentToProvideForCallback = 0;

      if (hasThis()) {
        if (!(pointcutBindsTarget && targetIsSameAsThis)) {
          if (pointcutBindsThis) {
            // they have supplied new this as first entry in object array, consume it
            ret.append(InstructionFactory.createLoad(objectArrayType, theObjectArrayLocalNumber));
            ret.append(Utility.createConstant(fact, 0));
            ret.append(InstructionFactory.createArrayLoad(Type.OBJECT));
            ret.append(Utility.createConversion(fact, Type.OBJECT, callbackMethod.getArgumentTypes()[0]));
          } else {
            // use local variable 0
            ret.append(InstructionFactory.createALOAD(0));
          }
          nextArgumentToProvideForCallback++;
        }
      }

      if (hasTarget()) {
        if (pointcutBindsTarget) {
          if (getKind().isTargetSameAsThis()) {
            ret.append(InstructionFactory.createLoad(objectArrayType, theObjectArrayLocalNumber));
            ret.append(Utility.createConstant(fact, pointcutBindsThis ? 1 : 0));
            ret.append(InstructionFactory.createArrayLoad(Type.OBJECT));
            ret.append(Utility.createConversion(fact, Type.OBJECT, callbackMethod.getArgumentTypes()[0]));
          } else {
            int position = (hasThis()/* && pointcutBindsThis */? 1 : 0);
            ret.append(InstructionFactory.createLoad(objectArrayType, theObjectArrayLocalNumber));
            ret.append(Utility.createConstant(fact, position));
            ret.append(InstructionFactory.createArrayLoad(Type.OBJECT));
            ret.append(Utility.createConversion(fact, Type.OBJECT, callbackMethod.getArgumentTypes()[position]));
          }
          nextArgumentToProvideForCallback++;
        } else {
          if (getKind().isTargetSameAsThis()) {
            // ret.append(new ALOAD(0));
          } else {
            ret.append(InstructionFactory.createLoad(localAdviceMethod.getArgumentTypes()[0], hasThis() ? 1 : 0));
            nextArgumentToProvideForCallback++;
          }
        }
      }

      // Where to start in the object array in order to pick up arguments
      int indexIntoObjectArrayForArguments = (pointcutBindsThis ? 1 : 0) + (pointcutBindsTarget ? 1 : 0);

      int len = callbackMethod.getArgumentTypes().length;
      for (int i = nextArgumentToProvideForCallback; i < len; i++) {
        Type stateType = callbackMethod.getArgumentTypes()[i];
        BcelWorld.fromBcel(stateType).resolve(world);
        if ("Lorg/aspectj/lang/JoinPoint;".equals(stateType.getSignature())) {
          ret.append(new InstructionLV(Constants.ALOAD, pjpLocalNumber));
        } else {
          ret.append(InstructionFactory.createLoad(objectArrayType, theObjectArrayLocalNumber));
          ret.append(Utility
              .createConstant(fact, i - nextArgumentToProvideForCallback + indexIntoObjectArrayForArguments));
          ret.append(InstructionFactory.createArrayLoad(Type.OBJECT));
          ret.append(Utility.createConversion(fact, Type.OBJECT, stateType));
        }
      }

    } else {
      Type proceedingJpType = Type.getType("Lorg/aspectj/lang/ProceedingJoinPoint;");
      int localJp = localAdviceMethod.allocateLocal(proceedingJpType);
      ret.append(InstructionFactory.createStore(proceedingJpType, localJp));

      int idx = 0;
      for (int i = 0, len = callbackMethod.getArgumentTypes().length; i < len; i++) {
        Type stateType = callbackMethod.getArgumentTypes()[i];
        /* ResolvedType stateTypeX = */
        BcelWorld.fromBcel(stateType).resolve(world);
        if ("Lorg/aspectj/lang/JoinPoint;".equals(stateType.getSignature())) {
          ret.append(InstructionFactory.createALOAD(localJp));// from localAdvice signature
          // } else if ("Lorg/aspectj/lang/ProceedingJoinPoint;".equals(stateType.getSignature())) {
          // //FIXME ALEX?
          // ret.append(new ALOAD(localJp));// from localAdvice signature
          // // ret.append(fact.createCheckCast(
          // // (ReferenceType) BcelWorld.makeBcelType(stateTypeX)
          // // ));
          // // cast ?
          //
          idx++;
        } else {
          ret.append(InstructionFactory.createLoad(stateType, idx));
          idx += stateType.getSize();
        }
      }
    }

    // do the callback invoke
    ret.append(Utility.createInvoke(fact, callbackMethod));

    // box it again. Handles cases where around advice does return something else than Object
    if (!UnresolvedType.OBJECT.equals(munger.getSignature().getReturnType())) {
      ret.append(Utility.createConversion(fact, callbackMethod.getReturnType(), Type.OBJECT));
    }
    ret.append(Utility.createConversion(fact, callbackMethod.getReturnType(), BcelWorld.makeBcelType(munger.getSignature()
        .getReturnType())));

    return ret;

    //
View Full Code Here

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

    // 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;")));
    }

    InstructionList advice = new InstructionList();
    advice.append(munger.getAdviceArgSetup(this, null, closureInstantiation));

    // invoke the advice
    advice.append(munger.getNonTestAdviceInstructions(this));
    advice.append(returnConversionCode);
    if (getKind() == Shadow.MethodExecution && linenumber > 0) {
      advice.getStart().addTargeter(new LineNumberTag(linenumber));
    }

    if (!hasDynamicTest) {
      range.append(advice);
    } else {
      InstructionList callback = makeCallToCallback(callbackMethod);
      InstructionList postCallback = new InstructionList();
      if (terminatesWithReturn()) {
        callback.append(InstructionFactory.createReturn(callbackMethod.getReturnType()));
      } else {
        advice.append(InstructionFactory.createBranchInstruction(Constants.GOTO, postCallback
            .append(InstructionConstants.NOP)));
      }
      range.append(munger.getTestInstructions(this, advice.getStart(), callback.getStart(), advice.getStart()));
      range.append(advice);
      range.append(callback);
View Full Code Here

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

  }

  // 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) {
      callback.append(BcelRenderer.renderExpr(fact, world, targetVar));
    }
    callback.append(BcelRenderer.renderExprs(fact, world, argVars));
    // remember to render tjps
    if (thisJoinPointVar != null) {
      callback.append(BcelRenderer.renderExpr(fact, world, thisJoinPointVar));
    }
    callback.append(Utility.createInvoke(fact, callbackMethod));
    return callback;
  }
View Full Code Here

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

    // 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);
      holder.appendStore(il, fact);
    }
    return il;
  }
View Full Code Here

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

    InstructionFactory fact = new InstructionFactory(closureClass.getConstantPool());

    // constructor
    LazyMethodGen constructor = new LazyMethodGen(Modifier.PUBLIC, Type.VOID, "<init>", new Type[] { objectArrayType },
        new String[] {}, closureClass);
    InstructionList cbody = constructor.getBody();
    cbody.append(InstructionFactory.createLoad(Type.OBJECT, 0));
    cbody.append(InstructionFactory.createLoad(objectArrayType, 1));
    cbody.append(fact
        .createInvoke(superClassName, "<init>", Type.VOID, new Type[] { objectArrayType }, Constants.INVOKESPECIAL));
    cbody.append(InstructionFactory.createReturn(Type.VOID));

    closureClass.addMethodGen(constructor);

    // method
    LazyMethodGen runMethod = new LazyMethodGen(Modifier.PUBLIC, Type.OBJECT, "run", new Type[] { objectArrayType },
        new String[] {}, closureClass);
    InstructionList mbody = runMethod.getBody();
    BcelVar proceedVar = new BcelVar(UnresolvedType.OBJECTARRAY.resolve(world), 1);
    // int proceedVarIndex = 1;
    BcelVar stateVar = new BcelVar(UnresolvedType.OBJECTARRAY.resolve(world), runMethod.allocateLocal(1));
    // int stateVarIndex = runMethod.allocateLocal(1);
    mbody.append(InstructionFactory.createThis());
    mbody.append(fact.createGetField(superClassName, "state", objectArrayType));
    mbody.append(stateVar.createStore(fact));
    // mbody.append(fact.createStore(objectArrayType, stateVarIndex));

    Type[] stateTypes = callbackMethod.getArgumentTypes();

    for (int i = 0, len = stateTypes.length; i < len; i++) {
      Type stateType = stateTypes[i];
      ResolvedType stateTypeX = BcelWorld.fromBcel(stateType).resolve(world);
      if (proceedMap.hasKey(i)) {
        mbody.append(proceedVar.createConvertableArrayLoad(fact, proceedMap.get(i), stateTypeX));
      } else {
        mbody.append(stateVar.createConvertableArrayLoad(fact, i, stateTypeX));
      }
    }

    mbody.append(Utility.createInvoke(fact, callbackMethod));

    if (getKind() == PreInitialization) {
      mbody.append(Utility.createSet(fact, AjcMemberMaker.aroundClosurePreInitializationField()));
      mbody.append(InstructionConstants.ACONST_NULL);
    } else {
      mbody.append(Utility.createConversion(fact, callbackMethod.getReturnType(), Type.OBJECT));
    }
    mbody.append(InstructionFactory.createReturn(Type.OBJECT));

    closureClass.addMethodGen(runMethod);

    // class
    getEnclosingClass().addGeneratedInner(closureClass);
View Full Code Here

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

    getEnclosingClass().addMethodGen(newMethod, adviceSourceLocation);
    return newMethod;
  }

  private void addPreInitializationReturnCode(LazyMethodGen extractedMethod, Type[] superConstructorTypes) {
    InstructionList body = extractedMethod.getBody();
    final InstructionFactory fact = getFactory();

    BcelVar arrayVar = new BcelVar(world.getCoreType(UnresolvedType.OBJECTARRAY), extractedMethod.allocateLocal(1));

    int len = superConstructorTypes.length;

    body.append(Utility.createConstant(fact, len));

    body.append(fact.createNewArray(Type.OBJECT, (short) 1));
    arrayVar.appendStore(body, fact);

    for (int i = len - 1; i >= 0; i++) {
      // convert thing on top of stack to object
      body.append(Utility.createConversion(fact, superConstructorTypes[i], Type.OBJECT));
      // push object array
      arrayVar.appendLoad(body, fact);
      // swap
      body.append(InstructionConstants.SWAP);
      // do object array store.
      body.append(Utility.createConstant(fact, i));
      body.append(InstructionConstants.SWAP);
      body.append(InstructionFactory.createArrayStore(Type.OBJECT));
    }
    arrayVar.appendLoad(body, fact);
    body.append(InstructionConstants.ARETURN);
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.