org.mmtk.plan
Class CollectorContext

java.lang.Object
  extended by org.mmtk.plan.CollectorContext
All Implemented Interfaces:
Constants
Direct Known Subclasses:
NoGCCollector, SimpleCollector

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 collector identifier
protected  BumpPointer immortal
          Per-collector allocator into the immortal space
protected  boolean resetConcurrentWork
          Used for aborting concurrent phases pre-empted by stop the world collection
protected  SanityCheckerLocal sanityLocal
          Used for sanity checking
 
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
protected CollectorContext()
          Initialization
 
Method Summary
 Address allocCopy(ObjectReference original, int bytes, int align, int offset, int allocator)
          Allocate memory when copying an object.
protected  void clearResetConcurrentWork()
          Allow concurrent work to continue.
abstract  void collect()
          Perform a garbage collection
abstract  void collectionPhase(short phaseId, boolean primary)
          Perform a (local) collection phase.
abstract  void concurrentCollect()
          Perform some concurrent garbage collection
abstract  void concurrentCollectionPhase(short phaseId)
          Perform some concurrent collection work.
 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.
abstract  TraceLocal getCurrentTrace()
           
 int getId()
           
 void initCollector(int id)
          Notify that the collector context is registered and ready to execute.
 void postCopy(ObjectReference ref, ObjectReference typeRef, int bytes, int allocator)
          Perform any post-copy actions.
protected  void resetConcurrentWork()
          Abort concurrent work due to pre-empt by stop the world collection.
 
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 collector identifier


immortal

protected final BumpPointer immortal
Per-collector allocator into the immortal space


resetConcurrentWork

protected boolean resetConcurrentWork
Used for aborting concurrent phases pre-empted by stop the world collection


sanityLocal

protected final SanityCheckerLocal sanityLocal
Used for sanity checking

Constructor Detail

CollectorContext

protected CollectorContext()
Initialization

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 memory when copying an object.

Parameters:
original - The object that is being copied.
bytes - The number of bytes required for the copy.
align - Required alignment for the copy.
offset - Offset associated with the alignment.
allocator - The allocator associated with this request.
Returns:
The address of the newly 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 dyncamically assigned to this allocation.

collect

public abstract void collect()
Perform a garbage collection


concurrentCollect

public abstract void concurrentCollect()
Perform some concurrent garbage collection


collectionPhase

public abstract void collectionPhase(short phaseId,
                                     boolean primary)
Perform a (local) collection phase.

Parameters:
phaseId - The unique phase identifier
primary - Should this thread be used to execute any single-threaded local operations?

concurrentCollectionPhase

public abstract void concurrentCollectionPhase(short phaseId)
Perform some concurrent collection work.

Parameters:
phaseId - The unique phase identifier

getCurrentTrace

public abstract TraceLocal getCurrentTrace()
Returns:
The current trace instance.

resetConcurrentWork

protected void resetConcurrentWork()
Abort concurrent work due to pre-empt by stop the world collection.


clearResetConcurrentWork

protected void clearResetConcurrentWork()
Allow concurrent work to continue.


getId

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