org.mmtk.utility.deque
Class LocalSSB

java.lang.Object
  extended by org.mmtk.utility.deque.Deque
      extended by org.mmtk.utility.deque.LocalSSB
All Implemented Interfaces:
Constants
Direct Known Subclasses:
LocalQueue, WriteBuffer

 class LocalSSB
extends Deque
implements Constants

This class implements a local (unsynchronized) sequential store buffer. An SSB is strictly FIFO (although this class does not implement dequeuing).

Each instance stores word-sized values into a local buffer. When the buffer is full, or if the flushLocal() method is called, the buffer enqueued at the tail of a SharedDeque. This class provides no mechanism for dequeing.

The implementation is intended to be as efficient as possible, in time and space, as it is used in critical code such as the GC work queue and the write buffer used by many "remembering" collectors. Each instance has just two fields: a bump pointer and a pointer to the SharedDeque

Preconditions: Buffers are always aligned on buffer-size address boundaries.

Invariants: Buffers are filled such that tuples (of the specified arity) are packed to the low end of the buffer. Thus buffer overflows on inserts and pops (underflow actually) will always arise when then cursor is buffer-size aligned.


Field Summary
protected  SharedDeque queue
          the shared queue
protected  Address tail
          the location in the buffer
protected  Address tailBufferEnd
          the end of the buffer
 
Fields inherited from class org.mmtk.utility.deque.Deque
BUFFER_MASK, BUFFER_SIZE, HEAD_INITIAL_VALUE, LOG_PAGES_PER_BUFFER, META_DATA_SIZE, NEXT_FIELD_OFFSET, PAGES_PER_BUFFER, TAIL_INITIAL_VALUE, USABLE_BUFFER_BYTES
 
Fields inherited from interface org.mmtk.utility.Constants
ALIGNMENT_VALUE, ARRAY_ELEMENT, BITS_IN_ADDRESS, BITS_IN_BYTE, BITS_IN_CHAR, BITS_IN_INT, BITS_IN_PAGE, BITS_IN_SHORT, BITS_IN_WORD, BYTES_IN_ADDRESS, BYTES_IN_BYTE, BYTES_IN_CHAR, BYTES_IN_INT, BYTES_IN_KBYTE, BYTES_IN_MBYTE, BYTES_IN_PAGE, BYTES_IN_SHORT, BYTES_IN_WORD, CARD_MASK, CARD_META_PAGES_PER_REGION, INSTANCE_FIELD, LOG_BITS_IN_ADDRESS, LOG_BITS_IN_BYTE, LOG_BITS_IN_CHAR, LOG_BITS_IN_INT, LOG_BITS_IN_PAGE, LOG_BITS_IN_SHORT, LOG_BITS_IN_WORD, LOG_BYTES_IN_ADDRESS, LOG_BYTES_IN_ADDRESS_SPACE, LOG_BYTES_IN_BYTE, LOG_BYTES_IN_CHAR, LOG_BYTES_IN_INT, LOG_BYTES_IN_KBYTE, LOG_BYTES_IN_MBYTE, LOG_BYTES_IN_PAGE, LOG_BYTES_IN_SHORT, LOG_BYTES_IN_WORD, LOG_CARD_BYTES, LOG_CARD_GRAIN, LOG_CARD_META_BYTES, LOG_CARD_META_PAGES, LOG_CARD_META_SIZE, LOG_CARD_UNITS, LOG_MIN_ALIGNMENT, MAX_ALIGNMENT, MAX_BYTES_PADDING, MAX_INT, MIN_ALIGNMENT, MIN_INT, SUPPORT_CARD_SCANNING
 
Constructor Summary
LocalSSB(SharedDeque queue)
          Constructor
 
Method Summary
protected  Offset bufferSentinel(int arity)
          Return the sentinel offset for a buffer of a given arity.
protected  void checkTailInsert(int arity)
          Check whether there is space in the buffer for a pending insert.
private  void closeAndEnqueueTail(int arity)
          Close the tail buffer (normalizing if necessary), and enqueue it at the tail of the shared buffer queue.
 void flushLocal()
          Flush the buffer and add it to the shared queue (this will make any entries in the buffer visible to any consumer associated with the shared queue).
 boolean isFlushed()
          Return true if this SSB is locally empty
protected  Address normalizeTail(int arity)
          In the case where a buffer must be flushed before being filled (either to the queue or to the head), the entries must be slid to the base of the buffer in order to preserve the invariant that all non-tail buffers will have entries starting at the base (which allows a simple test against the base to be used when popping entries).
 void reset()
           
 void resetLocal()
          Reset the local buffer (throwing away any local entries).
private  void tailOverflow(int arity)
          Buffer space has been exhausted, allocate a new buffer and enqueue the existing buffer (if any).
protected  void uncheckedTailInsert(Address value)
          Insert a value into the buffer.
 
Methods inherited from class org.mmtk.utility.deque.Deque
bufferEnd, bufferFirst, bufferLast, bufferLast, bufferLastOffset, bufferOffset, bufferStart
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tail

protected Address tail
the location in the buffer


tailBufferEnd

protected Address tailBufferEnd
the end of the buffer


queue

protected final SharedDeque queue
the shared queue

Constructor Detail

LocalSSB

LocalSSB(SharedDeque queue)
Constructor

Parameters:
queue - The shared queue to which this local ssb will append its buffers (when full or flushed).
Method Detail

flushLocal

public void flushLocal()
Flush the buffer and add it to the shared queue (this will make any entries in the buffer visible to any consumer associated with the shared queue).


reset

public void reset()

resetLocal

public void resetLocal()
Reset the local buffer (throwing away any local entries).


checkTailInsert

protected final void checkTailInsert(int arity)
Check whether there is space in the buffer for a pending insert. If there is not sufficient space, allocate a new buffer (dispatching the full buffer to the shared queue if not null).

Parameters:
arity - The arity of the values stored in this SSB: the buffer must contain enough space for this many words.

uncheckedTailInsert

protected final void uncheckedTailInsert(Address value)
Insert a value into the buffer. This is unchecked. The caller must first call checkInsert() to ensure the buffer can accommodate the insertion.

Parameters:
value - the value to be inserted.

normalizeTail

protected final Address normalizeTail(int arity)
In the case where a buffer must be flushed before being filled (either to the queue or to the head), the entries must be slid to the base of the buffer in order to preserve the invariant that all non-tail buffers will have entries starting at the base (which allows a simple test against the base to be used when popping entries). This is expensive, so should be avoided.

Parameters:
arity - The arity of the buffer in question
Returns:
The last slot in the normalized buffer that contains an entry

bufferSentinel

protected final Offset bufferSentinel(int arity)
Return the sentinel offset for a buffer of a given arity. This is used both to compute the address at the end of the buffer.

Parameters:
arity - The arity of this buffer
Returns:
The sentinel offset value for a buffer of the given arity.

tailOverflow

private void tailOverflow(int arity)
Buffer space has been exhausted, allocate a new buffer and enqueue the existing buffer (if any).

Parameters:
arity - The arity of this buffer (used for sanity test only).

closeAndEnqueueTail

private void closeAndEnqueueTail(int arity)
Close the tail buffer (normalizing if necessary), and enqueue it at the tail of the shared buffer queue.

Parameters:
arity - The arity of this buffer.

isFlushed

public final boolean isFlushed()
Return true if this SSB is locally empty

Returns:
true if this SSB is locally empty