Package org.apache.bcel.util

Examples of org.apache.bcel.util.InstructionFinder


    /**
     * Peephole optimization: Remove sequences of [ALOAD, POP].
     */
    private void peepHoleOptimization(MethodGenerator methodGen) {
  InstructionList il = methodGen.getInstructionList();
  InstructionFinder find = new InstructionFinder(il);
  InstructionHandle ih;
  String pattern;

  // Remove seqences of ALOAD, POP (GTM)
  pattern = "`ALOAD'`POP'`Instruction'";
  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
            }
  }
  // Replace sequences of ILOAD_?, ALOAD_?, SWAP with ALOAD_?, ILOAD_?
  pattern = "`ILOAD'`ALOAD'`SWAP'`Instruction'";
  for(Iterator iter=find.search(pattern); iter.hasNext();){
            InstructionHandle[] match = (InstructionHandle[])iter.next();
            try {
                org.apache.bcel.generic.Instruction iload;
                org.apache.bcel.generic.Instruction aload;
                if ((!match[0].hasTargeters()) &&
                    (!match[1].hasTargeters()) &&
                    (!match[2].hasTargeters())) {
                    iload = match[0].getInstruction();
                    aload = match[1].getInstruction();
                    il.insert(match[0], aload);
                    il.insert(match[0], iload);
                    il.delete(match[0], match[2]);
                }
            }
            catch (TargetLostException e) {
                // TODO: move target down into the list
            }
        }

        // Replace sequences of ALOAD_1, ALOAD_1 with ALOAD_1, DUP
  pattern = "`ALOAD_1'`ALOAD_1'`Instruction'";
        for(Iterator iter=find.search(pattern); iter.hasNext();){
            InstructionHandle[] match = (InstructionHandle[])iter.next();
            try {
          org.apache.bcel.generic.Instruction iload;
                org.apache.bcel.generic.Instruction aload;
                if ((!match[0].hasTargeters()) && (!match[1].hasTargeters())) {
View Full Code Here


     * 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

     * 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

                    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 ISTORE (GETSTATIC GETFIELD BIPUSH ISHR GETSTATIC IADD ISTORE)+");
                    if (e.hasNext()) {
                        InstructionHandle[] handles = (InstructionHandle[]) e.next();
                        String myplayer = ((GETSTATIC) handles[0].getInstruction()).getClassName(cpg) + "." + ((GETSTATIC) handles[0].getInstruction()).getFieldName(cpg);
                        String animable = ((GETFIELD) handles[1].getInstruction()).getClassName(cpg);
                        String plane = ((GETFIELD) handles[1].getInstruction()).getFieldName(cpg);
View Full Code Here

                        if (t instanceof ArrayType && ((ArrayType)t).getDimensions() == 3 && ((ArrayType)t).getBasicType().getSignature().startsWith("L")) {
                            ConstantPoolGen cpg = c.getValue().getConstantPool();
                            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 GETSTATIC AALOAD ILOAD AALOAD ILOAD BALOAD ICONST IAND");
                            if (e.hasNext()) {
                              InstructionHandle[] handles = (InstructionHandle[]) e.next();
                                String gba = ((GETSTATIC)handles[0].getInstruction()).getClassName(cpg) + "." + ((GETSTATIC)handles[0].getInstruction()).getFieldName(cpg);
                                data.addField("GroundSettingsArray", gba);
                                e = f.search("GETSTATIC (ICONST)+ GETSTATIC IADD AALOAD");
                                //System.out.println("Found method. Class: "+c.getValue().getClassName() + ", method: "+m.getName());
                                if (e.hasNext()) {
                                    handles = (InstructionHandle[]) e.next();
                                    String planearray = ((GETSTATIC)handles[0].getInstruction()).getClassName(cpg) + "." + ((GETSTATIC)handles[0].getInstruction()).getFieldName(cpg);
                                    String curplane = ((GETSTATIC)handles[2].getInstruction()).getClassName(cpg) + "." + ((GETSTATIC)handles[2].getInstruction()).getFieldName(cpg);
View Full Code Here

                if (m.isStatic()) {
                    ConstantPoolGen cpg = c.getValue().getConstantPool();
                    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("BASTORE GETSTATIC ILOAD ILOAD ILOAD ILOAD INVOKEVIRTUAL");
                    if (e.hasNext()) {
                        InstructionHandle[] handles = (InstructionHandle[]) e.next();
                        String curtoolkit = ((GETSTATIC)handles[1].getInstruction()).getClassName(cpg) + "." + ((GETSTATIC)handles[1].getInstruction()).getFieldName(cpg);
                        String toolkit = ((GETSTATIC)handles[1].getInstruction()).getSignature(cpg).replaceAll("L|;","");
                        data.addClass("Toolkit", toolkit);
View Full Code Here

                        count++;
                        if(count==7){
                          fi = iS.nextGETSTATIC();
                          sDestX = fi.getClassName(cpg)+'.'+fi.getFieldName(cpg);
                          data.addField("DestX", sDestX);
                          InstructionFinder f = new InstructionFinder(il);
                          Iterator e = f.search("IF_ICMPNE ICONST_M1 PUTSTATIC ICONST_M1 PUTSTATIC");
                              if(e.hasNext()){
                                InstructionHandle[] handles = (InstructionHandle[]) e.next();
                                String temp = ((FieldInstruction) ((PUTSTATIC) handles[2].getInstruction())).getClassName(cpg) + "." + ((PUTSTATIC) handles[2].getInstruction()).getFieldName(cpg);
                                if(!temp.equals(sDestX)){
                                  data.addField("DestY", temp);
View Full Code Here

                for (Method m : c.getMethods()) {
                    if (m.isStatic()) {
                        MethodGen gen = new MethodGen(m,c.getClassName(),cpg);
                        InstructionList il = gen.getInstructionList();
                        if (il == null) continue;
                        InstructionFinder f = new InstructionFinder(il);
                        Iterator e = f.search("GETSTATIC LDC FSUB PUTSTATIC");
                        if (e.hasNext()) {
                            InstructionHandle[] handles = (InstructionHandle[]) e.next();
                            data.addField("MapAngle", ((GETSTATIC)handles[0].getInstruction()).getClassName(cpg) + "." + ((GETSTATIC)handles[0].getInstruction()).getFieldName(cpg));
                            return SearchResult.Success;
                        }
View Full Code Here

                      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("INVOKESTATIC IFEQ GETSTATIC ICONST_2 IF_ICMPLE");
                      if (e.hasNext()) {
                          InstructionHandle[] handles = (InstructionHandle[]) e.next();
                          String opCount = ((GETSTATIC) handles[2].getInstruction()).getClassName(cpg)+'.'+((GETSTATIC) handles[2].getInstruction()).getFieldName(cpg);
                          data.addField("MenuOptionCount", opCount);
                          return SearchResult.Success;
View Full Code Here

                                MethodGen gen = new MethodGen(m, clazz.getClassName(), cpg);
                                InstructionList il = gen.getInstructionList();
                                if (il == null) {
                                    continue;
                                }
                                InstructionFinder f = new InstructionFinder(il);
                                Iterator e = f.search("ALOAD GETFIELD GETFIELD ALOAD GETFIELD GETFIELD");
                                if (e.hasNext()) {
                                    InstructionHandle[] handles = (InstructionHandle[]) e.next();
                                    String getviewport = ((GETFIELD) handles[1].getInstruction()).getFieldName(cpg);
                                    e = f.search("ILOAD ALOAD GETFIELD if_icmplt ILOAD ALOAD GETFIELD if_icmple", handles[handles.length - 1]);
                                    if (e.hasNext()) {
                                        handles = (InstructionHandle[]) e.next();
                                        String zmin = ((GETFIELD) handles[2].getInstruction()).getFieldName(cpg);
                                        String zmax = ((GETFIELD) handles[6].getInstruction()).getFieldName(cpg);
                                        e = f.search("ALOAD GETFIELD ALOAD GETFIELD GETFIELD ALOAD GETFIELD GETFIELD", handles[handles.length - 1]);
                                        if (e.hasNext()) {
                                            handles = (InstructionHandle[]) e.next();
                                            String xscale = ((GETFIELD) handles[1].getInstruction()).getFieldName(cpg);
                                            e = f.search("ALOAD GETFIELD ALOAD GETFIELD GETFIELD ALOAD GETFIELD GETFIELD", handles[handles.length - 1]);
                                            if (e.hasNext()) {
                                                handles = (InstructionHandle[]) e.next();
                                                String yscale = ((GETFIELD) handles[1].getInstruction()).getFieldName(cpg);
                                                e = f.search("ILOAD ALOAD GETFIELD if_icmplt ILOAD ALOAD GETFIELD if_icmpgt", handles[handles.length - 1]);
                                                if (e.hasNext()) {
                                                    handles = (InstructionHandle[]) e.next();
                                                    String xmin = ((GETFIELD) handles[2].getInstruction()).getFieldName(cpg);
                                                    String xmax = ((GETFIELD) handles[6].getInstruction()).getFieldName(cpg);
                                                    e = f.search("ILOAD ALOAD GETFIELD if_icmplt ILOAD ALOAD GETFIELD if_icmpgt", handles[handles.length - 1]);
                                                    if (e.hasNext()) {
                                                        handles = (InstructionHandle[]) e.next();
                                                        String ymin = ((GETFIELD) handles[2].getInstruction()).getFieldName(cpg);
                                                        String ymax = ((GETFIELD) handles[6].getInstruction()).getFieldName(cpg);
                                                        sdtoolkit.addField("xMin", xmin);
View Full Code Here

TOP

Related Classes of org.apache.bcel.util.InstructionFinder

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.