org.jikesrvm.mm.mmtk
Class FinalizableProcessor

java.lang.Object
  extended by org.mmtk.vm.FinalizableProcessor
      extended by org.jikesrvm.mm.mmtk.FinalizableProcessor
All Implemented Interfaces:
SizeConstants

public final class FinalizableProcessor
extends FinalizableProcessor
implements SizeConstants

This class manages the processing of finalizable objects.

TODO can this be a linked list?


Field Summary
private static FinalizableProcessor finalizableProcessor
          The FinalizableProcessor singleton
private static double GROWTH_FACTOR
          Amount to grow the table by when it is filled
private static int INITIAL_SIZE
          Initial size of the reference object table
private  int lastReadyIndex
          Last object ready to be finalized
private  Lock lock
          Used to ensure mutual exclusion during table manipulation
protected  int maxIndex
          Index of the first free slot in the table.
private  int nextReadyIndex
          Next object ready to be finalized
protected  int nurseryIndex
          Index of first entry created since last collection
protected  Object[] readyForFinalize
          The table of ready objects
private static boolean STRESS
          Stress the system?
protected  AddressArray table
          The table of candidates
 
Fields inherited from interface org.jikesrvm.SizeConstants
BITS_IN_ADDRESS, BITS_IN_BOOLEAN, BITS_IN_BYTE, BITS_IN_CHAR, BITS_IN_DOUBLE, BITS_IN_EXTENT, BITS_IN_FLOAT, BITS_IN_INT, BITS_IN_LONG, BITS_IN_OFFSET, BITS_IN_PAGE, BITS_IN_SHORT, BITS_IN_WORD, BYTES_IN_ADDRESS, BYTES_IN_BOOLEAN, BYTES_IN_BYTE, BYTES_IN_CHAR, BYTES_IN_DOUBLE, BYTES_IN_EXTENT, BYTES_IN_FLOAT, BYTES_IN_INT, BYTES_IN_LONG, BYTES_IN_OFFSET, BYTES_IN_PAGE, BYTES_IN_SHORT, BYTES_IN_WORD, LOG_BITS_IN_ADDRESS, LOG_BITS_IN_BOOLEAN, LOG_BITS_IN_BYTE, LOG_BITS_IN_CHAR, LOG_BITS_IN_DOUBLE, LOG_BITS_IN_EXTENT, LOG_BITS_IN_FLOAT, LOG_BITS_IN_INT, LOG_BITS_IN_LONG, LOG_BITS_IN_OFFSET, LOG_BITS_IN_PAGE, LOG_BITS_IN_SHORT, LOG_BITS_IN_WORD, LOG_BYTES_IN_ADDRESS, LOG_BYTES_IN_BOOLEAN, LOG_BYTES_IN_BYTE, LOG_BYTES_IN_CHAR, LOG_BYTES_IN_DOUBLE, LOG_BYTES_IN_EXTENT, LOG_BYTES_IN_FLOAT, LOG_BYTES_IN_INT, LOG_BYTES_IN_LONG, LOG_BYTES_IN_OFFSET, LOG_BYTES_IN_PAGE, LOG_BYTES_IN_SHORT, LOG_BYTES_IN_WORD
 
Constructor Summary
protected FinalizableProcessor()
          Create a new table.
 
Method Summary
 void add(Object object)
          Allocate an entry in the table.
static void addCandidate(Object object)
          Add a finalization candidate.
 void clear()
          Clear the contents of the table.
 int count()
          The number of entries in the table.
 int countReady()
          The number of entries ready to be finalized.
static int countReadyForFinalize()
          The number of objects waiting for finalize() calls.
 void forward(TraceLocal trace, boolean nursery)
          Iterate over and forward entries in the table.
 int freeReady()
          The number of entries ready to be finalized.
static Object getForFinalize()
          Get an object to call the finalize() method on it.
static FinalizableProcessor getProcessor()
          Get the singleton
 Object getReady()
          Get an object to run finalize().
 void scan(TraceLocal trace, boolean nursery)
          Scan through the list of references.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

finalizableProcessor

private static final FinalizableProcessor finalizableProcessor
The FinalizableProcessor singleton


STRESS

private static final boolean STRESS
Stress the system?

See Also:
Constant Field Values

INITIAL_SIZE

private static final int INITIAL_SIZE
Initial size of the reference object table

See Also:
Constant Field Values

GROWTH_FACTOR

private static final double GROWTH_FACTOR
Amount to grow the table by when it is filled

See Also:
Constant Field Values

lock

private final Lock lock
Used to ensure mutual exclusion during table manipulation


table

protected volatile AddressArray table
The table of candidates


readyForFinalize

protected volatile Object[] readyForFinalize
The table of ready objects


nurseryIndex

protected int nurseryIndex
Index of first entry created since last collection


maxIndex

protected volatile int maxIndex
Index of the first free slot in the table.


nextReadyIndex

private volatile int nextReadyIndex
Next object ready to be finalized


lastReadyIndex

private volatile int lastReadyIndex
Last object ready to be finalized

Constructor Detail

FinalizableProcessor

protected FinalizableProcessor()
Create a new table.

Method Detail

add

public void add(Object object)
Allocate an entry in the table. This should be called from an unpreemptible context so that the entry can be filled. This method is responsible for growing the table if necessary.


clear

public void clear()
Description copied from class: FinalizableProcessor
Clear the contents of the table. This is called when finalization is disabled to make it easier for VMs to change this setting at runtime.

Specified by:
clear in class FinalizableProcessor

forward

public void forward(TraceLocal trace,
                    boolean nursery)
Iterate over and forward entries in the table..

Currently ignores the nursery hint.

TODO parallelise this code?

Specified by:
forward in class FinalizableProcessor
Parameters:
trace - The trace
nursery - Is this a nursery collection ?

scan

public void scan(TraceLocal trace,
                 boolean nursery)
Scan through the list of references. Calls ReferenceProcessor's processReference method for each reference and builds a new list of those references still active.

Depending on the value of nursery, we will either scan all references, or just those created since the last scan.

TODO parallelise this code

Specified by:
scan in class FinalizableProcessor
Parameters:
nursery - Scan only the newly created references
trace - the thread local trace element.

getReady

public Object getReady()
Get an object to run finalize().

Returns:
The object to finalize()

count

public int count()
The number of entries in the table.


countReady

public int countReady()
The number of entries ready to be finalized.


freeReady

public int freeReady()
The number of entries ready to be finalized.


getProcessor

public static FinalizableProcessor getProcessor()
Get the singleton


addCandidate

public static void addCandidate(Object object)
Add a finalization candidate.

Parameters:
object - The object with a finalizer.

getForFinalize

public static Object getForFinalize()
Get an object to call the finalize() method on it.


countReadyForFinalize

public static int countReadyForFinalize()
The number of objects waiting for finalize() calls.