org.softevo.ample.sibrelib.extensions
Class InstanceTracer

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

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

Creates a tracer that instruments classes to trace information about the instance a method called was issued upon.


Field Summary
static java.lang.String FIELDNAME_ID
          The string that is traced when the method is static.
 
Fields inherited from class org.softevo.sibrelib.extensions.TraceInstrumentationExtension
context
 
Constructor Summary
InstanceTracer(org.softevo.sibrelib.InstrumentationContext context)
          Create a new instance.
 
Method Summary
 boolean allowTraceInstrumentation(org.apache.bcel.generic.MethodGen methodGenerator)
          This method gives extensions the possibility to forbid instrumentation of special methods that were added during the processJavaClass method.
protected  boolean isTopInstrumentedClass(org.apache.bcel.classfile.JavaClass javaClass)
           
 void postProcessJavaClass(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 performs the neccessary changes to a java class that are needed in order to guarantee tracing of instances by their address.
 
Methods inherited from class org.softevo.sibrelib.extensions.TraceInstrumentationExtension
createMethodStartCode, finishInstrumentation, preProcessJavaClass, verifyInstrumentation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FIELDNAME_ID

public static final java.lang.String FIELDNAME_ID
The string that is traced when the method is static.

See Also:
Constant Field Values
Constructor Detail

InstanceTracer

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

Parameters:
context - the instrumentation context
Method Detail

postProcessJavaClass

public void postProcessJavaClass(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 performs the neccessary changes to a java class that are needed in order to guarantee tracing of instances by their address.
The following changes are made:
  1. In case this class is a sub class of java.lang.Object, two fields are added: One holds a flag that signalizes the hashCode method to call its super class version (thus returning the object address) and the other one is used to store the retrieved value. Every constructor declared in the class is instrumented with code to set the flag, call the hashCode method, retrieve the address, store it in the ___add field and reset the flag
  2. Every declared version of hashCode is instrumentated with code to call the super class version if the ___flag field was set.

Overrides:
postProcessJavaClass 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

isTopInstrumentedClass

protected boolean isTopInstrumentedClass(org.apache.bcel.classfile.JavaClass javaClass)

allowTraceInstrumentation

public boolean allowTraceInstrumentation(org.apache.bcel.generic.MethodGen methodGenerator)
This method gives extensions the possibility to forbid instrumentation of special methods that were added during the processJavaClass method. The default implementation simply returns true

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