Package org.apache.bcel.util

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


    } 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

    /**
     * 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

   *
   * @return the handle to the super/this(...) constructor call.
   */
  public InstructionHandle lookUpSuperConstructorCall() {
    // construct a finder
    InstructionFinder finder =
      new InstructionFinder( iList );
   
    // do the search
    Iterator iter
      = finder.search(
        Constants.OPCODE_NAMES[Constants.INVOKESPECIAL] );
 
    if( iter.hasNext() ) {
      InstructionHandle[] ih
        = (InstructionHandle[])iter.next();
View Full Code Here

   * @return a list of matches
   */
  public List<CallMatch> lookUpMethodCall( Pattern invokePattern ) {
   
    // construct a finder
    InstructionFinder finder =
      new InstructionFinder( iList );
   
    // search all invokes
    Iterator iter
      = finder.search(
        Constants.OPCODE_NAMES[Constants.INVOKEINTERFACE]
        + "|"
        + Constants.OPCODE_NAMES[Constants.INVOKESPECIAL]
        + "|"
        + Constants.OPCODE_NAMES[Constants.INVOKESTATIC]
View Full Code Here

    int idx =
      constPoolGen.lookupMethodref(
        classname, name, signature );
   
    // construct a finder
    InstructionFinder finder =
      new InstructionFinder( iList );
   
    // do the search
    Iterator iter
      = finder.search(
        Constants.OPCODE_NAMES[Constants.INVOKEVIRTUAL],
        new MethodCallConstraint( idx ) );
   
    // the return list
    List<InstructionHandle> rc = new ArrayList<InstructionHandle>();
View Full Code Here

   * @return a list of return statments.
   */
  private List<InstructionHandle> lookUpReturnStatements( boolean skipLast ) {
   
    // construct a finder
    InstructionFinder finder =
      new InstructionFinder( iList );
   
    // do the search
    Iterator iter
      = finder.search( "IRETURN|LRETURN|FRETURN|DRETURN|ARETURN|RETURN" );
   
    List<InstructionHandle> rc = new ArrayList<InstructionHandle>();
   
    while( iter.hasNext() ) {
      InstructionHandle[] ih
View Full Code Here

   * @return an iterator of the search-results.
   */
  private Iterator searchLoadInstruction(
    int varIdx, String prefix, String postfix, int instructionIdx ) {

    InstructionFinder finder =
      new InstructionFinder( iList );
 
    if( varIdx > 3 ) { // a constraint checks the variable index
      return finder.search(
        prefix + " " +
        "ALOAD " + postfix,
        new LoadStoreConstraint( varIdx, instructionIdx ) );
    }
    else { // the variable index is included in the instruction
      return finder.search(
        prefix + " " 
        + new ALOAD( varIdx ).toString( false )
        + " " + postfix );
    }
  }
View Full Code Here

   * @return an iterator of the search-results.
   */
  private Iterator searchStoreInstruction(
      int varIdx, String prefix, String postfix, int instructionIdx ) {

    InstructionFinder finder =
      new InstructionFinder( iList );
 
    if( varIdx > 3 ) {  // a constraint checks the variable index
      return finder.search(
        prefix + " " +
        "ASTORE " + postfix,
        new LoadStoreConstraint( varIdx, instructionIdx ) );
    }
    else { // the variable index is included in the instruction
      return finder.search(
        prefix + " " 
        + new ASTORE( varIdx ).toString( false )
        + " " + postfix );
    }
  }
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.