edu.rice.cs.cunit
Class SyncPointBuffer

java.lang.Object
  extended by edu.rice.cs.cunit.SyncPointBuffer

public class SyncPointBuffer
extends java.lang.Object

Class that records synchronization points. NOTE: This class may not be instrumented with a strategy affecting synchronized methods or blocks! Do not instrument with SynchronizedMethodToBlockStrategy, SynchronizedBlockStrategy, CompactSynchronizedBlockStrategy, CompactSynchronizedBlockDebugStrategy, or CompactSynchronizedBlockReplayStrategy.

Author:
Mathias Ricken

Nested Class Summary
static class SyncPointBuffer.SP
          Enumeration of sync point codes.
 
Field Summary
private static int _compactIndex
          Index to be used next for the compact array.
private static long[] _compactSyncPoints
          Compact array of synchronization points.
private static long[] _immediateTransfer
          Array for immediate transfer.
private static int _index
          Index to be used next.
static java.lang.String _message
          Message description.
private static java.lang.Object _newBufferWaitObj
          Object that threads can wait for if they need to wait for a new buffer.
static long _nextObjectID
          Next object ID to be assigned.
static long _nextThreadID
          Next thread ID to be assigned.
private static boolean _recording
          True if points should be recorded.
private static boolean _replayBufferLoaded
          True if the initial buffer for replay has been loaded.
private static int _replayIndex
          Index to be used next for the replay array.
private static boolean _replaying
          True if scheduled replay has begun.
private static long[] _replaySyncPoints
          Record array of synchronization points.
private static java.lang.Object[] _replayWaitArray
          Object array with objects that threads may wait for.
private static int _replayWaitIndex
          Index to be used next for the replay wait array.
static long _runningThreads
          Number of running threads.
private static ISyncPoint[] _syncPoints
          Array of synchronization points.
private static boolean _transferImmediately
          True if points should be recorded immediately.
private static java.lang.Object _waitAlgoObj
          Object that threads can wait for if they need to enter the algorithm.
static int COMPACT_DEBUG_RECORD_SIZE
          Size of a record in the compact array with debug info.
static int COMPACT_RECORD_SIZE
          Size of a record in the compact array.
static int COMPACT_SIZE
          Size of compact array.
static int RANDOM_DELAY_MAGNITUDE
          Length of time in milliseconds between the shorted and the longest delay.
static int RANDOM_DELAY_MIN
          Length of the shortest delay in milliseconds.
static boolean RANDOM_DELAY_POST_MONITOR
          Enable delay after monitorenter/exit?
static boolean RANDOM_DELAY_POST_NOTIFY
          Enable delay after notify?
static boolean RANDOM_DELAY_POST_WAIT
          Enable delay after wait?
static boolean RANDOM_DELAY_PRE_MONITOR
          Enable delay before monitorenter/exit??
static boolean RANDOM_DELAY_PRE_NOTIFY
          Enable delay before notify?
static boolean RANDOM_DELAY_PRE_WAIT
          Enable delay before wait?
static boolean RANDOM_DELAY_THREAD_EXIT
          Enable delay on thread exit?
static boolean RANDOM_DELAY_THREAD_JOIN
          Enable delay on thread join?
static boolean RANDOM_DELAY_THREAD_RUN
          Enable delay on thread run?
static boolean RANDOM_DELAY_THREAD_START
          Enable delay on thread start?
static boolean RANDOM_YIELD_POST_MONITOR
          Enable yield after monitorenter/exit?
static boolean RANDOM_YIELD_POST_NOTIFY
          Enable yield after notify?
static boolean RANDOM_YIELD_POST_WAIT
          Enable yield after wait?
static boolean RANDOM_YIELD_PRE_MONITOR
          Enable yield before monitorenter/exit??
static boolean RANDOM_YIELD_PRE_NOTIFY
          Enable yield before notify?
static boolean RANDOM_YIELD_PRE_WAIT
          Enable yield before wait?
static float RANDOM_YIELD_PROB
          Probability of a yield.
static boolean RANDOM_YIELD_THREAD_EXIT
          Enable yield on thread exit?
static boolean RANDOM_YIELD_THREAD_JOIN
          Enable yield on thread join?
static boolean RANDOM_YIELD_THREAD_RUN
          Enable yield on thread run?
static boolean RANDOM_YIELD_THREAD_START
          Enable yield on thread start?
static int REPLAY_SIZE
          Size of replay array.
static int SIZE
          Size of array.
 
Constructor Summary
SyncPointBuffer()
           
 
Method Summary
static java.lang.Class<?> _class()
          A method to retrieve the .class field; this is required for pre-1.5 compatibility where simple field access to the .class field is not allowed.
static void add(ISyncPoint sp)
          Adds a synchronization point to the list.
static void compactAdd(long code, long tid)
          Adds a synchronization point to the compact list.
static void compactDebugAdd(long oid, long code, long tid, long classIndex, long methodAndPC)
          Adds a synchronization point to the compact list.
static void compactImmediateTransfer()
          Transfer immediately and empty compact array.
static void compactThreadExit(long tid)
          Notify the wait algorithm that a thread has ended and check if the next thread has to be woken up.
static void compactThreadExit(long tid, long classIndex, long methodAndPC)
          Notify the wait algorithm that a thread has ended and check if the next thread has to be woken up.
static void compactTransfer()
          Transfer and empty compact array.
static void compactWait(long code, long tid)
          Wait for this synchronization point in the compact list.
static void compactWait(long code, long tid, long classIndex, long methodAndPC)
          Wait for this synchronization point in the compact list.
static void delayObjectWait(boolean delay)
          Throw an exception if no other thread is alive anymore, otherwise sleep for a while.
static void delayThreadExit(boolean delay)
          Sleep for a while if there is concurrency, and then decrement the number of running threads.
static void delayThreadStart(boolean delay)
          Increment the number of running thread, and then sleep for a while if there is concurrency.
static boolean isOldThread()
          Marker for getting the value of the $$$oldThread$$$ field.
static boolean isRecording()
          Accessor for the recording flag.
static void monitorEnter(java.lang.Object o)
          Marker for monitorenter instructions.
static void monitorExit(java.lang.Object o)
          Marker for monitorexit instructions.
static void randomDelay(boolean delay)
          Sleep for a random amount of time, up to RANDOM_DELAY_MAGNITUDE milliseconds, if there is concurrency.
static void randomYield(boolean yield)
          Yield if random number < RANDOM_YIELD_PROB, but only if there is concurrency.
static void replayTransfer()
          Transfer and and reset replay array.
static void setMessage(java.lang.String message)
          Notify the monitor application of a message.
static void setOldThread()
          Marker for setting $$$oldThread$$$ field.
static void setRecording(boolean recording)
          Mutator for the recording flag.
static void transfer()
          Transfer and empty array.
static void yieldObjectWait(boolean yield)
          Throw an exception if no other thread is alive anymore, otherwise do a random yield.
static void yieldThreadExit(boolean yield)
          Do a random yield, and then decrement the number of running threads.
static void yieldThreadStart(boolean yield)
          Increment the number of running thread, and then do a random yield.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SIZE

public static final int SIZE
Size of array.

See Also:
Constant Field Values

_syncPoints

private static volatile ISyncPoint[] _syncPoints
Array of synchronization points.


_index

private static volatile int _index
Index to be used next.


COMPACT_RECORD_SIZE

public static final int COMPACT_RECORD_SIZE
Size of a record in the compact array.

See Also:
Constant Field Values

COMPACT_DEBUG_RECORD_SIZE

public static final int COMPACT_DEBUG_RECORD_SIZE
Size of a record in the compact array with debug info.

See Also:
Constant Field Values

COMPACT_SIZE

public static final int COMPACT_SIZE
Size of compact array.

See Also:
Constant Field Values

_compactSyncPoints

private static volatile long[] _compactSyncPoints
Compact array of synchronization points.


_compactIndex

private static volatile int _compactIndex
Index to be used next for the compact array.


REPLAY_SIZE

public static final int REPLAY_SIZE
Size of replay array.

See Also:
Constant Field Values

_replaySyncPoints

private static volatile long[] _replaySyncPoints
Record array of synchronization points.


_replayWaitArray

private static volatile java.lang.Object[] _replayWaitArray
Object array with objects that threads may wait for.


_waitAlgoObj

private static final java.lang.Object _waitAlgoObj
Object that threads can wait for if they need to enter the algorithm.


_newBufferWaitObj

private static final java.lang.Object _newBufferWaitObj
Object that threads can wait for if they need to wait for a new buffer.


_replayIndex

private static volatile int _replayIndex
Index to be used next for the replay array.


_replayWaitIndex

private static volatile int _replayWaitIndex
Index to be used next for the replay wait array.


_recording

private static volatile boolean _recording
True if points should be recorded.


_transferImmediately

private static volatile boolean _transferImmediately
True if points should be recorded immediately.


_immediateTransfer

private static volatile long[] _immediateTransfer
Array for immediate transfer.


_replaying

private static volatile boolean _replaying
True if scheduled replay has begun.


_replayBufferLoaded

private static volatile boolean _replayBufferLoaded
True if the initial buffer for replay has been loaded. Since this starts out as false, the buffer will be loaded.


_nextObjectID

public static volatile long _nextObjectID
Next object ID to be assigned.


_nextThreadID

public static volatile long _nextThreadID
Next thread ID to be assigned.


_message

public static volatile java.lang.String _message
Message description.


_runningThreads

public static volatile long _runningThreads
Number of running threads.


RANDOM_DELAY_MIN

public static final int RANDOM_DELAY_MIN
Length of the shortest delay in milliseconds. RANDOM_DELAY_MIN <= t < (RANDOM_DELAY_MIN + RANDOM_DELAY_MAGNITUDE)

See Also:
Constant Field Values

RANDOM_DELAY_MAGNITUDE

public static final int RANDOM_DELAY_MAGNITUDE
Length of time in milliseconds between the shorted and the longest delay. RANDOM_DELAY_MIN <= t < (RANDOM_DELAY_MIN + RANDOM_DELAY_MAGNITUDE)

See Also:
Constant Field Values

RANDOM_DELAY_THREAD_START

public static boolean RANDOM_DELAY_THREAD_START
Enable delay on thread start?


RANDOM_DELAY_THREAD_EXIT

public static boolean RANDOM_DELAY_THREAD_EXIT
Enable delay on thread exit?


RANDOM_DELAY_THREAD_RUN

public static boolean RANDOM_DELAY_THREAD_RUN
Enable delay on thread run?


RANDOM_DELAY_THREAD_JOIN

public static boolean RANDOM_DELAY_THREAD_JOIN
Enable delay on thread join?


RANDOM_DELAY_PRE_NOTIFY

public static boolean RANDOM_DELAY_PRE_NOTIFY
Enable delay before notify?


RANDOM_DELAY_POST_NOTIFY

public static boolean RANDOM_DELAY_POST_NOTIFY
Enable delay after notify?


RANDOM_DELAY_PRE_WAIT

public static boolean RANDOM_DELAY_PRE_WAIT
Enable delay before wait?


RANDOM_DELAY_POST_WAIT

public static boolean RANDOM_DELAY_POST_WAIT
Enable delay after wait?


RANDOM_DELAY_PRE_MONITOR

public static boolean RANDOM_DELAY_PRE_MONITOR
Enable delay before monitorenter/exit??


RANDOM_DELAY_POST_MONITOR

public static boolean RANDOM_DELAY_POST_MONITOR
Enable delay after monitorenter/exit?


RANDOM_YIELD_PROB

public static float RANDOM_YIELD_PROB
Probability of a yield.


RANDOM_YIELD_THREAD_START

public static boolean RANDOM_YIELD_THREAD_START
Enable yield on thread start?


RANDOM_YIELD_THREAD_EXIT

public static boolean RANDOM_YIELD_THREAD_EXIT
Enable yield on thread exit?


RANDOM_YIELD_THREAD_RUN

public static boolean RANDOM_YIELD_THREAD_RUN
Enable yield on thread run?


RANDOM_YIELD_THREAD_JOIN

public static boolean RANDOM_YIELD_THREAD_JOIN
Enable yield on thread join?


RANDOM_YIELD_PRE_NOTIFY

public static boolean RANDOM_YIELD_PRE_NOTIFY
Enable yield before notify?


RANDOM_YIELD_POST_NOTIFY

public static boolean RANDOM_YIELD_POST_NOTIFY
Enable yield after notify?


RANDOM_YIELD_PRE_WAIT

public static boolean RANDOM_YIELD_PRE_WAIT
Enable yield before wait?


RANDOM_YIELD_POST_WAIT

public static boolean RANDOM_YIELD_POST_WAIT
Enable yield after wait?


RANDOM_YIELD_PRE_MONITOR

public static boolean RANDOM_YIELD_PRE_MONITOR
Enable yield before monitorenter/exit??


RANDOM_YIELD_POST_MONITOR

public static boolean RANDOM_YIELD_POST_MONITOR
Enable yield after monitorenter/exit?

Constructor Detail

SyncPointBuffer

public SyncPointBuffer()
Method Detail

_class

public static final java.lang.Class<?> _class()
A method to retrieve the .class field; this is required for pre-1.5 compatibility where simple field access to the .class field is not allowed.


add

public static void add(ISyncPoint sp)
Adds a synchronization point to the list. NOTE: This method has to be synchronized, but it may NOT be instrumented as such! An infinite recursion would be the result. The monitor application has to check that no thread is currently holding the lock on SyncPointBuffer.class. Only then may it clear the list.

Parameters:
sp - synchronization point to add.

transfer

public static void transfer()
Transfer and empty array. NOTE: The master should set a "method entry event" at the beginning of this method and transfer the array.


compactAdd

public static void compactAdd(long code,
                              long tid)
Adds a synchronization point to the compact list. NOTE: This method has to be synchronized, but it may NOT be instrumented as such! An infinite recursion would be the result. The monitor application has to check that no thread is currently holding the lock on SyncPointBuffer.class. Only then may it clear the list.

Parameters:
code - code for this event
tid - thread id

compactDebugAdd

public static void compactDebugAdd(long oid,
                                   long code,
                                   long tid,
                                   long classIndex,
                                   long methodAndPC)
Adds a synchronization point to the compact list. NOTE: This method has to be synchronized, but it may NOT be instrumented as such! An infinite recursion would be the result. The monitor application has to check that no thread is currently holding the lock on SyncPointBuffer.class. Only then may it clear the list.

Parameters:
oid - object id
code - code for this event
tid - thread id
classIndex - index of the class in the method database
methodAndPC - method index and PC

compactTransfer

public static void compactTransfer()
Transfer and empty compact array. NOTE: The master should set a "method entry event" at the beginning of this method and transfer the array.


compactImmediateTransfer

public static void compactImmediateTransfer()
Transfer immediately and empty compact array. NOTE: The master should set a "method entry event" at the beginning of this method and transfer the array.


compactWait

public static void compactWait(long code,
                               long tid)
Wait for this synchronization point in the compact list. NOTE: This method has to be synchronized, but it may NOT be instrumented as such! An infinite recursion would be the result.

Parameters:
code - code for this event
tid - thread id

compactThreadExit

public static void compactThreadExit(long tid)
Notify the wait algorithm that a thread has ended and check if the next thread has to be woken up.

NOTE: This method has to be synchronized, but it may NOT be instrumented as such! An infinite recursion would be the result.

Parameters:
tid - thread id

compactWait

public static void compactWait(long code,
                               long tid,
                               long classIndex,
                               long methodAndPC)
Wait for this synchronization point in the compact list.

NOTE: This method has to be synchronized, but it may NOT be instrumented as such! An infinite recursion would be the result.

Parameters:
code - code for this event
tid - thread id
classIndex - index of the class in the method database
methodAndPC - method index and PC

compactThreadExit

public static void compactThreadExit(long tid,
                                     long classIndex,
                                     long methodAndPC)
Notify the wait algorithm that a thread has ended and check if the next thread has to be woken up. NOTE: This method has to be synchronized, but it may NOT be instrumented as such! An infinite recursion would be the result.

Parameters:
tid - thread id
classIndex - index of the class in the method database
methodAndPC - method index and PC

replayTransfer

public static void replayTransfer()
Transfer and and reset replay array. NOTE: The master should set a "method entry event" at the beginning of this method and transfer the array.


isRecording

public static boolean isRecording()
Accessor for the recording flag. NOTE: This method has to be synchronized, but should not be instrumented.

Returns:
true if recording

setRecording

public static void setRecording(boolean recording)
Mutator for the recording flag. NOTE: This method has to be synchronized, but should not be instrumented.

Parameters:
recording - true if recording should be enabled

setMessage

public static void setMessage(java.lang.String message)
Notify the monitor application of a message. NOTE: The master should set a "method exit event" at the end of this method and process the error.

Parameters:
message - message string

monitorEnter

public static void monitorEnter(java.lang.Object o)
Marker for monitorenter instructions. The invokestatic instruction should get replaced with a monitorenter.

Parameters:
o - object whose lock should be acquired

monitorExit

public static void monitorExit(java.lang.Object o)
Marker for monitorexit instructions. The invokestatic instruction should get replaced with a monitorexit.

Parameters:
o - object whose lock should be released

isOldThread

public static boolean isOldThread()
Marker for getting the value of the $$$oldThread$$$ field. The invokestatic instruction should get replaced with invokestatic java/lang/Thread.currentThread()Ljava/lang/Thread; getfield java/lang/Thread.$$$oldThread$$$

Returns:
value of the $$$oldThread$$$ field of the current thread (theoretically)

setOldThread

public static void setOldThread()
Marker for setting $$$oldThread$$$ field. The invokestatic instruction should get replaced with iconst_1 invokestatic java/lang/Thread.currentThread()Ljava/lang/Thread; setfield java/lang/Thread.$$$oldThread$$$


randomDelay

public static void randomDelay(boolean delay)
Sleep for a random amount of time, up to RANDOM_DELAY_MAGNITUDE milliseconds, if there is concurrency.

Parameters:
delay - true if delay is enabled

delayThreadStart

public static void delayThreadStart(boolean delay)
Increment the number of running thread, and then sleep for a while if there is concurrency.

Parameters:
delay - true if delay is enabled

delayThreadExit

public static void delayThreadExit(boolean delay)
Sleep for a while if there is concurrency, and then decrement the number of running threads.

Parameters:
delay - true if delay is enabled

delayObjectWait

public static void delayObjectWait(boolean delay)
Throw an exception if no other thread is alive anymore, otherwise sleep for a while.

Parameters:
delay - true if delay is enabled

randomYield

public static void randomYield(boolean yield)
Yield if random number < RANDOM_YIELD_PROB, but only if there is concurrency.

Parameters:
yield - true if yield is enabled

yieldThreadStart

public static void yieldThreadStart(boolean yield)
Increment the number of running thread, and then do a random yield.

Parameters:
yield - true if yield is enabled

yieldThreadExit

public static void yieldThreadExit(boolean yield)
Do a random yield, and then decrement the number of running threads.

Parameters:
yield - true if yield is enabled

yieldObjectWait

public static void yieldObjectWait(boolean yield)
Throw an exception if no other thread is alive anymore, otherwise do a random yield.

Parameters:
yield - true if yield is enabled