Package de.petris.dynamicaspects.util

Examples of de.petris.dynamicaspects.util.InstructionSearcher


        targetClass.getMethods()[methodIdx],
        targetClass.getClassName(),
      constPoolGen );

    // a searcher to look for the joinpoints
    InstructionSearcher searcher =
      new InstructionSearcher( constPoolGen, mGen.getInstructionList() );
   
    // look for joinpoints
    List<CallMatch> targets =
      searcher.lookUpMethodCall(
          Pattern.compile( joinpointPattern ) );
   
    // a patcher for the given method
    CallWrapperMethodPatcher mp =
      new CallWrapperMethodPatcher(
View Full Code Here


          targetClass.getMethods()[methodIdx.intValue()],
          targetClass.getClassName(),
        constPoolGen );
     
      // get a searcher for the joinpoints
      InstructionSearcher searcher =
        new InstructionSearcher( constPoolGen, mGen.getInstructionList() );
           
      // look for joinpoints
      List<CallMatch> targets =
        searcher.lookUpMethodCall( joinpointPattern );
     
      // are there any joinpoints  matching the pattern in this methdod?
      if( !targets.isEmpty() ) {
       
        // yes, so we install a wrapper here
View Full Code Here

   */
  private void patchMethod() {
   
    // patch before starts here
   
    InstructionSearcher aFinder =
      new InstructionSearcher( constPoolGen, iList );
   
    InstructionHandle first = null;
   
    // respect the super() and this(...)-call at the
    // beginning of constructors
    if( mGen.getName().equals( CONSTRUCTOR_NAME ) ) {
      first = aFinder.lookUpSuperConstructorCall().getNext();
    }
    else
      first = iList.getStart();
    }
   
    // save return statement
    InstructionHandle last = iList.getEnd();

    ExecutionWrapperVariableHandler vHandler
      = new ExecutionWrapperVariableHandler(
          mGen, iList, factory, constPoolGen );
   
    // create variable for argumentList
    int argListVarIdx =
      vHandler.createArgumentList( first );
   
    // create variable for executionwrapper
    int executionWrapperIdx =
      vHandler.createExecutionWrapper( first );
   
    // BEFORE CALL
   
    // load the executionwrapper
    iList.insert( first,
      InstructionFactory.createLoad(
        EXECUTIONWRAPPERTYPE,  executionWrapperIdx ) );
   
    // load parameter for before()-call
    iList.insert(
      first,
      InstructionFactory.createLoad(
        ExecutionWrapperVariableHandler.ARGLIST_TYPE,
        argListVarIdx ) );
     
    // call before()
    iList.insert(
      first,
      factory.createInvoke(
        ExecutionWrapper.class.getName(),
        Wrapper.getBeforeName(),
        Type.VOID,
        new Type[] {
          ExecutionWrapperVariableHandler.ARGLIST_TYPE },
        INVOKEVIRTUAL ) );

   
    // look for all return-statements
    List<InstructionHandle> returnStatements =
      aFinder.lookUpReturnStatements();
    Iterator<InstructionHandle> iter = returnStatements.iterator();
   
    while( iter.hasNext() ) {
     
      InstructionHandle curReturnStatement = iter.next();
View Full Code Here

   * Unpatches the method.
   */
  private void unpatchMethod() {

    // a finder for instructions
    InstructionSearcher aFinder =
      new InstructionSearcher( constPoolGen, iList );
   
    // lookup before() call
    List<InstructionHandle> beforeList =
      aFinder.lookUpMethodCall(
        ExecutionWrapper.class.getName(),
        Wrapper.getBeforeName(),
        Wrapper.getBeforeSignature() )
   
    // save before() call
    InstructionHandle beforeCall = beforeList.get(0);
   
    // look for all return-statements
    List<InstructionHandle> returnStatements =
      aFinder.lookUpReturnStatementsSkipLast();
    Iterator<InstructionHandle> iter = returnStatements.iterator();

    InstructionHandle exceptionHandler = null;
   
    while( iter.hasNext() ) {
     
      InstructionHandle curReturnStatement = iter.next();
     
      InstructionHandle last = curReturnStatement.getPrev();
      // save the exceptionhandler for the removeExceptionHandler-call,
      // ( we want the statement before the last return )
     
      exceptionHandler = curReturnStatement.getNext();
     
      InstructionHandle first = last;
     
            // after()-call may have been complex or simple
            // depending on the return type of the target method
      if( mGen.getReturnType().equals( Type.VOID ) ) {
        first = first.getPrev();
      }
      else {
                // two instructions backward for cat2type-operation
        if( Reflection.isCat2Type(
            mGen.getReturnType() ) ) {
          first = first.getPrev().getPrev();
        }
        else {
          first = first.getPrev();
        }

        first = first.getPrev();
       
        if( !(mGen.getReturnType() instanceof BasicType) ) {
          first = first.getPrev();
        }
      }
   
      // remove the after()-calls
      try {
        iList.delete( first, last );
      }
      catch( TargetLostException tle ) {
        Logger.debug( "removing after()-calls: %s", tle.toString() );
      }
    }
   
    removeExceptionHandler( exceptionHandler );
   
    // remove catch() block
    try {
      iList.delete(
        exceptionHandler,
        iList.getEnd() );
    }
    catch( TargetLostException tle ) {
      Logger.debug( "removing catch-block: %s", tle.toString() );
    }
   
   
    // remove variable creation and before call
   
    InstructionHandle first = null;
   
    // respect the super() and this(...)-call at the
    // beginning of constructors
    if( mGen.getName().equals( CONSTRUCTOR_NAME ) ) {
      first = aFinder.lookUpSuperConstructorCall().getNext();
    }
    else
      first = iList.getStart();
    }
   
View Full Code Here

  /**
   * Installs the wrapper for all the target calls within this method.
   */
  private void patchMethod() {
   
    InstructionSearcher aFinder =
      new InstructionSearcher( constPoolGen, iList );
   
    InstructionHandle first = null;
   
    // respect the super() or this(...)-call at the
    // beginning of constructors
    if( mGen.getName().equals( CONSTRUCTOR_NAME ) ) {
      first = aFinder.lookUpSuperConstructorCall().getNext();
    }
    else
      first = iList.getStart();
    }
   
View Full Code Here

  /**
   * Removes the wrapper from all the target calls within this method.
   */
  private void unpatchMethod() {
   
    InstructionSearcher aFinder =
      new InstructionSearcher( constPoolGen, iList );
   
    CallWrapperVariableHandler vHandler =
      new CallWrapperVariableHandler(
        mGen, iList,
        factory, constPoolGen,
        joinpointPattern );
   
        // the index of the wrapper to be deinstalled
    int callWrapperIdx = vHandler.getCallWrapperVariableIndex();
   
        // get the loads of this wrapper variable
    aFinder.setCallWrapperLoads( callWrapperIdx, targets );
    Iterator<CallMatch> cmIter = targets.iterator();
   
        // loop over the target calls
    while( cmIter.hasNext() ) {
   
      // REMOVE before()-call
     
            // get the argumentList variable
      int curArgListVarIdx =
        vHandler.getNextArgumentListVariableIndex();
      InstructionHandle curArgListInit =
        aFinder.lookUpArgumentListInit( curArgListVarIdx );
     
      CallMatch curCallMatch = cmIter.next();

      InstructionHandle beforeLoad =
        curCallMatch.getBeforeLoad();
     
      try {
        iList.delete( curArgListInit,
          vHandler.getLastReloadInstruction(
            beforeLoad.getNext().getNext(),
            curCallMatch.getCallInfo() ) );
      }
      catch( TargetLostException tle ) {
        Logger.debug( "removing before()-calls: %s", tle.toString() );
      }
     
     
      // REMOVE after-call
      InstructionHandle afterLoad =
        curCallMatch.getAfterLoad();
     
      try {
        iList.delete( afterLoad,
          getLastAfterInstruction(
            afterLoad, curCallMatch.getCallInfo() ) );
      }
      catch( TargetLostException tle ) {
        Logger.debug( "removing after()-calls: %s", tle.toString() );
      }
     
     
      // REMOVE Exception-handler
      InstructionHandle afterExceptionLoad =
        curCallMatch.getAfterExceptionLoad();

      removeExceptionHandler( afterExceptionLoad );
     
      try {
        iList.delete( afterExceptionLoad.getPrev(),
          afterExceptionLoad.getNext().getNext().
            getNext().getNext().getNext() );
      }
      catch( TargetLostException tle ) {
        Logger.debug(
          "removing afterException()-calls: %s", tle.toString() );
      }
    }
   
        // remove the creation of the wrapper variable
    List<InstructionHandle> callWrapperStores =
      aFinder.lookUpCallWrapperStores( callWrapperIdx );
   
    try {
      iList.delete(
          callWrapperStores.get(0).getPrev(),
          callWrapperStores.get(1) );
View Full Code Here

TOP

Related Classes of de.petris.dynamicaspects.util.InstructionSearcher

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.