Package org.aspectj.apache.bcel.generic

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


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

    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

    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

  }

  public InstructionList getAdviceArgSetup(BcelShadow shadow, BcelVar extraVar, InstructionList closureInstantiation) {
    InstructionFactory fact = shadow.getFactory();
    BcelWorld world = shadow.getWorld();
    InstructionList il = new InstructionList();

    // if (targetAspectField != null) {
    // il.append(fact.createFieldAccess(
    // targetAspectField.getDeclaringType().getName(),
    // targetAspectField.getName(),
    // BcelWorld.makeBcelType(targetAspectField.getType()),
    // Constants.GETSTATIC));
    // }
    //
    // System.err.println("BcelAdvice: " + exposedState);

    if (exposedState.getAspectInstance() != null) {
      il.append(BcelRenderer.renderExpr(fact, world, exposedState.getAspectInstance()));
    }
    // pr121385
    boolean x = this.getDeclaringAspect().resolve(world).isAnnotationStyleAspect();
    final boolean isAnnotationStyleAspect = getConcreteAspect() != null && getConcreteAspect().isAnnotationStyleAspect() && x;
    boolean previousIsClosure = false;
    for (int i = 0, len = exposedState.size(); i < len; i++) {
      if (exposedState.isErroneousVar(i)) {
        continue; // Erroneous vars have already had error msgs reported!
      }
      BcelVar v = (BcelVar) exposedState.get(i);

      if (v == null) {
        // if not @AJ aspect, go on with the regular binding handling
        if (!isAnnotationStyleAspect) {

        } else {
          // ATAJ: for @AJ aspects, handle implicit binding of xxJoinPoint
          // if (getKind() == AdviceKind.Around) {
          // previousIsClosure = true;
          // il.append(closureInstantiation);
          if ("Lorg/aspectj/lang/ProceedingJoinPoint;".equals(getSignature().getParameterTypes()[i].getSignature())) {
            // make sure we are in an around, since we deal with the closure, not the arg here
            if (getKind() != AdviceKind.Around) {
              previousIsClosure = false;
              getConcreteAspect()
                  .getWorld()
                  .getMessageHandler()
                  .handleMessage(
                      new Message("use of ProceedingJoinPoint is allowed only on around advice (" + "arg "
                          + i + " in " + toString() + ")", this.getSourceLocation(), true));
              // try to avoid verify error and pass in null
              il.append(InstructionConstants.ACONST_NULL);
            } else {
              if (previousIsClosure) {
                il.append(InstructionConstants.DUP);
              } else {
                previousIsClosure = true;
                il.append(closureInstantiation.copy());
              }
            }
          } else if ("Lorg/aspectj/lang/JoinPoint$StaticPart;".equals(getSignature().getParameterTypes()[i]
              .getSignature())) {
            previousIsClosure = false;
            if ((getExtraParameterFlags() & ThisJoinPointStaticPart) != 0) {
              shadow.getThisJoinPointStaticPartBcelVar().appendLoad(il, fact);
            }
          } else if ("Lorg/aspectj/lang/JoinPoint;".equals(getSignature().getParameterTypes()[i].getSignature())) {
            previousIsClosure = false;
            if ((getExtraParameterFlags() & ThisJoinPoint) != 0) {
              il.append(shadow.loadThisJoinPoint());
            }
          } else if ("Lorg/aspectj/lang/JoinPoint$EnclosingStaticPart;".equals(getSignature().getParameterTypes()[i]
              .getSignature())) {
            previousIsClosure = false;
            if ((getExtraParameterFlags() & ThisEnclosingJoinPointStaticPart) != 0) {
              shadow.getThisEnclosingJoinPointStaticPartBcelVar().appendLoad(il, fact);
            }
          } else if (hasExtraParameter()) {
            previousIsClosure = false;
            extraVar.appendLoadAndConvert(il, fact, getExtraParameterType().resolve(world));
          } else {
            previousIsClosure = false;
            getConcreteAspect()
                .getWorld()
                .getMessageHandler()
                .handleMessage(
                    new Message("use of ProceedingJoinPoint is allowed only on around advice (" + "arg " + i
                        + " in " + toString() + ")", this.getSourceLocation(), true));
            // try to avoid verify error and pass in null
            il.append(InstructionConstants.ACONST_NULL);
          }
        }
      } else {
        UnresolvedType desiredTy = getBindingParameterTypes()[i];
        v.appendLoadAndConvert(il, fact, desiredTy.resolve(world));
      }
    }

    // ATAJ: for code style aspect, handles the extraFlag as usual ie not
    // in the middle of the formal bindings but at the end, in a rock solid ordering
    if (!isAnnotationStyleAspect) {
      if (getKind() == AdviceKind.Around) {
        il.append(closureInstantiation);
      } else if (hasExtraParameter()) {
        extraVar.appendLoadAndConvert(il, fact, getExtraParameterType().resolve(world));
      }

      // handle thisJoinPoint parameters
      // these need to be in that same order as parameters in
      // org.aspectj.ajdt.internal.compiler.ast.AdviceDeclaration
      if ((getExtraParameterFlags() & ThisJoinPointStaticPart) != 0) {
        shadow.getThisJoinPointStaticPartBcelVar().appendLoad(il, fact);
      }

      if ((getExtraParameterFlags() & ThisJoinPoint) != 0) {
        il.append(shadow.loadThisJoinPoint());
      }

      if ((getExtraParameterFlags() & ThisEnclosingJoinPointStaticPart) != 0) {
        shadow.getThisEnclosingJoinPointStaticPartBcelVar().appendLoad(il, fact);
      }
View Full Code Here

    return il;
  }

  public InstructionList getNonTestAdviceInstructions(BcelShadow shadow) {
    return new InstructionList(Utility.createInvoke(shadow.getFactory(), shadow.getWorld(), getOriginalSignature()));
  }
View Full Code Here

      // flag the effective signature, so that we can deobfuscate the signature to apply method call pointcut
      method.addAttribute(Utility.bcelAttribute(methodAttributes.get(1), m_aspectGen.getConstantPool()));

      inlineAccessorMethodGens.add(method);

      InstructionList il = method.getBody();
      int register = 0;
      for (int i = 0; i < inlineAccessor.getParameterTypes().length; i++) {
        UnresolvedType typeX = inlineAccessor.getParameterTypes()[i];
        Type type = BcelWorld.makeBcelType(typeX);
        il.append(InstructionFactory.createLoad(type, register));
        register += type.getSize();
      }
      il.append(Utility.createInvoke(factory, Modifier.isStatic(resolvedMember.getModifiers()) ? Constants.INVOKESTATIC
          : Constants.INVOKEVIRTUAL, resolvedMember));
      il.append(InstructionFactory.createReturn(BcelWorld.makeBcelType(inlineAccessor.getReturnType())));

      m_inlineAccessorBcelMethods.put(accessor, new BcelMethod(m_aspectGen.getBcelObjectType(), method.getMethod(),
          methodAttributes));
    }
    return inlineAccessor;
View Full Code Here

      // flag the effective signature, so that we can deobfuscate the signature to apply method call pointcut
      method.addAttribute(Utility.bcelAttribute(methodAttributes.get(1), m_aspectGen.getConstantPool()));

      inlineAccessorMethodGens.add(method);

      InstructionList il = method.getBody();
      il.append(InstructionConstants.ALOAD_0);
      int register = 1;
      for (int i = 0; i < inlineAccessor.getParameterTypes().length; i++) {
        UnresolvedType typeX = inlineAccessor.getParameterTypes()[i];
        Type type = BcelWorld.makeBcelType(typeX);
        il.append(InstructionFactory.createLoad(type, register));
        register += type.getSize();
      }
      il.append(Utility.createInvoke(factory, Constants.INVOKESPECIAL, resolvedMember));
      il.append(InstructionFactory.createReturn(BcelWorld.makeBcelType(inlineAccessor.getReturnType())));

      m_inlineAccessorBcelMethods.put(accessor, new BcelMethod(m_aspectGen.getBcelObjectType(), method.getMethod(),
          methodAttributes));
    }
    return inlineAccessor;
View Full Code Here

      method.addAttribute(Utility.bcelAttribute(methodAttributes.get(0), m_aspectGen.getConstantPool()));
      method.addAttribute(Utility.bcelAttribute(methodAttributes.get(1), m_aspectGen.getConstantPool()));

      inlineAccessorMethodGens.add(method);

      InstructionList il = method.getBody();
      if (Modifier.isStatic(resolvedMember.getModifiers())) {
        // field accessed is static so no "this" as accessor sole parameter
      } else {
        il.append(InstructionConstants.ALOAD_0);
      }
      il.append(Utility.createGet(factory, resolvedMember));
      il.append(InstructionFactory.createReturn(BcelWorld.makeBcelType(inlineAccessor.getReturnType())));

      m_inlineAccessorBcelMethods.put(accessor, new BcelMethod(m_aspectGen.getBcelObjectType(), method.getMethod(),
          methodAttributes));
    }
    return inlineAccessor;
View Full Code Here

      // flag the effective signature, so that we can deobfuscate the signature to apply method call pointcut
      method.addAttribute(Utility.bcelAttribute(methodAttributes.get(1), m_aspectGen.getConstantPool()));

      inlineAccessorMethodGens.add(method);

      InstructionList il = method.getBody();
      if (Modifier.isStatic(resolvedMember.getModifiers())) {
        // field accessed is static so sole parameter is field value to be set
        il.append(InstructionFactory.createLoad(BcelWorld.makeBcelType(resolvedMember.getReturnType()), 0));
      } else {
        il.append(InstructionConstants.ALOAD_0);
        il.append(InstructionFactory.createLoad(BcelWorld.makeBcelType(resolvedMember.getReturnType()), 1));
      }
      il.append(Utility.createSet(factory, resolvedMember));
      il.append(InstructionConstants.RETURN);
      m_inlineAccessorBcelMethods.put(accessor, new BcelMethod(m_aspectGen.getBcelObjectType(), method.getMethod(),
          methodAttributes));
    }
    return inlineAccessor;
  }
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.