org.softevo.ample.sibrelib.extensions
Class ThreadTracer

java.lang.Object
  extended by org.softevo.sibrelib.extensions.TraceInstrumentationExtension
      extended by org.softevo.ample.sibrelib.extensions.ThreadTracer

public class ThreadTracer
extends org.softevo.sibrelib.extensions.TraceInstrumentationExtension

Traces an identifier for the active thread.


Field Summary
static java.lang.String METHODNAME_GETTHREADID
          Name for the getThreadId method.
 
Fields inherited from class org.softevo.sibrelib.extensions.TraceInstrumentationExtension
context
 
Constructor Summary
ThreadTracer(org.softevo.sibrelib.InstrumentationContext context)
          Create a new instance.
 
Method Summary
 boolean allowTraceInstrumentation(org.apache.bcel.generic.MethodGen methodGenerator)
          Forbids instrumentation of the getThreadId method (because otherwise an endless loop occurs).
private  org.apache.bcel.generic.MethodGen generateGetThreadIdMethod(org.apache.bcel.classfile.JavaClass javaClass, org.apache.bcel.generic.ClassGen classGenerator, org.apache.bcel.generic.ConstantPoolGen constantPoolGenerator, org.apache.bcel.generic.InstructionFactory factory)
          Generates a static method that determines a thread id for the active thread.
 void preProcessJavaClass(org.apache.bcel.classfile.JavaClass javaClass, org.apache.bcel.generic.ClassGen classGenerator, org.apache.bcel.generic.ConstantPoolGen constantPoolGenerator, org.apache.bcel.generic.InstructionFactory factory)
          This method simply adds a static method that determines an id for the active thread to every class whose super class is not instrumented.
 
Methods inherited from class org.softevo.sibrelib.extensions.TraceInstrumentationExtension
createMethodStartCode, finishInstrumentation, postProcessJavaClass, verifyInstrumentation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

METHODNAME_GETTHREADID

public static final java.lang.String METHODNAME_GETTHREADID
Name for the getThreadId method.

See Also:
Constant Field Values
Constructor Detail

ThreadTracer

public ThreadTracer(org.softevo.sibrelib.InstrumentationContext context)
Create a new instance.

Parameters:
context - the instrumentation context
Method Detail

preProcessJavaClass

public void preProcessJavaClass(org.apache.bcel.classfile.JavaClass javaClass,
                                org.apache.bcel.generic.ClassGen classGenerator,
                                org.apache.bcel.generic.ConstantPoolGen constantPoolGenerator,
                                org.apache.bcel.generic.InstructionFactory factory)
This method simply adds a static method that determines an id for the active thread to every class whose super class is not instrumented.

Overrides:
preProcessJavaClass in class org.softevo.sibrelib.extensions.TraceInstrumentationExtension
Parameters:
javaClass - the class to process
classGenerator - the generator for the new class
constantPoolGenerator - the generator for the new constant pool
factory - the factory for instructions

allowTraceInstrumentation

public boolean allowTraceInstrumentation(org.apache.bcel.generic.MethodGen methodGenerator)
Forbids instrumentation of the getThreadId method (because otherwise an endless loop occurs).

Overrides:
allowTraceInstrumentation in class org.softevo.sibrelib.extensions.TraceInstrumentationExtension
Parameters:
methodGenerator - the generator for the method
Returns:
true if the method should be instrumentated with trace code, false otherwise

generateGetThreadIdMethod

private org.apache.bcel.generic.MethodGen generateGetThreadIdMethod(org.apache.bcel.classfile.JavaClass javaClass,
                                                                    org.apache.bcel.generic.ClassGen classGenerator,
                                                                    org.apache.bcel.generic.ConstantPoolGen constantPoolGenerator,
                                                                    org.apache.bcel.generic.InstructionFactory factory)
Generates a static method that determines a thread id for the active thread.

Parameters:
javaClass - the class to process
methodGenerator - the generator for the method
constantPoolGenerator - the generator for the new constant pool
factory - the factory for instructions