Package org.aspectj.apache.bcel.generic

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


      // Now we add it to the new instruction list.
      InstructionHandle freshIh;
      if (freshI instanceof InstructionBranch) {
        // If it's a targeting instruction,
        // update the target(s) to point to the new copy instead of the old copy.
        InstructionBranch oldBranch = (InstructionBranch) oldI;
        InstructionBranch freshBranch = (InstructionBranch) freshI;
        InstructionHandle oldTarget = oldBranch.getTarget();
        oldTarget.removeTargeter(oldBranch);
        oldTarget.addTargeter(freshBranch);
        if (freshBranch instanceof InstructionSelect) {
          InstructionSelect oldSelect = (InstructionSelect) oldI;
View Full Code Here


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

        Field annotationCachingField = shadow.getEnclosingClass().getAnnotationCachingField(shadow, toType, isWithin);

        // Basic idea here is to check if the cached field is null, if it is then initialize it, otherwise use it
        il.append(fact.createGetStatic(shadow.getEnclosingClass().getName(), annotationCachingField.getName(), jlAnnotation));
        il.append(InstructionConstants.DUP);
        InstructionBranch ifNonNull = InstructionFactory.createBranchInstruction(Constants.IFNONNULL, null);
        il.append(ifNonNull);
        il.append(InstructionConstants.POP);
        il.append(fact.createConstant(BcelWorld.makeBcelType(containingType)));

        il.append(fact.createConstant(member.getName()));
        buildArray(il, fact, jlClass, paramTypes, 1);
        // OPTIMIZE cache result of getDeclaredMethod?
        il.append(fact.createInvoke("java/lang/Class", "getDeclaredMethod", jlrMethod,
            new Type[] { jlString, jlClassArray }, Constants.INVOKEVIRTUAL));
        il.append(pushConstant);// fact.createConstant(new ObjectType(toType.getName())));
        il.append(fact.createInvoke("java/lang/reflect/Method", "getAnnotation", jlaAnnotation, new Type[] { jlClass },
            Constants.INVOKEVIRTUAL));
        il.append(InstructionConstants.DUP);
        il.append(fact.createPutStatic(shadow.getEnclosingClass().getName(), annotationCachingField.getName(), jlAnnotation));
        InstructionHandle ifNullElse = il.append(InstructionConstants.NOP);
        ifNonNull.setTarget(ifNullElse);

      } else { // init/preinit/ctor-call/ctor-exec
        il.append(fact.createConstant(BcelWorld.makeBcelType(containingType)));
        buildArray(il, fact, jlClass, paramTypes, 1);
        Type jlrCtor = BcelWorld.makeBcelType(UnresolvedType.JAVA_LANG_REFLECT_CONSTRUCTOR);
View Full Code Here

    String annotationCachingFieldName = annotationCachingField.getName();

    // Basic idea here is to check if the cached field is null, if it is then initialize it, otherwise use it
    il.append(fact.createGetStatic(shadowEnclosingClass.getName(), annotationCachingFieldName, jlaAnnotation));
    il.appendDUP();
    InstructionBranch ifNonNull = new InstructionBranch(Constants.IFNONNULL, null);
    il.append(ifNonNull);
    il.appendPOP();

    // get the field of interest
    il.append(fact.createConstant(BcelWorld.makeBcelType(containingType)));
    il.append(fact.createConstant(member.getName()));
    il.append(fact.createInvoke("java/lang/Class", "getDeclaredField", jlrField, new Type[] { jlString },
        Constants.INVOKEVIRTUAL));
    il.append(pushConstantAnnotationType);
    il.append(fact.createInvoke("java/lang/reflect/Field", "getAnnotation", jlaAnnotation, new Type[] { jlClass },
        Constants.INVOKEVIRTUAL));
    il.appendDUP();
    il.append(fact.createPutStatic(shadowEnclosingClass.getName(), annotationCachingFieldName, jlaAnnotation));
    InstructionHandle ifNullElse = il.appendNOP();
    ifNonNull.setTarget(ifNullElse);
  }
View Full Code Here

    flagAsSynthetic(method, false);
    classGen.addMethodGen(method);

    InstructionList il = method.getBody();
    il.append(Utility.createGet(factory, AjcMemberMaker.perSingletonField(aspectType)));
    InstructionBranch ifNotNull = InstructionFactory.createBranchInstruction(Constants.IFNONNULL, null);
    il.append(ifNotNull);
    il.append(factory.createNew(AjcMemberMaker.NO_ASPECT_BOUND_EXCEPTION.getName()));
    il.append(InstructionConstants.DUP);
    il.append(InstructionFactory.PUSH(classGen.getConstantPool(), aspectType.getName()));
    il.append(Utility.createGet(factory, AjcMemberMaker.initFailureCauseField(aspectType)));
    il.append(factory.createInvoke(AjcMemberMaker.NO_ASPECT_BOUND_EXCEPTION.getName(), "<init>", Type.VOID, new Type[] {
        Type.STRING, new ObjectType("java.lang.Throwable") }, Constants.INVOKESPECIAL));
    il.append(InstructionConstants.ATHROW);
    InstructionHandle ifElse = il.append(Utility.createGet(factory, AjcMemberMaker.perSingletonField(aspectType)));
    il.append(InstructionFactory.createReturn(Type.OBJECT));
    ifNotNull.setTarget(ifElse);
  }
View Full Code Here

    flagAsSynthetic(method, false);
    classGen.addMethodGen(method);

    InstructionList il = method.getBody();
    il.append(Utility.createGet(factory, AjcMemberMaker.perSingletonField(aspectType)));
    InstructionBranch ifNull = InstructionFactory.createBranchInstruction(Constants.IFNULL, null);
    il.append(ifNull);
    il.append(InstructionFactory.PUSH(classGen.getConstantPool(), true));
    il.append(InstructionFactory.createReturn(Type.INT));
    InstructionHandle ifElse = il.append(InstructionFactory.PUSH(classGen.getConstantPool(), false));
    il.append(InstructionFactory.createReturn(Type.INT));
    ifNull.setTarget(ifElse);
  }
View Full Code Here

    // patch <clinit> to delegate to ajc$postClinit at the end
    LazyMethodGen clinit = classGen.getStaticInitializer();
    il = new InstructionList();
    InstructionHandle tryStart = il.append(factory.createInvoke(aspectType.getName(), NameMangler.AJC_POST_CLINIT_NAME,
        Type.VOID, Type.NO_ARGS, Constants.INVOKESTATIC));
    InstructionBranch tryEnd = InstructionFactory.createBranchInstruction(Constants.GOTO, null);
    il.append(tryEnd);
    InstructionHandle handler = il.append(InstructionConstants.ASTORE_0);
    il.append(InstructionConstants.ALOAD_0);
    il.append(Utility.createSet(factory, AjcMemberMaker.initFailureCauseField(aspectType)));
    il.append(InstructionFactory.createReturn(Type.VOID));
    tryEnd.setTarget(il.getEnd());

    // replace the original "return" with a "nop"
    // TODO AV - a bit odd, looks like Bcel alters bytecode and has a IMPDEP1 in its representation
    if (clinit.getBody().getEnd().getInstruction().opcode == Constants.IMPDEP1) {
      clinit.getBody().getEnd().getPrev().setInstruction(InstructionConstants.NOP);
View Full Code Here

    classGen.addMethodGen(method);

    InstructionList il = method.getBody();
    il.append(InstructionConstants.ALOAD_0);
    il.append(factory.createInstanceOf(interfaceType));
    InstructionBranch ifEq = InstructionFactory.createBranchInstruction(Constants.IFEQ, null);
    il.append(ifEq);
    il.append(InstructionConstants.ALOAD_0);
    il.append(factory.createCheckCast(interfaceType));
    il.append(Utility.createInvoke(factory, Constants.INVOKEINTERFACE, AjcMemberMaker.perObjectInterfaceGet(aspectType)));
    il.append(InstructionConstants.DUP);
    InstructionBranch ifNull = InstructionFactory.createBranchInstruction(Constants.IFNULL, null);
    il.append(ifNull);
    il.append(InstructionFactory.createReturn(BcelWorld.makeBcelType(aspectType)));
    InstructionHandle ifNullElse = il.append(InstructionConstants.POP);
    ifNull.setTarget(ifNullElse);
    InstructionHandle ifEqElse = il.append(factory.createNew(AjcMemberMaker.NO_ASPECT_BOUND_EXCEPTION.getName()));
    ifEq.setTarget(ifEqElse);
    il.append(InstructionConstants.DUP);
    il.append(factory.createInvoke(AjcMemberMaker.NO_ASPECT_BOUND_EXCEPTION.getName(), "<init>", Type.VOID, Type.NO_ARGS,
        Constants.INVOKESPECIAL));
View Full Code Here

    classGen.addMethodGen(method);

    InstructionList il = method.getBody();
    il.append(InstructionConstants.ALOAD_0);
    il.append(factory.createInstanceOf(interfaceType));
    InstructionBranch ifEq = InstructionFactory.createBranchInstruction(Constants.IFEQ, null);
    il.append(ifEq);
    il.append(InstructionConstants.ALOAD_0);
    il.append(factory.createCheckCast(interfaceType));
    il.append(Utility.createInvoke(factory, Constants.INVOKEINTERFACE, AjcMemberMaker.perObjectInterfaceGet(aspectType)));
    InstructionBranch ifNull = InstructionFactory.createBranchInstruction(Constants.IFNULL, null);
    il.append(ifNull);
    il.append(InstructionConstants.ICONST_1);
    il.append(InstructionFactory.createReturn(Type.INT));
    InstructionHandle ifEqElse = il.append(InstructionConstants.ICONST_0);
    ifEq.setTarget(ifEqElse);
    ifNull.setTarget(ifEqElse);
    il.append(InstructionFactory.createReturn(Type.INT));
  }
View Full Code Here

    classGen.addMethodGen(method);

    InstructionList il = method.getBody();
    il.append(InstructionConstants.ALOAD_0);
    il.append(factory.createInstanceOf(interfaceType));
    InstructionBranch ifEq = InstructionFactory.createBranchInstruction(Constants.IFEQ, null);
    il.append(ifEq);
    il.append(InstructionConstants.ALOAD_0);
    il.append(factory.createCheckCast(interfaceType));
    il.append(Utility.createInvoke(factory, Constants.INVOKEINTERFACE, AjcMemberMaker.perObjectInterfaceGet(aspectType)));
    InstructionBranch ifNonNull = InstructionFactory.createBranchInstruction(Constants.IFNONNULL, null);
    il.append(ifNonNull);
    il.append(InstructionConstants.ALOAD_0);
    il.append(factory.createCheckCast(interfaceType));
    il.append(factory.createNew(aspectType.getName()));
    il.append(InstructionConstants.DUP);
    il.append(factory.createInvoke(aspectType.getName(), "<init>", Type.VOID, Type.NO_ARGS, Constants.INVOKESPECIAL));
    il.append(Utility.createInvoke(factory, Constants.INVOKEINTERFACE, AjcMemberMaker.perObjectInterfaceSet(aspectType)));
    InstructionHandle end = il.append(InstructionFactory.createReturn(Type.VOID));
    ifEq.setTarget(end);
    ifNonNull.setTarget(end);
  }
View Full Code Here

TOP

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

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.