Package org.aspectj.apache.bcel.generic

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


  // Non child type, so it comes from a real type in the world.
  public LazyClassGen(BcelObjectType myType) {
    myGen = new ClassGen(myType.getJavaClass());
    cp = myGen.getConstantPool();
    fact = new InstructionFactory(myGen, cp);
    this.myType = myType;
    world = myType.getResolvedTypeX().getWorld();

    /* Does this class support serialization */
    if (implementsSerializable(getType())) {
View Full Code Here


    }
  }

  private InstructionList initInstructionList() {
    InstructionList list = new InstructionList();
    InstructionFactory fact = getFactory();

    // make a new factory
    list.append(fact.createNew(factoryType));
    list.append(InstructionFactory.createDup(1));

    list.append(InstructionFactory.PUSH(getConstantPool(), getFileName()));

    // load the current Class object
    // XXX check that this works correctly for inners/anonymous
    list.append(fact.PUSHCLASS(cp, myGen.getClassName()));
    // XXX do we need to worry about the fact the theorectically this could
    // throw
    // a ClassNotFoundException

    list.append(fact.createInvoke(factoryType.getClassName(), "<init>", Type.VOID, new Type[] { Type.STRING, classType },
        Constants.INVOKESPECIAL));

    list.append(InstructionFactory.createStore(factoryType, 0));
    return list;
  }
View Full Code Here

   * Create a single bridge method called 'theBridgeMethod' that bridges to 'whatToBridgeTo'
   */
  private static void createBridgeMethod(BcelWorld world, LazyMethodGen whatToBridgeToMethodGen, LazyClassGen clazz,
      ResolvedMember theBridgeMethod) {
    InstructionList body;
    InstructionFactory fact;
    int pos = 0;

    ResolvedMember whatToBridgeTo = whatToBridgeToMethodGen.getMemberView();

    if (whatToBridgeTo == null) {
      whatToBridgeTo = new ResolvedMemberImpl(Member.METHOD, whatToBridgeToMethodGen.getEnclosingClass().getType(),
          whatToBridgeToMethodGen.getAccessFlags(), whatToBridgeToMethodGen.getName(),
          whatToBridgeToMethodGen.getSignature());
    }
    // The bridge method in this type will have the same signature as the one in the supertype
    LazyMethodGen bridgeMethod = makeBridgeMethod(clazz, theBridgeMethod);
    int newflags = bridgeMethod.getAccessFlags() | 0x00000040;// BRIDGE = 0x00000040

    if ((newflags & 0x00000100) != 0) {
      newflags = newflags - 0x100;// NATIVE = 0x00000100 - need to clear it
    }

    bridgeMethod.setAccessFlags(newflags);
    Type returnType = BcelWorld.makeBcelType(theBridgeMethod.getReturnType());
    Type[] paramTypes = BcelWorld.makeBcelTypes(theBridgeMethod.getParameterTypes());
    Type[] newParamTypes = whatToBridgeToMethodGen.getArgumentTypes();
    body = bridgeMethod.getBody();
    fact = clazz.getFactory();

    if (!whatToBridgeToMethodGen.isStatic()) {
      body.append(InstructionFactory.createThis());
      pos++;
    }
    for (int i = 0, len = paramTypes.length; i < len; i++) {
      Type paramType = paramTypes[i];
      body.append(InstructionFactory.createLoad(paramType, pos));
      if (!newParamTypes[i].equals(paramTypes[i])) {
        if (world.forDEBUG_bridgingCode) {
          System.err.println("Bridging: Cast " + newParamTypes[i] + " from " + paramTypes[i]);
        }
        body.append(fact.createCast(paramTypes[i], newParamTypes[i]));
      }
      pos += paramType.getSize();
    }

    body.append(Utility.createInvoke(fact, world, whatToBridgeTo));
View Full Code Here

     * bother to pack.
     *
     * Allocate a new var for each formal param of the inlined. Fill with stack contents. Then copy the inlined instructions in
     * with the appropriate remap table. Any framelocs used by locals in inlined are reallocated to top of frame,
     */
    final InstructionFactory fact = recipient.getEnclosingClass().getFactory();

    IntMap frameEnv = new IntMap();

    // this also sets up the initial environment
    InstructionList argumentStores = genArgumentStores(donor, recipient, frameEnv, fact);
View Full Code Here

    if (trace.isTraceEnabled()) {
      trace.enter("transformSynchronizedMethod", synchronizedMethod);
    }
    // System.err.println("DEBUG: Transforming synchronized method: "+
    // synchronizedMethod.getName());
    final InstructionFactory fact = synchronizedMethod.getEnclosingClass().getFactory();
    InstructionList body = synchronizedMethod.getBody();
    InstructionList prepend = new InstructionList();
    Type enclosingClassType = BcelWorld.makeBcelType(synchronizedMethod.getEnclosingClass().getType());

    // STATIC METHOD TRANSFORMATION
    if (synchronizedMethod.isStatic()) {

      // What to do here depends on the level of the class file!
      // LDC can handle class literals in Java5 and above *sigh*
      if (synchronizedMethod.getEnclosingClass().isAtLeastJava5()) {
        // MONITORENTER logic:
        // 0: ldc #2; //class C
        // 2: dup
        // 3: astore_0
        // 4: monitorenter
        int slotForLockObject = synchronizedMethod.allocateLocal(enclosingClassType);
        prepend.append(fact.createConstant(enclosingClassType));
        prepend.append(InstructionFactory.createDup(1));
        prepend.append(InstructionFactory.createStore(enclosingClassType, slotForLockObject));
        prepend.append(InstructionFactory.MONITORENTER);

        // MONITOREXIT logic:

        // We basically need to wrap the code from the method in a
        // finally block that
        // will ensure monitorexit is called. Content on the finally
        // block seems to
        // be always:
        //
        // E1: ALOAD_1
        // MONITOREXIT
        // ATHROW
        //
        // so lets build that:
        InstructionList finallyBlock = new InstructionList();
        finallyBlock.append(InstructionFactory.createLoad(Type.getType(java.lang.Class.class), slotForLockObject));
        finallyBlock.append(InstructionConstants.MONITOREXIT);
        finallyBlock.append(InstructionConstants.ATHROW);

        // finally -> E1
        // | GETSTATIC java.lang.System.out Ljava/io/PrintStream; (line
        // 21)
        // | LDC "hello"
        // | INVOKEVIRTUAL java.io.PrintStream.println
        // (Ljava/lang/String;)V
        // | ALOAD_1 (line 20)
        // | MONITOREXIT
        // finally -> E1
        // GOTO L0
        // finally -> E1
        // | E1: ALOAD_1
        // | MONITOREXIT
        // finally -> E1
        // ATHROW
        // L0: RETURN (line 23)

        // search for 'returns' and make them jump to the
        // aload_<n>,monitorexit
        InstructionHandle walker = body.getStart();
        List<InstructionHandle> rets = new ArrayList<InstructionHandle>();
        while (walker != null) {
          if (walker.getInstruction().isReturnInstruction()) {
            rets.add(walker);
          }
          walker = walker.getNext();
        }
        if (!rets.isEmpty()) {
          // need to ensure targeters for 'return' now instead target
          // the load instruction
          // (so we never jump over the monitorexit logic)

          for (Iterator<InstructionHandle> iter = rets.iterator(); iter.hasNext();) {
            InstructionHandle element = iter.next();
            InstructionList monitorExitBlock = new InstructionList();
            monitorExitBlock.append(InstructionFactory.createLoad(enclosingClassType, slotForLockObject));
            monitorExitBlock.append(InstructionConstants.MONITOREXIT);
            // monitorExitBlock.append(Utility.copyInstruction(element
            // .getInstruction()));
            // element.setInstruction(InstructionFactory.createLoad(
            // classType,slotForThis));
            InstructionHandle monitorExitBlockStart = body.insert(element, monitorExitBlock);

            // now move the targeters from the RET to the start of
            // the monitorexit block
            for (InstructionTargeter targeter : element.getTargetersCopy()) {
              // what kinds are there?
              if (targeter instanceof LocalVariableTag) {
                // ignore
              } else if (targeter instanceof LineNumberTag) {
                // ignore
                // } else if (targeter instanceof
                // InstructionBranch &&
                // ((InstructionBranch)targeter).isGoto()) {
                // // move it...
                // targeter.updateTarget(element,
                // monitorExitBlockStart);
              } else if (targeter instanceof InstructionBranch) {
                // move it
                targeter.updateTarget(element, monitorExitBlockStart);
              } else {
                throw new BCException("Unexpected targeter encountered during transform: " + targeter);
              }
            }
          }
        }

        // now the magic, putting the finally block around the code
        InstructionHandle finallyStart = finallyBlock.getStart();

        InstructionHandle tryPosition = body.getStart();
        InstructionHandle catchPosition = body.getEnd();
        body.insert(body.getStart(), prepend); // now we can put the
        // monitorenter stuff on
        synchronizedMethod.getBody().append(finallyBlock);
        synchronizedMethod.addExceptionHandler(tryPosition, catchPosition, finallyStart, null/* ==finally */, false);
        synchronizedMethod.addExceptionHandler(finallyStart, finallyStart.getNext(), finallyStart, null, false);
      } else {

        // TRANSFORMING STATIC METHOD ON PRE JAVA5

        // Hideous nightmare, class literal references prior to Java5

        // YIKES! this is just the code for MONITORENTER !
        // 0: getstatic #59; //Field class$1:Ljava/lang/Class;
        // 3: dup
        // 4: ifnonnull 32
        // 7: pop
        // try
        // 8: ldc #61; //String java.lang.String
        // 10: invokestatic #44; //Method
        // java/lang/Class.forName:(Ljava/lang/String;)Ljava/lang/Class;
        // 13: dup
        // catch
        // 14: putstatic #59; //Field class$1:Ljava/lang/Class;
        // 17: goto 32
        // 20: new #46; //class java/lang/NoClassDefFoundError
        // 23: dup_x1
        // 24: swap
        // 25: invokevirtual #52; //Method
        // java/lang/Throwable.getMessage:()Ljava/lang/String;
        // 28: invokespecial #54; //Method
        // java/lang/NoClassDefFoundError."<init>":(Ljava/lang/String;)V
        // 31: athrow
        // 32: dup <-- partTwo (branch target)
        // 33: astore_0
        // 34: monitorenter
        //
        // plus exceptiontable entry!
        // 8 13 20 Class java/lang/ClassNotFoundException
        Type classType = BcelWorld.makeBcelType(synchronizedMethod.getEnclosingClass().getType());
        Type clazzType = Type.getType(Class.class);

        InstructionList parttwo = new InstructionList();
        parttwo.append(InstructionFactory.createDup(1));
        int slotForThis = synchronizedMethod.allocateLocal(classType);
        parttwo.append(InstructionFactory.createStore(clazzType, slotForThis)); // ? should be the real type ? String or
        // something?
        parttwo.append(InstructionFactory.MONITORENTER);

        String fieldname = synchronizedMethod.getEnclosingClass().allocateField("class$");
        FieldGen f = new FieldGen(Modifier.STATIC | Modifier.PRIVATE, Type.getType(Class.class), fieldname,
            synchronizedMethod.getEnclosingClass().getConstantPool());
        synchronizedMethod.getEnclosingClass().addField(f, null);

        // 10: invokestatic #44; //Method
        // java/lang/Class.forName:(Ljava/lang/String;)Ljava/lang/Class;
        // 13: dup
        // 14: putstatic #59; //Field class$1:Ljava/lang/Class;
        // 17: goto 32
        // 20: new #46; //class java/lang/NoClassDefFoundError
        // 23: dup_x1
        // 24: swap
        // 25: invokevirtual #52; //Method
        // java/lang/Throwable.getMessage:()Ljava/lang/String;
        // 28: invokespecial #54; //Method
        // java/lang/NoClassDefFoundError."<init>":(Ljava/lang/String;)V
        // 31: athrow
        String name = synchronizedMethod.getEnclosingClass().getName();

        prepend.append(fact.createGetStatic(name, fieldname, Type.getType(Class.class)));
        prepend.append(InstructionFactory.createDup(1));
        prepend.append(InstructionFactory.createBranchInstruction(Constants.IFNONNULL, parttwo.getStart()));
        prepend.append(InstructionFactory.POP);

        prepend.append(fact.createConstant(name));
        InstructionHandle tryInstruction = prepend.getEnd();
        prepend.append(fact.createInvoke("java.lang.Class", "forName", clazzType,
            new Type[] { Type.getType(String.class) }, Constants.INVOKESTATIC));
        InstructionHandle catchInstruction = prepend.getEnd();
        prepend.append(InstructionFactory.createDup(1));

        prepend.append(fact.createPutStatic(synchronizedMethod.getEnclosingClass().getType().getName(), fieldname,
            Type.getType(Class.class)));
        prepend.append(InstructionFactory.createBranchInstruction(Constants.GOTO, parttwo.getStart()));

        // start of catch block
        InstructionList catchBlockForLiteralLoadingFail = new InstructionList();
        catchBlockForLiteralLoadingFail.append(fact.createNew((ObjectType) Type.getType(NoClassDefFoundError.class)));
        catchBlockForLiteralLoadingFail.append(InstructionFactory.createDup_1(1));
        catchBlockForLiteralLoadingFail.append(InstructionFactory.SWAP);
        catchBlockForLiteralLoadingFail.append(fact.createInvoke("java.lang.Throwable", "getMessage",
            Type.getType(String.class), new Type[] {}, Constants.INVOKEVIRTUAL));
        catchBlockForLiteralLoadingFail.append(fact.createInvoke("java.lang.NoClassDefFoundError", "<init>", Type.VOID,
            new Type[] { Type.getType(String.class) }, Constants.INVOKESPECIAL));
        catchBlockForLiteralLoadingFail.append(InstructionFactory.ATHROW);
        InstructionHandle catchBlockStart = catchBlockForLiteralLoadingFail.getStart();
        prepend.append(catchBlockForLiteralLoadingFail);
        prepend.append(parttwo);
View Full Code Here

   * Create a single bridge method called 'theBridgeMethod' that bridges to 'whatToBridgeTo'
   */
  private static void createBridgeMethod(BcelWorld world, LazyMethodGen whatToBridgeToMethodGen, LazyClassGen clazz,
      ResolvedMember theBridgeMethod) {
    InstructionList body;
    InstructionFactory fact;
    int pos = 0;

    ResolvedMember whatToBridgeTo = whatToBridgeToMethodGen.getMemberView();

    if (whatToBridgeTo == null) {
      whatToBridgeTo = new ResolvedMemberImpl(Member.METHOD, whatToBridgeToMethodGen.getEnclosingClass().getType(),
          whatToBridgeToMethodGen.getAccessFlags(), whatToBridgeToMethodGen.getName(),
          whatToBridgeToMethodGen.getSignature());
    }
    // The bridge method in this type will have the same signature as the one in the supertype
    LazyMethodGen bridgeMethod = makeBridgeMethod(clazz, theBridgeMethod);
    int newflags = bridgeMethod.getAccessFlags() | 0x00000040;// BRIDGE = 0x00000040

    if ((newflags & 0x00000100) != 0) {
      newflags = newflags - 0x100;// NATIVE = 0x00000100 - need to clear it
    }

    bridgeMethod.setAccessFlags(newflags);
    Type returnType = BcelWorld.makeBcelType(theBridgeMethod.getReturnType());
    Type[] paramTypes = BcelWorld.makeBcelTypes(theBridgeMethod.getParameterTypes());
    Type[] newParamTypes = whatToBridgeToMethodGen.getArgumentTypes();
    body = bridgeMethod.getBody();
    fact = clazz.getFactory();

    if (!whatToBridgeToMethodGen.isStatic()) {
      body.append(InstructionFactory.createThis());
      pos++;
    }
    for (int i = 0, len = paramTypes.length; i < len; i++) {
      Type paramType = paramTypes[i];
      body.append(InstructionFactory.createLoad(paramType, pos));
      if (!newParamTypes[i].equals(paramTypes[i])) {
        if (world.forDEBUG_bridgingCode) {
          System.err.println("Bridging: Cast " + newParamTypes[i] + " from " + paramTypes[i]);
        }
        body.append(fact.createCast(paramTypes[i], newParamTypes[i]));
      }
      pos += paramType.getSize();
    }

    body.append(Utility.createInvoke(fact, world, whatToBridgeTo));
View Full Code Here

     * bother to pack.
     *
     * Allocate a new var for each formal param of the inlined. Fill with stack contents. Then copy the inlined instructions in
     * with the appropriate remap table. Any framelocs used by locals in inlined are reallocated to top of frame,
     */
    final InstructionFactory fact = recipient.getEnclosingClass().getFactory();

    IntMap frameEnv = new IntMap();

    // this also sets up the initial environment
    InstructionList argumentStores = genArgumentStores(donor, recipient, frameEnv, fact);
View Full Code Here

    if (trace.isTraceEnabled()) {
      trace.enter("transformSynchronizedMethod", synchronizedMethod);
    }
    // System.err.println("DEBUG: Transforming synchronized method: "+
    // synchronizedMethod.getName());
    final InstructionFactory fact = synchronizedMethod.getEnclosingClass().getFactory();
    InstructionList body = synchronizedMethod.getBody();
    InstructionList prepend = new InstructionList();
    Type enclosingClassType = BcelWorld.makeBcelType(synchronizedMethod.getEnclosingClass().getType());

    // STATIC METHOD TRANSFORMATION
    if (synchronizedMethod.isStatic()) {

      // What to do here depends on the level of the class file!
      // LDC can handle class literals in Java5 and above *sigh*
      if (synchronizedMethod.getEnclosingClass().isAtLeastJava5()) {
        // MONITORENTER logic:
        // 0: ldc #2; //class C
        // 2: dup
        // 3: astore_0
        // 4: monitorenter
        int slotForLockObject = synchronizedMethod.allocateLocal(enclosingClassType);
        prepend.append(fact.createConstant(enclosingClassType));
        prepend.append(InstructionFactory.createDup(1));
        prepend.append(InstructionFactory.createStore(enclosingClassType, slotForLockObject));
        prepend.append(InstructionFactory.MONITORENTER);

        // MONITOREXIT logic:

        // We basically need to wrap the code from the method in a
        // finally block that
        // will ensure monitorexit is called. Content on the finally
        // block seems to
        // be always:
        //
        // E1: ALOAD_1
        // MONITOREXIT
        // ATHROW
        //
        // so lets build that:
        InstructionList finallyBlock = new InstructionList();
        finallyBlock.append(InstructionFactory.createLoad(Type.getType(java.lang.Class.class), slotForLockObject));
        finallyBlock.append(InstructionConstants.MONITOREXIT);
        finallyBlock.append(InstructionConstants.ATHROW);

        // finally -> E1
        // | GETSTATIC java.lang.System.out Ljava/io/PrintStream; (line
        // 21)
        // | LDC "hello"
        // | INVOKEVIRTUAL java.io.PrintStream.println
        // (Ljava/lang/String;)V
        // | ALOAD_1 (line 20)
        // | MONITOREXIT
        // finally -> E1
        // GOTO L0
        // finally -> E1
        // | E1: ALOAD_1
        // | MONITOREXIT
        // finally -> E1
        // ATHROW
        // L0: RETURN (line 23)

        // search for 'returns' and make them jump to the
        // aload_<n>,monitorexit
        InstructionHandle walker = body.getStart();
        List<InstructionHandle> rets = new ArrayList<InstructionHandle>();
        while (walker != null) {
          if (walker.getInstruction().isReturnInstruction()) {
            rets.add(walker);
          }
          walker = walker.getNext();
        }
        if (!rets.isEmpty()) {
          // need to ensure targeters for 'return' now instead target
          // the load instruction
          // (so we never jump over the monitorexit logic)

          for (Iterator<InstructionHandle> iter = rets.iterator(); iter.hasNext();) {
            InstructionHandle element = iter.next();
            InstructionList monitorExitBlock = new InstructionList();
            monitorExitBlock.append(InstructionFactory.createLoad(enclosingClassType, slotForLockObject));
            monitorExitBlock.append(InstructionConstants.MONITOREXIT);
            // monitorExitBlock.append(Utility.copyInstruction(element
            // .getInstruction()));
            // element.setInstruction(InstructionFactory.createLoad(
            // classType,slotForThis));
            InstructionHandle monitorExitBlockStart = body.insert(element, monitorExitBlock);

            // now move the targeters from the RET to the start of
            // the monitorexit block
            for (InstructionTargeter targeter : element.getTargetersCopy()) {
              // what kinds are there?
              if (targeter instanceof LocalVariableTag) {
                // ignore
              } else if (targeter instanceof LineNumberTag) {
                // ignore
                // } else if (targeter instanceof
                // InstructionBranch &&
                // ((InstructionBranch)targeter).isGoto()) {
                // // move it...
                // targeter.updateTarget(element,
                // monitorExitBlockStart);
              } else if (targeter instanceof InstructionBranch) {
                // move it
                targeter.updateTarget(element, monitorExitBlockStart);
              } else {
                throw new BCException("Unexpected targeter encountered during transform: " + targeter);
              }
            }
          }
        }

        // now the magic, putting the finally block around the code
        InstructionHandle finallyStart = finallyBlock.getStart();

        InstructionHandle tryPosition = body.getStart();
        InstructionHandle catchPosition = body.getEnd();
        body.insert(body.getStart(), prepend); // now we can put the
        // monitorenter stuff on
        synchronizedMethod.getBody().append(finallyBlock);
        synchronizedMethod.addExceptionHandler(tryPosition, catchPosition, finallyStart, null/* ==finally */, false);
        synchronizedMethod.addExceptionHandler(finallyStart, finallyStart.getNext(), finallyStart, null, false);
      } else {

        // TRANSFORMING STATIC METHOD ON PRE JAVA5

        // Hideous nightmare, class literal references prior to Java5

        // YIKES! this is just the code for MONITORENTER !
        // 0: getstatic #59; //Field class$1:Ljava/lang/Class;
        // 3: dup
        // 4: ifnonnull 32
        // 7: pop
        // try
        // 8: ldc #61; //String java.lang.String
        // 10: invokestatic #44; //Method
        // java/lang/Class.forName:(Ljava/lang/String;)Ljava/lang/Class;
        // 13: dup
        // catch
        // 14: putstatic #59; //Field class$1:Ljava/lang/Class;
        // 17: goto 32
        // 20: new #46; //class java/lang/NoClassDefFoundError
        // 23: dup_x1
        // 24: swap
        // 25: invokevirtual #52; //Method
        // java/lang/Throwable.getMessage:()Ljava/lang/String;
        // 28: invokespecial #54; //Method
        // java/lang/NoClassDefFoundError."<init>":(Ljava/lang/String;)V
        // 31: athrow
        // 32: dup <-- partTwo (branch target)
        // 33: astore_0
        // 34: monitorenter
        //
        // plus exceptiontable entry!
        // 8 13 20 Class java/lang/ClassNotFoundException
        Type classType = BcelWorld.makeBcelType(synchronizedMethod.getEnclosingClass().getType());
        Type clazzType = Type.getType(Class.class);

        InstructionList parttwo = new InstructionList();
        parttwo.append(InstructionFactory.createDup(1));
        int slotForThis = synchronizedMethod.allocateLocal(classType);
        parttwo.append(InstructionFactory.createStore(clazzType, slotForThis)); // ? should be the real type ? String or
        // something?
        parttwo.append(InstructionFactory.MONITORENTER);

        String fieldname = synchronizedMethod.getEnclosingClass().allocateField("class$");
        FieldGen f = new FieldGen(Modifier.STATIC | Modifier.PRIVATE, Type.getType(Class.class), fieldname,
            synchronizedMethod.getEnclosingClass().getConstantPool());
        synchronizedMethod.getEnclosingClass().addField(f, null);

        // 10: invokestatic #44; //Method
        // java/lang/Class.forName:(Ljava/lang/String;)Ljava/lang/Class;
        // 13: dup
        // 14: putstatic #59; //Field class$1:Ljava/lang/Class;
        // 17: goto 32
        // 20: new #46; //class java/lang/NoClassDefFoundError
        // 23: dup_x1
        // 24: swap
        // 25: invokevirtual #52; //Method
        // java/lang/Throwable.getMessage:()Ljava/lang/String;
        // 28: invokespecial #54; //Method
        // java/lang/NoClassDefFoundError."<init>":(Ljava/lang/String;)V
        // 31: athrow
        String name = synchronizedMethod.getEnclosingClass().getName();

        prepend.append(fact.createGetStatic(name, fieldname, Type.getType(Class.class)));
        prepend.append(InstructionFactory.createDup(1));
        prepend.append(InstructionFactory.createBranchInstruction(Constants.IFNONNULL, parttwo.getStart()));
        prepend.append(InstructionFactory.POP);

        prepend.append(fact.createConstant(name));
        InstructionHandle tryInstruction = prepend.getEnd();
        prepend.append(fact.createInvoke("java.lang.Class", "forName", clazzType,
            new Type[] { Type.getType(String.class) }, Constants.INVOKESTATIC));
        InstructionHandle catchInstruction = prepend.getEnd();
        prepend.append(InstructionFactory.createDup(1));

        prepend.append(fact.createPutStatic(synchronizedMethod.getEnclosingClass().getType().getName(), fieldname,
            Type.getType(Class.class)));
        prepend.append(InstructionFactory.createBranchInstruction(Constants.GOTO, parttwo.getStart()));

        // start of catch block
        InstructionList catchBlockForLiteralLoadingFail = new InstructionList();
        catchBlockForLiteralLoadingFail.append(fact.createNew((ObjectType) Type.getType(NoClassDefFoundError.class)));
        catchBlockForLiteralLoadingFail.append(InstructionFactory.createDup_1(1));
        catchBlockForLiteralLoadingFail.append(InstructionFactory.SWAP);
        catchBlockForLiteralLoadingFail.append(fact.createInvoke("java.lang.Throwable", "getMessage",
            Type.getType(String.class), new Type[] {}, Constants.INVOKEVIRTUAL));
        catchBlockForLiteralLoadingFail.append(fact.createInvoke("java.lang.NoClassDefFoundError", "<init>", Type.VOID,
            new Type[] { Type.getType(String.class) }, Constants.INVOKESPECIAL));
        catchBlockForLiteralLoadingFail.append(InstructionFactory.ATHROW);
        InstructionHandle catchBlockStart = catchBlockForLiteralLoadingFail.getStart();
        prepend.append(catchBlockForLiteralLoadingFail);
        prepend.append(parttwo);
View Full Code Here

  public LazyClassGen(String class_name, String super_class_name, String file_name, int access_flags, String[] interfaces,
      World world) {
    myGen = new ClassGen(class_name, super_class_name, file_name, access_flags, interfaces);
    cp = myGen.getConstantPool();
    fact = new InstructionFactory(myGen, cp);
    regenerateGenericSignatureAttribute = true;
    this.world = world;
  }
View Full Code Here

  // Non child type, so it comes from a real type in the world.
  public LazyClassGen(BcelObjectType myType) {
    myGen = new ClassGen(myType.getJavaClass());
    cp = myGen.getConstantPool();
    fact = new InstructionFactory(myGen, cp);
    this.myType = myType;
    world = myType.getResolvedTypeX().getWorld();

    /* Does this class support serialization */
    if (implementsSerializable(getType())) {
View Full Code Here

TOP

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

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.