Examples of InstructionFinder


Examples of org.apache.bcel.util.InstructionFinder

                    MethodGen gen = new MethodGen(m, c.getValue().getClassName(), cpg);
                    InstructionList il = gen.getInstructionList();
                    if (il == null) {
                        continue;
                    }
                    InstructionFinder f = new InstructionFinder(il);
                    Iterator e = f.search("GETSTATIC GETFIELD ICONST IALOAD LDC ISHR ISTORE GETSTATIC GETFIELD ICONST IALOAD LDC");
                    if (e.hasNext()) {
                        InstructionHandle[] handles = (InstructionHandle[]) e.next();
                        String queueX = ((GETFIELD) handles[8].getInstruction()).getFieldName(cpg);
                        String queueY = ((GETFIELD) handles[1].getInstruction()).getFieldName(cpg);
                        RSClass characterClass = data.getProperClass("Character");
View Full Code Here

Examples of org.apache.bcel.util.InstructionFinder

          if(m.isStatic() && m.isFinal() && m.getReturnType().equals(Type.VOID) &&
              m.getArgumentTypes().length == 0){
            ConstantPoolGen cpg = c.getValue().getConstantPool();
            MethodGen mg = new MethodGen(m, c.getValue().getClassName(), cpg);
            InstructionList il = mg.getInstructionList();
            InstructionFinder f = new InstructionFinder(il);
            Iterator e = f.search("INVOKEVIRTUAL CHECKCAST GETFIELD ASTORE ALOAD GETFIELD IFEQ");
            if(e.hasNext()){
              InstructionHandle[] handles = (InstructionHandle[]) e.next();
              String getHits = ((GETFIELD) handles[5].getInstruction()).getFieldName(cpg);
              InstructionSearcher iS = new InstructionSearcher(il, cpg);
              iS.nextGETSTATIC();
View Full Code Here

Examples of org.apache.bcel.util.InstructionFinder

                MethodGen gen = new MethodGen(m, c.getValue().getClassName(), cpg);
                InstructionList il = gen.getInstructionList();
                if (il == null) {
                   continue;
                }
                InstructionFinder f = new InstructionFinder(il);
                            // ISTORE GETSTATIC ISTORE GETSTATIC
                Iterator e = f.search("GETSTATIC ISTORE GETSTATIC ICONST IADD PUTSTATIC GETSTATIC ISTORE GETSTATIC");
                if (e.hasNext()) {
                  InstructionHandle[] handles = (InstructionHandle[]) e.next();
                      String menuX = ((GETSTATIC) handles[6].getInstruction()).getClassName(cpg) + "." + ((GETSTATIC) handles[6].getInstruction()).getFieldName(cpg);
                      String menuY = ((GETSTATIC) handles[8].getInstruction()).getClassName(cpg) + "." + ((GETSTATIC) handles[8].getInstruction()).getFieldName(cpg);
                      data.addField("MenuX", menuX);
View Full Code Here

Examples of org.apache.bcel.util.InstructionFinder

    /**
      * Peephole optimization.
      */
    private void peepHoleOptimization(MethodGenerator methodGen) {
        InstructionList il = methodGen.getInstructionList();
        InstructionFinder find = new InstructionFinder(il);
  InstructionHandle ih;
  String pattern;

  // LoadInstruction, POP => (removed)
  pattern = "LoadInstruction POP";
  for (Iterator iter = find.search(pattern); iter.hasNext();) {
      InstructionHandle[] match = (InstructionHandle[]) iter.next();
      try {
    if (!match[0].hasTargeters() && !match[1].hasTargeters()) {
                    il.delete(match[0], match[1]);
                }
      }
      catch (TargetLostException e) {
                // TODO: move target down into the list
            }
  }
       
  // ILOAD_N, ILOAD_N, SWAP, ISTORE_N => ILOAD_N
  pattern = "ILOAD ILOAD SWAP ISTORE";
  for (Iterator iter = find.search(pattern); iter.hasNext();) {
            InstructionHandle[] match = (InstructionHandle[]) iter.next();
            try {             
                org.apache.bcel.generic.ILOAD iload1 =
                    (org.apache.bcel.generic.ILOAD) match[0].getInstruction();
                org.apache.bcel.generic.ILOAD iload2 =
                    (org.apache.bcel.generic.ILOAD) match[1].getInstruction();
                org.apache.bcel.generic.ISTORE istore =
                    (org.apache.bcel.generic.ISTORE) match[3].getInstruction();
               
                if (!match[1].hasTargeters() &&
                    !match[2].hasTargeters() &&
                    !match[3].hasTargeters() &&
                    iload1.getIndex() == iload2.getIndex() &&
                    iload2.getIndex() == istore.getIndex())
                {
                    il.delete(match[1], match[3]);
                }
            }
            catch (TargetLostException e) {
                // TODO: move target down into the list
            }
        }

        // LoadInstruction_N, LoadInstruction_M, SWAP => LoadInstruction_M, LoadInstruction_N
  pattern = "LoadInstruction LoadInstruction SWAP";
  for (Iterator iter = find.search(pattern); iter.hasNext();) {
            InstructionHandle[] match = (InstructionHandle[])iter.next();
            try {
                if (!match[0].hasTargeters() &&
                    !match[1].hasTargeters() &&
                    !match[2].hasTargeters())
                {
                    Instruction load_m = match[1].getInstruction();
                    il.insert(match[0], load_m);
                    il.delete(match[1], match[2]);
                }
            }
            catch (TargetLostException e) {
                // TODO: move target down into the list
            }
        }
               
        // ALOAD_N ALOAD_N => ALOAD_N DUP
  pattern = "ALOAD ALOAD";
        for (Iterator iter = find.search(pattern); iter.hasNext();) {
            InstructionHandle[] match = (InstructionHandle[])iter.next();
            try {
                if (!match[1].hasTargeters()) {
                    org.apache.bcel.generic.ALOAD aload1 =
                        (org.apache.bcel.generic.ALOAD) match[0].getInstruction();
View Full Code Here

Examples of org.apache.bcel.util.InstructionFinder

     * Peephole optimization: Remove sequences of [ALOAD, POP].
     */
    private void peepHoleOptimization(MethodGenerator methodGen) {
  final String pattern = "`aload'`pop'`instruction'";
  final InstructionList il = methodGen.getInstructionList();
  final InstructionFinder find = new InstructionFinder(il);
  for(Iterator iter=find.search(pattern); iter.hasNext(); ) {
      InstructionHandle[] match = (InstructionHandle[])iter.next();
      try {
    il.delete(match[0], match[1]);
      }
      catch (TargetLostException e) {
View Full Code Here

Examples of org.apache.bcel.util.InstructionFinder

     * Peephole optimization: Remove sequences of [ALOAD, POP].
     */
    private void peepHoleOptimization(MethodGenerator methodGen) {
  final String pattern = "`aload'`pop'`instruction'";
  final InstructionList il = methodGen.getInstructionList();
  final InstructionFinder find = new InstructionFinder(il);
  for(Iterator iter=find.search(pattern); iter.hasNext(); ) {
      InstructionHandle[] match = (InstructionHandle[])iter.next();
      try {
    il.delete(match[0], match[1]);
      }
      catch (TargetLostException e) {
View Full Code Here

Examples of org.apache.bcel.util.InstructionFinder

    /**
      * Peephole optimization.
      */
    private void peepHoleOptimization(MethodGenerator methodGen) {
        InstructionList il = methodGen.getInstructionList();
        InstructionFinder find = new InstructionFinder(il);
  InstructionHandle ih;
  String pattern;

  // LoadInstruction, POP => (removed)
  pattern = "LoadInstruction POP";
  for (Iterator iter = find.search(pattern); iter.hasNext();) {
      InstructionHandle[] match = (InstructionHandle[]) iter.next();
      try {
    if (!match[0].hasTargeters() && !match[1].hasTargeters()) {
                    il.delete(match[0], match[1]);
                }
      }
      catch (TargetLostException e) {
                // TODO: move target down into the list
            }
  }
       
  // ILOAD_N, ILOAD_N, SWAP, ISTORE_N => ILOAD_N
  pattern = "ILOAD ILOAD SWAP ISTORE";
  for (Iterator iter = find.search(pattern); iter.hasNext();) {
            InstructionHandle[] match = (InstructionHandle[]) iter.next();
            try {             
                org.apache.bcel.generic.ILOAD iload1 =
                    (org.apache.bcel.generic.ILOAD) match[0].getInstruction();
                org.apache.bcel.generic.ILOAD iload2 =
                    (org.apache.bcel.generic.ILOAD) match[1].getInstruction();
                org.apache.bcel.generic.ISTORE istore =
                    (org.apache.bcel.generic.ISTORE) match[3].getInstruction();
               
                if (!match[1].hasTargeters() &&
                    !match[2].hasTargeters() &&
                    !match[3].hasTargeters() &&
                    iload1.getIndex() == iload2.getIndex() &&
                    iload2.getIndex() == istore.getIndex())
                {
                    il.delete(match[1], match[3]);
                }
            }
            catch (TargetLostException e) {
                // TODO: move target down into the list
            }
        }

        // LoadInstruction_N, LoadInstruction_M, SWAP => LoadInstruction_M, LoadInstruction_N
  pattern = "LoadInstruction LoadInstruction SWAP";
  for (Iterator iter = find.search(pattern); iter.hasNext();) {
            InstructionHandle[] match = (InstructionHandle[])iter.next();
            try {
                if (!match[0].hasTargeters() &&
                    !match[1].hasTargeters() &&
                    !match[2].hasTargeters())
                {
                    Instruction load_m = match[1].getInstruction();
                    il.insert(match[0], load_m);
                    il.delete(match[1], match[2]);
                }
            }
            catch (TargetLostException e) {
                // TODO: move target down into the list
            }
        }
               
        // ALOAD_N ALOAD_N => ALOAD_N DUP
  pattern = "ALOAD ALOAD";
        for (Iterator iter = find.search(pattern); iter.hasNext();) {
            InstructionHandle[] match = (InstructionHandle[])iter.next();
            try {
                if (!match[1].hasTargeters()) {
                    org.apache.bcel.generic.ALOAD aload1 =
                        (org.apache.bcel.generic.ALOAD) match[0].getInstruction();
View Full Code Here

Examples of org.apache.bcel.util.InstructionFinder

   * IF_ICMP__, Instruction
   *
   * where the IF_ICMP__ now branches to the target of the previous IFEQ instruction.
   */
  private static final void optimizeIFs(InstructionList il) {
    InstructionFinder f   = new InstructionFinder(il);
    String      pat = "IF_ICMP ICONST_1 GOTO ICONST_0 IFEQ Instruction";

    for(Iterator it = f.search(pat, my_constraint); it.hasNext();) {
      InstructionHandle[] match = (InstructionHandle[])it.next();
      // Everything ok, update code
      BranchInstruction ifeq    = (BranchInstruction)(match[4].getInstruction());
      BranchHandle      if_icmp = (BranchHandle)match[0];

View Full Code Here

Examples of org.apache.bcel.util.InstructionFinder

    } catch(Exception e) { e.printStackTrace(); }
  }

  private static final Method removeNOPs(MethodGen mg) {
    InstructionList   il    = mg.getInstructionList();
    InstructionFinder f     = new InstructionFinder(il);
    String            pat   = "NOP+"; // Find at least one NOP
    InstructionHandle next  = null;
    int               count = 0;

    for(Iterator e = f.search(pat); e.hasNext(); ) {
      InstructionHandle[] match = (InstructionHandle[])e.next();
      InstructionHandle   first = match[0];
      InstructionHandle   last  = match[match.length - 1];
     
      /* Some nasty Java compilers may add NOP at end of method.
View Full Code Here

Examples of org.apache.bcel.util.InstructionFinder

    } catch(Exception e) { e.printStackTrace(); }
  }

  private static final Method removeNOPs(MethodGen mg) {
    InstructionList   il    = mg.getInstructionList();
    InstructionFinder f     = new InstructionFinder(il);
    String            pat   = "NOP+"; // Find at least one NOP
    InstructionHandle next  = null;
    int               count = 0;

    for(Iterator i = f.search(pat); i.hasNext(); ) {
      InstructionHandle[] match = (InstructionHandle[])e.next();
      InstructionHandle   first = match[0];
      InstructionHandle   last  = match[match.length - 1];
     
      /* Some nasty Java compilers may add NOP at end of method.
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.