com.futureshocked.classloader
Class DebuggerClassVisitor

java.lang.Object
  extended by org.objectweb.asm.ClassAdapter
      extended by com.futureshocked.classloader.DebuggerClassVisitor
All Implemented Interfaces:
org.objectweb.asm.ClassVisitor, org.objectweb.asm.Opcodes

public class DebuggerClassVisitor
extends org.objectweb.asm.ClassAdapter
implements org.objectweb.asm.Opcodes

An org.objectweb.asm.ClassAdapter that will modify classes as needed. As a class is loaded the appropriate visit*() methods are called in this class.

By default, an InterceptedMethod object that requests a static debugging call will call StaticDebugger.printDebugInformation().

See also: Visitor design pattern.


Nested Class Summary
(package private)  class DebuggerClassVisitor.RecursionLimiterMethodAdapter
          Inner class that adds recursion limiting instructions to the end of a method.
 
Field Summary
protected  java.lang.String className
          The name of the class currently being visited.
protected  ClassTransforms ct
          A ClassTransforms that holds InterceptedMethod objects.
protected  java.lang.String message
          The message to be printed when the recursion limit is exceeded.
protected  java.lang.String staticDebugClass
          The name of the class that contains a static method to be called for debugging purposes.
protected  java.lang.String staticDebugDescription
          The description of the static method to be called for debugging.
protected  java.lang.String staticDebugMethod
          The name of the static method to be called for debugging purposes.
protected  boolean verbose
          true if debugging information should be displayed.
 
Fields inherited from class org.objectweb.asm.ClassAdapter
cv
 
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, DREM, DRETURN, DSTORE, 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, 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, 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, LOOKUPSWITCH, LOR, LREM, LRETURN, LSHL, LSHR, LSTORE, LSUB, LUSHR, LXOR, MONITORENTER, MONITOREXIT, MULTIANEWARRAY, NEW, NEWARRAY, NOP, 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, V1_1, V1_2, V1_3, V1_4, V1_5
 
Constructor Summary
DebuggerClassVisitor(org.objectweb.asm.ClassVisitor cv, java.lang.String className, ClassTransforms ct, boolean verbose)
          Constructor that sets the appropriate instance variables.
 
Method Summary
 org.objectweb.asm.MethodVisitor addRecursionLimiter(org.objectweb.asm.MethodVisitor mv, InterceptedMethod im, java.lang.String returnType)
          Adds a recursion limit to a recursive limit - keeps recursive methods that are buggy from causing a stack overflow.
 org.objectweb.asm.MethodVisitor addStaticDebuggerCall(org.objectweb.asm.MethodVisitor mv, InterceptedMethod im)
          Adds the bytecode to call the static debugger.
private  java.lang.String getFieldNameByMethod(java.lang.String method)
          Returns the name of the field that holds the current recursion count for the method.
private  java.lang.String getReturnTypeFromDescription(java.lang.String desc)
          Parses the return type from the method description.
 void visit(int version, int access, java.lang.String name, java.lang.String signature, java.lang.String superName, java.lang.String[] interfaces)
          visit() is called when a class is first created.
 org.objectweb.asm.MethodVisitor visitMethod(int access, java.lang.String name, java.lang.String desc, java.lang.String signature, java.lang.String[] exceptions)
          Called for every method in a class.
 
Methods inherited from class org.objectweb.asm.ClassAdapter
visitAnnotation, visitAttribute, visitEnd, visitField, visitInnerClass, visitOuterClass, visitSource
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

className

protected java.lang.String className
The name of the class currently being visited.


ct

protected ClassTransforms ct
A ClassTransforms that holds InterceptedMethod objects.


verbose

protected boolean verbose
true if debugging information should be displayed.


message

protected java.lang.String message
The message to be printed when the recursion limit is exceeded.


staticDebugClass

protected java.lang.String staticDebugClass
The name of the class that contains a static method to be called for debugging purposes.


staticDebugMethod

protected java.lang.String staticDebugMethod
The name of the static method to be called for debugging purposes.


staticDebugDescription

protected java.lang.String staticDebugDescription
The description of the static method to be called for debugging. Should be in the appropriate ASM format - see ApplicationDebugger for an example.

Constructor Detail

DebuggerClassVisitor

public DebuggerClassVisitor(org.objectweb.asm.ClassVisitor cv,
                            java.lang.String className,
                            ClassTransforms ct,
                            boolean verbose)
Constructor that sets the appropriate instance variables.

Parameters:
cv - A ClassVisitor or ClassWriter that has already been created.
className - The name of the class being visited.
ct - Container for InterceptedMethod objects.
verbose - true if debugging info should be displayed.
Method Detail

visit

public void visit(int version,
                  int access,
                  java.lang.String name,
                  java.lang.String signature,
                  java.lang.String superName,
                  java.lang.String[] interfaces)
visit() is called when a class is first created. All extra fields related to recursion limited are created here.

Specified by:
visit in interface org.objectweb.asm.ClassVisitor
Overrides:
visit in class org.objectweb.asm.ClassAdapter
Parameters:
version - see ASM documentation.
access - Access flags - see ASM documentation.
name - The name of the class.
signature - The class signature - see ASM documentation.
superName - The name of the parent class - see ASM documentation.
interfaces - Interfaces implemented by this object.

visitMethod

public org.objectweb.asm.MethodVisitor visitMethod(int access,
                                                   java.lang.String name,
                                                   java.lang.String desc,
                                                   java.lang.String signature,
                                                   java.lang.String[] exceptions)
Called for every method in a class. If this is called for a method we wish to intercept, this method will add the appropriate bytecode.

Specified by:
visitMethod in interface org.objectweb.asm.ClassVisitor
Overrides:
visitMethod in class org.objectweb.asm.ClassAdapter
Parameters:
access - Access flags for the method - see ASM documentation.
name - The name of the method.
desc - The description of the method - see ApplicationDebugger or ASM documentation.
signature - Method signature - see ASM documentation.
exceptions - Exceptions thrown by this method - see ASM documentation.
Returns:
MethodVisitor object

addStaticDebuggerCall

public org.objectweb.asm.MethodVisitor addStaticDebuggerCall(org.objectweb.asm.MethodVisitor mv,
                                                             InterceptedMethod im)
Adds the bytecode to call the static debugger.

Parameters:
mv - The current MethodVisitor
im - The InterceptedMethod object that represents the method that will be modified.
Returns:
MethodVisitor object passed in

addRecursionLimiter

public org.objectweb.asm.MethodVisitor addRecursionLimiter(org.objectweb.asm.MethodVisitor mv,
                                                           InterceptedMethod im,
                                                           java.lang.String returnType)
Adds a recursion limit to a recursive limit - keeps recursive methods that are buggy from causing a stack overflow.

Parameters:
mv - The current MethodVisitor
im - The InterceptedMethod object that represents the method that will be modified.
returnType - The return type of the method being modified - this is the same type as in ASM description, not full class names such as String.
Returns:
The current MethodVisitor

getFieldNameByMethod

private java.lang.String getFieldNameByMethod(java.lang.String method)
Returns the name of the field that holds the current recursion count for the method.

Parameters:
method - The method that needs to know it's recursion count.
Returns:
A String that holds the field name.

getReturnTypeFromDescription

private java.lang.String getReturnTypeFromDescription(java.lang.String desc)
Parses the return type from the method description.

Parameters:
desc - The method description - see ApplicationDebugger.
Returns:
A String containing the type.