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.marksweep;
014
015import org.mmtk.plan.*;
016import org.mmtk.policy.MarkSweepSpace;
017import org.mmtk.policy.Space;
018import org.mmtk.utility.heap.VMRequest;
019
020import org.vmmagic.pragma.*;
021import org.vmmagic.unboxed.*;
022
023/**
024 * This class implements the global state of a simple mark-sweep collector.<p>
025 *
026 * All plans make a clear distinction between <i>global</i> and
027 * <i>thread-local</i> activities, and divides global and local state
028 * into separate class hierarchies.  Global activities must be
029 * synchronized, whereas no synchronization is required for
030 * thread-local activities.  There is a single instance of Plan (or the
031 * appropriate sub-class), and a 1:1 mapping of PlanLocal to "kernel
032 * threads" (aka CPUs).  Thus instance
033 * methods of PlanLocal allow fast, unsychronized access to functions such as
034 * allocation and collection.<p>
035 *
036 * The global instance defines and manages static resources
037 * (such as memory and virtual memory resources).  This mapping of threads to
038 * instances is crucial to understanding the correctness and
039 * performance properties of MMTk plans.
040 */
041@Uninterruptible
042public class MS extends StopTheWorld {
043
044  /****************************************************************************
045   * Class variables
046   */
047
048  /**
049   *
050   */
051  public static final MarkSweepSpace msSpace = new MarkSweepSpace("ms", VMRequest.discontiguous());
052  public static final int MARK_SWEEP = msSpace.getDescriptor();
053
054  public static final int SCAN_MARK = 0;
055
056
057  /****************************************************************************
058   * Instance variables
059   */
060
061  /**
062   *
063   */
064  public final Trace msTrace = new Trace(metaDataSpace);
065
066
067  /*****************************************************************************
068   * Collection
069   */
070
071  /**
072   * {@inheritDoc}
073   */
074  @Inline
075  @Override
076  public void collectionPhase(short phaseId) {
077
078    if (phaseId == PREPARE) {
079      super.collectionPhase(phaseId);
080      msTrace.prepare();
081      msSpace.prepare(true);
082      return;
083    }
084
085    if (phaseId == CLOSURE) {
086      msTrace.prepare();
087      return;
088    }
089    if (phaseId == RELEASE) {
090      msTrace.release();
091      msSpace.release();
092      super.collectionPhase(phaseId);
093      return;
094    }
095
096    super.collectionPhase(phaseId);
097  }
098
099  /*****************************************************************************
100   * Accounting
101   */
102
103  /**
104   * {@inheritDoc}
105   * The superclass accounts for its spaces, we just
106   * augment this with the mark-sweep space's contribution.
107   */
108  @Override
109  public int getPagesUsed() {
110    return (msSpace.reservedPages() + super.getPagesUsed());
111  }
112
113  /*****************************************************************************
114   * Miscellaneous
115   */
116
117  /**
118   * {@inheritDoc}
119   */
120  @Override
121  public boolean willNeverMove(ObjectReference object) {
122    if (Space.isInSpace(MARK_SWEEP, object))
123      return true;
124    return super.willNeverMove(object);
125  }
126
127  @Interruptible
128  @Override
129  protected void registerSpecializedMethods() {
130    TransitiveClosure.registerSpecializedScan(SCAN_MARK, MSTraceLocal.class);
131    super.registerSpecializedMethods();
132  }
133}