Package org.aspectj.apache.bcel.generic

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


    this.name = name;
    this.argumentTypes = paramTypes;
    // this.argumentNames = Utility.makeArgNames(paramTypes.length);
    this.declaredExceptions = declaredExceptions;
    if (!Modifier.isAbstract(modifiers)) {
      body = new InstructionList();
      setMaxLocals(calculateMaxLocals());
    } else {
      body = null;
    }
    this.attributes = new ArrayList<Attribute>();
View Full Code Here


  public void print(PrintStream out, WeaverVersionInfo weaverVersion) {
    out.print("  " + toShortString());
    printAspectAttributes(out, weaverVersion);

    InstructionList body = getBody();
    if (body == null) {
      out.println(";");
      return;
    }
    out.println(":");
View Full Code Here

    if (enclosingClass.getWorld().isJoinpointSynchronizationEnabled()
        && enclosingClass.getWorld().areSynchronizationPointcutsInUse()) {
      flags = getAccessFlagsWithoutSynchronized();
    }
    MethodGen gen = new MethodGen(flags, getReturnType(), getArgumentTypes(), null, // getArgumentNames(),
        getName(), getEnclosingClass().getName(), new InstructionList(), getEnclosingClass().getConstantPool());
    for (int i = 0, len = declaredExceptions.length; i < len; i++) {
      gen.addException(declaredExceptions[i]);
    }

    for (Attribute attr : attributes) {
View Full Code Here

  /**
   * fill the newly created method gen with our body, inspired by InstructionList.copy()
   */
  public void packBody(MethodGen gen) {
    InstructionList fresh = gen.getInstructionList();
    Map<InstructionHandle, InstructionHandle> map = copyAllInstructionsExceptRangeInstructionsInto(fresh);

    // at this point, no rangeHandles are in fresh. Let's use that...

    /*
     * Update branch targets and insert various attributes. Insert our exceptionHandlers into a sorted list, so they can be
     * added in order later.
     */
    InstructionHandle oldInstructionHandle = getBody().getStart();
    InstructionHandle newInstructionHandle = fresh.getStart();
    LinkedList<ExceptionRange> exceptionList = new LinkedList<ExceptionRange>();

    Map<LocalVariableTag, LVPosition> localVariables = new HashMap<LocalVariableTag, LVPosition>();

    int currLine = -1;
View Full Code Here

  /*
   * Optimized packing that does a 'local packing' of the code rather than building a brand new method and packing into it. Only
   * usable when the packing is going to be done just once.
   */
  public void optimizedPackBody(MethodGen gen) {
    InstructionList theBody = getBody();
    InstructionHandle iHandle = theBody.getStart();

    int currLine = -1;
    int lineNumberOffset = (fromFilename == null) ? 0 : getEnclosingClass().getSourceDebugExtensionOffset(fromFilename);
    Map<LocalVariableTag, LVPosition> localVariables = new HashMap<LocalVariableTag, LVPosition>();
    LinkedList<ExceptionRange> exceptionList = new LinkedList<ExceptionRange>();
    Set<InstructionHandle> forDeletion = new HashSet<InstructionHandle>();
    Set<BranchHandle> branchInstructions = new HashSet<BranchHandle>();
    // OPTIMIZE sort out in here: getRange()/insertHandler() and type of
    // exceptionList
    while (iHandle != null) {
      Instruction inst = iHandle.getInstruction();
      // InstructionHandle nextInst = iHandle.getNext();
      // OPTIMIZE remove this instructionhandle as it now points to
      // nowhere?
      if (inst == Range.RANGEINSTRUCTION) {
        Range r = Range.getRange(iHandle);
        if (r instanceof ExceptionRange) {
          ExceptionRange er = (ExceptionRange) r;
          if (er.getStart() == iHandle) {
            if (!er.isEmpty()) {
              // order is important, insert handlers in order of start
              insertHandler(er, exceptionList);
            }
          }
        }
        forDeletion.add(iHandle);
      } else {
        if (inst instanceof InstructionBranch) {
          branchInstructions.add((BranchHandle) iHandle);
        }

        for (InstructionTargeter targeter : iHandle.getTargetersCopy()) {
          if (targeter instanceof LineNumberTag) {
            int line = ((LineNumberTag) targeter).getLineNumber();
            if (line != currLine) {
              gen.addLineNumber(iHandle, line + lineNumberOffset);
              currLine = line;
            }
          } else if (targeter instanceof LocalVariableTag) {
            LocalVariableTag lvt = (LocalVariableTag) targeter;
            LVPosition p = localVariables.get(lvt);
            // If we don't know about it, create a new position
            // and store
            // If we do know about it - update its end position
            if (p == null) {
              LVPosition newp = new LVPosition();
              newp.start = newp.end = iHandle;
              localVariables.put(lvt, newp);
            } else {
              p.end = iHandle;
            }
          }
        }
      }
      iHandle = iHandle.getNext();
    }
    for (BranchHandle branchHandle : branchInstructions) {
      handleBranchInstruction(branchHandle, forDeletion);
    }
    // now add exception handlers
    for (ExceptionRange r : exceptionList) {
      if (r.isEmpty()) {
        continue;
      }
      gen.addExceptionHandler(jumpForward(r.getRealStart(), forDeletion), jumpForward(r.getRealEnd(), forDeletion),
          jumpForward(r.getHandler(), forDeletion),
          (r.getCatchType() == null) ? null : (ObjectType) BcelWorld.makeBcelType(r.getCatchType()));
    }

    for (InstructionHandle handle : forDeletion) {
      try {
        theBody.delete(handle);
      } catch (TargetLostException e) {
        e.printStackTrace();
      }
    }
    gen.setInstructionList(theBody);
View Full Code Here

      il = initializeAllTjps();
    }

    if (serialVersionUIDRequiresInitialization) {
      InstructionList[] ilSVUID = new InstructionList[1];
      ilSVUID[0] = new InstructionList();
      ilSVUID[0].append(InstructionFactory.PUSH(getConstantPool(), calculatedSerialVersionUID));
      ilSVUID[0].append(getFactory().createFieldAccess(getClassName(), "serialVersionUID", BasicType.LONG,
          Constants.PUTSTATIC));
      if (il == null) {
        il = ilSVUID;
View Full Code Here

      prevMethod = nextMethod;
    }
  }

  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

  }

  private InstructionList[] initializeAllTjps() {
    Vector<InstructionList> lists = new Vector<InstructionList>();

    InstructionList list = initInstructionList();
    lists.add(list);

    List<Map.Entry<BcelShadow, Field>> entries = new ArrayList<Map.Entry<BcelShadow, Field>>(tjpFields.entrySet());
    Collections.sort(entries, new Comparator<Map.Entry<BcelShadow, Field>>() {
      public int compare(Map.Entry<BcelShadow, Field> a, Map.Entry<BcelShadow, Field> b) {
        return (a.getValue()).getName().compareTo((b.getValue()).getName());
      }
    });

    long estimatedSize = 0;
    for (Iterator<Map.Entry<BcelShadow, Field>> i = entries.iterator(); i.hasNext();) {
      Map.Entry<BcelShadow, Field> entry = i.next();
      if (estimatedSize > Constants.MAX_CODE_SIZE) {
        estimatedSize = 0;
        list = initInstructionList();
        lists.add(list);
      }
      estimatedSize += entry.getValue().getSignature().getBytes().length;
      initializeTjp(fact, list, entry.getValue(), entry.getKey());
    }
    InstructionList listArrayModel[] = new InstructionList[1];
    return lists.toArray(listArrayModel);
  }
View Full Code Here

    gen.addField(f, getSourceLocation());

    // Modify the ajc$preClinit() method to initialize it.
    // Something like: "ajc$cflowCounter$0 = new CflowCounter();"
    LazyMethodGen clinit = gen.getAjcPreClinit(); // StaticInitializer();
    InstructionList setup = new InstructionList();
    InstructionFactory fact = gen.getFactory();

    setup.append(fact.createNew(new ObjectType(NameMangler.CFLOW_COUNTER_TYPE)));
    setup.append(InstructionFactory.createDup(1));
    setup.append(fact.createInvoke(NameMangler.CFLOW_COUNTER_TYPE, "<init>", Type.VOID, new Type[0], Constants.INVOKESPECIAL));

    setup.append(Utility.createSet(fact, cflowCounterField));
    clinit.getBody().insert(setup);

    return true;
  }
View Full Code Here

      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<Definition.Pointcut> 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<NameValuePair> elems = new ArrayList<NameValuePair>();
      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);
    }

    // Construct any defined declare error/warnings
    if (concreteAspect.deows.size() > 0) {
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.