org.jboss.aop.instrument
Class Instrumentor

java.lang.Object
  extended by org.jboss.aop.instrument.Instrumentor
Direct Known Subclasses:
ClassicInstrumentor, GeneratedAdvisorInstrumentor

public abstract class Instrumentor
extends Object

Transforms byte code, making a class advisable. Implements command line class instrumentor as well. Reads classes from class path and creates advised versions in specified directory. Usage:

 Instrumentor [dest. directory] [class[ class...]]
 
You can control which instrumentor to use by passing in the jboss.aop.instrumentor system property.

Version:
$Revision: 79818 $
Author:
Bill Burke, Austin Chau, Bob Lee, Kabir Khan

Field Summary
static String AOP_PACKAGE
          Package of AOP classes.
static String ASPECT_MANAGER_CLASS_NAME
          Name of helper class.
protected  boolean basicsSet
           
protected  AOPClassPool classPool
           
protected  javassist.CodeConverter converter
           
static String HELPER_FIELD_NAME
          Helper class's field name.
protected  JoinpointClassifier joinpointClassifier
           
protected  AspectManager manager
           
protected static Collection<javassist.CtClass> processedClasses
           
 
Constructor Summary
protected Instrumentor(AOPClassPool pool, AspectManager manager, JoinpointClassifier joinpointClassifier, DynamicTransformationObserver observer)
          Constructs new instrumentor.
protected Instrumentor(AspectManager manager, JoinpointClassifier joinpointClassifier)
           
 
Method Summary
protected  javassist.CtMethod addMixinMethod(Advisor advisor, javassist.CtMethod method, javassist.CtClass clazz, javassist.CtMethod delegate, long hash)
           
protected  javassist.CtField addProtectedField(javassist.CtClass clazz, String name, String typeName, javassist.CtField.Initializer initializer)
          Adds a protected field to a class.
protected  javassist.CtField addStaticField(javassist.CtClass clazz, String name, String typeName, javassist.CtField.Initializer initializer)
          Adds a static field to a class.
static void addSyntheticAttribute(javassist.CtConstructor ctor)
           
static void addSyntheticAttribute(javassist.CtField field)
           
static void addSyntheticAttribute(javassist.CtMethod method)
           
static void addSyntheticAttribute(javassist.bytecode.MethodInfo info)
           
 boolean applyCallerPointcuts(javassist.CtClass clazz, ClassAdvisor advisor)
           
 void convertProcessedClasses(HotSwapper hotSwapper, javassist.CtClass clazz, Collection<javassist.CtField> fieldReads, Collection<javassist.CtField> fieldWrites, boolean constructor)
          Converts all processed classes to make wrapping of the appropriate joinpoints.
protected  boolean convertReferences(javassist.CtClass clazz, ClassAdvisor clazzAdvisor)
          Find all classes that this class references.
protected  javassist.CtMethod createInvokeMethod(javassist.CtClass clazz)
          Creates generic invoke method to be wrapped by real signatures.
protected abstract  javassist.CtMethod createMixinInvokeMethod(javassist.CtClass clazz, javassist.CtClass mixinClass, String initializer, javassist.CtMethod method, long hash)
          Creates generic invoke method to be wrapped by real signatures.
protected abstract  void doSetupBasics(javassist.CtClass clazz)
           
 javassist.CtClass forName(javassist.ClassPool pool, String name)
          Gets a class by its name.
 javassist.CtClass forName(String name)
          Gets a class by its name.
static List<javassist.CtField> getAdvisableFields(javassist.CtClass clazz)
          Gets sorted collection of advisable methods.
 javassist.ClassPool getClassPool()
           
 List<javassist.CtConstructor> getConstructors(javassist.CtClass clazz)
           
static boolean implementsAdvised(javassist.CtClass clazz)
           
 void interceptorChainsUpdated(Collection<JoinpointStatusUpdate> joinpointUpdates, HotSwapper hotSwapper)
          Notifies the Instrumentor that some joinpoint status were updated.
protected abstract  void intitialiseTransformers()
           
 boolean isAdvised(javassist.CtClass clazz)
           
protected  boolean isBaseClass(javassist.CtClass clazz)
           
 boolean isProxyObject(javassist.CtClass clazz)
           
static boolean isTransformable(javassist.CtClass clazz)
           
protected static String mixinFieldName(javassist.CtClass mixinClass)
           
 void prepareClassForTransformation(javassist.CtClass clazz)
           
 void setupBasics(javassist.CtClass clazz)
           
protected  boolean shouldNotTransform(javassist.CtClass clazz)
           
 boolean transform(javassist.CtClass clazz, ClassAdvisor advisor)
          Makes class advisable.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

AOP_PACKAGE

public static final String AOP_PACKAGE
Package of AOP classes.


ASPECT_MANAGER_CLASS_NAME

public static final String ASPECT_MANAGER_CLASS_NAME
Name of helper class.


HELPER_FIELD_NAME

public static final String HELPER_FIELD_NAME
Helper class's field name.

See Also:
Constant Field Values

classPool

protected AOPClassPool classPool

basicsSet

protected boolean basicsSet

converter

protected javassist.CodeConverter converter

manager

protected AspectManager manager

joinpointClassifier

protected JoinpointClassifier joinpointClassifier

processedClasses

protected static Collection<javassist.CtClass> processedClasses
Constructor Detail

Instrumentor

protected Instrumentor(AOPClassPool pool,
                       AspectManager manager,
                       JoinpointClassifier joinpointClassifier,
                       DynamicTransformationObserver observer)
Constructs new instrumentor.

Parameters:
joinpointClassifier - algorithm of joinpoint classification to be used.
observer - need be notified of every joinpoint wrapping caused only by pointcuts dynamicaly added.

Instrumentor

protected Instrumentor(AspectManager manager,
                       JoinpointClassifier joinpointClassifier)
Method Detail

intitialiseTransformers

protected abstract void intitialiseTransformers()

getClassPool

public javassist.ClassPool getClassPool()

isAdvised

public boolean isAdvised(javassist.CtClass clazz)
                  throws javassist.NotFoundException
Throws:
javassist.NotFoundException

isProxyObject

public boolean isProxyObject(javassist.CtClass clazz)
                      throws javassist.NotFoundException
Throws:
javassist.NotFoundException

prepareClassForTransformation

public void prepareClassForTransformation(javassist.CtClass clazz)
                                   throws javassist.NotFoundException
Throws:
javassist.NotFoundException

implementsAdvised

public static boolean implementsAdvised(javassist.CtClass clazz)
                                 throws javassist.NotFoundException
Throws:
javassist.NotFoundException

isTransformable

public static boolean isTransformable(javassist.CtClass clazz)
                               throws javassist.NotFoundException
Throws:
javassist.NotFoundException

isBaseClass

protected boolean isBaseClass(javassist.CtClass clazz)
                       throws javassist.NotFoundException
Throws:
javassist.NotFoundException

mixinFieldName

protected static String mixinFieldName(javassist.CtClass mixinClass)

addMixinMethod

protected javassist.CtMethod addMixinMethod(Advisor advisor,
                                            javassist.CtMethod method,
                                            javassist.CtClass clazz,
                                            javassist.CtMethod delegate,
                                            long hash)
                                     throws Exception
Throws:
Exception

applyCallerPointcuts

public boolean applyCallerPointcuts(javassist.CtClass clazz,
                                    ClassAdvisor advisor)
                             throws javassist.CannotCompileException
Throws:
javassist.CannotCompileException

convertReferences

protected boolean convertReferences(javassist.CtClass clazz,
                                    ClassAdvisor clazzAdvisor)
                             throws Exception
Find all classes that this class references. If any of those classes are advised and have field and/or constructor interception, do instrumentation on this class so that those fields and constructors are instrumented

Throws:
Exception

shouldNotTransform

protected boolean shouldNotTransform(javassist.CtClass clazz)
                              throws javassist.NotFoundException
Throws:
javassist.NotFoundException

transform

public boolean transform(javassist.CtClass clazz,
                         ClassAdvisor advisor)
Makes class advisable.


getConstructors

public List<javassist.CtConstructor> getConstructors(javassist.CtClass clazz)

getAdvisableFields

public static List<javassist.CtField> getAdvisableFields(javassist.CtClass clazz)
                                                  throws javassist.NotFoundException
Gets sorted collection of advisable methods.

Throws:
javassist.NotFoundException

createInvokeMethod

protected javassist.CtMethod createInvokeMethod(javassist.CtClass clazz)
                                         throws javassist.CannotCompileException
Creates generic invoke method to be wrapped by real signatures.

Throws:
javassist.CannotCompileException

forName

public javassist.CtClass forName(String name)
                          throws javassist.NotFoundException
Gets a class by its name.

Throws:
javassist.NotFoundException

forName

public javassist.CtClass forName(javassist.ClassPool pool,
                                 String name)
                          throws javassist.NotFoundException
Gets a class by its name.

Throws:
javassist.NotFoundException

addStaticField

protected javassist.CtField addStaticField(javassist.CtClass clazz,
                                           String name,
                                           String typeName,
                                           javassist.CtField.Initializer initializer)
                                    throws javassist.CannotCompileException,
                                           javassist.NotFoundException
Adds a static field to a class.

Throws:
javassist.CannotCompileException
javassist.NotFoundException

addProtectedField

protected javassist.CtField addProtectedField(javassist.CtClass clazz,
                                              String name,
                                              String typeName,
                                              javassist.CtField.Initializer initializer)
                                       throws javassist.CannotCompileException,
                                              javassist.NotFoundException
Adds a protected field to a class.

Throws:
javassist.CannotCompileException
javassist.NotFoundException

setupBasics

public void setupBasics(javassist.CtClass clazz)
                 throws javassist.CannotCompileException,
                        javassist.NotFoundException
Throws:
javassist.CannotCompileException
javassist.NotFoundException

interceptorChainsUpdated

public void interceptorChainsUpdated(Collection<JoinpointStatusUpdate> joinpointUpdates,
                                     HotSwapper hotSwapper)
Notifies the Instrumentor that some joinpoint status were updated. This method hot swaps the code of afected classes.

Parameters:
joinpointUpdates - a collection of org.jboss.aop.instrument.JoinpointStatusUpdate.
hotSwapper - object capable of hot swapping classes.

addSyntheticAttribute

public static void addSyntheticAttribute(javassist.CtMethod method)

addSyntheticAttribute

public static void addSyntheticAttribute(javassist.bytecode.MethodInfo info)

addSyntheticAttribute

public static void addSyntheticAttribute(javassist.CtConstructor ctor)

addSyntheticAttribute

public static void addSyntheticAttribute(javassist.CtField field)

convertProcessedClasses

public void convertProcessedClasses(HotSwapper hotSwapper,
                                    javassist.CtClass clazz,
                                    Collection<javassist.CtField> fieldReads,
                                    Collection<javassist.CtField> fieldWrites,
                                    boolean constructor)
Converts all processed classes to make wrapping of the appropriate joinpoints. This method must be called if some dynamic transformation ocurred (i. e. a class has just been loaded and one or more of its joinpoints were wrapped due only to bindings added dynamicaly; in this case, the previously loaded classes may not call the wrappers of this joinpoints, and need to be instrumented).

Parameters:
hotSwapper - responsible for performing any hot swapping operations when needed.
clazz - the clazz whose transformation involved dynamic wrapping.
fieldReads - collection of fields whose read joinpoit was dynamicaly wrapped.
fieldWrites - collection of fields whose read joinpoit was dynamicaly wrapped.
constructor - true if the clazz constructors were dynamicaly wrapped.

doSetupBasics

protected abstract void doSetupBasics(javassist.CtClass clazz)
                               throws javassist.CannotCompileException,
                                      javassist.NotFoundException
Throws:
javassist.CannotCompileException
javassist.NotFoundException

createMixinInvokeMethod

protected abstract javassist.CtMethod createMixinInvokeMethod(javassist.CtClass clazz,
                                                              javassist.CtClass mixinClass,
                                                              String initializer,
                                                              javassist.CtMethod method,
                                                              long hash)
                                                       throws javassist.CannotCompileException,
                                                              javassist.NotFoundException,
                                                              Exception
Creates generic invoke method to be wrapped by real signatures.

Throws:
javassist.CannotCompileException
javassist.NotFoundException
Exception


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