com.vladium.emma.instr
Class InstrVisitor

java.lang.Object
  extended by com.vladium.jcd.cls.AbstractClassDefVisitor
      extended by com.vladium.emma.instr.InstrVisitor
All Implemented Interfaces:
IAttributeVisitor, IClassDefVisitor, IOpcodes, IConstants

public final class InstrVisitor
extends AbstractClassDefVisitor
implements IClassDefVisitor, IAttributeVisitor, IOpcodes, IConstants

Author:
Vlad Roubtsov, (C) 2003

Nested Class Summary
private static class InstrVisitor.Block
           
private static class InstrVisitor.BlockList
           
(package private) static class InstrVisitor.BlockSegment
           
(package private) static class InstrVisitor.Branch
          A Branch does not add any maxlocals/maxstack requirements.
(package private) static class InstrVisitor.clinitHeader
           
(package private) static class InstrVisitor.CodeSegment
          TODO: CodeSegment right now must be 100% position-independent code; otherwise it must follow maxlengtt() Branch pattern...
(package private) static class InstrVisitor.EmitCtx
           
(package private) static class InstrVisitor.IFJUMP2
           
static class InstrVisitor.InstrResult
           
(package private) static class InstrVisitor.JUMP2
           
(package private) static class InstrVisitor.JUMP4
           
private static class InstrVisitor.LineNumberComparator
           
(package private) static class InstrVisitor.LOOKUPSWITCH
           
(package private) static class InstrVisitor.methodHeader
           
(package private) static class InstrVisitor.RET
           
(package private) static class InstrVisitor.TABLESWITCH
           
(package private) static class InstrVisitor.TERMINATE
           
 
Nested classes/interfaces inherited from interface com.vladium.jcd.opcodes.IOpcodes
IOpcodes.clinit
 
Field Summary
private static java.lang.String COVERAGE_FIELD_NAME
           
private static int EMIT_CTX_MIN_INIT_CAPACITY
           
private static byte[] EMPTY_BYTE_ARRAY
           
private static java.lang.String JAVA_IO_EXTERNALIZABLE_NAME
           
private static java.lang.String JAVA_IO_SERIALIZABLE_NAME
           
private static InstrVisitor.LineNumberComparator LINE_NUMBER_COMPARATOR
           
(package private)  int[] m_classBlockCounts
           
private  int[][][] m_classBlockMetadata
           
(package private)  int m_classInstrMethodCount
           
private  MethodDescriptor[] m_classMethodDescriptors
           
private  java.lang.String m_className
           
(package private)  int m_classNameConstantIndex
           
private  java.lang.String m_classPackageName
           
private  long m_classSignature
           
private  java.lang.String m_classSrcFileName
           
private  int m_clinitID
           
private  int m_clinitStatus
           
(package private)  ClassDef m_cls
           
(package private)  int m_coverageFieldrefIndex
           
private  boolean m_doSUIDCompensation
           
private  boolean m_excludeBridgeMethods
           
private  boolean m_excludeSyntheticMethods
           
private  boolean m_ignoreAlreadyInstrumented
           
private  boolean m_instrument
           
private  Logger m_log
           
private  boolean m_metadata
           
private  int[] m_methodBlockOffsets
           
private  int[] m_methodBlockSizes
           
private  int m_methodFirstLine
           
(package private)  int m_methodID
           
private  int[] m_methodJumpAdjOffsets
           
private  int[] m_methodJumpAdjValues
           
private  java.lang.String m_methodName
           
(package private)  int m_preclinitMethodrefIndex
           
private  int m_registerMethodrefIndex
           
private  int m_stampIndex
           
private  int m_syntheticStringIndex
           
private  boolean m_warningIssued
           
private static boolean MARK_ADDED_ELEMENTS_SYNTHETIC
           
private static long NBEAST
           
private static int PRECLINIT_INIT_CAPACITY
           
private static java.lang.String PRECLINIT_METHOD_NAME
           
private static boolean SKIP_SYNTHETIC_CLASSES
           
private static java.lang.String SUID_FIELD_NAME
           
 
Fields inherited from interface com.vladium.jcd.opcodes.IOpcodes
_aaload, _aastore, _aconst_null, _aload, _aload_0, _aload_1, _aload_2, _aload_3, _anewarray, _areturn, _arraylength, _astore, _astore_0, _astore_1, _astore_2, _astore_3, _athrow, _baload, _bastore, _bipush, _breakpoint, _caload, _castore, _checkcast, _d2f, _d2i, _d2l, _dadd, _daload, _dastore, _dcmpg, _dcmpl, _dconst_0, _dconst_1, _ddiv, _dload, _dload_0, _dload_1, _dload_2, _dload_3, _dmul, _dneg, _drem, _dreturn, _dstore, _dstore_0, _dstore_1, _dstore_2, _dstore_3, _dsub, _dup, _dup_x1, _dup_x2, _dup2, _dup2_x1, _dup2_x2, _f2d, _f2i, _f2l, _fadd, _faload, _fastore, _fcmpg, _fcmpl, _fconst_0, _fconst_1, _fconst_2, _fdiv, _fload, _fload_0, _fload_1, _fload_2, _fload_3, _fmul, _fneg, _frem, _freturn, _fstore, _fstore_0, _fstore_1, _fstore_2, _fstore_3, _fsub, _getfield, _getstatic, _goto, _goto_w, _i2b, _i2c, _i2d, _i2f, _i2l, _i2s, _iadd, _iaload, _iand, _iastore, _iconst_0, _iconst_1, _iconst_2, _iconst_3, _iconst_4, _iconst_5, _iconst_m1, _idiv, _if_acmpeq, _if_acmpne, _if_icmpeq, _if_icmpge, _if_icmpgt, _if_icmple, _if_icmplt, _if_icmpne, _ifeq, _ifge, _ifgt, _ifle, _iflt, _ifne, _ifnonnull, _ifnull, _iinc, _iload, _iload_0, _iload_1, _iload_2, _iload_3, _impdep1, _impdep2, _imul, _ineg, _instanceof, _invokeinterface, _invokespecial, _invokestatic, _invokevirtual, _ior, _irem, _ireturn, _ishl, _ishr, _istore, _istore_0, _istore_1, _istore_2, _istore_3, _isub, _iushr, _ixor, _jsr, _jsr_w, _l2d, _l2f, _l2i, _ladd, _laload, _land, _lastore, _lcmp, _lconst_0, _lconst_1, _ldc, _ldc_w, _ldc2_w, _ldiv, _lload, _lload_0, _lload_1, _lload_2, _lload_3, _lmul, _lneg, _lookupswitch, _lor, _lrem, _lreturn, _lshl, _lshr, _lstore, _lstore_0, _lstore_1, _lstore_2, _lstore_3, _lsub, _lushr, _lxor, _monitorenter, _monitorexit, _multianewarray, _new, _newarray, _nop, _pop, _pop2, _putfield, _putstatic, _ret, _return, _saload, _sastore, _sipush, _swap, _tableswitch, _unused, _wide, BRANCHES, COMPOUND_CONDITIONAL_BRANCHES, CONDITIONAL_BRANCHES, MNEMONICS, NARROW_SIZE, UNCONDITIONAL_BRANCHES, WIDE_SIZE
 
Fields inherited from interface com.vladium.util.IConstants
EMPTY_FILE_ARRAY, EMPTY_INT_ARRAY, EMPTY_STRING_ARRAY, EOL, INDENT_INCREMENT
 
Constructor Summary
InstrVisitor(CoverageOptions options)
           
 
Method Summary
private  void consumeSignatureData(int methodID, int[] basicBlockOffsets)
           
private static int lowbound(int[] values, int x)
          Returns the maximum index 'i' such that (values[i] <= x).
 void process(ClassDef cls, boolean ignoreAlreadyInstrumented, boolean instrument, boolean metadata, InstrVisitor.InstrResult out)
          Analyzes 'cls' and/or instruments it for coverage: if 'instrument' is true, the class definition is instrumented for coverage if that is feasible if 'metadata' is true, the class definition is analysed to create a ClassDescriptor for the original class definition This method returns null if 'metadata' is 'false' *or* if 'cls' is an interface [the latter precludes coverage of interface static initializers and may be removed in the future].
private  void reset()
           
private  void setClassName(java.lang.String fullName)
           
 java.lang.Object visit(BridgeAttribute_info attribute, java.lang.Object ctx)
           
 java.lang.Object visit(ClassDef ignore, java.lang.Object ctx)
           
 java.lang.Object visit(CodeAttribute_info attribute, java.lang.Object ctx)
           
 java.lang.Object visit(ConstantValueAttribute_info attribute, java.lang.Object ctx)
           
 java.lang.Object visit(ExceptionsAttribute_info attribute, java.lang.Object ctx)
           
 java.lang.Object visit(GenericAttribute_info attribute, java.lang.Object ctx)
           
 java.lang.Object visit(IAttributeCollection attributes, java.lang.Object ctx)
           
 java.lang.Object visit(IMethodCollection methods, java.lang.Object ctx)
           
 java.lang.Object visit(InnerClassesAttribute_info attribute, java.lang.Object ctx)
           
 java.lang.Object visit(LineNumberTableAttribute_info attribute, java.lang.Object ctx)
           
 java.lang.Object visit(SourceFileAttribute_info attribute, java.lang.Object ctx)
           
 java.lang.Object visit(SyntheticAttribute_info attribute, java.lang.Object ctx)
           
 
Methods inherited from class com.vladium.jcd.cls.AbstractClassDefVisitor
visit, visit, visit
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.vladium.jcd.cls.IClassDefVisitor
visit, visit, visit
 

Field Detail

m_excludeSyntheticMethods

private final boolean m_excludeSyntheticMethods

m_excludeBridgeMethods

private final boolean m_excludeBridgeMethods

m_doSUIDCompensation

private final boolean m_doSUIDCompensation

m_log

private final Logger m_log

m_warningIssued

private boolean m_warningIssued

m_instrument

private boolean m_instrument

m_metadata

private boolean m_metadata

m_ignoreAlreadyInstrumented

private boolean m_ignoreAlreadyInstrumented

m_cls

ClassDef m_cls

m_classPackageName

private java.lang.String m_classPackageName

m_className

private java.lang.String m_className

m_classSrcFileName

private java.lang.String m_classSrcFileName

m_classBlockMetadata

private int[][][] m_classBlockMetadata

m_classMethodDescriptors

private MethodDescriptor[] m_classMethodDescriptors

m_syntheticStringIndex

private int m_syntheticStringIndex

m_coverageFieldrefIndex

int m_coverageFieldrefIndex

m_registerMethodrefIndex

private int m_registerMethodrefIndex

m_preclinitMethodrefIndex

int m_preclinitMethodrefIndex

m_classNameConstantIndex

int m_classNameConstantIndex

m_stampIndex

private int m_stampIndex

m_clinitID

private int m_clinitID

m_clinitStatus

private int m_clinitStatus

m_classInstrMethodCount

int m_classInstrMethodCount

m_classBlockCounts

int[] m_classBlockCounts

m_classSignature

private long m_classSignature

m_methodID

int m_methodID

m_methodName

private java.lang.String m_methodName

m_methodFirstLine

private int m_methodFirstLine

m_methodBlockOffsets

private int[] m_methodBlockOffsets

m_methodBlockSizes

private int[] m_methodBlockSizes

m_methodJumpAdjOffsets

private int[] m_methodJumpAdjOffsets

m_methodJumpAdjValues

private int[] m_methodJumpAdjValues

NBEAST

private static final long NBEAST
See Also:
Constant Field Values

COVERAGE_FIELD_NAME

private static final java.lang.String COVERAGE_FIELD_NAME
See Also:
Constant Field Values

SUID_FIELD_NAME

private static final java.lang.String SUID_FIELD_NAME
See Also:
Constant Field Values

PRECLINIT_METHOD_NAME

private static final java.lang.String PRECLINIT_METHOD_NAME
See Also:
Constant Field Values

JAVA_IO_SERIALIZABLE_NAME

private static final java.lang.String JAVA_IO_SERIALIZABLE_NAME
See Also:
Constant Field Values

JAVA_IO_EXTERNALIZABLE_NAME

private static final java.lang.String JAVA_IO_EXTERNALIZABLE_NAME
See Also:
Constant Field Values

EMIT_CTX_MIN_INIT_CAPACITY

private static final int EMIT_CTX_MIN_INIT_CAPACITY
See Also:
Constant Field Values

PRECLINIT_INIT_CAPACITY

private static final int PRECLINIT_INIT_CAPACITY
See Also:
Constant Field Values

MARK_ADDED_ELEMENTS_SYNTHETIC

private static final boolean MARK_ADDED_ELEMENTS_SYNTHETIC
See Also:
Constant Field Values

SKIP_SYNTHETIC_CLASSES

private static final boolean SKIP_SYNTHETIC_CLASSES
See Also:
Constant Field Values

LINE_NUMBER_COMPARATOR

private static final InstrVisitor.LineNumberComparator LINE_NUMBER_COMPARATOR

EMPTY_BYTE_ARRAY

private static final byte[] EMPTY_BYTE_ARRAY
Constructor Detail

InstrVisitor

public InstrVisitor(CoverageOptions options)
Method Detail

process

public void process(ClassDef cls,
                    boolean ignoreAlreadyInstrumented,
                    boolean instrument,
                    boolean metadata,
                    InstrVisitor.InstrResult out)
Analyzes 'cls' and/or instruments it for coverage: This method returns null if 'metadata' is 'false' *or* if 'cls' is an interface [the latter precludes coverage of interface static initializers and may be removed in the future].

NOTE: if 'instrument' is 'true', the caller should always assume that 'cls' has been mutated by this method even if it returned null. The caller should then revert to the original class definition that was created as a cls.clone() or by retaining the original definition bytes. This part of contract is for efficienty and also simplifies the implementation.


visit

public java.lang.Object visit(ClassDef ignore,
                              java.lang.Object ctx)
Specified by:
visit in interface IClassDefVisitor
Overrides:
visit in class AbstractClassDefVisitor

visit

public java.lang.Object visit(IMethodCollection methods,
                              java.lang.Object ctx)
Specified by:
visit in interface IClassDefVisitor
Overrides:
visit in class AbstractClassDefVisitor

visit

public java.lang.Object visit(IAttributeCollection attributes,
                              java.lang.Object ctx)
Specified by:
visit in interface IClassDefVisitor
Overrides:
visit in class AbstractClassDefVisitor

visit

public java.lang.Object visit(CodeAttribute_info attribute,
                              java.lang.Object ctx)
Specified by:
visit in interface IAttributeVisitor

visit

public java.lang.Object visit(LineNumberTableAttribute_info attribute,
                              java.lang.Object ctx)
Specified by:
visit in interface IAttributeVisitor

visit

public java.lang.Object visit(ExceptionsAttribute_info attribute,
                              java.lang.Object ctx)
Specified by:
visit in interface IAttributeVisitor

visit

public java.lang.Object visit(ConstantValueAttribute_info attribute,
                              java.lang.Object ctx)
Specified by:
visit in interface IAttributeVisitor

visit

public java.lang.Object visit(SourceFileAttribute_info attribute,
                              java.lang.Object ctx)
Specified by:
visit in interface IAttributeVisitor

visit

public java.lang.Object visit(SyntheticAttribute_info attribute,
                              java.lang.Object ctx)
Specified by:
visit in interface IAttributeVisitor

visit

public java.lang.Object visit(BridgeAttribute_info attribute,
                              java.lang.Object ctx)
Specified by:
visit in interface IAttributeVisitor

visit

public java.lang.Object visit(InnerClassesAttribute_info attribute,
                              java.lang.Object ctx)
Specified by:
visit in interface IAttributeVisitor

visit

public java.lang.Object visit(GenericAttribute_info attribute,
                              java.lang.Object ctx)
Specified by:
visit in interface IAttributeVisitor

setClassName

private void setClassName(java.lang.String fullName)

consumeSignatureData

private void consumeSignatureData(int methodID,
                                  int[] basicBlockOffsets)

lowbound

private static int lowbound(int[] values,
                            int x)
Returns the maximum index 'i' such that (values[i] <= x). values[] contains distinct non-negative integers in increasing order. values[0] is 0, 'x' is non-negative. Edge case: returns values.length-1 if values [values.length - 1] < x


reset

private void reset()