public class InjectCodeClassInstrumenter extends AbstractFindTouchPointsClassInstrumenter
This class is responsible for real instrumentation of the user's class.
It uses information acquired
by BuildClassMapClassVisitor
( classMap
) and
DetectDuplicatedCodeClassVisitor
and injects
code snippet provided by CodeProvider
( codeProvider
).
Modifier and Type | Class and Description |
---|---|
private class |
InjectCodeClassInstrumenter.GenerateCallCoberturaInitMethodVisitor
Method instrumenter that injects
CodeProvider#generateCINITmethod(MethodVisitor, String, int) code, and
then forwards the whole previous content of the method. |
Modifier and Type | Field and Description |
---|---|
private ClassMap |
classMap
ClassMap generated in previous instrumentation pass by BuildClassMapClassVisitor |
private CodeProvider |
codeProvider
CodeProvider used to generate pieces of asm code that is injected into instrumented class. |
private java.util.Set<java.lang.String> |
ignoredMethods |
private InjectCodeTouchPointListener |
touchPointListener
This class is responsible for injecting code inside 'interesting places' of methods inside instrumented class
|
private boolean |
wasStaticInitMethodVisited
When we processing the class we want to now if we processed 'static initialization block' (clinit method).
|
duplicatedLinesMap, eventIdGenerator, lineIdGenerator
Constructor and Description |
---|
InjectCodeClassInstrumenter(org.objectweb.asm.ClassVisitor cv,
java.util.Collection<java.util.regex.Pattern> ignoreRegexes,
boolean threadsafeRigorous,
ClassMap classMap,
java.util.Map<java.lang.Integer,java.util.Map<java.lang.Integer,java.lang.Integer>> duplicatedLinesMap,
java.util.Set<java.lang.String> ignoredMethods) |
Modifier and Type | Method and Description |
---|---|
void |
visit(int version,
int access,
java.lang.String name,
java.lang.String signature,
java.lang.String supertype,
java.lang.String[] interfaces)
Marks the class 'already instrumented' and injects code connected to the fields that are keeping counters.
|
void |
visitEnd()
If there was no 'static initialization block' in the class, the method is responsible for generating the method.
|
org.objectweb.asm.MethodVisitor |
visitMethod(int access,
java.lang.String name,
java.lang.String desc,
java.lang.String signature,
java.lang.String[] exceptions)
Instrumenting a code in a single method.
|
getIgnoreRegexp, setIgnoreRegexp
private final InjectCodeTouchPointListener touchPointListener
private final ClassMap classMap
ClassMap
generated in previous instrumentation pass by BuildClassMapClassVisitor
private final CodeProvider codeProvider
CodeProvider
used to generate pieces of asm code that is injected into instrumented class.
We are strictly recommending here using FastArrayCodeProvider
instead of AtomicArrayCodeProvider
because
of performance.private boolean wasStaticInitMethodVisited
If there is no such a method in the instrumented class - we will need to generate it at the end
private final java.util.Set<java.lang.String> ignoredMethods
public InjectCodeClassInstrumenter(org.objectweb.asm.ClassVisitor cv, java.util.Collection<java.util.regex.Pattern> ignoreRegexes, boolean threadsafeRigorous, ClassMap classMap, java.util.Map<java.lang.Integer,java.util.Map<java.lang.Integer,java.lang.Integer>> duplicatedLinesMap, java.util.Set<java.lang.String> ignoredMethods)
cv
- - a listener for code-instrumentation eventsignoreRegexp
- - list of patters of method calls that should be ignored from line-coverage-measurementclassMap
- - map of all interesting places in the class. You should acquire it by BuildClassMapClassVisitor
and remember to
prepare it using ClassMap.assignCounterIds()
before using it with InjectCodeClassInstrumenter
duplicatedLinesMap
- - map of found duplicates in the class. You should use DetectDuplicatedCodeClassVisitor
to find the duplicated lines.public void visit(int version, int access, java.lang.String name, java.lang.String signature, java.lang.String supertype, java.lang.String[] interfaces)
Marks the class 'already instrumented' and injects code connected to the fields that are keeping counters.
visit
in class org.objectweb.asm.ClassVisitor
public org.objectweb.asm.MethodVisitor visitMethod(int access, java.lang.String name, java.lang.String desc, java.lang.String signature, java.lang.String[] exceptions)
Instrumenting a code in a single method. Special conditions for processing 'static initialization block'.
This method also uses ShiftVariableMethodAdapter
that is used firstly to calculate the index of internal
variable injected to store information about last 'processed' jump or switch in runtime ( ShiftVariableMethodAdapter#calculateFirstStackVariable(int, String)
),
and then is used to inject code responsible for keeping the variable and shifting (+1) all previously seen variables.
visitMethod
in class org.objectweb.asm.ClassVisitor
public void visitEnd()
If there was no 'static initialization block' in the class, the method is responsible for generating the method.
It is also responsible for generating method that keeps mapping of counterIds into source places connected to them
visitEnd
in class org.objectweb.asm.ClassVisitor