org.mmtk.plan.generational
Class GenMutator

java.lang.Object
  extended by org.mmtk.plan.MutatorContext
      extended by org.mmtk.plan.SimpleMutator
          extended by org.mmtk.plan.StopTheWorldMutator
              extended by org.mmtk.plan.generational.GenMutator
All Implemented Interfaces:
Constants
Direct Known Subclasses:
GenCopyMutator, GenImmixMutator, GenMSMutator

public class GenMutator
extends StopTheWorldMutator

This abstract class implements per-mutator thread behavior and state for generational copying collectors.

Specifically, this class defines mutator-time allocation into the nursery; write barrier semantics, and per-mutator thread collection semantics (flushing and restoring per-mutator allocator and remset state).

See Also:
Gen, GenCollector, StopTheWorldMutator, MutatorContext

Field Summary
protected  AddressPairDeque arrayRemset
           
private  ObjectReferenceDeque modbuf
           
protected  CopyLocal nursery
           
protected  WriteBuffer remset
           
 
Fields inherited from class org.mmtk.plan.MutatorContext
immortal, lgcode, log, los, nonmove, smcode
 
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
GenMutator()
          Constructor Note that each mutator is a producer of remsets, while each collector is a consumer.
 
Method Summary
 Address alloc(int bytes, int align, int offset, int allocator, int site)
          Allocate memory for an object.
 void assertRemsetsFlushed()
          Assert that the remsets have been flushed.
 void collectionPhase(short phaseId, boolean primary)
          Perform a per-mutator collection phase.
private  void fastPath(Address slot, ObjectReference tgt)
          Perform the root write barrier fast path, which may involve remembering a reference if necessary.
private  void fastPath(ObjectReference src, Address slot, ObjectReference tgt, int mode)
          Perform the write barrier fast path, which may involve remembering a reference if necessary.
 void flushRememberedSets()
          Flush per-mutator remembered sets into the global remset pool.
 Allocator getAllocatorFromSpace(Space space)
          Return the allocator instance associated with a space space, for this plan instance.
private static Gen global()
           
 boolean objectReferenceBulkCopy(ObjectReference src, Offset srcOffset, ObjectReference dst, Offset dstOffset, int bytes)
          A number of references are about to be copied from object src to object dst (as in an array copy).
 void objectReferenceNonHeapWrite(Address slot, ObjectReference tgt, Word metaDataA, Word metaDataB)
          A new reference is about to be created in a location that is not a regular heap object.
 boolean objectReferenceTryCompareAndSwap(ObjectReference src, Address slot, ObjectReference old, ObjectReference tgt, Word metaDataA, Word metaDataB, int mode)
          Attempt to atomically exchange the value in the given slot with the passed replacement value.
 void objectReferenceWrite(ObjectReference src, Address slot, ObjectReference tgt, Word metaDataA, Word metaDataB, int mode)
          Write an object reference.
 void postAlloc(ObjectReference ref, ObjectReference typeRef, int bytes, int allocator)
          Perform post-allocation actions.
 
Methods inherited from class org.mmtk.plan.MutatorContext
addressBulkCopy, addressRead, addressTryCompareAndSwap, addressWrite, booleanBulkCopy, booleanRead, booleanWrite, byteBulkCopy, byteRead, byteWrite, charBulkCopy, charRead, charWrite, checkAllocator, deinitMutator, doubleBulkCopy, doubleRead, doubleWrite, extentBulkCopy, extentRead, extentWrite, floatBulkCopy, floatRead, floatWrite, flush, getId, getLog, initMutator, intBulkCopy, intRead, intTryCompareAndSwap, intWrite, javaLangReferenceReadBarrier, longBulkCopy, longRead, longTryCompareAndSwap, longWrite, objectReferenceNonHeapRead, objectReferenceRead, offsetBulkCopy, offsetRead, offsetWrite, shortBulkCopy, shortRead, shortWrite, wordBulkCopy, wordRead, wordTryCompareAndSwap, wordWrite
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

nursery

protected final CopyLocal nursery

modbuf

private final ObjectReferenceDeque modbuf

remset

protected final WriteBuffer remset

arrayRemset

protected final AddressPairDeque arrayRemset
Constructor Detail

GenMutator

public GenMutator()
Constructor

Note that each mutator is a producer of remsets, while each collector is a consumer. The GenCollector class is responsible for construction of the consumer.

See Also:
GenCollector
Method Detail

alloc

public Address alloc(int bytes,
                     int align,
                     int offset,
                     int allocator,
                     int site)
Allocate memory for an object.

Overrides:
alloc in class MutatorContext
Parameters:
bytes - The number of bytes required for the object.
align - Required alignment for the object.
offset - Offset associated with the alignment.
allocator - The allocator associated with this request.
site - Allocation site
Returns:
The low address of the allocated chunk.

postAlloc

public void postAlloc(ObjectReference ref,
                      ObjectReference typeRef,
                      int bytes,
                      int allocator)
Description copied from class: MutatorContext
Perform post-allocation actions. For many allocators none are required.

Overrides:
postAlloc in class MutatorContext
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 number to be used for this allocation

getAllocatorFromSpace

public Allocator getAllocatorFromSpace(Space space)
Description copied from class: MutatorContext
Return the allocator instance associated with a space space, for this plan instance.

Overrides:
getAllocatorFromSpace in class MutatorContext
Parameters:
space - The space for which the allocator instance is desired.
Returns:
The allocator instance associated with this plan instance which is allocating into space, or null if no appropriate allocator can be established.

fastPath

private void fastPath(ObjectReference src,
                      Address slot,
                      ObjectReference tgt,
                      int mode)
Perform the write barrier fast path, which may involve remembering a reference if necessary.

Parameters:
src - The object into which the new reference will be stored
slot - The address into which the new reference will be stored.
tgt - The target of the new reference
mode - The mode of the store (eg putfield, putstatic etc)

objectReferenceWrite

public final void objectReferenceWrite(ObjectReference src,
                                       Address slot,
                                       ObjectReference tgt,
                                       Word metaDataA,
                                       Word metaDataB,
                                       int mode)
Write an object reference. Take appropriate write barrier actions.

By default do nothing, override if appropriate.

In this case, we remember the address of the source of the pointer if the new reference points into the nursery from non-nursery space.

Overrides:
objectReferenceWrite in class MutatorContext
Parameters:
src - The object into which the new reference will be stored
slot - The address into which the new reference will be stored.
tgt - The value of the new reference
metaDataA - A value that assists the host VM in creating a store
metaDataB - A value that assists the host VM in creating a store
mode - The context in which the store occurred

fastPath

private void fastPath(Address slot,
                      ObjectReference tgt)
Perform the root write barrier fast path, which may involve remembering a reference if necessary.

Parameters:
slot - The address into which the new reference will be stored.
tgt - The target of the new reference

objectReferenceNonHeapWrite

public final void objectReferenceNonHeapWrite(Address slot,
                                              ObjectReference tgt,
                                              Word metaDataA,
                                              Word metaDataB)
A new reference is about to be created in a location that is not a regular heap object. Take appropriate write barrier actions.

By default do nothing, override if appropriate.

In this case, we remember the address of the source of the pointer if the new reference points into the nursery from non-nursery space.

Overrides:
objectReferenceNonHeapWrite in class MutatorContext
Parameters:
slot - The address into which the new reference will be stored.
tgt - The target of the new reference
metaDataA - A value that assists the host VM in creating a store
metaDataB - A value that assists the host VM in creating a store

objectReferenceTryCompareAndSwap

public boolean objectReferenceTryCompareAndSwap(ObjectReference src,
                                                Address slot,
                                                ObjectReference old,
                                                ObjectReference tgt,
                                                Word metaDataA,
                                                Word metaDataB,
                                                int mode)
Attempt to atomically exchange the value in the given slot with the passed replacement value. If a new reference is created, we must then take appropriate write barrier actions.

By default do nothing, override if appropriate.

In this case, we remember the address of the source of the pointer if the new reference points into the nursery from non-nursery space.

Overrides:
objectReferenceTryCompareAndSwap in class MutatorContext
Parameters:
src - The object into which the new reference will be stored
slot - The address into which the new reference will be stored.
old - The old reference to be swapped out
tgt - The target of the new reference
metaDataA - A value that assists the host VM in creating a store
metaDataB - A value that assists the host VM in creating a store
mode - The context in which the store occurred
Returns:
True if the swap was successful.

objectReferenceBulkCopy

public final boolean objectReferenceBulkCopy(ObjectReference src,
                                             Offset srcOffset,
                                             ObjectReference dst,
                                             Offset dstOffset,
                                             int bytes)
A number of references are about to be copied from object src to object dst (as in an array copy). Thus, dst is the mutated object. Take appropriate write barrier actions.

In this case, we remember the mutated source address range and will scan that address range at GC time.

Overrides:
objectReferenceBulkCopy in class MutatorContext
Parameters:
src - The source array
srcOffset - The starting source offset
dst - The destination array
dstOffset - The starting destination offset
bytes - The number of bytes to be copied
Returns:
true if the update was performed by the barrier, false if left to the caller (always false in this case).

flushRememberedSets

public final void flushRememberedSets()
Description copied from class: MutatorContext
Flush per-mutator remembered sets into the global remset pool.

Overrides:
flushRememberedSets in class MutatorContext

assertRemsetsFlushed

public final void assertRemsetsFlushed()
Description copied from class: MutatorContext
Assert that the remsets have been flushed. This is critical to correctness. We need to maintain the invariant that remset entries do not accrue during GC. If the host JVM generates barrier entries it is its own responsibility to ensure that they are flushed before returning to MMTk.

Overrides:
assertRemsetsFlushed in class MutatorContext

collectionPhase

public void collectionPhase(short phaseId,
                            boolean primary)
Perform a per-mutator collection phase. This is executed by one collector thread on behalf of a mutator thread.

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

global

private static Gen global()
Returns:
The active global plan as a Gen instance.