edu.rice.cs.cunit.instrumentors.threadCheck
Class AThreadCheckStrategy

java.lang.Object
  extended by edu.rice.cs.cunit.instrumentors.threadCheck.AThreadCheckStrategy
All Implemented Interfaces:
IInstrumentationStrategy
Direct Known Subclasses:
AAddThreadCheckStrategy

public abstract class AThreadCheckStrategy
extends java.lang.Object
implements IInstrumentationStrategy

Abstract instrumentor with core routines.

Author:
Mathias Ricken

Nested Class Summary
static class AThreadCheckStrategy.SharedData
          Data shared among all AAddThreadCheckStrategy instances.
 
Field Summary
(package private)  AThreadCheckStrategy.SharedData _sharedData
          Data shared among all AThreadCheckStrategy instances.
static java.lang.String CLASS_PATH_PARAM_PREFIX
          Prefix for the parameter that determines the paths to consider when searching.
static java.lang.String CLASS_SIG_SEPARATOR_STRING
          The separator string between class name and method signature.
static java.lang.String DEFAULT_XML_CONC_DEF_PATH_PREFIX
          Default XML path prefix before for concurrency definitions.
static java.lang.String DEFAULT_XML_PATH_PREFIX
          Default XML path prefix before the class name.
static java.lang.String UPDATE_PARAM_ORDER_PREFIX
          Prefix for the parameter that specifies whether the method attribute of a @PredicateLink annotation gets updated to include the order of the parameters.
static java.lang.String XML_ANNOT_FORMAT_PARAM
          The parameter that determines that the XML file will be written out using concurrency definitions, i.e.
static java.lang.String XML_ANNOT_PARAM_PREFIX
          Prefix for the parameter that determines the XML file that contains additional annotations.
 
Constructor Summary
AThreadCheckStrategy(java.util.List<java.lang.String> parameters, AThreadCheckStrategy.SharedData shared)
          Constructor for this strategy.
 
Method Summary
protected  void checkCombineMembers(ClassFile annotCF, boolean passMethods)
          Check that the members of the annotation class file are all Thread Checker annotations or arrays thereof.
protected  void checkPredicateMembers(ClassFile annotCF, boolean passMethods)
          Check that the members of the annotation class do not contain annotations or arrays of annotations
protected  boolean checkPublicStaticIfNestedClass(ClassFile predicateCF, ClassFile cf)
          Check that the class file, should it be a nested class and not a top-level class, is public static, and the same applies to all its enclosing classes.
 void done()
          Instrumentation of all classes is done.
protected  void extractAnnotationArray(AAnnotationsAttributeInfo.Annotation.AMemberValue mv, java.util.HashSet<java.lang.String> threadNames, java.util.HashSet<java.lang.Long> threadIds, java.util.HashSet<java.lang.String> threadGroups, Ref<OnlyRunBy.EVENT_THREAD> eventThread)
          Extract the data in the annotation's string array and put it in the set of strings.
protected  void extractLists(java.lang.String typeName, java.util.ArrayList<AAttributeInfo> attributesList, java.util.HashSet<java.lang.String> threadNames, java.util.HashSet<java.lang.Long> threadIds, java.util.HashSet<java.lang.String> threadGroups, Ref<OnlyRunBy.EVENT_THREAD> eventThread)
          Extract the lists of thread names, ids and groups from a list of attributes.
protected  void extractLongArray(AAnnotationsAttributeInfo.Annotation.AMemberValue mv, java.util.HashSet<java.lang.Long> set)
          Extract the data in the annotation's long array and put it in the set of longs.
protected  void extractPredicateSet(java.util.ArrayList<AAttributeInfo> attributesList, java.util.ArrayList<PredicateAnnotationRecord> predicateSet, java.lang.String methodSig)
          Extract the list of predicate annotation records.
protected  void extractStringArray(AAnnotationsAttributeInfo.Annotation.AMemberValue mv, java.util.HashSet<java.lang.String> set)
          Extract the data in the annotation's string array and put it in the set of strings.
protected  boolean getAnnotationClassFile(java.lang.String annotType, Ref<ClassFileTools.ClassLocation> refCL, Ref<AAnnotationsAttributeInfo.Annotation> predicateLink, Ref<AAnnotationsAttributeInfo.Annotation> combineAnnot)
          Return the annotations class file, or null if it is not a Thread Checker annotation.
protected  AAnnotationsAttributeInfo.Annotation getCombineMode(java.util.ArrayList<AAttributeInfo> attributesList)
          Return the combine attribute, or null if not found
protected  PredicateAnnotationRecord getPredicateAnnotationRecord(AAnnotationsAttributeInfo.Annotation annot, ClassFileTools.ClassLocation annotCL, ClassFile predicateCF, java.lang.String predicateMethod, Combine.Mode combineMode, boolean passArguments)
          Return the method info for the predicate method, or null if not found.
protected  AAnnotationsAttributeInfo.Annotation getPredicateLink(java.util.ArrayList<AAttributeInfo> attributesList)
          Return the predicate link, or null if not found
protected  void includePredicateMethodParameterOrder(java.lang.String predicateMethod, java.util.ArrayList<java.lang.String> paramNames, ClassFileTools.ClassLocation annotCL)
          Update the method attribute in the @PredicateLink to include the parameter order.
protected  PredicateAnnotationRecord processAnnotation(AAnnotationsAttributeInfo.Annotation annot)
          Process the specified annotation and return a PredicateAnnotationRecord if the annotation is a Thread Checker predicate annotation, or null otherwise.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface edu.rice.cs.cunit.instrumentors.IInstrumentationStrategy
instrument
 

Field Detail

CLASS_PATH_PARAM_PREFIX

public static final java.lang.String CLASS_PATH_PARAM_PREFIX
Prefix for the parameter that determines the paths to consider when searching. This is a prefix to a list of paths separated by the "path.separator" property. If this parameter isn't specified, then the "java.class.path" and the default rt.jar file (as determined by TCFileInstrumentor.getDefaultSourceRtJarName) will be used as class path.

See Also:
Constant Field Values

DEFAULT_XML_PATH_PREFIX

public static final java.lang.String DEFAULT_XML_PATH_PREFIX
Default XML path prefix before the class name.

See Also:
Constant Field Values

DEFAULT_XML_CONC_DEF_PATH_PREFIX

public static final java.lang.String DEFAULT_XML_CONC_DEF_PATH_PREFIX
Default XML path prefix before for concurrency definitions.

See Also:
Constant Field Values

XML_ANNOT_PARAM_PREFIX

public static final java.lang.String XML_ANNOT_PARAM_PREFIX
Prefix for the parameter that determines the XML file that contains additional annotations. If this parameter is not specified, then no additional file will be used.

See Also:
Constant Field Values

XML_ANNOT_FORMAT_PARAM

public static final java.lang.String XML_ANNOT_FORMAT_PARAM
The parameter that determines that the XML file will be written out using concurrency definitions, i.e. using nodes. If this parameter is not specified, then will be used.

See Also:
Constant Field Values

UPDATE_PARAM_ORDER_PREFIX

public static final java.lang.String UPDATE_PARAM_ORDER_PREFIX
Prefix for the parameter that specifies whether the method attribute of a @PredicateLink annotation gets updated to include the order of the parameters. The default is true. This process changes the value of the method attribute from the form "methodName" to the form "methodName(param1,param2,param3)".

See Also:
Constant Field Values

CLASS_SIG_SEPARATOR_STRING

public static final java.lang.String CLASS_SIG_SEPARATOR_STRING
The separator string between class name and method signature.

See Also:
Constant Field Values

_sharedData

AThreadCheckStrategy.SharedData _sharedData
Data shared among all AThreadCheckStrategy instances.

Constructor Detail

AThreadCheckStrategy

public AThreadCheckStrategy(java.util.List<java.lang.String> parameters,
                            AThreadCheckStrategy.SharedData shared)
Constructor for this strategy.

Parameters:
parameters - parameters for the instrumentors
shared - data shared among all AThreadCheckStrategy instances
Method Detail

extractLists

protected void extractLists(java.lang.String typeName,
                            java.util.ArrayList<AAttributeInfo> attributesList,
                            java.util.HashSet<java.lang.String> threadNames,
                            java.util.HashSet<java.lang.Long> threadIds,
                            java.util.HashSet<java.lang.String> threadGroups,
                            Ref<OnlyRunBy.EVENT_THREAD> eventThread)
Extract the lists of thread names, ids and groups from a list of attributes.

Parameters:
typeName - name of the annotation type
attributesList - list of attributes
threadNames - the set of thread names to fill
threadIds - the set of thread ids to fill
threadGroups - the set of thread groups to fill
eventThread - mutable flag for checking the event thread

extractAnnotationArray

protected void extractAnnotationArray(AAnnotationsAttributeInfo.Annotation.AMemberValue mv,
                                      java.util.HashSet<java.lang.String> threadNames,
                                      java.util.HashSet<java.lang.Long> threadIds,
                                      java.util.HashSet<java.lang.String> threadGroups,
                                      Ref<OnlyRunBy.EVENT_THREAD> eventThread)
Extract the data in the annotation's string array and put it in the set of strings.

Parameters:
mv - member value, i.e. the string array
threadNames - the set of thread names to fill
threadIds - the set of thread ids to fill
threadGroups - the set of thread groups to fill
eventThread - mutable flag for checking the event thread

extractStringArray

protected void extractStringArray(AAnnotationsAttributeInfo.Annotation.AMemberValue mv,
                                  java.util.HashSet<java.lang.String> set)
Extract the data in the annotation's string array and put it in the set of strings.

Parameters:
mv - member value, i.e. the string array
set - set to contain the strings

extractLongArray

protected void extractLongArray(AAnnotationsAttributeInfo.Annotation.AMemberValue mv,
                                java.util.HashSet<java.lang.Long> set)
Extract the data in the annotation's long array and put it in the set of longs.

Parameters:
mv - member value, i.e. the long array
set - set to contain the longs

extractPredicateSet

protected void extractPredicateSet(java.util.ArrayList<AAttributeInfo> attributesList,
                                   java.util.ArrayList<PredicateAnnotationRecord> predicateSet,
                                   java.lang.String methodSig)
Extract the list of predicate annotation records.

Parameters:
attributesList - list of attributes
predicateSet - list of predicate annotation records to create
methodSig - method signature

getPredicateLink

protected AAnnotationsAttributeInfo.Annotation getPredicateLink(java.util.ArrayList<AAttributeInfo> attributesList)
Return the predicate link, or null if not found

Parameters:
attributesList - list of attributes
Returns:
predicate link annotation

getCombineMode

protected AAnnotationsAttributeInfo.Annotation getCombineMode(java.util.ArrayList<AAttributeInfo> attributesList)
Return the combine attribute, or null if not found

Parameters:
attributesList - list of attributes
Returns:
combine annotation

processAnnotation

protected PredicateAnnotationRecord processAnnotation(AAnnotationsAttributeInfo.Annotation annot)
Process the specified annotation and return a PredicateAnnotationRecord if the annotation is a Thread Checker predicate annotation, or null otherwise.

Parameters:
annot - annotation to process
Returns:
PredicateAnnotationRecord, or null if the annotation is not a Thread Checker predicate annotation

getAnnotationClassFile

protected boolean getAnnotationClassFile(java.lang.String annotType,
                                         Ref<ClassFileTools.ClassLocation> refCL,
                                         Ref<AAnnotationsAttributeInfo.Annotation> predicateLink,
                                         Ref<AAnnotationsAttributeInfo.Annotation> combineAnnot)
Return the annotations class file, or null if it is not a Thread Checker annotation.

Parameters:
annotType - class name of the annotation, in the form "Ljava/lang/Object;"
refCL - reference to the class file; will get filled in by this method
predicateLink - reference to the predicate link; will get filled in by this method
combineAnnot - reference to the combine annotation; will get filled in by this method
Returns:
true if this is an annotation for the Thread Checker

getPredicateAnnotationRecord

protected PredicateAnnotationRecord getPredicateAnnotationRecord(AAnnotationsAttributeInfo.Annotation annot,
                                                                 ClassFileTools.ClassLocation annotCL,
                                                                 ClassFile predicateCF,
                                                                 java.lang.String predicateMethod,
                                                                 Combine.Mode combineMode,
                                                                 boolean passArguments)
Return the method info for the predicate method, or null if not found.

Parameters:
annot - the annotation linked to the predicate
annotCL - class file location for the annotation linked to the predicate
predicateCF - class file for the class containing the predicate method, or null if not specified
predicateMethod - name of the predicate method
combineMode - mode to combine results from several predicates
passArguments - whether method arguments should be passed as well
Returns:
method info for the predicate method

checkPublicStaticIfNestedClass

protected boolean checkPublicStaticIfNestedClass(ClassFile predicateCF,
                                                 ClassFile cf)
Check that the class file, should it be a nested class and not a top-level class, is public static, and the same applies to all its enclosing classes. If this is not the case, a BadPredicateAnnotationWarning is added and false is returned. This check is performed by examining the InnerClasses attribute.

Parameters:
predicateCF - original predicate class file for which this check is performed; does not change in recursion
cf - class file to check
Returns:
false if the class is a nested class and not accessible from everywhere
Throws:
BadPredicateAnnotationWarning

checkCombineMembers

protected void checkCombineMembers(ClassFile annotCF,
                                   boolean passMethods)
Check that the members of the annotation class file are all Thread Checker annotations or arrays thereof.

Parameters:
annotCF - annotation class file

checkPredicateMembers

protected void checkPredicateMembers(ClassFile annotCF,
                                     boolean passMethods)
Check that the members of the annotation class do not contain annotations or arrays of annotations

Parameters:
annotCF - annotation class file
passMethods - whether method arguments should be passed ass well

includePredicateMethodParameterOrder

protected void includePredicateMethodParameterOrder(java.lang.String predicateMethod,
                                                    java.util.ArrayList<java.lang.String> paramNames,
                                                    ClassFileTools.ClassLocation annotCL)
Update the method attribute in the @PredicateLink to include the parameter order.

Parameters:
predicateMethod - name of the predicate method
paramNames - order of the parameters, ignoring the first "Object thisO" parameter
annotCL - class file location of the annotation

done

public void done()
Instrumentation of all classes is done.

Specified by:
done in interface IInstrumentationStrategy