org.mmtk.plan
Class CollectorContext

java.lang.Object
  extended by org.mmtk.plan.CollectorContext
All Implemented Interfaces:
Constants
Direct Known Subclasses:
ConcurrentZeroingContext, ControllerCollectorContext, ParallelCollector

public abstract class CollectorContext
extends Object
implements Constants

This class (and its sub-classes) implement per-collector thread behavior. We assume N collector threads and M mutator threads, where N is often equal to the number of available processors, P (for P-way parallelism at GC-time), and M may simply be the number of mutator (application) threads. Both N and M are determined by the VM, not MMTk. In the case where a VM uses posix threads (pthreads) for each mutator ("1:1" threading), M will typically be equal to the number of mutator threads. When a uses "green threads" or a hybrid threading scheme (such as Jikes RVM), M will typically be equal to the level of true parallelism (ie the number of underlying kernel threads).

Collector operations are separated into per-collector thread operations (the bulk of the GC), and per-mutator thread operations (important in flushing and restoring per-mutator state such as allocator state and write buffer/remset state). SimplePhase ensures that per-collector thread GC phases are performed by each collector thread, and that the M per-mutator thread operations are multiplexed across the N active collector threads.

MMTk assumes that the VM instantiates instances of CollectorContext in thread local storage (TLS) for each thread participating in collection. Accesses to this state are therefore assumed to be low-cost at GC time.

MMTk explicitly separates thread-local (this class) and global operations (See Plan), so that syncrhonization is localized and explicit, and thus hopefully minimized (See Plan). Global (Plan) and per-thread (this class) state are also explicitly separated. Operations in this class (and its children) are therefore strictly local to each collector thread, and synchronized operations always happen via access to explicitly global classes such as Plan and its children.

This class (and its children) therefore typically implement per-collector thread structures such as collection work queues.

See Also:
MutatorContext, ActivePlan, Plan

Field Summary
private  int id
          Unique identifier.
protected  Log log
          Used for printing log information in a thread safe manner
 
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
CollectorContext()
           
 
Method Summary
 Address allocCopy(ObjectReference original, int bytes, int align, int offset, int allocator)
          Allocate space for copying an object (this method does not copy the object, it only allocates space)
 int copyCheckAllocator(ObjectReference from, int bytes, int align, int allocator)
          Run-time check of the allocator to use for a given copy allocation.
 int getId()
           
 Log getLog()
           
 void initCollector(int id)
          Notify that the collector context is registered and ready to execute.
 int parallelWorkerCount()
          The number of parallel workers currently executing with this collector context.
 int parallelWorkerOrdinal()
          The ordinal of the current worker.
 void postCopy(ObjectReference ref, ObjectReference typeRef, int bytes, int allocator)
          Perform any post-copy actions.
 int rendezvous()
          Get the executing context to rendezvous with other contexts working in parallel.
abstract  void run()
          Entry point for the collector context.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

id

private int id
Unique identifier.


log

protected final Log log
Used for printing log information in a thread safe manner

Constructor Detail

CollectorContext

public CollectorContext()
Method Detail

initCollector

public void initCollector(int id)
Notify that the collector context is registered and ready to execute.

Parameters:
id - The id of this collector context.

allocCopy

public Address allocCopy(ObjectReference original,
                         int bytes,
                         int align,
                         int offset,
                         int allocator)
Allocate space for copying an object (this method does not copy the object, it only allocates space)

Parameters:
original - The object that is being copied.
bytes - The size of the space to be allocated (in bytes)
align - Required alignment for the copy
offset - Offset associated with the alignment.
allocator - The allocator associated with this request
Returns:
The address of the first byte of the allocated region

postCopy

public void postCopy(ObjectReference ref,
                     ObjectReference typeRef,
                     int bytes,
                     int allocator)
Perform any post-copy actions.

Parameters:
ref - The newly allocated object.
typeRef - the type reference for the instance being created.
bytes - The size of the space to be allocated (in bytes).
allocator - The allocator statically assigned to this allocation.

copyCheckAllocator

public int copyCheckAllocator(ObjectReference from,
                              int bytes,
                              int align,
                              int allocator)
Run-time check of the allocator to use for a given copy allocation.

At the moment this method assumes that allocators will use the simple (worst) method of aligning to determine if the object is a large object to ensure that no objects are larger than other allocators can handle.

Parameters:
from - The object that is being copied.
bytes - The number of bytes to be allocated.
align - The requested alignment.
allocator - The allocator statically assigned to this allocation.
Returns:
The allocator dynamically assigned to this allocation.

run

public abstract void run()
Entry point for the collector context.


parallelWorkerCount

public int parallelWorkerCount()
The number of parallel workers currently executing with this collector context. This can be queried from anywhere within a collector context to determine how best to perform load-balancing.

Returns:
The number of parallel workers.

parallelWorkerOrdinal

public int parallelWorkerOrdinal()
The ordinal of the current worker. This is in the range of 0 to the result of parallelWorkerCount() exclusive.

Returns:
The ordinal of this collector context, starting from 0.

rendezvous

public int rendezvous()
Get the executing context to rendezvous with other contexts working in parallel.

Returns:
The order this context reached the rendezvous, starting from 0.

getLog

public final Log getLog()
Returns:
the Log instance for this collector context.

getId

public int getId()
Returns:
The unique identifier for this collector context.