chord.instr
Class Instrumentor

java.lang.Object
  extended by javassist.expr.ExprEditor
      extended by chord.instr.BasicInstrumentor
          extended by chord.instr.Instrumentor

public class Instrumentor
extends BasicInstrumentor

Bytecode instrumentor for instrumenting a variety of common events. Instrumentor will modify a class to insert calls to an EventHandler; your analysis-specific logic can live in EventHandler and you need not fold app-specific logic into this class. Note that if you tell Instrumentor to trigger events of a particular kind, you must define appropriately-named handle methods in your EventHandler. If not, you will get MethodNotFound errors (or the like) at runtime. Note for authors of subclasses: domains (such as I, H, etc) are constructed only as-needed. Make sure that the instrumentation scheme you use correctly describes the domains you'll need.

Author:
Mayur Naik (mhn@cs.stanford.edu)

Field Summary
protected  InstrScheme.EventFormat acquireLockEvent
           
protected  java.lang.String acquireLockEventCall
           
protected  java.lang.String aftMethodCallEventCall
           
protected  java.lang.String aftNewEventCall
           
protected  java.lang.String aloadPriEventCall
           
protected  InstrScheme.EventFormat aloadPrimitiveEvent
           
protected  InstrScheme.EventFormat aloadReferenceEvent
           
protected  java.lang.String aloadRefEventCall
           
protected  java.lang.String astorePriEventCall
           
protected  InstrScheme.EventFormat astorePrimitiveEvent
           
protected  InstrScheme.EventFormat astoreReferenceEvent
           
protected  java.lang.String astoreRefEventCall
           
protected  java.lang.String basicBlockEventCall
           
protected  gnu.trove.TIntObjectHashMap<java.lang.String> bciToInstrMap
           
protected  java.lang.String befMethodCallEventCall
           
protected  java.lang.String befNewEventCall
           
protected  IndexMap<java.lang.String> Bmap
           
protected  joeq.Class.jq_Class currClass
           
protected  joeq.Class.jq_Method currMethod
           
protected  java.lang.String currSign
           
protected  DomB domB
           
protected  DomE domE
           
protected  DomF domF
           
protected  DomH domH
           
protected  DomI domI
           
protected  DomL domL
           
protected  DomM domM
           
protected  DomP domP
           
protected  DomR domR
           
protected  IndexMap<java.lang.String> Emap
           
protected  InstrScheme.EventFormat enterMainMethodEvent
           
protected  java.lang.String enterMainMethodEventCall
           
protected  InstrScheme.EventFormat enterMethodEvent
           
protected  java.lang.String enterMethodEventCall
           
protected  java.lang.String eventHandlerClassName
           
protected  IndexMap<java.lang.String> Fmap
           
protected  boolean genBasicBlockEvent
           
protected  boolean genQuadEvent
           
protected  java.lang.String getfieldPriEventCall
           
protected  InstrScheme.EventFormat getfieldPrimitiveEvent
           
protected  java.lang.String getfieldReference
           
protected  InstrScheme.EventFormat getfieldReferenceEvent
           
protected  java.lang.String getstaticPriEventCall
           
protected  InstrScheme.EventFormat getstaticPrimitiveEvent
           
protected  java.lang.String getstaticRefEcentCall
           
protected  InstrScheme.EventFormat getstaticReferenceEvent
           
protected  IndexMap<java.lang.String> Hmap
           
protected  IndexMap<java.lang.String> Imap
           
protected  InstrScheme.EventFormat leaveMethodEvent
           
protected  java.lang.String leaveMethodEventCall
           
protected  IndexMap<java.lang.String> Lmap
           
protected  joeq.Class.jq_Method mainMethod
           
protected  InstrScheme.EventFormat methodCallEvent
           
protected  IndexMap<java.lang.String> Mmap
           
protected  InstrScheme.EventFormat newArrayEvent
           
protected  java.lang.String newArrayEventCall
           
protected  InstrScheme.EventFormat newEvent
           
protected  java.lang.String notifyAllEventCall
           
protected  InstrScheme.EventFormat notifyEvent
           
protected  java.lang.String notifyEventCall
           
protected  IndexMap<java.lang.String> Pmap
           
protected  Program program
           
protected  java.lang.String putfieldPriEventCall
           
protected  InstrScheme.EventFormat putfieldPrimitiveEvent
           
protected  InstrScheme.EventFormat putfieldReferenceEvent
           
protected  java.lang.String putfieldRefEventCall
           
protected  java.lang.String putstaticPriEventCall
           
protected  InstrScheme.EventFormat putstaticPrimitiveEvent
           
protected  InstrScheme.EventFormat putstaticReferenceEvent
           
protected  java.lang.String putstaticRefEventCall
           
protected  java.lang.String quadEventCall
           
protected  InstrScheme.EventFormat releaseLockEvent
           
protected  java.lang.String releaseLockEventCall
           
protected  IndexMap<java.lang.String> Rmap
           
protected  InstrScheme scheme
           
protected  InstrScheme.EventFormat threadJoinEvent
           
protected  java.lang.String threadJoinEventCall
           
protected  InstrScheme.EventFormat threadStartEvent
           
protected  java.lang.String threadStartEventCall
           
protected  InstrScheme.EventFormat waitEvent
           
protected  java.lang.String waitEventCall
           
 
Fields inherited from class chord.instr.BasicInstrumentor
argsMap, currentClass, currentMethod, EVENT_HANDLER_ARGS_KEY, EVENT_HANDLER_CLASS_KEY, eventHandlerDoneCall, eventHandlerInitCall, INSTRUMENTOR_CLASS_KEY, isMainClass, pool, scopeExcludeAry, USE_JVMTI_KEY, useJvmti, verbose
 
Constructor Summary
Instrumentor(java.util.Map<java.lang.String,java.lang.String> argsMap)
           
 
Method Summary
protected  java.lang.String aloadPrimitive(javassist.expr.ArrayAccess e)
           
protected  java.lang.String aloadReference(javassist.expr.ArrayAccess e)
           
protected  java.lang.String astorePrimitive(javassist.expr.ArrayAccess e)
           
protected  java.lang.String astoreReference(javassist.expr.ArrayAccess e)
           
protected  void attachInstrToBCIAft(java.lang.String str, int bci)
           
protected  void attachInstrToBCIBef(java.lang.String str, int bci)
           
 void edit(javassist.expr.ArrayAccess e)
           
 void edit(javassist.expr.ConstructorCall e)
           
 void edit(javassist.CtBehavior method)
          Provides a hook to instrument a method specified in Javassist's representation.
 javassist.CtClass edit(javassist.CtClass clazz)
          Provides a hook to instrument a class specified in Javassist's representation.
 void edit(javassist.expr.FieldAccess e)
           
 void edit(javassist.expr.MethodCall e)
           
 void edit(javassist.expr.MonitorEnter e)
           
 void edit(javassist.expr.MonitorExit e)
           
 void edit(javassist.expr.NewArray e)
           
 void edit(javassist.expr.NewExpr e)
           
protected  int getBCI(joeq.Compiler.Quad.BasicBlock b, joeq.Class.jq_Method m)
           
 IndexMap<java.lang.String> getBmap()
           
protected  java.lang.String getDomainName(IndexMap<java.lang.String> map)
           
 DomB getDomB()
           
 DomE getDomE()
           
 DomF getDomF()
           
 DomH getDomH()
           
 DomI getDomI()
           
 DomL getDomL()
           
 DomM getDomM()
           
 DomP getDomP()
           
 DomR getDomR()
           
 IndexMap<java.lang.String> getEmap()
           
protected  int getFid(javassist.CtField field)
           
protected  java.lang.String getfieldPrimitive(javassist.expr.FieldAccess e, javassist.CtField f)
           
protected  java.lang.String getfieldReference(javassist.expr.FieldAccess e, javassist.CtField f)
           
 IndexMap<java.lang.String> getFmap()
           
 IndexMap<java.lang.String> getHmap()
           
 IndexMap<java.lang.String> getImap()
           
 InstrScheme getInstrScheme()
           
 IndexMap<java.lang.String> getLmap()
           
 IndexMap<java.lang.String> getMmap()
           
 IndexMap<java.lang.String> getPmap()
           
 IndexMap<java.lang.String> getRmap()
           
protected  java.lang.String getstaticPrimitive(javassist.expr.FieldAccess e, javassist.CtField f)
           
protected  java.lang.String getstaticReference(javassist.expr.FieldAccess e, javassist.CtField f)
           
protected
<T> IndexMap<java.lang.String>
getUniqueStringMap(ProgramDom<T> dom)
           
 java.lang.String insertBefore(int pos)
          Provides a hook to insert instrumentation just before the specified bytecode instruction in its containing method.
static boolean isRelevant(joeq.Compiler.Quad.Quad q)
           
protected  java.lang.String processThreadRelatedCall(javassist.expr.MethodCall e, javassist.CtBehavior m)
           
protected  java.lang.String putfieldPrimitive(javassist.expr.FieldAccess e, javassist.CtField f)
           
protected  java.lang.String putfieldReference(javassist.expr.FieldAccess e, javassist.CtField f)
           
protected  java.lang.String putstaticPrimitive(javassist.expr.FieldAccess e, javassist.CtField f)
           
protected  java.lang.String putstaticReference(javassist.expr.FieldAccess e, javassist.CtField f)
           
protected  int set(IndexMap<java.lang.String> map, javassist.expr.Expr e)
           
protected  int set(IndexMap<java.lang.String> map, int bci)
           
 
Methods inherited from class chord.instr.BasicInstrumentor
edit, getPool, isExcluded, isExplicitlyExcluded, isImplicitlyExcluded
 
Methods inherited from class javassist.expr.ExprEditor
doit, edit, edit, edit
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

program

protected final Program program

scheme

protected final InstrScheme scheme

eventHandlerClassName

protected final java.lang.String eventHandlerClassName

mainMethod

protected final joeq.Class.jq_Method mainMethod

genBasicBlockEvent

protected final boolean genBasicBlockEvent

genQuadEvent

protected final boolean genQuadEvent

enterMainMethodEvent

protected final InstrScheme.EventFormat enterMainMethodEvent

enterMethodEvent

protected final InstrScheme.EventFormat enterMethodEvent

leaveMethodEvent

protected final InstrScheme.EventFormat leaveMethodEvent

newEvent

protected final InstrScheme.EventFormat newEvent

newArrayEvent

protected final InstrScheme.EventFormat newArrayEvent

getstaticPrimitiveEvent

protected final InstrScheme.EventFormat getstaticPrimitiveEvent

getstaticReferenceEvent

protected final InstrScheme.EventFormat getstaticReferenceEvent

putstaticPrimitiveEvent

protected final InstrScheme.EventFormat putstaticPrimitiveEvent

putstaticReferenceEvent

protected final InstrScheme.EventFormat putstaticReferenceEvent

getfieldPrimitiveEvent

protected final InstrScheme.EventFormat getfieldPrimitiveEvent

getfieldReferenceEvent

protected final InstrScheme.EventFormat getfieldReferenceEvent

putfieldPrimitiveEvent

protected final InstrScheme.EventFormat putfieldPrimitiveEvent

putfieldReferenceEvent

protected final InstrScheme.EventFormat putfieldReferenceEvent

aloadPrimitiveEvent

protected final InstrScheme.EventFormat aloadPrimitiveEvent

aloadReferenceEvent

protected final InstrScheme.EventFormat aloadReferenceEvent

astorePrimitiveEvent

protected final InstrScheme.EventFormat astorePrimitiveEvent

astoreReferenceEvent

protected final InstrScheme.EventFormat astoreReferenceEvent

threadStartEvent

protected final InstrScheme.EventFormat threadStartEvent

threadJoinEvent

protected final InstrScheme.EventFormat threadJoinEvent

acquireLockEvent

protected final InstrScheme.EventFormat acquireLockEvent

releaseLockEvent

protected final InstrScheme.EventFormat releaseLockEvent

waitEvent

protected final InstrScheme.EventFormat waitEvent

notifyEvent

protected final InstrScheme.EventFormat notifyEvent

methodCallEvent

protected final InstrScheme.EventFormat methodCallEvent

enterMainMethodEventCall

protected final java.lang.String enterMainMethodEventCall

enterMethodEventCall

protected final java.lang.String enterMethodEventCall

leaveMethodEventCall

protected final java.lang.String leaveMethodEventCall

befNewEventCall

protected final java.lang.String befNewEventCall

aftNewEventCall

protected final java.lang.String aftNewEventCall

newArrayEventCall

protected final java.lang.String newArrayEventCall

getstaticPriEventCall

protected final java.lang.String getstaticPriEventCall

putstaticPriEventCall

protected final java.lang.String putstaticPriEventCall

getstaticRefEcentCall

protected final java.lang.String getstaticRefEcentCall

putstaticRefEventCall

protected final java.lang.String putstaticRefEventCall

getfieldPriEventCall

protected final java.lang.String getfieldPriEventCall

putfieldPriEventCall

protected final java.lang.String putfieldPriEventCall

getfieldReference

protected final java.lang.String getfieldReference

putfieldRefEventCall

protected final java.lang.String putfieldRefEventCall

aloadPriEventCall

protected final java.lang.String aloadPriEventCall

aloadRefEventCall

protected final java.lang.String aloadRefEventCall

astorePriEventCall

protected final java.lang.String astorePriEventCall

astoreRefEventCall

protected final java.lang.String astoreRefEventCall

befMethodCallEventCall

protected final java.lang.String befMethodCallEventCall

aftMethodCallEventCall

protected final java.lang.String aftMethodCallEventCall

quadEventCall

protected final java.lang.String quadEventCall

basicBlockEventCall

protected final java.lang.String basicBlockEventCall

threadStartEventCall

protected final java.lang.String threadStartEventCall

threadJoinEventCall

protected final java.lang.String threadJoinEventCall

waitEventCall

protected final java.lang.String waitEventCall

notifyEventCall

protected final java.lang.String notifyEventCall

notifyAllEventCall

protected final java.lang.String notifyAllEventCall

acquireLockEventCall

protected final java.lang.String acquireLockEventCall

releaseLockEventCall

protected final java.lang.String releaseLockEventCall

domF

protected DomF domF

domM

protected DomM domM

domH

protected DomH domH

domE

protected DomE domE

domI

protected DomI domI

domL

protected DomL domL

domR

protected DomR domR

domP

protected DomP domP

domB

protected DomB domB

Fmap

protected IndexMap<java.lang.String> Fmap

Mmap

protected IndexMap<java.lang.String> Mmap

Hmap

protected IndexMap<java.lang.String> Hmap

Emap

protected IndexMap<java.lang.String> Emap

Imap

protected IndexMap<java.lang.String> Imap

Lmap

protected IndexMap<java.lang.String> Lmap

Rmap

protected IndexMap<java.lang.String> Rmap

Pmap

protected IndexMap<java.lang.String> Pmap

Bmap

protected IndexMap<java.lang.String> Bmap

bciToInstrMap

protected gnu.trove.TIntObjectHashMap<java.lang.String> bciToInstrMap

currClass

protected joeq.Class.jq_Class currClass

currMethod

protected joeq.Class.jq_Method currMethod

currSign

protected java.lang.String currSign
Constructor Detail

Instrumentor

public Instrumentor(java.util.Map<java.lang.String,java.lang.String> argsMap)
Method Detail

getDomF

public DomF getDomF()

getDomM

public DomM getDomM()

getDomH

public DomH getDomH()

getDomE

public DomE getDomE()

getDomI

public DomI getDomI()

getDomL

public DomL getDomL()

getDomR

public DomR getDomR()

getDomP

public DomP getDomP()

getDomB

public DomB getDomB()

getFmap

public IndexMap<java.lang.String> getFmap()

getMmap

public IndexMap<java.lang.String> getMmap()

getHmap

public IndexMap<java.lang.String> getHmap()

getEmap

public IndexMap<java.lang.String> getEmap()

getImap

public IndexMap<java.lang.String> getImap()

getLmap

public IndexMap<java.lang.String> getLmap()

getRmap

public IndexMap<java.lang.String> getRmap()

getPmap

public IndexMap<java.lang.String> getPmap()

getBmap

public IndexMap<java.lang.String> getBmap()

getInstrScheme

public InstrScheme getInstrScheme()

getBCI

protected int getBCI(joeq.Compiler.Quad.BasicBlock b,
                     joeq.Class.jq_Method m)

attachInstrToBCIAft

protected void attachInstrToBCIAft(java.lang.String str,
                                   int bci)

attachInstrToBCIBef

protected void attachInstrToBCIBef(java.lang.String str,
                                   int bci)

getUniqueStringMap

protected <T> IndexMap<java.lang.String> getUniqueStringMap(ProgramDom<T> dom)

edit

public javassist.CtClass edit(javassist.CtClass clazz)
                       throws javassist.CannotCompileException
Description copied from class: BasicInstrumentor
Provides a hook to instrument a class specified in Javassist's representation. The default implementation calls the hooks to instrument all its methods, including its class initializer method (if any), all its declared constructors, and all its declared methods.

Overrides:
edit in class BasicInstrumentor
Parameters:
clazz - Javassist's representation of the class to be instrumented.
Returns:
The instrumented class in Javassist's representation. It must be null if the class is not instrumented.
Throws:
javassist.CannotCompileException - If Javassist fails to correctly instrument the class.

edit

public void edit(javassist.CtBehavior method)
          throws javassist.CannotCompileException
Description copied from class: BasicInstrumentor
Provides a hook to instrument a method specified in Javassist's representation. The default implementation visits each bytecode instruction in the method's code, calling the BasicInstrumentor.insertBefore(int) method for each instruction, ws well as the relevant edit method for certain kinds of instructions (namely, object allocation, field access, array access, monitor enter/exit, and method invocation).

Overrides:
edit in class BasicInstrumentor
Parameters:
method - Javassist's representation of the method to be instrumented in the currently instrumented class.
Throws:
javassist.CannotCompileException - If Javassist fails to correctly instrument the class.

isRelevant

public static boolean isRelevant(joeq.Compiler.Quad.Quad q)

set

protected int set(IndexMap<java.lang.String> map,
                  javassist.expr.Expr e)

getDomainName

protected java.lang.String getDomainName(IndexMap<java.lang.String> map)

set

protected int set(IndexMap<java.lang.String> map,
                  int bci)

getFid

protected int getFid(javassist.CtField field)

insertBefore

public java.lang.String insertBefore(int pos)
Description copied from class: BasicInstrumentor
Provides a hook to insert instrumentation just before the specified bytecode instruction in its containing method.

Overrides:
insertBefore in class BasicInstrumentor
Parameters:
pos - Index of a bytecode instruction in the currently instrumented method.
Returns:
Code string to be inserted just before the index.

edit

public void edit(javassist.expr.NewExpr e)
          throws javassist.CannotCompileException
Overrides:
edit in class BasicInstrumentor
Throws:
javassist.CannotCompileException

edit

public void edit(javassist.expr.NewArray e)
          throws javassist.CannotCompileException
Overrides:
edit in class BasicInstrumentor
Throws:
javassist.CannotCompileException

edit

public void edit(javassist.expr.FieldAccess e)
          throws javassist.CannotCompileException
Overrides:
edit in class BasicInstrumentor
Throws:
javassist.CannotCompileException

edit

public void edit(javassist.expr.ArrayAccess e)
          throws javassist.CannotCompileException
Overrides:
edit in class BasicInstrumentor
Throws:
javassist.CannotCompileException

edit

public void edit(javassist.expr.MonitorEnter e)
          throws javassist.CannotCompileException
Overrides:
edit in class BasicInstrumentor
Throws:
javassist.CannotCompileException

edit

public void edit(javassist.expr.MonitorExit e)
          throws javassist.CannotCompileException
Overrides:
edit in class BasicInstrumentor
Throws:
javassist.CannotCompileException

edit

public void edit(javassist.expr.ConstructorCall e)
          throws javassist.CannotCompileException
Overrides:
edit in class BasicInstrumentor
Throws:
javassist.CannotCompileException

edit

public void edit(javassist.expr.MethodCall e)
          throws javassist.CannotCompileException
Overrides:
edit in class BasicInstrumentor
Throws:
javassist.CannotCompileException

getstaticPrimitive

protected java.lang.String getstaticPrimitive(javassist.expr.FieldAccess e,
                                              javassist.CtField f)

getstaticReference

protected java.lang.String getstaticReference(javassist.expr.FieldAccess e,
                                              javassist.CtField f)

putstaticPrimitive

protected java.lang.String putstaticPrimitive(javassist.expr.FieldAccess e,
                                              javassist.CtField f)

putstaticReference

protected java.lang.String putstaticReference(javassist.expr.FieldAccess e,
                                              javassist.CtField f)

getfieldPrimitive

protected java.lang.String getfieldPrimitive(javassist.expr.FieldAccess e,
                                             javassist.CtField f)

getfieldReference

protected java.lang.String getfieldReference(javassist.expr.FieldAccess e,
                                             javassist.CtField f)

putfieldPrimitive

protected java.lang.String putfieldPrimitive(javassist.expr.FieldAccess e,
                                             javassist.CtField f)

putfieldReference

protected java.lang.String putfieldReference(javassist.expr.FieldAccess e,
                                             javassist.CtField f)

aloadPrimitive

protected java.lang.String aloadPrimitive(javassist.expr.ArrayAccess e)

aloadReference

protected java.lang.String aloadReference(javassist.expr.ArrayAccess e)

astorePrimitive

protected java.lang.String astorePrimitive(javassist.expr.ArrayAccess e)

astoreReference

protected java.lang.String astoreReference(javassist.expr.ArrayAccess e)

processThreadRelatedCall

protected java.lang.String processThreadRelatedCall(javassist.expr.MethodCall e,
                                                    javassist.CtBehavior m)