edu.rice.cs.cunit.threadCheck.subAnnot
Class SubAnnotThreadCheck

java.lang.Object
  extended by edu.rice.cs.cunit.threadCheck.subAnnot.SubAnnotThreadCheck

public class SubAnnotThreadCheck
extends java.lang.Object

Class that checks whether threads may execute certain classes at runtime.

Author:
Mathias Ricken

Nested Class Summary
static class SubAnnotThreadCheck.PredicateViolation
           
static class SubAnnotThreadCheck.ReflectionPredicateViolation
           
static class SubAnnotThreadCheck.ThreadCheckAnnotationRecord
          Storage class for predicate annotations.
static class SubAnnotThreadCheck.Violation
           
 
Field Summary
private static long _checkCount
          Number of checks performed.
private static java.util.HashSet<java.lang.Thread> _inCheckCode
          True if the code currently executing is due to thread checking; used to avoid infinite recursions.
private static java.io.PrintWriter _log
          PrintWriter with the warning log.
private static java.io.ObjectOutputStream _logData
          ObjectOutputStream with the warning log as data.
private static long _violationCount
          Number of violationms found.
static java.lang.String DEFAULT_DAT_SUFFIX
          Default filename for the data log, if none specified by Java property.
static java.lang.String DEFAULT_LOG_FILENAME
          Default filename for the log, if none specified by Java property.
static java.lang.String LOG_FILENAME_PROPERTY
          Name of the Java property that determines the log filename.
 
Constructor Summary
SubAnnotThreadCheck()
           
 
Method Summary
static void checkCurrentThreadReflection(java.lang.Class callerClass, java.lang.String methodName, java.lang.String methodDesc, java.lang.Object thisO, java.lang.Object[] methodArgs)
          Checks if the current thread may execute the method from where this method was called purely using reflection.
static void checkForSubtypingClassWarnings(ClassEx cf, MethodEx mi, ClassEx scf, SubAnnotThreadCheck.ThreadCheckAnnotationRecord classAR, SubAnnotThreadCheck.ThreadCheckAnnotationRecord superClassAR)
          Check for subtyping warnings.
static boolean checkInvariantAnnotation(InvariantAnnotation value, java.lang.Object thisObject, java.lang.Object[] methodArgs)
          Convenience method to get the result of an invariant annotation check.
static java.lang.Boolean checkPredicateLinkAnnotation(java.lang.annotation.Annotation ann, PredicateLink pl, java.lang.Object thisO, java.lang.Object[] methodArgs)
          Handle a @PredicateLink-style annotation.
static void flushLog()
          Flush the log.
static java.lang.String form(java.lang.String word, long count)
          Return the correct form, singular or plural, of the word, depending on the count.
static SubAnnotThreadCheck.ThreadCheckAnnotationRecord getClassAnnotations(ClassEx cf)
          Get the annotations for the specified class file.
static SubAnnotThreadCheck.ThreadCheckAnnotationRecord getMethodAnnotations(ClassEx cf, MethodEx mi)
          Get the annotations for the specified method in the specified class file.
static java.lang.String getMethodDescriptor(MethodEx m)
          Return the method descriptor for the method.
static MethodEx getMethodWithNameAndDescriptor(ClassEx methodClass, java.lang.String methodName, java.lang.String methodDesc)
          Return the method with the specified name and descriptor.
static SubAnnotThreadCheck.ThreadCheckAnnotationRecord getPredicateSets(java.lang.annotation.Annotation[] annotations)
          Get the predicate sets from the array of annotations.
static void initLog()
          Initialize the error log.
static void log(java.lang.String s)
          Log to the log file.
static void writeLog(SubAnnotThreadCheck.Violation v)
          Write to the error log, and potentially initialize it first.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG_FILENAME_PROPERTY

public static final java.lang.String LOG_FILENAME_PROPERTY
Name of the Java property that determines the log filename.

See Also:
Constant Field Values

DEFAULT_LOG_FILENAME

public static final java.lang.String DEFAULT_LOG_FILENAME
Default filename for the log, if none specified by Java property.

See Also:
Constant Field Values

DEFAULT_DAT_SUFFIX

public static final java.lang.String DEFAULT_DAT_SUFFIX
Default filename for the data log, if none specified by Java property.

See Also:
Constant Field Values

_inCheckCode

private static volatile java.util.HashSet<java.lang.Thread> _inCheckCode
True if the code currently executing is due to thread checking; used to avoid infinite recursions.


_log

private static volatile java.io.PrintWriter _log
PrintWriter with the warning log.


_logData

private static volatile java.io.ObjectOutputStream _logData
ObjectOutputStream with the warning log as data.


_checkCount

private static volatile long _checkCount
Number of checks performed.


_violationCount

private static volatile long _violationCount
Number of violationms found.

Constructor Detail

SubAnnotThreadCheck

public SubAnnotThreadCheck()
Method Detail

writeLog

public static void writeLog(SubAnnotThreadCheck.Violation v)
Write to the error log, and potentially initialize it first.

Parameters:
v - violation to log

initLog

public static void initLog()
Initialize the error log.


log

public static void log(java.lang.String s)
Log to the log file.

Parameters:
s - string

flushLog

public static void flushLog()
Flush the log.


checkCurrentThreadReflection

public static void checkCurrentThreadReflection(java.lang.Class callerClass,
                                                java.lang.String methodName,
                                                java.lang.String methodDesc,
                                                java.lang.Object thisO,
                                                java.lang.Object[] methodArgs)
Checks if the current thread may execute the method from where this method was called purely using reflection. If it may not execute, a violation is logged.

Parameters:
callerClass - class of the caller
methodName - name of the method
methodDesc - descriptor of the method
thisO - value of this, or null in a static context
methodArgs - array of method arguments, or null if none passed

checkInvariantAnnotation

public static boolean checkInvariantAnnotation(InvariantAnnotation value,
                                               java.lang.Object thisObject,
                                               java.lang.Object[] methodArgs)
Convenience method to get the result of an invariant annotation check.

Parameters:
value - the invariant annotation
thisObject - value of this, or null if static
methodArgs - array of method arguments
Returns:
true if check succeeded

checkPredicateLinkAnnotation

public static java.lang.Boolean checkPredicateLinkAnnotation(java.lang.annotation.Annotation ann,
                                                             PredicateLink pl,
                                                             java.lang.Object thisO,
                                                             java.lang.Object[] methodArgs)
Handle a @PredicateLink-style annotation.

Parameters:
ann - annotation
pl - associated @PredicateLink
thisO - value of this, or null
Returns:
false if there was a violation, or null if there was an error

getMethodWithNameAndDescriptor

public static MethodEx getMethodWithNameAndDescriptor(ClassEx methodClass,
                                                      java.lang.String methodName,
                                                      java.lang.String methodDesc)
Return the method with the specified name and descriptor.

Parameters:
methodClass - class
methodName - name
methodDesc - descriptor
Returns:
method, or null

getMethodDescriptor

public static java.lang.String getMethodDescriptor(MethodEx m)
Return the method descriptor for the method.

Parameters:
m - method
Returns:
descriptor

form

public static java.lang.String form(java.lang.String word,
                                    long count)
Return the correct form, singular or plural, of the word, depending on the count.

Parameters:
word - word
count - count
Returns:
word+"s" if count!=1, or word if count==1

getMethodAnnotations

public static SubAnnotThreadCheck.ThreadCheckAnnotationRecord getMethodAnnotations(ClassEx cf,
                                                                                   MethodEx mi)
Get the annotations for the specified method in the specified class file.

Parameters:
cf - class file
mi - method information
Returns:
annotations

getClassAnnotations

public static SubAnnotThreadCheck.ThreadCheckAnnotationRecord getClassAnnotations(ClassEx cf)
Get the annotations for the specified class file.

Parameters:
cf - class file
Returns:
annotations

getPredicateSets

public static SubAnnotThreadCheck.ThreadCheckAnnotationRecord getPredicateSets(java.lang.annotation.Annotation[] annotations)
Get the predicate sets from the array of annotations.

Parameters:
annotations - array of annotations
Returns:
annotation record.

checkForSubtypingClassWarnings

public static void checkForSubtypingClassWarnings(ClassEx cf,
                                                  MethodEx mi,
                                                  ClassEx scf,
                                                  SubAnnotThreadCheck.ThreadCheckAnnotationRecord classAR,
                                                  SubAnnotThreadCheck.ThreadCheckAnnotationRecord superClassAR)
Check for subtyping warnings.

Parameters:
cf - class file
mi - method information, or null if on class level
scf - superclass/interface class file
classAR - subclass annotations
superClassAR - superclass annotations