de.uka.ipd.sdq.ByCounter.instrumentation
Class MethodCountMethodAdapter

java.lang.Object
  extended by org.objectweb.asm.MethodAdapter
      extended by de.uka.ipd.sdq.ByCounter.instrumentation.MethodCountMethodAdapter
All Implemented Interfaces:
org.objectweb.asm.MethodVisitor, org.objectweb.asm.Opcodes

public final class MethodCountMethodAdapter
extends org.objectweb.asm.MethodAdapter
implements org.objectweb.asm.Opcodes

Visitor for a method declaration. This class implements the method modifying instrumentation.

It creates initialisation code for local variables that hold counters, it insert incrementing code for these counters. Finally, it inserts code that creates arrays and fills them with the values of the counter variables. These arrays are then used as parameters for the code that calls CountingResultCollector on method exit.

There are separate counter variables/arrays for

Basic block and range blocks work not by counting opcodes but by incrementing counters whenever the label a block starts with is visited. Results are then reported with a mark that allows for identifying the blocks.

Since:
0.1
Version:
1.2
Author:
Martin Krogmann, Michael Kuperberg

Field Summary
static java.lang.String INSTRUMENTATION_MARKER
          This is the magic string constant that is inserted (loaded and popped off the stack again) at the beginning of instrumented methods to mark them as instrumented.
 int statNumberOfCountingStatementsAdded
          Statistical counter.
 
Fields inherited from interface org.objectweb.asm.Opcodes
AALOAD, AASTORE, ACC_ABSTRACT, ACC_ANNOTATION, ACC_BRIDGE, ACC_DEPRECATED, ACC_ENUM, ACC_FINAL, ACC_INTERFACE, ACC_NATIVE, ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC, ACC_STATIC, ACC_STRICT, ACC_SUPER, ACC_SYNCHRONIZED, ACC_SYNTHETIC, ACC_TRANSIENT, ACC_VARARGS, ACC_VOLATILE, ACONST_NULL, ALOAD, ANEWARRAY, ARETURN, ARRAYLENGTH, ASTORE, ATHROW, BALOAD, BASTORE, BIPUSH, CALOAD, CASTORE, CHECKCAST, D2F, D2I, D2L, DADD, DALOAD, DASTORE, DCMPG, DCMPL, DCONST_0, DCONST_1, DDIV, DLOAD, DMUL, DNEG, DOUBLE, DREM, DRETURN, DSTORE, DSUB, DUP, DUP_X1, DUP_X2, DUP2, DUP2_X1, DUP2_X2, F_APPEND, F_CHOP, F_FULL, F_NEW, F_SAME, F_SAME1, F2D, F2I, F2L, FADD, FALOAD, FASTORE, FCMPG, FCMPL, FCONST_0, FCONST_1, FCONST_2, FDIV, FLOAD, FLOAT, FMUL, FNEG, FREM, FRETURN, FSTORE, FSUB, GETFIELD, GETSTATIC, GOTO, 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, IMUL, INEG, INSTANCEOF, INTEGER, INVOKEDYNAMIC, INVOKEDYNAMIC_OWNER, INVOKEINTERFACE, INVOKESPECIAL, INVOKESTATIC, INVOKEVIRTUAL, IOR, IREM, IRETURN, ISHL, ISHR, ISTORE, ISUB, IUSHR, IXOR, JSR, L2D, L2F, L2I, LADD, LALOAD, LAND, LASTORE, LCMP, LCONST_0, LCONST_1, LDC, LDIV, LLOAD, LMUL, LNEG, LONG, LOOKUPSWITCH, LOR, LREM, LRETURN, LSHL, LSHR, LSTORE, LSUB, LUSHR, LXOR, MONITORENTER, MONITOREXIT, MULTIANEWARRAY, NEW, NEWARRAY, NOP, NULL, POP, POP2, PUTFIELD, PUTSTATIC, RET, RETURN, SALOAD, SASTORE, SIPUSH, SWAP, T_BOOLEAN, T_BYTE, T_CHAR, T_DOUBLE, T_FLOAT, T_INT, T_LONG, T_SHORT, TABLESWITCH, TOP, UNINITIALIZED_THIS, V1_1, V1_2, V1_3, V1_4, V1_5, V1_6, V1_7
 
Constructor Summary
MethodCountMethodAdapter(org.objectweb.asm.MethodVisitor v, int access, java.lang.String superName, java.lang.String className, java.lang.String qualifyingMethodName, java.lang.String desc, InstrumentationParameters instrumentationParameters, InstrumentationState instrumentationState, MethodDescriptor method)
          Creates the method adapter.
 
Method Summary
 void registerCharacterisationHook(ICharacterisationHook hook)
          Register a ICharacterisationHook.
 void setIsAlreadyInstrumented(boolean isInstrumented, java.lang.String name, java.lang.String signature)
           
 void setLVS(org.objectweb.asm.commons.LocalVariablesSorter pLvars)
          Sets the LocalVariableSorter that is used to generate new locals.
 void setMethodInvocations(AdditionalOpcodeInformation additionalOpcInfo)
          Sets the MethodInvocationsFinder that is used to determine registers for method invocation counts.
 void visitCode()
          This is being called at the beginning of the method.
 void visitEnd()
           
 void visitFieldInsn(int opcode, java.lang.String owner, java.lang.String name, java.lang.String desc)
           
 void visitIincInsn(int var, int increment)
           
 void visitInsn(int opcode)
          Step into every call to insert counters.
 void visitIntInsn(int opcode, int operand)
           
 void visitJumpInsn(int opcode, org.objectweb.asm.Label label)
           
 void visitLabel(org.objectweb.asm.Label label)
           
 void visitLdcInsn(java.lang.Object constant)
           
 void visitLookupSwitchInsn(org.objectweb.asm.Label dflt, int[] keys, org.objectweb.asm.Label[] labels)
           
 void visitMethodInsn(int opcode, java.lang.String owner, java.lang.String name, java.lang.String desc)
           
 void visitMultiANewArrayInsn(java.lang.String desc, int dims)
           
 void visitTableSwitchInsn(int min, int max, org.objectweb.asm.Label dflt, org.objectweb.asm.Label[] labels)
           
 void visitTypeInsn(int opcode, java.lang.String desc)
           
 void visitVarInsn(int opcode, int var)
           
 
Methods inherited from class org.objectweb.asm.MethodAdapter
visitAnnotation, visitAnnotationDefault, visitAttribute, visitFrame, visitLineNumber, visitLocalVariable, visitMaxs, visitParameterAnnotation, visitTryCatchBlock
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

statNumberOfCountingStatementsAdded

public int statNumberOfCountingStatementsAdded
Statistical counter. This is a counter that is increased for every inserted counting statement.


INSTRUMENTATION_MARKER

public static final java.lang.String INSTRUMENTATION_MARKER
This is the magic string constant that is inserted (loaded and popped off the stack again) at the beginning of instrumented methods to mark them as instrumented.

See Also:
Constant Field Values
Constructor Detail

MethodCountMethodAdapter

public MethodCountMethodAdapter(org.objectweb.asm.MethodVisitor v,
                                int access,
                                java.lang.String superName,
                                java.lang.String className,
                                java.lang.String qualifyingMethodName,
                                java.lang.String desc,
                                InstrumentationParameters instrumentationParameters,
                                InstrumentationState instrumentationState,
                                MethodDescriptor method)
Creates the method adapter.

Parameters:
v - Preceding visitor in the chain.
access - Access flags for this method.
superName - Name of the superclass.
qualifyingMethodName - Qualifying name of the method (used for reporting).
desc - Parameter descriptor in Java bytecode notation.
instrumentationParameters - User specified parameters.
instrumentationState - Intermediate instrumention state.
Method Detail

registerCharacterisationHook

public void registerCharacterisationHook(ICharacterisationHook hook)
Register a ICharacterisationHook.

Parameters:
hook -
See Also:
ICharacterisationHook

setLVS

public void setLVS(org.objectweb.asm.commons.LocalVariablesSorter pLvars)
Sets the LocalVariableSorter that is used to generate new locals. This must be called before this Adapter is evaluated.

Parameters:
pLvars - LocalVariableSorter

setMethodInvocations

public void setMethodInvocations(AdditionalOpcodeInformation additionalOpcInfo)
Sets the MethodInvocationsFinder that is used to determine registers for method invocation counts. This must be called before this Adapter is evaluated.//TODO is this ensured/asserted/checken?

Parameters:
additionalOpcInfo - Finder instance.

visitCode

public void visitCode()
This is being called at the beginning of the method.

Specified by:
visitCode in interface org.objectweb.asm.MethodVisitor
Overrides:
visitCode in class org.objectweb.asm.MethodAdapter

visitEnd

public void visitEnd()
Specified by:
visitEnd in interface org.objectweb.asm.MethodVisitor
Overrides:
visitEnd in class org.objectweb.asm.MethodAdapter

visitFieldInsn

public void visitFieldInsn(int opcode,
                           java.lang.String owner,
                           java.lang.String name,
                           java.lang.String desc)
Specified by:
visitFieldInsn in interface org.objectweb.asm.MethodVisitor
Overrides:
visitFieldInsn in class org.objectweb.asm.MethodAdapter

visitIincInsn

public void visitIincInsn(int var,
                          int increment)
Specified by:
visitIincInsn in interface org.objectweb.asm.MethodVisitor
Overrides:
visitIincInsn in class org.objectweb.asm.MethodAdapter

visitInsn

public void visitInsn(int opcode)
Step into every call to insert counters.

Specified by:
visitInsn in interface org.objectweb.asm.MethodVisitor
Overrides:
visitInsn in class org.objectweb.asm.MethodAdapter

visitIntInsn

public void visitIntInsn(int opcode,
                         int operand)
Specified by:
visitIntInsn in interface org.objectweb.asm.MethodVisitor
Overrides:
visitIntInsn in class org.objectweb.asm.MethodAdapter

visitJumpInsn

public void visitJumpInsn(int opcode,
                          org.objectweb.asm.Label label)
Specified by:
visitJumpInsn in interface org.objectweb.asm.MethodVisitor
Overrides:
visitJumpInsn in class org.objectweb.asm.MethodAdapter

visitLabel

public void visitLabel(org.objectweb.asm.Label label)
Specified by:
visitLabel in interface org.objectweb.asm.MethodVisitor
Overrides:
visitLabel in class org.objectweb.asm.MethodAdapter

visitLdcInsn

public void visitLdcInsn(java.lang.Object constant)
Specified by:
visitLdcInsn in interface org.objectweb.asm.MethodVisitor
Overrides:
visitLdcInsn in class org.objectweb.asm.MethodAdapter

visitLookupSwitchInsn

public void visitLookupSwitchInsn(org.objectweb.asm.Label dflt,
                                  int[] keys,
                                  org.objectweb.asm.Label[] labels)
Specified by:
visitLookupSwitchInsn in interface org.objectweb.asm.MethodVisitor
Overrides:
visitLookupSwitchInsn in class org.objectweb.asm.MethodAdapter

visitMethodInsn

public void visitMethodInsn(int opcode,
                            java.lang.String owner,
                            java.lang.String name,
                            java.lang.String desc)
Specified by:
visitMethodInsn in interface org.objectweb.asm.MethodVisitor
Overrides:
visitMethodInsn in class org.objectweb.asm.MethodAdapter

visitMultiANewArrayInsn

public void visitMultiANewArrayInsn(java.lang.String desc,
                                    int dims)
Specified by:
visitMultiANewArrayInsn in interface org.objectweb.asm.MethodVisitor
Overrides:
visitMultiANewArrayInsn in class org.objectweb.asm.MethodAdapter

visitTableSwitchInsn

public void visitTableSwitchInsn(int min,
                                 int max,
                                 org.objectweb.asm.Label dflt,
                                 org.objectweb.asm.Label[] labels)
Specified by:
visitTableSwitchInsn in interface org.objectweb.asm.MethodVisitor
Overrides:
visitTableSwitchInsn in class org.objectweb.asm.MethodAdapter

visitTypeInsn

public void visitTypeInsn(int opcode,
                          java.lang.String desc)
Specified by:
visitTypeInsn in interface org.objectweb.asm.MethodVisitor
Overrides:
visitTypeInsn in class org.objectweb.asm.MethodAdapter

visitVarInsn

public void visitVarInsn(int opcode,
                         int var)
Specified by:
visitVarInsn in interface org.objectweb.asm.MethodVisitor
Overrides:
visitVarInsn in class org.objectweb.asm.MethodAdapter

setIsAlreadyInstrumented

public void setIsAlreadyInstrumented(boolean isInstrumented,
                                     java.lang.String name,
                                     java.lang.String signature)
Parameters:
isInstrumented - When true, this method will not be instrumented again.
signature -
name -