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.concurrent.marksweep;
014
015import org.mmtk.plan.*;
016import org.mmtk.plan.concurrent.ConcurrentCollector;
017import org.mmtk.vm.VM;
018
019import org.vmmagic.pragma.*;
020
021/**
022 * This class implements <i>per-collector thread</i> behavior
023 * and state for the <i>CMS</i> plan, which implements a full-heap
024 * concurrent mark-sweep collector.
025 */
026@Uninterruptible
027public class CMSCollector extends ConcurrentCollector {
028
029  /****************************************************************************
030   * Instance fields
031   */
032  protected final CMSTraceLocal trace;
033
034  /****************************************************************************
035   * Initialization
036   */
037
038  /**
039   * Constructor
040   */
041  public CMSCollector() {
042    trace = new CMSTraceLocal(global().msTrace);
043  }
044
045  /****************************************************************************
046   *
047   * Collection
048   */
049
050  /**
051   * {@inheritDoc}
052   */
053  @Override
054  @Inline
055  public void collectionPhase(short phaseId, boolean primary) {
056    if (phaseId == CMS.PREPARE) {
057      super.collectionPhase(phaseId, primary);
058      trace.prepare();
059      return;
060    }
061
062    if (phaseId == CMS.CLOSURE) {
063      trace.completeTrace();
064      return;
065    }
066
067    if (phaseId == CMS.RELEASE) {
068      trace.release();
069      super.collectionPhase(phaseId, primary);
070      return;
071    }
072
073    super.collectionPhase(phaseId, primary);
074  }
075
076  @Override
077  protected boolean concurrentTraceComplete() {
078    if (!global().msTrace.hasWork()) {
079      return true;
080    }
081    return false;
082  }
083
084  /****************************************************************************
085   *
086   * Miscellaneous
087   */
088
089  /** @return The active global plan as an <code>MS</code> instance. */
090  @Inline
091  private static CMS global() {
092    return (CMS) VM.activePlan.global();
093  }
094
095  /** @return The current trace instance. */
096  @Override
097  public final TraceLocal getCurrentTrace() {
098    return trace;
099  }
100}