001/*
002 *  This file is part of the Jikes RVM project (http://jikesrvm.org).
003 *
004 *  This file is licensed to You under the Eclipse Public License (EPL);
005 *  You may not use this file except in compliance with the License. You
006 *  may obtain a copy of the License at
007 *
008 *      http://www.opensource.org/licenses/eclipse-1.0.php
009 *
010 *  See the COPYRIGHT.txt file distributed with this work for information
011 *  regarding copyright ownership.
012 */
013package org.mmtk.plan.generational.marksweep;
014
015import org.mmtk.plan.generational.Gen;
016import org.mmtk.plan.Trace;
017import org.mmtk.plan.TransitiveClosure;
018import org.mmtk.policy.MarkSweepSpace;
019import org.mmtk.policy.Space;
020import org.mmtk.utility.heap.VMRequest;
021
022import org.vmmagic.pragma.*;
023import org.vmmagic.unboxed.*;
024
025/**
026 * This class implements the functionality of a two-generation copying
027 * collector where <b>the higher generation is a mark-sweep space</b>
028 * (free list allocation, mark-sweep collection).  Nursery collections
029 * occur when either the heap is full or the nursery is full.  The
030 * nursery size is determined by an optional command line argument.
031 * If undefined, the nursery size is "infinite", so nursery
032 * collections only occur when the heap is full (this is known as a
033 * flexible-sized nursery collector).  Thus both fixed and flexible
034 * nursery sizes are supported.  Full heap collections occur when the
035 * nursery size has dropped to a statically defined threshold,
036 * <code>NURSERY_THRESHOLD</code><p>
037 *
038 * See the Jones &amp; Lins GC book, chapter 7 for a detailed discussion
039 * of generational collection and section 7.3 for an overview of the
040 * flexible nursery behavior ("The Standard ML of New Jersey
041 * collector"), or go to Appel's paper "Simple generational garbage
042 * collection and fast allocation." SP&amp;E 19(2):171--183, 1989.<p>
043 *
044 *
045 * For general comments about the global/local distinction among classes refer
046 * to Plan.java and PlanLocal.java.
047 */
048@Uninterruptible
049public class GenMS extends Gen {
050
051  /*****************************************************************************
052   *
053   * Class fields
054   */
055
056  /** The mature space, which for GenMS uses a mark sweep collection policy. */
057  public static final MarkSweepSpace msSpace = new MarkSweepSpace("ms", VMRequest.discontiguous());
058
059  public static final int MS = msSpace.getDescriptor();
060
061  /****************************************************************************
062   *
063   * Instance fields
064   */
065
066  /** The trace class for a full-heap collection */
067  public final Trace matureTrace = new Trace(metaDataSpace);
068
069  /*****************************************************************************
070   *
071   * Collection
072   */
073
074  /**
075   * {@inheritDoc}
076   */
077  @Inline
078  @Override
079  public final void collectionPhase(short phaseId) {
080    if (traceFullHeap()) {
081      if (phaseId == PREPARE) {
082        super.collectionPhase(phaseId);
083        matureTrace.prepare();
084        msSpace.prepare(true);
085        return;
086      }
087
088      if (phaseId == CLOSURE) {
089        matureTrace.prepare();
090        return;
091      }
092      if (phaseId == RELEASE) {
093        matureTrace.release();
094        msSpace.release();
095        super.collectionPhase(phaseId);
096        return;
097      }
098    }
099    super.collectionPhase(phaseId);
100  }
101
102  /*****************************************************************************
103   *
104   * Accounting
105   */
106
107  /**
108   * Return the number of pages reserved for use given the pending
109   * allocation.
110   */
111  @Inline
112  @Override
113  public int getPagesUsed() {
114    return msSpace.reservedPages() + super.getPagesUsed();
115  }
116
117  @Override
118  public int getMaturePhysicalPagesAvail() {
119    return (int) (msSpace.availablePhysicalPages() / MarkSweepSpace.WORST_CASE_FRAGMENTATION);
120  }
121
122  /*****************************************************************************
123   *
124   * Miscellaneous
125   */
126
127  /**
128   * {@inheritDoc}
129   */
130  @Override
131  @Inline
132  protected final Space activeMatureSpace() {
133    return msSpace;
134  }
135
136  @Override
137  public boolean willNeverMove(ObjectReference object) {
138    if (Space.isInSpace(MS, object))
139      return true;
140    return super.willNeverMove(object);
141  }
142
143  @Override
144  @Interruptible
145  protected void registerSpecializedMethods() {
146    TransitiveClosure.registerSpecializedScan(SCAN_MATURE, GenMSMatureTraceLocal.class);
147    super.registerSpecializedMethods();
148  }
149}