ataspectj.instrumentation
Class InstrumentationRepository

java.lang.Object
  extended by ataspectj.AtAspectjComponent
      extended by ataspectj.instrumentation.InstrumentationRepository
All Implemented Interfaces:
java.lang.Comparable<InstrumentationRepository>

public class InstrumentationRepository
extends AtAspectjComponent
implements java.lang.Comparable<InstrumentationRepository>

It store the information relative to an annotated block to be extruded.

Author:
Marco Poggi

Field Summary
protected  atjava.lang.annotation.AnnotatedBlock _annotatedBlock
          The annotated block to instrument.
protected  byte[] _annotatedBytecode
          The annotated bytecode.
protected  org.apache.bcel.generic.InstructionList _annotatedIl
          The annotated instruction list.
protected  java.lang.Class _class
          The owner class of the annotated block.
protected  org.apache.bcel.generic.ClassGen _classGen
          The ClassGen associated with the class.
protected  org.apache.bcel.generic.ConstantPoolGen _cpgen
          The constant pool gen associated with the class.
protected static java.util.Hashtable<java.lang.String,java.lang.Integer> _freeIndex
          Hash table used to store for each method wich free index is available.
protected  int _freeLocalIndex
          It stores the first local index freee.
protected  org.apache.bcel.generic.InstructionList _invoke
          The invoke instruction list of the new method.
protected  IndexRepository[] _irAnnotated
          The index repository array to trace all the variables envolved.
protected  org.apache.bcel.classfile.JavaClass _javaclass
          The JavaClass object of the class.
protected  java.lang.String _keyFreeIndexHash
           
protected  org.apache.bcel.classfile.Method _method
          The Bcel version of the object.
protected  org.apache.bcel.generic.MethodGen _methodGen
          The MethodGen object relative to the method
protected  boolean[] _modified
          Bit vector to remeber which instruction are already modified.
protected  byte[] _newBytecode
          The new bytecode modified by the instrumentation process, it will be the final bytecode of the method.
protected  org.apache.bcel.generic.InstructionList _newIl
          The final instruction list after the change.
protected  java.lang.String _newMethodName
          The new method name
protected  int _numParam
          the number of parameter of the new method.
protected  java.lang.reflect.AccessibleObject _obj
          The AccessibleObject relative to the method or constructor.
protected  org.apache.bcel.generic.InstructionList _oldIl
          The original Instruction List
protected  byte[] _oldMethodBytecode
          The original bytecode of the method
protected static java.lang.String METHOD_SUFFIX
          The suffix of the new method to be created
 
Fields inherited from class ataspectj.AtAspectjComponent
barrier, CODEPRINT, DEBUG, VERBOSE
 
Constructor Summary
InstrumentationRepository()
          The standard constructor of the class.
InstrumentationRepository(java.lang.reflect.AccessibleObject obj, java.lang.Class clazz, org.apache.bcel.classfile.JavaClass jclazz, org.apache.bcel.classfile.Method bcelmethod, atjava.lang.annotation.AnnotatedBlock annBlock)
          The real constructor of the class.
 
Method Summary
 org.apache.bcel.classfile.Method addNewInvokeInstructionList(org.apache.bcel.generic.MethodGen mg, int endPc, org.apache.bcel.generic.InstructionList invokeList, org.apache.bcel.generic.ConstantPoolGen cg)
          It adds the new invoke instruction list to the original method.
 boolean compareAnnotatedBlock(atjava.lang.annotation.AnnotatedBlock auxB)
           
 int compareTo(InstrumentationRepository o)
          Compares two InstrumentationRepository object.
 java.lang.reflect.AccessibleObject getAccessibleObject()
          The getter method for the AccessibleObject field
 atjava.lang.annotation.AnnotatedBlock getAnnotatedBlock()
          The getter method for AnnotatedBlock object.
 byte[] getAnnotatedBytecode()
          The getter method for the annotated bytecode.
 org.apache.bcel.generic.InstructionList getAnnotatedInstructionList()
          The getter method for the annoted instruction list object.
protected  byte[] getBytecode(byte[] bc, int start, int end)
          Retrieves a piece of bytecode.
 org.apache.bcel.generic.ClassGen getClassGen()
          The getter method for ClassGen object.
 java.lang.Class getClassToInstrument()
          The getter method for Class object.
 org.apache.bcel.classfile.ConstantPool getConstantPool()
          The getter method for the constant pool object.
 org.apache.bcel.generic.ConstantPoolGen getConstantPoolGen()
          The getter method for ConstantPoolGen object.
 int getEndPc()
          The getter method for the end pc of the annotated block
 java.lang.Integer getFreeIndex()
           
 IndexRepository[] getIndexUsedIntoAnnotation()
          The getter method for index repository array.
 org.apache.bcel.classfile.JavaClass getJavaClass()
          The getter method for the JavaClass object.
 int getLocalVariableFirstFreeIndex()
          It search the first local variable index free to be used.
 org.apache.bcel.classfile.Method getMethod()
          The getter method for the bcel Method obejct.
 org.apache.bcel.generic.MethodGen getMethodGen()
          The getter method for MethodGen object.
 java.lang.String getMethodName()
          The getter method for the method name
 org.apache.bcel.generic.InstructionList getNewMethodInvokeInstructionList(org.apache.bcel.generic.ConstantPoolGen cg)
          It Creates the new method invocation instruction list.
 java.lang.String getNewMethodName()
          The getter method for the new method name.
 byte[] getOldMethodBytecode()
          The getter method for the original bytecode of the method.
 int getStartPc()
          The getter method for the start pc of the annotated block
protected  IndexRepository[] getUsedIndex(int pc, org.apache.bcel.generic.Instruction[] il, org.apache.bcel.classfile.LocalVariableTable lvt)
          It checks the instruction list to retrieve the information about the local variables involved.
 boolean isStatic()
          Check if the method is static.
protected  void setIndexWrapperIntoNewMethod(IndexRepository[] irs, int lastIndexUsed)
          It sets the index for the new wrapper object in the new method instruction list.
protected  void setNewIndexs(IndexRepository[] irs)
          It updates the local variables index for the new non-static method.
protected  void setNewIndexsForStatic(IndexRepository[] irs)
          It updates the local variables index for the new static method.
 void update(java.lang.Class c, org.apache.bcel.classfile.JavaClass jc, org.apache.bcel.generic.ClassGen cg, org.apache.bcel.generic.ConstantPoolGen cpg, org.apache.bcel.generic.MethodGen mg)
          It updates the pricipal field to propagate the changes.
 
Methods inherited from class ataspectj.AtAspectjComponent
done
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

METHOD_SUFFIX

protected static java.lang.String METHOD_SUFFIX
The suffix of the new method to be created


_class

protected java.lang.Class _class
The owner class of the annotated block.


_classGen

protected org.apache.bcel.generic.ClassGen _classGen
The ClassGen associated with the class.


_cpgen

protected org.apache.bcel.generic.ConstantPoolGen _cpgen
The constant pool gen associated with the class.


_javaclass

protected org.apache.bcel.classfile.JavaClass _javaclass
The JavaClass object of the class.


_obj

protected java.lang.reflect.AccessibleObject _obj
The AccessibleObject relative to the method or constructor.


_method

protected org.apache.bcel.classfile.Method _method
The Bcel version of the object.


_methodGen

protected org.apache.bcel.generic.MethodGen _methodGen
The MethodGen object relative to the method


_annotatedBlock

protected atjava.lang.annotation.AnnotatedBlock _annotatedBlock
The annotated block to instrument.


_annotatedBytecode

protected byte[] _annotatedBytecode
The annotated bytecode.


_oldMethodBytecode

protected byte[] _oldMethodBytecode
The original bytecode of the method


_oldIl

protected org.apache.bcel.generic.InstructionList _oldIl
The original Instruction List


_annotatedIl

protected org.apache.bcel.generic.InstructionList _annotatedIl
The annotated instruction list.


_newBytecode

protected byte[] _newBytecode
The new bytecode modified by the instrumentation process, it will be the final bytecode of the method.


_newIl

protected org.apache.bcel.generic.InstructionList _newIl
The final instruction list after the change.


_modified

protected boolean[] _modified
Bit vector to remeber which instruction are already modified.


_irAnnotated

protected IndexRepository[] _irAnnotated
The index repository array to trace all the variables envolved.


_numParam

protected int _numParam
the number of parameter of the new method.


_invoke

protected org.apache.bcel.generic.InstructionList _invoke
The invoke instruction list of the new method.


_newMethodName

protected java.lang.String _newMethodName
The new method name


_freeLocalIndex

protected int _freeLocalIndex
It stores the first local index freee.


_keyFreeIndexHash

protected java.lang.String _keyFreeIndexHash

_freeIndex

protected static final java.util.Hashtable<java.lang.String,java.lang.Integer> _freeIndex
Hash table used to store for each method wich free index is available.

Constructor Detail

InstrumentationRepository

public InstrumentationRepository()
The standard constructor of the class.


InstrumentationRepository

public InstrumentationRepository(java.lang.reflect.AccessibleObject obj,
                                 java.lang.Class clazz,
                                 org.apache.bcel.classfile.JavaClass jclazz,
                                 org.apache.bcel.classfile.Method bcelmethod,
                                 atjava.lang.annotation.AnnotatedBlock annBlock)
The real constructor of the class.

Parameters:
obj - the AccessibleObject
clazz - the Class object.
jclazz - the JavaClass object.
bcelmethod - the bcel Mehtod object.
annBlock - the annotatedBlock.
Method Detail

update

public void update(java.lang.Class c,
                   org.apache.bcel.classfile.JavaClass jc,
                   org.apache.bcel.generic.ClassGen cg,
                   org.apache.bcel.generic.ConstantPoolGen cpg,
                   org.apache.bcel.generic.MethodGen mg)
            throws java.lang.Exception
It updates the pricipal field to propagate the changes.

Parameters:
c - the Class object.
jc - The JavaClass object.
cg - The ClassGen object.
cpg - The ConstantPoolGen object.
mg - The MethodGen object.
Throws:
java.lang.Exception - if something wrong happnes.

compareAnnotatedBlock

public boolean compareAnnotatedBlock(atjava.lang.annotation.AnnotatedBlock auxB)

getFreeIndex

public java.lang.Integer getFreeIndex()

getStartPc

public int getStartPc()
The getter method for the start pc of the annotated block


getEndPc

public int getEndPc()
The getter method for the end pc of the annotated block


getAccessibleObject

public java.lang.reflect.AccessibleObject getAccessibleObject()
The getter method for the AccessibleObject field


getAnnotatedBlock

public atjava.lang.annotation.AnnotatedBlock getAnnotatedBlock()
The getter method for AnnotatedBlock object.


getJavaClass

public org.apache.bcel.classfile.JavaClass getJavaClass()
The getter method for the JavaClass object.


getClassToInstrument

public java.lang.Class getClassToInstrument()
The getter method for Class object.


getIndexUsedIntoAnnotation

public IndexRepository[] getIndexUsedIntoAnnotation()
The getter method for index repository array.


getMethodName

public java.lang.String getMethodName()
The getter method for the method name


getMethod

public org.apache.bcel.classfile.Method getMethod()
The getter method for the bcel Method obejct.


getNewMethodName

public java.lang.String getNewMethodName()
The getter method for the new method name.


getAnnotatedInstructionList

public org.apache.bcel.generic.InstructionList getAnnotatedInstructionList()
The getter method for the annoted instruction list object.


getAnnotatedBytecode

public byte[] getAnnotatedBytecode()
The getter method for the annotated bytecode.


getOldMethodBytecode

public byte[] getOldMethodBytecode()
The getter method for the original bytecode of the method.


getConstantPool

public org.apache.bcel.classfile.ConstantPool getConstantPool()
The getter method for the constant pool object.


isStatic

public boolean isStatic()
Check if the method is static.


getClassGen

public org.apache.bcel.generic.ClassGen getClassGen()
The getter method for ClassGen object.


getConstantPoolGen

public org.apache.bcel.generic.ConstantPoolGen getConstantPoolGen()
The getter method for ConstantPoolGen object.


getMethodGen

public org.apache.bcel.generic.MethodGen getMethodGen()
The getter method for MethodGen object.


getUsedIndex

protected IndexRepository[] getUsedIndex(int pc,
                                         org.apache.bcel.generic.Instruction[] il,
                                         org.apache.bcel.classfile.LocalVariableTable lvt)
It checks the instruction list to retrieve the information about the local variables involved.

Parameters:
pc - the start program counter
il - the instruction list to check.
lvt - the local variable table.
Returns:
the IndexRepository array builded.

getNewMethodInvokeInstructionList

public org.apache.bcel.generic.InstructionList getNewMethodInvokeInstructionList(org.apache.bcel.generic.ConstantPoolGen cg)
It Creates the new method invocation instruction list. param cg the constant pool gen object.

Returns:
the new invoke instruction list.

addNewInvokeInstructionList

public org.apache.bcel.classfile.Method addNewInvokeInstructionList(org.apache.bcel.generic.MethodGen mg,
                                                                    int endPc,
                                                                    org.apache.bcel.generic.InstructionList invokeList,
                                                                    org.apache.bcel.generic.ConstantPoolGen cg)
It adds the new invoke instruction list to the original method.

Parameters:
mg - the method gen object.
endPc - the end pc of the annotated block where we have to add the invoke list.
invokeList - the new invoke list.
cg - the constant pool gen object.

getLocalVariableFirstFreeIndex

public int getLocalVariableFirstFreeIndex()
It search the first local variable index free to be used.

Returns:
the first free index.

setNewIndexs

protected void setNewIndexs(IndexRepository[] irs)
It updates the local variables index for the new non-static method.

Parameters:
irs - the indexrepository array.

setNewIndexsForStatic

protected void setNewIndexsForStatic(IndexRepository[] irs)
It updates the local variables index for the new static method.

Parameters:
irs - the indexrepository array.

setIndexWrapperIntoNewMethod

protected void setIndexWrapperIntoNewMethod(IndexRepository[] irs,
                                            int lastIndexUsed)
It sets the index for the new wrapper object in the new method instruction list.

Parameters:
irs - the index repository array.
lastIndexUsed - the last index used.

compareTo

public int compareTo(InstrumentationRepository o)
Compares two InstrumentationRepository object.

Specified by:
compareTo in interface java.lang.Comparable<InstrumentationRepository>

getBytecode

protected byte[] getBytecode(byte[] bc,
                             int start,
                             int end)
Retrieves a piece of bytecode.

Parameters:
bc - the total bytecode.
start - the start index.
end - the end index.