org.jboss.aop.instrument
Class FieldAccessTransformer

java.lang.Object
  extended by org.jboss.aop.instrument.FieldAccessTransformer
Direct Known Subclasses:
GeneratedAdvisorFieldAccessTransformer, NonOptimizedFieldAccessTransformer, OptimizedFieldAccessTransformer

public abstract class FieldAccessTransformer
extends Object

Author:
Kabir Khan

Nested Class Summary
protected  class FieldAccessTransformer.FieldAccessExprEditor
           
 
Field Summary
protected static int GET_INDEX
           
protected static int SET_INDEX
           
protected static String[] transformations
           
protected static WrapperTransformer wrapper
           
 
Constructor Summary
protected FieldAccessTransformer(Instrumentor instrumentor)
           
 
Method Summary
protected  String addFieldReadInfoFieldWithAccessors(int modifiers, javassist.CtClass addTo, javassist.CtField field)
           
protected  String addFieldReadInfoFieldWithAccessors(int modifiers, javassist.CtClass addTo, javassist.CtField field, javassist.CtField.Initializer init)
          Adds a FieldInfo field to the passed in class
protected  String addFieldWriteInfoField(int modifiers, javassist.CtClass addTo, javassist.CtField field)
           
protected  String addFieldWriteInfoField(int modifiers, javassist.CtClass addTo, javassist.CtField field, javassist.CtField.Initializer init)
          Adds a FieldInfo field to the passed in class
protected  boolean addInfoAsWeakReference()
           
protected  void buildFieldWrappers(javassist.CtClass clazz, ClassAdvisor advisor, boolean shouldReplaceArrayAccess)
           
protected  javassist.CtMethod buildReadWrapperPlaceHolder(javassist.CtClass clazz, javassist.CtField field, String wrapperName, int mod)
          Builds the read wrapper place holder for preparation of field read joinpoint.
protected  void buildWrapperPlaceHolders(javassist.CtClass clazz, javassist.CtField field, boolean doGet, boolean doSet, int mod)
          Generate the wrapper place holders.
protected  javassist.CtMethod buildWriteWrapperPlaceHolder(javassist.CtClass clazz, javassist.CtField field, String wrapperName, int mod)
          Builds the write wrapper place holder for preparation of field read joinpoint.
 void codeConverted()
          Notifies this transformer that the code conversion is done.
protected abstract  void doBuildFieldWrappers(javassist.CtClass clazz, javassist.CtField field, int index, boolean shouldReplaceArrayAccess, JoinpointClassification classificationGet, JoinpointClassification classificationSet)
           
protected static String fieldInfoFromWeakReference(String localName, String fieldInfoName)
           
protected  int fieldOffset(javassist.CtClass clazz)
           
static String fieldRead(String fieldName)
           
static String fieldWrite(String fieldName)
           
protected  String getArrayWriteRegistration(boolean shouldReplaceArrayAccess, String target, javassist.CtField field, String oldValue, String newValue)
           
static String getFieldReadInfoFieldName(String fieldName)
           
static String getFieldWriteInfoFieldName(String fieldName)
           
protected  int getStaticModifiers(javassist.CtField field)
           
protected abstract  String getWrapperBody(javassist.CtClass clazz, javassist.CtField field, boolean get, int fieldIndex)
          Returns the wrapper body of the field joinpoint.
protected  javassist.CtMethod getWrapperReadMethod(javassist.CtField field, javassist.CtClass clazz)
           
protected  javassist.CtMethod getWrapperWriteMethod(javassist.CtField field, javassist.CtClass clazz)
           
protected  boolean isPrepared(JoinpointClassification classification)
           
protected  boolean markInfoAsSynthetic()
           
 boolean replaceFieldAccess(List<javassist.CtField> fields, javassist.CtClass clazz, ClassAdvisor fieldsAdvisor)
          replace field access for possible public/protected fields that are intercepted don't need to replace access for private fields.
protected abstract  void replaceFieldAccessInternally(javassist.CtClass clazz, javassist.CtField field, boolean doGet, boolean doSet, int index)
          This function replaces internal field accesses with bytecode hooks into framework todo this must do it for inherited protected/public fields as well
 void unwrap(javassist.CtClass clazz, Collection<Integer> fieldsGet, Collection<Integer> fieldsSet)
          Unwraps the field joinpoints contained in fieldsGet and fieldsSet.
 void wrap(javassist.CtClass clazz, Collection<Integer> fieldsGet, Collection<Integer> fieldsSet)
          Wraps the field joinpoints contained in fieldsGet and fieldsSet.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

transformations

protected static final String[] transformations

GET_INDEX

protected static final int GET_INDEX
See Also:
Constant Field Values

SET_INDEX

protected static final int SET_INDEX
See Also:
Constant Field Values

wrapper

protected static final WrapperTransformer wrapper
Constructor Detail

FieldAccessTransformer

protected FieldAccessTransformer(Instrumentor instrumentor)
Method Detail

buildFieldWrappers

protected void buildFieldWrappers(javassist.CtClass clazz,
                                  ClassAdvisor advisor,
                                  boolean shouldReplaceArrayAccess)
                           throws javassist.NotFoundException,
                                  javassist.CannotCompileException
Throws:
javassist.NotFoundException
javassist.CannotCompileException

isPrepared

protected boolean isPrepared(JoinpointClassification classification)

doBuildFieldWrappers

protected abstract void doBuildFieldWrappers(javassist.CtClass clazz,
                                             javassist.CtField field,
                                             int index,
                                             boolean shouldReplaceArrayAccess,
                                             JoinpointClassification classificationGet,
                                             JoinpointClassification classificationSet)
                                      throws javassist.NotFoundException,
                                             javassist.CannotCompileException
Throws:
javassist.NotFoundException
javassist.CannotCompileException

getArrayWriteRegistration

protected String getArrayWriteRegistration(boolean shouldReplaceArrayAccess,
                                           String target,
                                           javassist.CtField field,
                                           String oldValue,
                                           String newValue)
                                    throws javassist.NotFoundException
Throws:
javassist.NotFoundException

replaceFieldAccess

public boolean replaceFieldAccess(List<javassist.CtField> fields,
                                  javassist.CtClass clazz,
                                  ClassAdvisor fieldsAdvisor)
                           throws javassist.NotFoundException
replace field access for possible public/protected fields that are intercepted don't need to replace access for private fields.

Parameters:
clazz -
fieldsAdvisor -
Returns:
Throws:
javassist.NotFoundException

wrap

public void wrap(javassist.CtClass clazz,
                 Collection<Integer> fieldsGet,
                 Collection<Integer> fieldsSet)
          throws javassist.CannotCompileException,
                 javassist.NotFoundException
Wraps the field joinpoints contained in fieldsGet and fieldsSet.

Parameters:
clazz - the class being instrumented.
fieldsGet - a collection of java.lang.Integer indentifying the field reads to be wrapped.
fieldsSet - a collection of java.lang.Integer indentifying the field writes to be wrapped.
Throws:
javassist.CannotCompileException
javassist.NotFoundException

getWrapperReadMethod

protected javassist.CtMethod getWrapperReadMethod(javassist.CtField field,
                                                  javassist.CtClass clazz)
                                           throws javassist.NotFoundException
Throws:
javassist.NotFoundException

getWrapperWriteMethod

protected javassist.CtMethod getWrapperWriteMethod(javassist.CtField field,
                                                   javassist.CtClass clazz)
                                            throws javassist.NotFoundException
Throws:
javassist.NotFoundException

unwrap

public void unwrap(javassist.CtClass clazz,
                   Collection<Integer> fieldsGet,
                   Collection<Integer> fieldsSet)
            throws javassist.CannotCompileException,
                   javassist.NotFoundException
Unwraps the field joinpoints contained in fieldsGet and fieldsSet.

Parameters:
clazz - the class being instrumented.
fieldsGet - a collection of java.lang.Integer indentifying the field reads to be unwrapped.
fieldsSet - a collection of java.lang.Integer indentifying the field writes to be unwrapped.
Throws:
javassist.CannotCompileException
javassist.NotFoundException

codeConverted

public void codeConverted()
                   throws javassist.NotFoundException,
                          javassist.CannotCompileException
Notifies this transformer that the code conversion is done.

Throws:
javassist.NotFoundException
javassist.CannotCompileException

fieldOffset

protected int fieldOffset(javassist.CtClass clazz)
                   throws javassist.NotFoundException
Throws:
javassist.NotFoundException

addFieldReadInfoFieldWithAccessors

protected String addFieldReadInfoFieldWithAccessors(int modifiers,
                                                    javassist.CtClass addTo,
                                                    javassist.CtField field)
                                             throws javassist.NotFoundException,
                                                    javassist.CannotCompileException
Throws:
javassist.NotFoundException
javassist.CannotCompileException

addFieldReadInfoFieldWithAccessors

protected String addFieldReadInfoFieldWithAccessors(int modifiers,
                                                    javassist.CtClass addTo,
                                                    javassist.CtField field,
                                                    javassist.CtField.Initializer init)
                                             throws javassist.NotFoundException,
                                                    javassist.CannotCompileException
Adds a FieldInfo field to the passed in class

Throws:
javassist.NotFoundException
javassist.CannotCompileException

addFieldWriteInfoField

protected String addFieldWriteInfoField(int modifiers,
                                        javassist.CtClass addTo,
                                        javassist.CtField field)
                                 throws javassist.NotFoundException,
                                        javassist.CannotCompileException
Throws:
javassist.NotFoundException
javassist.CannotCompileException

addFieldWriteInfoField

protected String addFieldWriteInfoField(int modifiers,
                                        javassist.CtClass addTo,
                                        javassist.CtField field,
                                        javassist.CtField.Initializer init)
                                 throws javassist.NotFoundException,
                                        javassist.CannotCompileException
Adds a FieldInfo field to the passed in class

Throws:
javassist.NotFoundException
javassist.CannotCompileException

addInfoAsWeakReference

protected boolean addInfoAsWeakReference()

markInfoAsSynthetic

protected boolean markInfoAsSynthetic()

getFieldReadInfoFieldName

public static String getFieldReadInfoFieldName(String fieldName)

getFieldWriteInfoFieldName

public static String getFieldWriteInfoFieldName(String fieldName)

fieldRead

public static String fieldRead(String fieldName)

fieldWrite

public static String fieldWrite(String fieldName)

fieldInfoFromWeakReference

protected static String fieldInfoFromWeakReference(String localName,
                                                   String fieldInfoName)

getStaticModifiers

protected int getStaticModifiers(javassist.CtField field)

replaceFieldAccessInternally

protected abstract void replaceFieldAccessInternally(javassist.CtClass clazz,
                                                     javassist.CtField field,
                                                     boolean doGet,
                                                     boolean doSet,
                                                     int index)
                                              throws javassist.CannotCompileException
This function replaces internal field accesses with bytecode hooks into framework todo this must do it for inherited protected/public fields as well

Parameters:
clazz -
field -
doGet -
doSet -
index -
Throws:
javassist.CannotCompileException

buildWrapperPlaceHolders

protected void buildWrapperPlaceHolders(javassist.CtClass clazz,
                                        javassist.CtField field,
                                        boolean doGet,
                                        boolean doSet,
                                        int mod)
                                 throws javassist.NotFoundException,
                                        javassist.CannotCompileException
Generate the wrapper place holders.

PS: Removed from inside inner classes to avoid code repetition.

Throws:
javassist.NotFoundException
javassist.CannotCompileException

buildReadWrapperPlaceHolder

protected javassist.CtMethod buildReadWrapperPlaceHolder(javassist.CtClass clazz,
                                                         javassist.CtField field,
                                                         String wrapperName,
                                                         int mod)
                                                  throws javassist.NotFoundException,
                                                         javassist.CannotCompileException
Builds the read wrapper place holder for preparation of field read joinpoint.

Parameters:
clazz - the clazz to add wrapper to
field - the field whose read joinpoint wrapper will be generated.
wrapperName - The name of the field wrapper to be generated
mod - the modifiers of the generated wrapper.
Throws:
javassist.NotFoundException
javassist.CannotCompileException

buildWriteWrapperPlaceHolder

protected javassist.CtMethod buildWriteWrapperPlaceHolder(javassist.CtClass clazz,
                                                          javassist.CtField field,
                                                          String wrapperName,
                                                          int mod)
                                                   throws javassist.NotFoundException,
                                                          javassist.CannotCompileException
Builds the write wrapper place holder for preparation of field read joinpoint.

Parameters:
clazz - the class the wrapper will be added to
field - the field whose write joinpoint wrapper will be generated.
wrapperName - The name of the field wrapper to be generated
mod - the modifiers of the generated wrapper.
Throws:
javassist.NotFoundException
javassist.CannotCompileException

getWrapperBody

protected abstract String getWrapperBody(javassist.CtClass clazz,
                                         javassist.CtField field,
                                         boolean get,
                                         int fieldIndex)
                                  throws javassist.NotFoundException,
                                         javassist.CannotCompileException
Returns the wrapper body of the field joinpoint.

Parameters:
clazz - the class declaring field.
field - the field whose joinpoint wrapper code will be generated.
get - indicates if the wrapper is a field read wrapper or a field write wrapper.
fieldIndex - the index of field.
Returns:
teh wrapper body code.
Throws:
javassist.NotFoundException
javassist.CannotCompileException


Copyright © 2008 JBoss, a division of Red Hat, Inc.. All Rights Reserved.