edu.rice.cs.cunit.instrumentors.util
Class AInsertAtOpcodeStrategy

java.lang.Object
  extended by edu.rice.cs.cunit.instrumentors.util.AInsertAtOpcodeStrategy
All Implemented Interfaces:
IInstrumentationStrategy
Direct Known Subclasses:
CallOnObjectNotifyStrategy, CallOnObjectWaitStrategy, CallOnSynchronizedBlockStrategy, CallOnThreadExitStrategy, CallOnThreadJoinStrategy, CallOnThreadRunStrategy, CallOnThreadStartStrategy, CompactRecordBufferCodeStrategy

public abstract class AInsertAtOpcodeStrategy
extends java.lang.Object
implements IInstrumentationStrategy

Abstract instrumentation strategy that insert code before an opcode.

Author:
Mathias Ricken

Field Summary
protected  IPredicate.Ternary<ClassFile,MethodInfo,InstructionList> _afterOpcodePredicate
          Predicate that decides if code should be inserted AFTER this opcode.
protected  IPredicate.Ternary<ClassFile,MethodInfo,InstructionList> _beforeOpcodePredicate
          Predicate that decides if code should be inserted BEFORE this opcode.
protected  IPredicate<ClassFile> _classPredicate
          Predicate that decides if this class should be instrumented.
protected  IPredicate.Binary<ClassFile,MethodInfo> _methodPredicate
          Predicate that decides if this method should be instrumented.
protected static IPredicate.Ternary<ClassFile,MethodInfo,InstructionList> OPCODE_NEVER
          A predicate that always returns false, i.e.
 
Constructor Summary
protected AInsertAtOpcodeStrategy(IPredicate<ClassFile> classPredicate, IPredicate.Binary<ClassFile,MethodInfo> methodPredicate, IPredicate.Ternary<ClassFile,MethodInfo,InstructionList> beforeOpcodePredicate, IPredicate.Ternary<ClassFile,MethodInfo,InstructionList> afterOpcodePredicate)
          Create a new strategy with the specified predicates.
 
Method Summary
 void done()
          Instrumentation of all classes is done.
abstract  boolean insertEndOfMethod(ClassFile cf, MethodInfo mi, InstructionList il, boolean insertBefore, boolean insertAfter)
          Insert instructions at the end of the method.
abstract  void insertInstructionsAfter(ClassFile cf, MethodInfo mi, InstructionList il)
          Insert instructions after and advance past the instruction.
abstract  void insertInstructionsBefore(ClassFile cf, MethodInfo mi, InstructionList il)
          Insert instructions before.
 void instrument(ClassFile cf)
          Instrument the class.
abstract  void modifyStackAndLocals(ClassFile cf, MethodInfo mi, InstructionList il, boolean insertBefore, boolean insertAfter, boolean insertEndOfMethod)
          Modify the stack size and number of local variables so that the added instructions can execute.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_classPredicate

protected IPredicate<ClassFile> _classPredicate
Predicate that decides if this class should be instrumented.


_methodPredicate

protected IPredicate.Binary<ClassFile,MethodInfo> _methodPredicate
Predicate that decides if this method should be instrumented.


_beforeOpcodePredicate

protected IPredicate.Ternary<ClassFile,MethodInfo,InstructionList> _beforeOpcodePredicate
Predicate that decides if code should be inserted BEFORE this opcode.


_afterOpcodePredicate

protected IPredicate.Ternary<ClassFile,MethodInfo,InstructionList> _afterOpcodePredicate
Predicate that decides if code should be inserted AFTER this opcode.


OPCODE_NEVER

protected static final IPredicate.Ternary<ClassFile,MethodInfo,InstructionList> OPCODE_NEVER
A predicate that always returns false, i.e. never causes code to be inserted.

Constructor Detail

AInsertAtOpcodeStrategy

protected AInsertAtOpcodeStrategy(IPredicate<ClassFile> classPredicate,
                                  IPredicate.Binary<ClassFile,MethodInfo> methodPredicate,
                                  IPredicate.Ternary<ClassFile,MethodInfo,InstructionList> beforeOpcodePredicate,
                                  IPredicate.Ternary<ClassFile,MethodInfo,InstructionList> afterOpcodePredicate)
Create a new strategy with the specified predicates.

Parameters:
classPredicate - predicate that decides if this class should be instrumented
methodPredicate - predicate that decides if this method should be instrumented
beforeOpcodePredicate - predicate that decides if this opcode should be instrumented
afterOpcodePredicate - predicate that decides if this opcode should be instrumented
Method Detail

instrument

public void instrument(ClassFile cf)
Instrument the class.

Specified by:
instrument in interface IInstrumentationStrategy
Parameters:
cf - class file info

insertInstructionsBefore

public abstract void insertInstructionsBefore(ClassFile cf,
                                              MethodInfo mi,
                                              InstructionList il)
Insert instructions before. NOTE: The method is expected to move back exactly to the instruction it was on. If it moves to a place before the instruction, an infinite loop may occur. If it moves to a place after the instruction, future inserts may not occur.

Parameters:
cf - class file
mi - method information
il - instruction list

insertInstructionsAfter

public abstract void insertInstructionsAfter(ClassFile cf,
                                             MethodInfo mi,
                                             InstructionList il)
Insert instructions after and advance past the instruction. NOTE: The method is expected to move exactly to the last instruction that was inserted. If it moves to a place before the instruction, an infinite loop may occur. If it moves to a place after the instruction, future inserts may not occur.

Parameters:
cf - class file
mi - method information
il - instruction list

insertEndOfMethod

public abstract boolean insertEndOfMethod(ClassFile cf,
                                          MethodInfo mi,
                                          InstructionList il,
                                          boolean insertBefore,
                                          boolean insertAfter)
Insert instructions at the end of the method. NOTE: The method is expected to move exactly to the last instruction that was inserted. If it moves to a place before the instruction, an infinite loop may occur. If it moves to a place after the instruction, future inserts may not occur.

Parameters:
cf - class file
mi - method information
il - instruction list
insertBefore - true if code was inserted before an opcode
insertAfter - true if code was inserted after an opcode
Returns:
true if code was inserted

modifyStackAndLocals

public abstract void modifyStackAndLocals(ClassFile cf,
                                          MethodInfo mi,
                                          InstructionList il,
                                          boolean insertBefore,
                                          boolean insertAfter,
                                          boolean insertEndOfMethod)
Modify the stack size and number of local variables so that the added instructions can execute. Called only once per method.

Parameters:
cf - class file
mi - method information
il - instruction list
insertBefore - true if code was inserted before an opcode
insertAfter - true if code was inserted after an opcode
insertEndOfMethod - true if code was inserted at the end of the method

done

public void done()
Instrumentation of all classes is done.

Specified by:
done in interface IInstrumentationStrategy