chord.instr
Class BasicInstrumentor

java.lang.Object
  extended by javassist.expr.ExprEditor
      extended by chord.instr.BasicInstrumentor
Direct Known Subclasses:
Instrumentor, LoadedClassesInstrumentor, ReflectInstrumentor

public class BasicInstrumentor
extends javassist.expr.ExprEditor

Basic bytecode instrumentor providing hooks for transforming classes, methods, and instructions. Custom instrumentors must extend either this class or class Instrumentor.

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

Field Summary
protected  java.util.Map<java.lang.String,java.lang.String> argsMap
           
protected  javassist.CtClass currentClass
           
protected  javassist.CtBehavior currentMethod
           
static java.lang.String EVENT_HANDLER_ARGS_KEY
           
static java.lang.String EVENT_HANDLER_CLASS_KEY
           
protected  java.lang.String eventHandlerDoneCall
           
protected  java.lang.String eventHandlerInitCall
           
static java.lang.String INSTRUMENTOR_CLASS_KEY
           
protected  boolean isMainClass
           
protected  JavassistPool pool
           
protected  java.lang.String[] scopeExcludeAry
           
static java.lang.String USE_JVMTI_KEY
           
protected  boolean useJvmti
           
protected  int verbose
           
 
Constructor Summary
BasicInstrumentor(java.util.Map<java.lang.String,java.lang.String> argsMap)
          Constructor.
 
Method Summary
 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)
           
 javassist.CtClass edit(java.lang.String cName)
          Provides a hook to instrument a class specified by name.
 JavassistPool getPool()
           
 java.lang.String insertBefore(int pos)
          Provides a hook to insert instrumentation just before the specified bytecode instruction in its containing method.
 boolean isExcluded(java.lang.String cName)
           
 boolean isExplicitlyExcluded(java.lang.String cName)
           
 boolean isImplicitlyExcluded(java.lang.String cName)
           
 
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

INSTRUMENTOR_CLASS_KEY

public static final java.lang.String INSTRUMENTOR_CLASS_KEY
See Also:
Constant Field Values

EVENT_HANDLER_CLASS_KEY

public static final java.lang.String EVENT_HANDLER_CLASS_KEY
See Also:
Constant Field Values

EVENT_HANDLER_ARGS_KEY

public static final java.lang.String EVENT_HANDLER_ARGS_KEY
See Also:
Constant Field Values

USE_JVMTI_KEY

public static final java.lang.String USE_JVMTI_KEY
See Also:
Constant Field Values

verbose

protected int verbose

pool

protected final JavassistPool pool

scopeExcludeAry

protected java.lang.String[] scopeExcludeAry

argsMap

protected java.util.Map<java.lang.String,java.lang.String> argsMap

currentClass

protected javassist.CtClass currentClass

currentMethod

protected javassist.CtBehavior currentMethod

useJvmti

protected boolean useJvmti

isMainClass

protected boolean isMainClass

eventHandlerInitCall

protected java.lang.String eventHandlerInitCall

eventHandlerDoneCall

protected java.lang.String eventHandlerDoneCall
Constructor Detail

BasicInstrumentor

public BasicInstrumentor(java.util.Map<java.lang.String,java.lang.String> argsMap)
Constructor.

Parameters:
argsMap - Arguments to the instrumentor in the form of a map of (key, value) pairs.
Method Detail

getPool

public JavassistPool getPool()

isExplicitlyExcluded

public boolean isExplicitlyExcluded(java.lang.String cName)

isImplicitlyExcluded

public boolean isImplicitlyExcluded(java.lang.String cName)

isExcluded

public boolean isExcluded(java.lang.String cName)

edit

public javassist.CtClass edit(java.lang.String cName)
                       throws javassist.NotFoundException,
                              javassist.CannotCompileException
Provides a hook to instrument a class specified by name. The default implementation excludes instrumenting classes that are excluded implicitly or explicitly; for each class that is not excluded, it calls the edit(CtClass) method.

Parameters:
cName - Name of the class to be instrumented (e.g., java.lang.Object).
Returns:
The instrumented class in Javassist's representation. It must be null if the class is not instrumented.
Throws:
javassist.NotFoundException - If Javassist fails to find the class.
javassist.CannotCompileException - If Javassist fails to correctly instrument the class.

edit

public javassist.CtClass edit(javassist.CtClass clazz)
                       throws javassist.CannotCompileException
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.

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
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 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).

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.

insertBefore

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

Overrides:
insertBefore in class javassist.expr.ExprEditor
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 javassist.expr.ExprEditor
Throws:
javassist.CannotCompileException

edit

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

edit

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

edit

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

edit

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

edit

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

edit

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

edit

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