|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.rice.cs.cunit.threadCheck.ThreadCheck
public class ThreadCheck
Class that checks whether threads may execute certain classes at runtime..
Nested Class Summary | |
---|---|
static class |
ThreadCheck.ArgumentPredicateViolation
|
static class |
ThreadCheck.ExceptionInArgumentPredicateViolation
|
static class |
ThreadCheck.ExceptionInPredicateViolation
|
static class |
ThreadCheck.NotRunByIdViolation
|
static class |
ThreadCheck.NotRunByThreadGroupViolation
|
static class |
ThreadCheck.NotRunByThreadNameViolation
|
static class |
ThreadCheck.OnlyRunByViolation
|
static class |
ThreadCheck.PredicateViolation
|
static class |
ThreadCheck.ReflectionPredicateViolation
|
static class |
ThreadCheck.ThreadCheckAnnotationRecord
Storage class for predicate annotations. |
static class |
ThreadCheck.Violation
|
Field Summary | |
---|---|
private static java.util.Map<java.lang.Thread,java.util.HashSet<java.lang.String>> |
_allowedGroups
Map from thread to a list of allowed thread group names for the next call of checkCurrentThread_OnlyRunBy. |
private static java.util.Map<java.lang.Thread,java.util.HashSet<java.lang.Long>> |
_allowedIds
Map from thread to a list of allowed ids for the next call of checkCurrentThread_OnlyRunBy. |
private static java.util.Map<java.lang.Thread,java.util.HashSet<java.lang.String>> |
_allowedNames
Map from thread to a list of allowed thread names for the next call of checkCurrentThread_OnlyRunBy. |
private static java.util.Map<java.lang.Thread,java.lang.Boolean> |
_allowEventThread
Map from thread to a boolean indicating whether the event thread is allowed to run. |
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 | |
---|---|
ThreadCheck()
|
Method Summary | |
---|---|
static void |
addAllowedGroup_OnlyRunBy(java.lang.String allowed)
Add an allowed group name pattern to the list. |
static void |
addAllowedId_OnlyRunBy(long allowed)
Add an allowed id to the list. |
static void |
addAllowedName_OnlyRunBy(java.lang.String allowed)
Add an allowed thread name pattern to the list. |
static java.lang.Boolean |
checkCombineAnnotation(java.lang.annotation.Annotation ann,
Combine co,
java.lang.Object thisO,
java.lang.Object[] methodArgs)
Handle a @Combine-style annotation. |
static void |
checkCurrentThread_OnlyRunBy()
Check if the current thread's name, id or, or group matches any of items in the three _allowed* lists, and if that is NOT the case, records a warning. |
static void |
checkCurrentThread_Predicate(boolean predicateResult,
java.lang.String predicateClass)
Check if a predicate has failed, and if so, log a violation. |
static void |
checkCurrentThread_Predicate(java.lang.Object[] args,
boolean predicateResult,
java.lang.String predicateClass)
Check if a predicate has failed, and if so, log a violation. |
static void |
checkCurrentThread_PredicateException(java.lang.Throwable t,
java.lang.Object[] args,
java.lang.String predicateClass)
Log an exception in a predicate. |
static void |
checkCurrentThread_PredicateException(java.lang.Throwable t,
java.lang.String predicateClass)
Log an exception in a predicate. |
static void |
checkCurrentThreadGroup(java.lang.String threadGroupName)
Check if the current thread matches the regex for the thread group name, and if this is true, records a warning. |
static void |
checkCurrentThreadId(long threadId)
Check if the current thread matches the thread ID, and if this is true, records a warning. |
static void |
checkCurrentThreadName(java.lang.String threadName)
Check if the current thread matches the regex for the thread name, and if that is the case, records a warning. |
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(java.lang.Class cf,
java.lang.reflect.Method mi,
java.lang.Class scf,
ThreadCheck.ThreadCheckAnnotationRecord classAR,
ThreadCheck.ThreadCheckAnnotationRecord superClassAR)
Check for subtyping warnings. |
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 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 ThreadCheck.ThreadCheckAnnotationRecord |
getClassAnnotations(java.lang.Class cf)
Get the annotations for the specified class file. |
static ThreadCheck.ThreadCheckAnnotationRecord |
getMethodAnnotations(java.lang.Class cf,
java.lang.reflect.Method mi)
Get the annotations for the specified method in the specified class file. |
static java.lang.String |
getMethodDescriptor(java.lang.reflect.Method m)
Return the method descriptor for the method. |
static java.lang.reflect.Method |
getMethodWithNameAndDescriptor(java.lang.Class methodClass,
java.lang.String methodName,
java.lang.String methodDesc)
Return the method with the specified name and descriptor. |
static ThreadCheck.ThreadCheckAnnotationRecord |
getPredicateSets(java.lang.annotation.Annotation[] annotations)
Get the predicate sets from the array of annotations. |
private static void |
initLog()
Initialize the error log. |
private static java.lang.Boolean |
processCombineMember(java.lang.annotation.Annotation member,
PredicateLink memberPL,
Combine memberCO,
java.lang.Object thisO,
java.lang.Object[] methodArgs)
Process the value of a member annotation in a @Combine-style annotation. |
static void |
setAllowedEventThread_OnlyRunBy(boolean realized)
Allow the event thread at the next call of checkCurrentThread_OnlyRunBy. |
static void |
writeLog(ThreadCheck.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 |
---|
public static final java.lang.String LOG_FILENAME_PROPERTY
public static final java.lang.String DEFAULT_LOG_FILENAME
public static final java.lang.String DEFAULT_DAT_SUFFIX
private static volatile java.util.HashSet<java.lang.Thread> _inCheckCode
private static volatile java.io.PrintWriter _log
private static volatile java.io.ObjectOutputStream _logData
private static volatile long _checkCount
private static volatile long _violationCount
private static volatile java.util.Map<java.lang.Thread,java.util.HashSet<java.lang.String>> _allowedNames
private static volatile java.util.Map<java.lang.Thread,java.util.HashSet<java.lang.Long>> _allowedIds
private static volatile java.util.Map<java.lang.Thread,java.util.HashSet<java.lang.String>> _allowedGroups
private static volatile java.util.Map<java.lang.Thread,java.lang.Boolean> _allowEventThread
Constructor Detail |
---|
public ThreadCheck()
Method Detail |
---|
public static void checkCurrentThreadName(java.lang.String threadName)
threadName
- regex of a thread name that the current thread's name may NOT matchpublic static void checkCurrentThreadId(long threadId)
threadId
- ID number that the current thread's ID may not matchpublic static void checkCurrentThreadGroup(java.lang.String threadGroupName)
threadGroupName
- regex of a thread group name that the current thread's group name may NOT matchpublic static void writeLog(ThreadCheck.Violation v)
v
- violation to logprivate static void initLog()
public static void addAllowedName_OnlyRunBy(java.lang.String allowed)
allowed
- regex that is allowedpublic static void addAllowedId_OnlyRunBy(long allowed)
allowed
- id that is allowedpublic static void addAllowedGroup_OnlyRunBy(java.lang.String allowed)
allowed
- regex that is allowedpublic static void setAllowedEventThread_OnlyRunBy(boolean realized)
realized
- true if the component has been realized (or if the check should always be performed)public static void checkCurrentThread_OnlyRunBy()
public static void checkCurrentThread_Predicate(boolean predicateResult, java.lang.String predicateClass)
predicateResult
- result of the call to the predicate methodpredicateClass
- name of the predicate (name of the annotation)public static void checkCurrentThread_Predicate(java.lang.Object[] args, boolean predicateResult, java.lang.String predicateClass)
args
- method argumentspredicateResult
- result of the call to the predicate methodpredicateClass
- name of the predicate (name of the annotation)public static void checkCurrentThread_PredicateException(java.lang.Throwable t, java.lang.String predicateClass)
t
- exception thrownpredicateClass
- name of the predicate (name of the annotation)public static void checkCurrentThread_PredicateException(java.lang.Throwable t, java.lang.Object[] args, java.lang.String predicateClass)
t
- exception thrownargs
- method argumentspredicateClass
- name of the predicate (name of the annotation)public static void checkCurrentThreadReflection(java.lang.Class callerClass, java.lang.String methodName, java.lang.String methodDesc, java.lang.Object thisO, java.lang.Object[] methodArgs)
callerClass
- class of the callermethodName
- name of the methodmethodDesc
- descriptor of the methodthisO
- value of this, or null in a static contextmethodArgs
- array of method arguments, or null if none passedpublic static java.lang.Boolean checkPredicateLinkAnnotation(java.lang.annotation.Annotation ann, PredicateLink pl, java.lang.Object thisO, java.lang.Object[] methodArgs)
ann
- annotationpl
- associated @PredicateLinkthisO
- value of this, or null
public static java.lang.Boolean checkCombineAnnotation(java.lang.annotation.Annotation ann, Combine co, java.lang.Object thisO, java.lang.Object[] methodArgs)
ann
- annotationco
- associated @CombinethisO
- value of this, or nullmethodArgs
- array of method arguments, or null if none passed
private static java.lang.Boolean processCombineMember(java.lang.annotation.Annotation member, PredicateLink memberPL, Combine memberCO, java.lang.Object thisO, java.lang.Object[] methodArgs)
member
- member annotationmemberPL
- @PredicateLink meta-annotation associated with this membermemberCO
- @Combine meta-annotation associated with this memberthisO
- value of thismethodArgs
- array of method arguments, or null if none passed
public static java.lang.reflect.Method getMethodWithNameAndDescriptor(java.lang.Class methodClass, java.lang.String methodName, java.lang.String methodDesc)
methodClass
- classmethodName
- namemethodDesc
- descriptor
public static java.lang.String getMethodDescriptor(java.lang.reflect.Method m)
m
- method
public static java.lang.String form(java.lang.String word, long count)
word
- wordcount
- count
public static ThreadCheck.ThreadCheckAnnotationRecord getMethodAnnotations(java.lang.Class cf, java.lang.reflect.Method mi)
cf
- class filemi
- method information
public static ThreadCheck.ThreadCheckAnnotationRecord getClassAnnotations(java.lang.Class cf)
cf
- class file
public static ThreadCheck.ThreadCheckAnnotationRecord getPredicateSets(java.lang.annotation.Annotation[] annotations)
annotations
- array of annotations
public static void checkForSubtypingClassWarnings(java.lang.Class cf, java.lang.reflect.Method mi, java.lang.Class scf, ThreadCheck.ThreadCheckAnnotationRecord classAR, ThreadCheck.ThreadCheckAnnotationRecord superClassAR)
cf
- class filemi
- method information, or null if on class levelscf
- superclass/interface class fileclassAR
- subclass annotationssuperClassAR
- superclass annotations
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |