korat.instrumentation
Class ArrayFieldInstrumenter

java.lang.Object
  extended by korat.instrumentation.AbstractInstrumenter
      extended by korat.instrumentation.FieldInstrumenter
          extended by korat.instrumentation.ArrayFieldInstrumenter
All Implemented Interfaces:
IInstrumenter

 class ArrayFieldInstrumenter
extends FieldInstrumenter

This class does all the instrumentation related to array fields. First, it replaces declarations all array fields with the corresponding IKoratArray field declarations. Then, in all methods, it replaces accesses to those fields with appropriate method calls to their corresponding IKoratArray fields. For instance, the following piece of code

     class C {
         int[] foo;
         void f() {
             foo = new int[10];
             foo[0] = 15;
             int x = foo[0];
             x += foo.length()
         }
     }
 
after the instrumentation looks like
     class C {
         Korat_Array_int __koratArray_foo;
         // ... (stuff that FieldInstrumenter adds to foo field)
         void f() {
             __koratArray_foo = new Korat_Array_int(10);
             __koratArray_foo.set(0, 15);
             int x = __koratArray_foo.get(0);
             x += __koratArray_foo.getLength();    
         }
     }
 

Author:
Aleksandar Milicevic
See Also:
ArrayGenerator, AbstractInstrumenter, FieldInstrumenter, SpecialConstructorInstrumenter

Field Summary
private  Set<CtField> fieldsToRemove
          Keep the track of the arrays fields that need to be removed at the end.
 
Fields inherited from class korat.instrumentation.AbstractInstrumenter
cp
 
Constructor Summary
ArrayFieldInstrumenter()
           
 
Method Summary
protected  void handleArrayFieldDeclaration(CtClass clz, CtField f)
          For the given array field creates new field of the corresponding KoratArray_fieldType type.
protected  void instrumentFieldDeclarations(CtClass clz)
           For each field in the given class adds additional stuff needed for instrumentation (by calling handleFieldDeclaration.
private  void removeOriginalArrayFields(CtClass clz)
          Removes original array fields from the class.
protected  void replaceFieldAccesses(CtClass clz)
           Traverses through all methods in the given class, looks for the bytecode instructions related to arrays and modifies them appropriately.
 
Methods inherited from class korat.instrumentation.FieldInstrumenter
addGetSetterMethod, addGetterMethod, addIdField, createNestedSetterClass, getGetSetterSrc, getGetterSrc, handleFieldDeclaration, instrument
 
Methods inherited from class korat.instrumentation.AbstractInstrumenter
getBytecode, shouldProcessField, shouldProcessMethod
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fieldsToRemove

private Set<CtField> fieldsToRemove
Keep the track of the arrays fields that need to be removed at the end.

Constructor Detail

ArrayFieldInstrumenter

ArrayFieldInstrumenter()
Method Detail

instrumentFieldDeclarations

protected void instrumentFieldDeclarations(CtClass clz)
                                    throws NotFoundException,
                                           CannotCompileException
Description copied from class: FieldInstrumenter

For each field in the given class adds additional stuff needed for instrumentation (by calling handleFieldDeclaration. Fields of type array are not handled by this class.

Overrides:
instrumentFieldDeclarations in class FieldInstrumenter
Throws:
NotFoundException
CannotCompileException

handleArrayFieldDeclaration

protected void handleArrayFieldDeclaration(CtClass clz,
                                           CtField f)
                                    throws CannotCompileException,
                                           NotFoundException
For the given array field creates new field of the corresponding KoratArray_fieldType type. For the newly created field, handleNonArrayField is called. The given field is than added to fieldsToRemove set since it is not possible to delete it right away.

Throws:
CannotCompileException
NotFoundException
See Also:
FieldInstrumenter.handleFieldDeclaration(CtClass, CtField)

replaceFieldAccesses

protected void replaceFieldAccesses(CtClass clz)

Traverses through all methods in the given class, looks for the bytecode instructions related to arrays and modifies them appropriately. Since all array fields have been replaced with fields of the KoratArray classes, field accesses also have to be replaced with method calls to corresponding substitution field.

Overrides:
replaceFieldAccesses in class FieldInstrumenter

removeOriginalArrayFields

private void removeOriginalArrayFields(CtClass clz)
                                throws NotFoundException
Removes original array fields from the class.

Parameters:
clz - - class of the fields to be removed
Throws:
NotFoundException