org.softevo.ample.sibrelib.extensions
Class InstanceTracer
java.lang.Object
org.softevo.sibrelib.extensions.TraceInstrumentationExtension
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 |
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
InstanceTracer
public InstanceTracer(org.softevo.sibrelib.InstrumentationContext context)
- Create a new instance.
- Parameters:
context
- the instrumentation context
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:
- 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
- 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 processclassGenerator
- the generator for the new classconstantPoolGenerator
- the generator for the new constant poolfactory
- 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