Examples of InstructionList


Examples of com.sun.org.apache.bcel.internal.generic.InstructionList

    compileSortRecordFactory(sortObjects, classGen, methodGen,
        sortRecordClass);
  }

  final ConstantPoolGen cpg = classGen.getConstantPool();
  final InstructionList il = methodGen.getInstructionList();

        // Backwards branches are prohibited if an uninitialized object is
        // on the stack by section 4.9.4 of the JVM Specification, 2nd Ed.
        // We don't know whether this code might contain backwards branches
        // so we mustn't create the new object until after we've created
        // the suspect arguments to its constructor.  Instead we calculate
        // the values of the arguments to the constructor first, store them
        // in temporary variables, create the object and reload the
        // arguments from the temporaries to avoid the problem.

  // Compile code that initializes the static _sortOrder
        LocalVariableGen sortOrderTemp
                 = methodGen.addLocalVariable("sort_order_tmp",
                                      Util.getJCRefType("[" + STRING_SIG),
                                      il.getEnd(), null);
  il.append(new PUSH(cpg, nsorts));
  il.append(new ANEWARRAY(cpg.addClass(STRING)));
  for (int level = 0; level < nsorts; level++) {
      final Sort sort = (Sort)sortObjects.elementAt(level);
      il.append(DUP);
      il.append(new PUSH(cpg, level));
      sort.translateSortOrder(classGen, methodGen);
      il.append(AASTORE);
  }
        il.append(new ASTORE(sortOrderTemp.getIndex()));

        LocalVariableGen sortTypeTemp
                 = methodGen.addLocalVariable("sort_type_tmp",
                                      Util.getJCRefType("[" + STRING_SIG),
                                      il.getEnd(), null);
  il.append(new PUSH(cpg, nsorts));
  il.append(new ANEWARRAY(cpg.addClass(STRING)));
  for (int level = 0; level < nsorts; level++) {
      final Sort sort = (Sort)sortObjects.elementAt(level);
      il.append(DUP);
      il.append(new PUSH(cpg, level));
      sort.translateSortType(classGen, methodGen);
      il.append(AASTORE);
  }
        il.append(new ASTORE(sortTypeTemp.getIndex()));

        LocalVariableGen sortLangTemp
                 = methodGen.addLocalVariable("sort_lang_tmp",
                                      Util.getJCRefType("[" + STRING_SIG),
                                      il.getEnd(), null);
        il.append(new PUSH(cpg, nsorts));
        il.append(new ANEWARRAY(cpg.addClass(STRING)));
        for (int level = 0; level < nsorts; level++) {
              final Sort sort = (Sort)sortObjects.elementAt(level);
              il.append(DUP);
              il.append(new PUSH(cpg, level));
              sort.translateLang(classGen, methodGen);
              il.append(AASTORE);
        }
        il.append(new ASTORE(sortLangTemp.getIndex()));

        LocalVariableGen sortCaseOrderTemp
                 = methodGen.addLocalVariable("sort_case_order_tmp",
                                      Util.getJCRefType("[" + STRING_SIG),
                                      il.getEnd(), null);
        il.append(new PUSH(cpg, nsorts));
        il.append(new ANEWARRAY(cpg.addClass(STRING)));
        for (int level = 0; level < nsorts; level++) {
            final Sort sort = (Sort)sortObjects.elementAt(level);
            il.append(DUP);
            il.append(new PUSH(cpg, level));
            sort.translateCaseOrder(classGen, methodGen);
            il.append(AASTORE);
        }
        il.append(new ASTORE(sortCaseOrderTemp.getIndex()));
 
  il.append(new NEW(cpg.addClass(sortRecordFactoryClass)));
  il.append(DUP);
  il.append(methodGen.loadDOM());
  il.append(new PUSH(cpg, sortRecordClass));
  il.append(classGen.loadTranslet());

        il.append(new ALOAD(sortOrderTemp.getIndex()));
        il.append(new ALOAD(sortTypeTemp.getIndex()));
        il.append(new ALOAD(sortLangTemp.getIndex()));
        il.append(new ALOAD(sortCaseOrderTemp.getIndex()));

  il.append(new INVOKESPECIAL(
      cpg.addMethodref(sortRecordFactoryClass, "<init>",
    "(" + DOM_INTF_SIG
        + STRING_SIG
        + TRANSLET_INTF_SIG
        + "[" + STRING_SIG
                    + "[" + STRING_SIG
                    + "[" + STRING_SIG
        + "[" + STRING_SIG + ")V")));

  // Initialize closure variables in sortRecordFactory
  final ArrayList dups = new ArrayList();

  for (int j = 0; j < nsorts; j++) {
      final Sort sort = (Sort) sortObjects.get(j);
      final int length = (sort._closureVars == null) ? 0 :
    sort._closureVars.size();

      for (int i = 0; i < length; i++) {
    VariableRefBase varRef = (VariableRefBase) sort._closureVars.get(i);

    // Discard duplicate variable references
    if (dups.contains(varRef)) continue;

    final VariableBase var = varRef.getVariable();

    // Store variable in new closure
    il.append(DUP);
    il.append(var.loadInstruction());
    il.append(new PUTFIELD(
      cpg.addFieldref(sortRecordFactoryClass, var.getEscapedName(),
          var.getType().toSignature())));
    dups.add(varRef);
      }
  }
View Full Code Here

Examples of org.apache.bcel.generic.InstructionList

           
        }
       
        // create the method generator with empty instruction list
        String[] names = (String[])s_argNameLists.get(args.length);
        m_instructionList = new InstructionList();
        m_stackState = new StringStack();
        m_instructionBuilder = cf.getInstructionBuilder();
        m_generator = new MethodGen(access | SYNTHETIC_ACCESS_FLAG, ret, args,
            names, name, cf.getName(), m_instructionList, cf.getConstPoolGen());
       
View Full Code Here

Examples of org.apache.bcel.generic.InstructionList

    else
      endLocations = new java.util.Vector();


    // obtain the bytecode for the method
    InstructionList iList = null;
    byte[] code = null;
    try {
      code = doGetByteCode(m.getDeclaringClass(),m);
      iList=new InstructionList(code);
    }
    catch (Throwable e) {
      code = doGetByteCodeWithoutJvmdi(m);
      iList= new InstructionList(code);
    }

    // search the bytecode for the method for 'return' bytecodes
    InstructionHandle[] instructions = iList.getInstructionHandles();
    for (int i=0; i < instructions.length; i++) {
      if (instructions[i].getInstruction() instanceof ReturnInstruction)
        endLocations.add(new Integer(instructions[i].getPosition()));
    }
View Full Code Here

Examples of org.apache.bcel.generic.InstructionList

                "This method "
                    + mg.getName()
                    + " is a special method and won't be modified.");
            return orig;
        }
        InstructionList il = null;
        InstructionHandle handle = null;
        Instruction inst = null;

        GETSTATIC getStatic = null;

        Method m = null;

        try {
            il = mg.getInstructionList();
            handle = il.getStart();
            if (level_enters == SIMPLEENTER) {

                insertEnter(mg, il, handle, cp);
                insertFork(il, il.getStart(), handle.getPrev(), cp);
            }

            for (; handle != null; handle = handle.getNext()) {
                inst = handle.getInstruction();
                logger.info("next instruction: " + inst);
                if (level_exits == SIMPLEEXIT
                    && inst instanceof ReturnInstruction) {
                    InstructionHandle lastLogHandle = handle;
                    logger.info(
                        "Found a ReturnInstruction of type: "
                            + inst.toString());
                    int stackSize =
                        inst.consumeStack(cp) - inst.produceStack(cp);
                    while (stackSize != 0) {
                        handle = handle.getPrev();
                        inst = handle.getInstruction();
                        logger.info("prev instruction: " + inst);
                        stackSize += inst.consumeStack(cp)
                            - inst.produceStack(cp);
                    }

                    InstructionHandle insertHandle =
                        insertExit(mg, il, handle, cp);
                    if (insertHandle != null) {
                      // We need to redirect branches etc.... twice
                      // so that the if fork doesn't get erroneous modified.
                        il.redirectBranches(handle, insertHandle);
                        il.redirectExceptionHandlers(
                            mg.getExceptionHandlers(),
                            handle,
                            insertHandle);
                        il.redirectLocalVariables(
                            mg.getLocalVariables(),
                            handle,
                            insertHandle);
                        handle =
                            insertFork(il, insertHandle, handle.getPrev(), cp);
                        il.redirectBranches(insertHandle, handle );
                        il.redirectExceptionHandlers(
                            mg.getExceptionHandlers(),
              insertHandle,
                            handle);
                        il.redirectLocalVariables(
                            mg.getLocalVariables(),
                            insertHandle,
              handle);
                    }

                    handle = lastLogHandle;
                }
                if (inst instanceof GETSTATIC) {
                    getStatic = (GETSTATIC) inst;
                    Type type = getStatic.getFieldType(cp);
                    logger.info(
                        "Found a GETSTATIC instruction of type: "
                            + type.toString());

                    if (getStatic
                        .getFieldName(cp)
                        .equals(loggerAttribute.getName())) {
                        logger.info("This is a logger access");
                        transform(mg, il, handle, cp);
                    }
                }
            }
            if (orig.getLineNumberTable() == null) {
                logger.info("Removing line numbers");
                mg.removeLineNumbers();
            }
            if (orig.getLocalVariableTable() == null) {
                logger.info("Removing Local variables table");
                mg.removeLocalVariables();
            }
            m = mg.getMethod();
        } finally {

            il.dispose();
        }
        return m;
    }
View Full Code Here

Examples of org.apache.bcel.generic.InstructionList

            }
            if (ln) {
                mg.removeLineNumbers();
            }
            mg.stripAttributes(skipDebug);
            InstructionList il = mg.getInstructionList();
            if (il != null) {
                InstructionHandle ih = il.getStart();
                while (ih != null) {
                    ih = ih.getNext();
                }
                if (compute) {
                    mg.setMaxStack();
View Full Code Here

Examples of org.apache.flex.abc.instructionlist.InstructionList

     * expression for an MXMLBindingNode
     */
    private InstructionListNode getTargetExprNode(IMXMLUnitData data, IMXMLTagAttributeData attr)
    {
        InstructionListNode expr = null;
        InstructionList il = getTargetInstructions(data, attr);
        if (il != null)
        {
            expr = new InstructionListNode(il);
        }

View Full Code Here

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

    il.insert(createLoadInstructions(getType(), fact));
  }

  private InstructionList createLoadInstructions(ResolvedType toType, InstructionFactory fact) {

    InstructionList il = new InstructionList();

    Type jlClass = BcelWorld.makeBcelType(UnresolvedType.JL_CLASS);
    Type jlString = BcelWorld.makeBcelType(UnresolvedType.JL_STRING);
    Type jlClassArray = BcelWorld.makeBcelType(UnresolvedType.JAVA_LANG_CLASS_ARRAY);
    Type jlaAnnotation = BcelWorld.makeBcelType(UnresolvedType.JAVA_LANG_ANNOTATION);

    Instruction pushConstant = fact.createConstant(new ObjectType(toType.getName()));

    if (kind == Shadow.MethodCall || kind == Shadow.MethodExecution || kind == Shadow.PreInitialization
        || kind == Shadow.Initialization || kind == Shadow.ConstructorCall || kind == Shadow.ConstructorExecution
        || kind == Shadow.AdviceExecution ||
        // annotations for fieldset/fieldget when an ITD is involved are stored against a METHOD
        ((kind == Shadow.FieldGet || kind == Shadow.FieldSet) && member.getKind() == Member.METHOD)) {

      Type jlrMethod = BcelWorld.makeBcelType(UnresolvedType.forSignature("Ljava/lang/reflect/Method;"));
      Type jlAnnotation = BcelWorld.makeBcelType(UnresolvedType.forSignature("Ljava/lang/annotation/Annotation;"));
      Type[] paramTypes = BcelWorld.makeBcelTypes(member.getParameterTypes());

      // il.append(fact.createConstant(BcelWorld.makeBcelType(containingType)));

      if (kind == Shadow.MethodCall
          || kind == Shadow.MethodExecution
          || kind == Shadow.AdviceExecution
          ||
          // annotations for fieldset/fieldget when an ITD is involved are stored against a METHOD
          ((kind == Shadow.FieldGet || kind == Shadow.FieldSet) && member.getKind() == Member.METHOD)
          || ((kind == Shadow.ConstructorCall || kind == Shadow.ConstructorExecution) && member.getKind() == Member.METHOD)) {

        // Need to look at the cached annotation before going to fetch it again
        Field annotationCachingField = shadow.getEnclosingClass().getAnnotationCachingField(shadow, toType);

        // 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);
        // OPTIMIZE cache result of getDeclaredConstructor and getAnnotation? Might be able to use it again if someone else
        // needs the same annotations?
        il.append(fact.createInvoke("java/lang/Class", "getDeclaredConstructor", jlrCtor, new Type[] { jlClassArray },
            Constants.INVOKEVIRTUAL));
        il.append(pushConstant);
        il.append(fact.createInvoke("java/lang/reflect/Constructor", "getAnnotation", jlaAnnotation,
            new Type[] { jlClass }, Constants.INVOKEVIRTUAL));
      }
    } else if (kind == Shadow.FieldSet || kind == Shadow.FieldGet) {
      Type jlrField = BcelWorld.makeBcelType(UnresolvedType.JAVA_LANG_REFLECT_FIELD);
      il.append(fact.createConstant(BcelWorld.makeBcelType(containingType))); // Stick the target on the stack
      il.append(fact.createConstant(member.getName())); // Stick what we are after on the stack
      il.append(fact.createInvoke("java/lang/Class", "getDeclaredField", jlrField, new Type[] { jlString },
          Constants.INVOKEVIRTUAL));
      il.append(pushConstant);
      il.append(fact.createInvoke("java/lang/reflect/Field", "getAnnotation", jlaAnnotation, new Type[] { jlClass },
          Constants.INVOKEVIRTUAL));
    } else if (kind == Shadow.StaticInitialization || kind == Shadow.ExceptionHandler) {
      il.append(fact.createConstant(BcelWorld.makeBcelType(containingType)));
      il.append(pushConstant);
      il.append(fact.createInvoke("java/lang/Class", "getAnnotation", jlaAnnotation, new Type[] { jlClass },
          Constants.INVOKEVIRTUAL));
    } else {
      throw new RuntimeException("Don't understand this kind " + kind);
    }
    il.append(Utility.createConversion(fact, jlaAnnotation, BcelWorld.makeBcelType(toType)));
    return il;
  }
View Full Code Here

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

  }

  public static InstructionList createConversion(InstructionFactory fact, Type fromType, Type toType, boolean allowAutoboxing) {
    // System.out.println("cast to: " + toType);

    InstructionList il = new InstructionList();

    // PR71273
    if ((fromType.equals(Type.BYTE) || fromType.equals(Type.CHAR) || fromType.equals(Type.SHORT)) && (toType.equals(Type.INT))) {
      return il;
    }

    if (fromType.equals(toType)) {
      return il;
    }
    if (toType.equals(Type.VOID)) {
      il.append(InstructionFactory.createPop(fromType.getSize()));
      return il;
    }

    if (fromType.equals(Type.VOID)) {
      if (toType instanceof BasicType) {
        throw new BCException("attempting to cast from void to basic type");
      }
      il.append(InstructionFactory.createNull(Type.OBJECT));
      return il;
    }

    if (fromType.equals(Type.OBJECT)) {
      if (toType instanceof BasicType) {
        String name = toType.toString() + "Value";
        il.append(fact.createInvoke("org.aspectj.runtime.internal.Conversions", name, toType, new Type[] { Type.OBJECT },
            Constants.INVOKESTATIC));
        return il;
      }
    }

    if (toType.equals(Type.OBJECT)) {
      if (fromType instanceof BasicType) {
        String name = fromType.toString() + "Object";
        il.append(fact.createInvoke("org.aspectj.runtime.internal.Conversions", name, Type.OBJECT, new Type[] { fromType },
            Constants.INVOKESTATIC));
        return il;
      } else if (fromType instanceof ReferenceType) {
        return il;
      } else {
        throw new RuntimeException();
      }
    }

    if (fromType instanceof ReferenceType && ((ReferenceType) fromType).isAssignmentCompatibleWith(toType)) {
      return il;
    }

    if (allowAutoboxing) {
      if (toType instanceof BasicType && fromType instanceof ReferenceType) {
        // unboxing
        String name = toType.toString() + "Value";
        il.append(fact.createInvoke("org.aspectj.runtime.internal.Conversions", name, toType, new Type[] { Type.OBJECT },
            Constants.INVOKESTATIC));
        return il;
      }

      if (fromType instanceof BasicType && toType instanceof ReferenceType) {
        // boxing
        String name = fromType.toString() + "Object";
        il.append(fact.createInvoke("org.aspectj.runtime.internal.Conversions", name, Type.OBJECT, new Type[] { fromType },
            Constants.INVOKESTATIC));
        il.append(fact.createCast(Type.OBJECT, toType));
        return il;
      }
    }

    il.append(fact.createCast(fromType, toType));
    return il;
  }
View Full Code Here

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

   * @param branchInstruction the branch instruction to replace ih with
   * @param enclosingMethod where to find ih's instruction list.
   */
  public static void replaceInstruction(InstructionHandle ih, InstructionList replacementInstructions,
      LazyMethodGen enclosingMethod) {
    InstructionList il = enclosingMethod.getBody();
    InstructionHandle fresh = il.append(ih, replacementInstructions);
    deleteInstruction(ih, fresh, enclosingMethod);
  }
View Full Code Here

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

   * @param ih the instruction handle to delete
   * @param retargetTo the instruction handle to retarget targeters of ih to.
   * @param enclosingMethod where to find ih's instruction list.
   */
  public static void deleteInstruction(InstructionHandle ih, InstructionHandle retargetTo, LazyMethodGen enclosingMethod) {
    InstructionList il = enclosingMethod.getBody();
    for (InstructionTargeter targeter : ih.getTargetersCopy()) {
      targeter.updateTarget(ih, retargetTo);
    }
    ih.removeAllTargeters();
    try {
      il.delete(ih);
    } catch (TargetLostException e) {
      throw new BCException("this really can't happen");
    }
  }
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.