Examples of InstructionList


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

  }

  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

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

    return il;
  }

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

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

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

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

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

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

      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

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

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

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

  InstructionList getAdviceInstructions(BcelShadow s, BcelVar extraArgVar, InstructionHandle ifNoAdvice) {
    BcelShadow shadow = s;
    InstructionFactory fact = shadow.getFactory();
    BcelWorld world = shadow.getWorld();

    InstructionList il = new InstructionList();

    // we test to see if we have the right kind of thing...
    // after throwing does this just by the exception mechanism.
    if (hasExtraParameter() && getKind() == AdviceKind.AfterReturning) {
      UnresolvedType extraParameterType = getExtraParameterType();
      if (!extraParameterType.equals(UnresolvedType.OBJECT) && !extraParameterType.isPrimitiveType()) {
        il.append(BcelRenderer.renderTest(fact, world,
            Test.makeInstanceof(extraArgVar, getExtraParameterType().resolve(world)), null, ifNoAdvice, null));
      }
    }
    il.append(getAdviceArgSetup(shadow, extraArgVar, null));
    il.append(getNonTestAdviceInstructions(shadow));

    InstructionHandle ifYesAdvice = il.getStart();
    il.insert(getTestInstructions(shadow, ifYesAdvice, ifNoAdvice, ifYesAdvice));

    // If inserting instructions at the start of a method, we need a nice line number for this entry
    // in the stack trace
    if (shadow.getKind() == Shadow.MethodExecution && getKind() == AdviceKind.Before) {
      int lineNumber = 0;
      // Uncomment this code if you think we should use the method decl line number when it exists...
      // // If the advised join point is in a class built by AspectJ, we can use the declaration line number
      // boolean b = shadow.getEnclosingMethod().getMemberView().hasDeclarationLineNumberInfo();
      // if (b) {
      // lineNumber = shadow.getEnclosingMethod().getMemberView().getDeclarationLineNumber();
      // } else { // If it wasn't, the best we can do is the line number of the first instruction in the method
      lineNumber = shadow.getEnclosingMethod().getMemberView().getLineNumberOfFirstInstruction();
      // }
      InstructionHandle start = il.getStart();
      if (lineNumber > 0) {
        start.addTargeter(new LineNumberTag(lineNumber));
      }
      // Fix up the local variables: find any that have a startPC of 0 and ensure they target the new start of the method
      LocalVariableTable lvt = shadow.getEnclosingMethod().getMemberView().getMethod().getLocalVariableTable();
View Full Code Here

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

    List<LazyMethodGen> mgs = newParentTarget.getMethodGens();

    // Look for ctors to modify
    for (LazyMethodGen aMethod : mgs) {
      if (LazyMethodGen.isConstructor(aMethod)) {
        InstructionList insList = aMethod.getBody();
        InstructionHandle handle = insList.getStart();
        while (handle != null) {
          if (handle.getInstruction().opcode == Constants.INVOKESPECIAL) {
            ConstantPool cpg = newParentTarget.getConstantPool();
            InvokeInstruction invokeSpecial = (InvokeInstruction) handle.getInstruction();
            if (invokeSpecial.getClassName(cpg).equals(currentParent)
View Full Code Here

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

    return false;
  }

  private void addFieldGetter(LazyClassGen gen, ResolvedMember field, ResolvedMember accessMethod) {
    LazyMethodGen mg = makeMethodGen(gen, accessMethod);
    InstructionList il = new InstructionList();
    InstructionFactory fact = gen.getFactory();
    if (Modifier.isStatic(field.getModifiers())) {
      il.append(fact.createFieldAccess(gen.getClassName(), field.getName(), BcelWorld.makeBcelType(field.getType()),
          Constants.GETSTATIC));
    } else {
      il.append(InstructionConstants.ALOAD_0);
      il.append(fact.createFieldAccess(gen.getClassName(), field.getName(), BcelWorld.makeBcelType(field.getType()),
          Constants.GETFIELD));
    }
    il.append(InstructionFactory.createReturn(BcelWorld.makeBcelType(field.getType())));
    mg.getBody().insert(il);

    gen.addMethodGen(mg, getSignature().getSourceLocation());
  }
View Full Code Here

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

    gen.addMethodGen(mg, getSignature().getSourceLocation());
  }

  private void addFieldSetter(LazyClassGen gen, ResolvedMember field, ResolvedMember accessMethod) {
    LazyMethodGen mg = makeMethodGen(gen, accessMethod);
    InstructionList il = new InstructionList();
    InstructionFactory fact = gen.getFactory();
    Type fieldType = BcelWorld.makeBcelType(field.getType());

    if (Modifier.isStatic(field.getModifiers())) {
      il.append(InstructionFactory.createLoad(fieldType, 0));
      il.append(fact.createFieldAccess(gen.getClassName(), field.getName(), fieldType, Constants.PUTSTATIC));
    } else {
      il.append(InstructionConstants.ALOAD_0);
      il.append(InstructionFactory.createLoad(fieldType, 1));
      il.append(fact.createFieldAccess(gen.getClassName(), field.getName(), fieldType, Constants.PUTFIELD));
    }
    il.append(InstructionFactory.createReturn(Type.VOID));
    mg.getBody().insert(il);

    gen.addMethodGen(mg, getSignature().getSourceLocation());
  }
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.