ataspectj.instrumentation
Class InstructionInstrumentationFactory

java.lang.Object
  extended by ataspectj.AtAspectjComponent
      extended by ataspectj.instrumentation.InstructionInstrumentationFactory

public class InstructionInstrumentationFactory
extends AtAspectjComponent

Used to modify the instruction list of the annotated blocks and to create the new istruction list for the new methods extracted.

Author:
Marco Poggi

Field Summary
 
Fields inherited from class ataspectj.AtAspectjComponent
barrier, CODEPRINT, DEBUG, VERBOSE
 
Constructor Summary
InstructionInstrumentationFactory()
           
 
Method Summary
static boolean checkIfThereIsWrapperExpressionCall(org.apache.bcel.generic.Instruction invk, org.apache.bcel.generic.ConstantPoolGen cg)
          Checks if there is a call to a wrapper expression annotation method.
static org.apache.bcel.generic.Instruction createALoadInstruction(int index, org.apache.bcel.generic.Type tprim, org.apache.bcel.generic.InstructionFactory ifact)
          It cretes a ALOAD instruction
static org.apache.bcel.generic.Instruction createAStoreInstruction(int index, org.apache.bcel.generic.Type tprim, org.apache.bcel.generic.InstructionFactory ifact)
          It cretes a ASTORE instruction
static org.apache.bcel.generic.Instruction createGetField(org.apache.bcel.generic.Type primType, java.lang.String fieldName, org.apache.bcel.generic.InstructionFactory ifact)
          TO DO CHECK Field name It create a get field instruction.
static org.apache.bcel.generic.Instruction createPutField(org.apache.bcel.generic.Type primType, java.lang.String fieldName, org.apache.bcel.generic.InstructionFactory ifact)
          TO DO CHECK Field name It create a put field instruction.
static org.apache.bcel.generic.Instruction createTypeValue(org.apache.bcel.generic.Type primType, org.apache.bcel.generic.InstructionFactory ifact)
          It creates a typeValue method invocation instruction, where the type used is the appropriate one for the given primitive type
static org.apache.bcel.generic.Instruction createValueOf(org.apache.bcel.generic.Type primType, org.apache.bcel.generic.InstructionFactory ifact)
          It creates a valueOf method invocation instruction, where the type used is the appropriate one for the given primitive type
static int[] getIndexes(java.lang.String s)
           
static org.apache.bcel.generic.Type getTypeFromPrimitive(org.apache.bcel.generic.Type t)
          It returns the appropriate wrapper type for the given primitive type.
static boolean isIINCInstruction(org.apache.bcel.generic.Instruction i)
          It checks if the given instruction is a IINC instruction.
static boolean isLoadInstruction(org.apache.bcel.generic.Instruction i)
          It checks if the given instruction is a load instruction.
static boolean isLocalVariableInstruction(org.apache.bcel.generic.Instruction i)
          It checks if the given instruction is a local variable instruction.
static boolean isStoreInstruction(org.apache.bcel.generic.Instruction i)
          It checks if the given instruction is a store instruction.
static IndexRepository searchIndexRepository(int oldIndex, IndexRepository[] allRep)
          It searchs the IndexRepository that store the information for the given index.
static java.lang.String selectValueMethodName(org.apache.bcel.generic.Type primType)
          It selects the appropriate method name for the type value.
static void updateIINCInstruction(org.apache.bcel.generic.InstructionHandle ih, org.apache.bcel.generic.InstructionList oldIl, IndexRepository indexRep, org.apache.bcel.generic.InstructionFactory ifact, int freeIndex, int increment)
          It updates the IINC insruction, it replaces the IINC with a Load, and IADD
static org.apache.bcel.generic.InstructionList updateInstructionList(InstrumentationRepository irep, IndexRepository[] allIndexRep, org.apache.bcel.generic.ConstantPoolGen cg, boolean isStatic)
          It updates the index of local variables instruction of the InstructionList contained into the InstrumentationRepository, to do that use the the indexes stored into the IndexRepositories.
static void updatePrimTypeLoadInstruction(org.apache.bcel.generic.InstructionHandle ih, org.apache.bcel.generic.InstructionList oldIl, IndexRepository indexRep, org.apache.bcel.generic.InstructionFactory ifact)
          It updates a primitive types LOAD instrcution, it replaces the LOAD with a Load, and GETFIELD
static void updatePrimTypeStoreInstruction(org.apache.bcel.generic.InstructionHandle ih, org.apache.bcel.generic.InstructionList oldIl, IndexRepository indexRep, org.apache.bcel.generic.InstructionFactory ifact)
          It updates a primitive types store instrcution, it replaces the STORE with a Load, and PUTFIELD
static void updatePrimTypeStoreInstructionWrapCall(org.apache.bcel.generic.InstructionHandle ih, org.apache.bcel.generic.InstructionList oldIl, IndexRepository indexRep, org.apache.bcel.generic.InstructionFactory ifact, org.apache.bcel.generic.ConstantPoolGen cg)
          It updates a primitive types store instrcution, it replaces the STORE with a Load, and PUTFIELD, in case there is wrapperExpressionCall
 
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
 

Constructor Detail

InstructionInstrumentationFactory

public InstructionInstrumentationFactory()
Method Detail

updateInstructionList

public static org.apache.bcel.generic.InstructionList updateInstructionList(InstrumentationRepository irep,
                                                                            IndexRepository[] allIndexRep,
                                                                            org.apache.bcel.generic.ConstantPoolGen cg,
                                                                            boolean isStatic)
                                                                     throws java.lang.Exception
It updates the index of local variables instruction of the InstructionList contained into the InstrumentationRepository, to do that use the the indexes stored into the IndexRepositories.

Parameters:
irep - the InstrumentationRepository containing the InstructionList to update.
allIndexRep - the IndexRepository of the local variables involved.
cg - the ConstantPoolGen.
isStatic - true if the InstructionList belongs to a static method.
Returns:
the updated InstrucionList.
Throws:
java.lang.Exception - TODO investifare sulla eccezione che puo' essere sollevata.

checkIfThereIsWrapperExpressionCall

public static boolean checkIfThereIsWrapperExpressionCall(org.apache.bcel.generic.Instruction invk,
                                                          org.apache.bcel.generic.ConstantPoolGen cg)
Checks if there is a call to a wrapper expression annotation method.

Parameters:
invk - the istruction to check.
cg - the constant pool.

updateIINCInstruction

public static void updateIINCInstruction(org.apache.bcel.generic.InstructionHandle ih,
                                         org.apache.bcel.generic.InstructionList oldIl,
                                         IndexRepository indexRep,
                                         org.apache.bcel.generic.InstructionFactory ifact,
                                         int freeIndex,
                                         int increment)
                                  throws org.apache.bcel.generic.TargetLostException
It updates the IINC insruction, it replaces the IINC with a Load, and IADD

Parameters:
ih - the InstructionHandle of the IINC instruction.
oldIl - the old InstructionList to update.
indexRep - the IndexRep storing the information of the local variable involved.
ifact - the InstructionFactory to create the needed instruction.
freeIndex - the free index to update
increment - the increment params of the IINC
Throws:
org.apache.bcel.generic.TargetLostException - raised if the IINC instruction is a target of a jump.

updatePrimTypeStoreInstruction

public static void updatePrimTypeStoreInstruction(org.apache.bcel.generic.InstructionHandle ih,
                                                  org.apache.bcel.generic.InstructionList oldIl,
                                                  IndexRepository indexRep,
                                                  org.apache.bcel.generic.InstructionFactory ifact)
                                           throws org.apache.bcel.generic.TargetLostException
It updates a primitive types store instrcution, it replaces the STORE with a Load, and PUTFIELD

Parameters:
ih - the InstructionHandle of the STORE instruction.
oldIl - the old InstructionList to update.
indexRep - the IndexRep storing the information of the local variable involved.
ifact - the InstructionFactory to create the needed instruction.
Throws:
org.apache.bcel.generic.TargetLostException - raised if the STORE instruction is a target of a jump.

updatePrimTypeStoreInstructionWrapCall

public static void updatePrimTypeStoreInstructionWrapCall(org.apache.bcel.generic.InstructionHandle ih,
                                                          org.apache.bcel.generic.InstructionList oldIl,
                                                          IndexRepository indexRep,
                                                          org.apache.bcel.generic.InstructionFactory ifact,
                                                          org.apache.bcel.generic.ConstantPoolGen cg)
                                                   throws org.apache.bcel.generic.TargetLostException
It updates a primitive types store instrcution, it replaces the STORE with a Load, and PUTFIELD, in case there is wrapperExpressionCall

Parameters:
ih - the InstructionHandle of the STORE instruction.
oldIl - the old InstructionList to update.
indexRep - the IndexRep storing the information of the local variable involved.
ifact - the InstructionFactory to create the needed instruction.
Throws:
org.apache.bcel.generic.TargetLostException - raised if the STORE instruction is a target of a jump.

getIndexes

public static int[] getIndexes(java.lang.String s)

updatePrimTypeLoadInstruction

public static void updatePrimTypeLoadInstruction(org.apache.bcel.generic.InstructionHandle ih,
                                                 org.apache.bcel.generic.InstructionList oldIl,
                                                 IndexRepository indexRep,
                                                 org.apache.bcel.generic.InstructionFactory ifact)
                                          throws org.apache.bcel.generic.TargetLostException
It updates a primitive types LOAD instrcution, it replaces the LOAD with a Load, and GETFIELD

Parameters:
ih - the InstructionHandle of the LOAD instruction.
oldIl - the old InstructionList to update.
indexRep - the IndexRep storing the information of the local variable involved.
ifact - the InstructionFactory to create the needed instruction.
Throws:
org.apache.bcel.generic.TargetLostException - raised if the LOAD instruction is a target of a jump.

searchIndexRepository

public static IndexRepository searchIndexRepository(int oldIndex,
                                                    IndexRepository[] allRep)
It searchs the IndexRepository that store the information for the given index.

Parameters:
oldIndex - the old index to search.
allRep - the index repositories to search in.
Returns:
the appropriate index repository.

createAStoreInstruction

public static org.apache.bcel.generic.Instruction createAStoreInstruction(int index,
                                                                          org.apache.bcel.generic.Type tprim,
                                                                          org.apache.bcel.generic.InstructionFactory ifact)
It cretes a ASTORE instruction

Parameters:
index - the index where store the primitive type.
tprim - the primitive type to store.
ifact - the instruction factory to use.
Returns:
the created instruction.

createALoadInstruction

public static org.apache.bcel.generic.Instruction createALoadInstruction(int index,
                                                                         org.apache.bcel.generic.Type tprim,
                                                                         org.apache.bcel.generic.InstructionFactory ifact)
It cretes a ALOAD instruction

Parameters:
index - the index where load the primitive type.
tprim - the primitive type to load.
ifact - the instruction factory to use.
Returns:
the created instruction.

getTypeFromPrimitive

public static org.apache.bcel.generic.Type getTypeFromPrimitive(org.apache.bcel.generic.Type t)
It returns the appropriate wrapper type for the given primitive type.

Parameters:
t - The primitive type.
Returns:
The @aspectj wrapper type.

isLocalVariableInstruction

public static boolean isLocalVariableInstruction(org.apache.bcel.generic.Instruction i)
It checks if the given instruction is a local variable instruction.

Parameters:
i - The instruction to check.
Returns:
True if the given instruction is a local variable instrucion.

isStoreInstruction

public static boolean isStoreInstruction(org.apache.bcel.generic.Instruction i)
It checks if the given instruction is a store instruction.

Parameters:
i - The instruction to check.
Returns:
True if the given instruction is a store variable instrucion.

isLoadInstruction

public static boolean isLoadInstruction(org.apache.bcel.generic.Instruction i)
It checks if the given instruction is a load instruction.

Parameters:
i - The instruction to check.
Returns:
True if the given instruction is a load instrucion.

isIINCInstruction

public static boolean isIINCInstruction(org.apache.bcel.generic.Instruction i)
It checks if the given instruction is a IINC instruction.

Parameters:
i - The instruction to check.
Returns:
True if the given instruction is a IINC instrucion.

createTypeValue

public static org.apache.bcel.generic.Instruction createTypeValue(org.apache.bcel.generic.Type primType,
                                                                  org.apache.bcel.generic.InstructionFactory ifact)
It creates a typeValue method invocation instruction, where the type used is the appropriate one for the given primitive type

Parameters:
primType - The primitive type to use.
ifact - The instruction factory to use.
Returns:
The instruction created.

createValueOf

public static org.apache.bcel.generic.Instruction createValueOf(org.apache.bcel.generic.Type primType,
                                                                org.apache.bcel.generic.InstructionFactory ifact)
It creates a valueOf method invocation instruction, where the type used is the appropriate one for the given primitive type

Parameters:
primType - The primitive type to use.
ifact - The instruction factory to use.
Returns:
The instruction created.

createGetField

public static org.apache.bcel.generic.Instruction createGetField(org.apache.bcel.generic.Type primType,
                                                                 java.lang.String fieldName,
                                                                 org.apache.bcel.generic.InstructionFactory ifact)
TO DO CHECK Field name It create a get field instruction.

Parameters:
primType - The primitive type to get.
fieldName - The name of the field to get.
ifact - The instruction factory to use.
Returns:
The instrucion created.

createPutField

public static org.apache.bcel.generic.Instruction createPutField(org.apache.bcel.generic.Type primType,
                                                                 java.lang.String fieldName,
                                                                 org.apache.bcel.generic.InstructionFactory ifact)
TO DO CHECK Field name It create a put field instruction.

Parameters:
primType - The primitive type to fill.
fieldName - The name of the field to fill.
ifact - The instruction factory to use.
Returns:
The instrucion created.

selectValueMethodName

public static java.lang.String selectValueMethodName(org.apache.bcel.generic.Type primType)
It selects the appropriate method name for the type value.

Parameters:
primType - The primitive type to use.
Returns:
The method name selected.