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

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

public class AddPredicateThreadCheckStrategy
extends AAddThreadCheckStrategy

Instrumentor to add calls to ThreadCheck.checkCurrentThreadName/Id/Group to check if the current thread is not allowed to execute a class or method.

This instrumentor checks for every method if there are @NotRunBy or @OnlyRunBy annotations attached to the method, the containing class, the same method in one of the superclasses or interfaces, or a superclass or interface, and then at the beginning of the method inserts calls to ThreadCheck..

Author:
Mathias Ricken

Nested Class Summary
 
Nested classes/interfaces inherited from class edu.rice.cs.cunit.instrumentors.threadCheck.AAddThreadCheckStrategy
AAddThreadCheckStrategy.CacheInfo, AAddThreadCheckStrategy.OnlyAfterRealizedWarning, AAddThreadCheckStrategy.SharedAddData
 
Nested classes/interfaces inherited from class edu.rice.cs.cunit.instrumentors.threadCheck.AThreadCheckStrategy
AThreadCheckStrategy.SharedData
 
Field Summary
protected  java.io.File _classOutputDir
          The output directory for the generated class files, corresponding to the default package.
protected  SoftHashMap<java.lang.String,PredicateAnnotationRecord> _generatedPredicateRecords
          Hash table from a fully-qualified class name of the @Combine-type annotation to the generated predicate annotation record.
protected  java.lang.String _predicatePackage
          The package for the generated class files, or null if none set (that is ok unless we have to auto-generate class files).
protected  java.io.File _predicatePackageDir
          The directory where the generated class files go, corresponding to the package in _predicatePackage, or null if none set (that is ok unless we have to auto-generate class files).
protected  ClassFile _templatePredicateClassFile
          The predicate class file which is cloned for the auto-generated predicates.
static java.lang.String PRED_OUT_DIR_PARAM_PREFIX
          Prefix for the parameter that determines the output directory of the generated class files.
static java.lang.String PRED_OUT_PACKAGE_PARAM_PREFIX
          Prefix for the parameter that determines the package of the generated class files.
 
Fields inherited from class edu.rice.cs.cunit.instrumentors.threadCheck.AAddThreadCheckStrategy
_sharedAddData, XML_ANNOT_SAVE_MERGED_PREFIX
 
Fields inherited from class edu.rice.cs.cunit.instrumentors.threadCheck.AThreadCheckStrategy
_sharedData, CLASS_PATH_PARAM_PREFIX, CLASS_SIG_SEPARATOR_STRING, DEFAULT_XML_CONC_DEF_PATH_PREFIX, DEFAULT_XML_PATH_PREFIX, UPDATE_PARAM_ORDER_PREFIX, XML_ANNOT_FORMAT_PARAM, XML_ANNOT_PARAM_PREFIX
 
Constructor Summary
AddPredicateThreadCheckStrategy(AThreadCheckStrategy.SharedData shared, AAddThreadCheckStrategy.SharedAddData sharedAdd)
          Constructor for this strategy.
AddPredicateThreadCheckStrategy(java.util.List<java.lang.String> parameters, AThreadCheckStrategy.SharedData shared, AAddThreadCheckStrategy.SharedAddData sharedAdd)
          Constructor for this strategy.
 
Method Summary
protected  PredicateAnnotationRecord generatePredicateAnnotationRecord(PredicateAnnotationRecord par, java.lang.String miDescriptor)
          Generate the predicate annotation record for the @Combine-type annotation that contains all information except for the valueList.
protected  PredicateAnnotationRecord getGeneratedPredicate(ClassFile cf, PredicateAnnotationRecord par, java.lang.String miDescriptor)
          Return a generated predicate annotation record for a @Combine-type annotation.
protected  java.lang.String getMethodName(PredicateAnnotationRecord par)
          Return the name of the predicate method for a @Combine-type annotation, taking annotation array sizes into account.
protected  void getMethodNameHelper(PredicateAnnotationRecord par, java.lang.StringBuilder sb, java.lang.String suffix)
          Return part of the method name.
protected  int insertPredicateCall(ClassFile cf, MethodInfo mi, InstructionList il, PredicateAnnotationRecord par)
          Insert a call to the predicate sp
 void instrument(ClassFile cf)
          Instrument the class.
private  int loadAndTransferMemberValue(AAnnotationsAttributeInfo.Annotation.AMemberValue value, java.lang.String paramType, ClassFile cf, MethodInfo mi, InstructionList il)
          Transfer the annotation member value to the class file.
private  void loadArguments(ClassFile cf, MethodInfo mi, InstructionList il)
           
protected  void performCombineTreeWalk(PredicateAnnotationRecord par, ILambda.Ternary<java.lang.Object,java.lang.String,java.lang.String,AAnnotationsAttributeInfo.Annotation.AMemberValue> lambda, java.lang.String suffix)
          Walk the tree of combined predicates and apply the lambda for each parameter name-parameter type-value triple.
protected  void transferAnnotation(AAnnotationsAttributeInfo.Annotation a, ClassFile cf, MethodInfo mi)
          Transfer the annotation to the class file.
 
Methods inherited from class edu.rice.cs.cunit.instrumentors.threadCheck.AAddThreadCheckStrategy
checkForSubtypingClassWarnings, checkXMLConcDef, done, extractMemberValue, extractXMLAnnotations, extractXMLConcDef, extractXMLConcDef, getClassAnnotations, getMethodAnnotations, insertCtorCall
 
Methods inherited from class edu.rice.cs.cunit.instrumentors.threadCheck.AThreadCheckStrategy
checkCombineMembers, checkPredicateMembers, checkPublicStaticIfNestedClass, extractAnnotationArray, extractLists, extractLongArray, extractPredicateSet, extractStringArray, getAnnotationClassFile, getCombineMode, getPredicateAnnotationRecord, getPredicateLink, includePredicateMethodParameterOrder, processAnnotation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_generatedPredicateRecords

protected SoftHashMap<java.lang.String,PredicateAnnotationRecord> _generatedPredicateRecords
Hash table from a fully-qualified class name of the @Combine-type annotation to the generated predicate annotation record. Only the PredicateAnnotationRecord.valueList has not been filled in.


_templatePredicateClassFile

protected ClassFile _templatePredicateClassFile
The predicate class file which is cloned for the auto-generated predicates.


PRED_OUT_DIR_PARAM_PREFIX

public static final java.lang.String PRED_OUT_DIR_PARAM_PREFIX
Prefix for the parameter that determines the output directory of the generated class files.

See Also:
Constant Field Values

_classOutputDir

protected java.io.File _classOutputDir
The output directory for the generated class files, corresponding to the default package.


_predicatePackageDir

protected java.io.File _predicatePackageDir
The directory where the generated class files go, corresponding to the package in _predicatePackage, or null if none set (that is ok unless we have to auto-generate class files).


PRED_OUT_PACKAGE_PARAM_PREFIX

public static final java.lang.String PRED_OUT_PACKAGE_PARAM_PREFIX
Prefix for the parameter that determines the package of the generated class files.

See Also:
Constant Field Values

_predicatePackage

protected java.lang.String _predicatePackage
The package for the generated class files, or null if none set (that is ok unless we have to auto-generate class files).

Constructor Detail

AddPredicateThreadCheckStrategy

public AddPredicateThreadCheckStrategy(AThreadCheckStrategy.SharedData shared,
                                       AAddThreadCheckStrategy.SharedAddData sharedAdd)
Constructor for this strategy.

Parameters:
shared - data shared among all AThreadCheckStrategy instances
sharedAdd - data for all AAddThreadCheckStrategy instances

AddPredicateThreadCheckStrategy

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

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

instrument

public void instrument(ClassFile cf)
Instrument the class.

Parameters:
cf - class file info

insertPredicateCall

protected int insertPredicateCall(ClassFile cf,
                                  MethodInfo mi,
                                  InstructionList il,
                                  PredicateAnnotationRecord par)
Insert a call to the predicate sp

Parameters:
cf - current class file
mi - current method information
il - instruction list
par - predicate annotation record describing the check to add
Returns:
stack usage

loadArguments

private void loadArguments(ClassFile cf,
                           MethodInfo mi,
                           InstructionList il)

loadAndTransferMemberValue

private int loadAndTransferMemberValue(AAnnotationsAttributeInfo.Annotation.AMemberValue value,
                                       java.lang.String paramType,
                                       ClassFile cf,
                                       MethodInfo mi,
                                       InstructionList il)
Transfer the annotation member value to the class file.

Parameters:
value - annotation pair value
paramType - parameter type, or null if that information is not available
cf - target class file
mi - method info
il - instruction list, or null if this is a member value to be loaded
Returns:
stack space required (2 for long and double, 1 otherwise)

transferAnnotation

protected void transferAnnotation(AAnnotationsAttributeInfo.Annotation a,
                                  ClassFile cf,
                                  MethodInfo mi)
Transfer the annotation to the class file.

Parameters:
a - annotation
cf - target class file
mi - method info

getGeneratedPredicate

protected PredicateAnnotationRecord getGeneratedPredicate(ClassFile cf,
                                                          PredicateAnnotationRecord par,
                                                          java.lang.String miDescriptor)
Return a generated predicate annotation record for a @Combine-type annotation.

Parameters:
cf - current class file
par - predicate annotation record describing the @Combine-type annotation
miDescriptor - method destrictor
Returns:
generated predicate annotation record that can be used like that of a @PredicateLink-type annotation

generatePredicateAnnotationRecord

protected PredicateAnnotationRecord generatePredicateAnnotationRecord(PredicateAnnotationRecord par,
                                                                      java.lang.String miDescriptor)
Generate the predicate annotation record for the @Combine-type annotation that contains all information except for the valueList.

Parameters:
par - predicate annotation record describing the @Combine-type annotation
miDescriptor - method destrictor
Returns:
predicate annotation record without valueList

performCombineTreeWalk

protected void performCombineTreeWalk(PredicateAnnotationRecord par,
                                      ILambda.Ternary<java.lang.Object,java.lang.String,java.lang.String,AAnnotationsAttributeInfo.Annotation.AMemberValue> lambda,
                                      java.lang.String suffix)
Walk the tree of combined predicates and apply the lambda for each parameter name-parameter type-value triple.

Parameters:
par - record describing the combined predicate annotation
lambda - lambda to apply to each parameter name-parameter type-value triple; return value is ignored
suffix - string suffix for variable names to distinguish them

getMethodName

protected java.lang.String getMethodName(PredicateAnnotationRecord par)
Return the name of the predicate method for a @Combine-type annotation, taking annotation array sizes into account. The method will start with the method name "check", perform a pre-order tree traversal, and for every annotation array found, it will append a string of the format "$value$member$$1$id$$$4", where "$value$$0$member$$1$id" represents the path of @Combine-type annotation members that have lead to this annotation array, with the last element being the name of the annotation array itself, and the number after the "$$$" represents the size of the array. If an annotation member on the path is an array, then the index of the array element chosen is represented after the array member name and "$$". In the example above, "$value$member$$1$id$$$4", the array "id" has size 4. It is contained in element 1 of the array "member", which is contained in the non-array member "value".

Parameters:
par - record describing the combined predicate annotation
Returns:
method name

getMethodNameHelper

protected void getMethodNameHelper(PredicateAnnotationRecord par,
                                   java.lang.StringBuilder sb,
                                   java.lang.String suffix)
Return part of the method name.

Parameters:
par - record describing the combined predicate annotation
sb - string builder accumulating the nethod name
suffix - string suffix for variable names to distinguish them