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     */
013    package org.mmtk.plan.marksweep;
014    
015    import org.mmtk.plan.*;
016    import org.mmtk.vm.VM;
017    
018    import org.vmmagic.pragma.*;
019    
020    /**
021     * This class implements <i>per-collector thread</i> behavior
022     * and state for the <i>MS</i> plan, which implements a full-heap
023     * mark-sweep collector.<p>
024     *
025     * Specifically, this class defines <i>MS</i> collection behavior
026     * (through <code>trace</code> and the <code>collectionPhase</code>
027     * method).<p>
028     *
029     * @see MS for an overview of the mark-sweep algorithm.<p>
030     *
031     * @see MS
032     * @see MSMutator
033     * @see StopTheWorldCollector
034     * @see CollectorContext
035     */
036    @Uninterruptible
037    public class MSCollector extends StopTheWorldCollector {
038    
039      /****************************************************************************
040       * Instance fields
041       */
042      protected MSTraceLocal fullTrace = new MSTraceLocal(global().msTrace, null);;
043      protected TraceLocal currentTrace = fullTrace;
044    
045    
046      /****************************************************************************
047       * Collection
048       */
049    
050      /**
051       * Perform a per-collector collection phase.
052       *
053       * @param phaseId The collection phase to perform
054       * @param primary Perform any single-threaded activities using this thread.
055       */
056      @Inline
057      @Override
058      public void collectionPhase(short phaseId, boolean primary) {
059        if (phaseId == MS.PREPARE) {
060          super.collectionPhase(phaseId, primary);
061          fullTrace.prepare();
062          return;
063        }
064    
065        if (phaseId == MS.CLOSURE) {
066          fullTrace.completeTrace();
067          return;
068        }
069    
070        if (phaseId == MS.RELEASE) {
071          fullTrace.release();
072          super.collectionPhase(phaseId, primary);
073          return;
074        }
075    
076        super.collectionPhase(phaseId, primary);
077      }
078    
079    
080      /****************************************************************************
081       * Miscellaneous
082       */
083    
084      /** @return The active global plan as an <code>MS</code> instance. */
085      @Inline
086      private static MS global() {
087        return (MS) VM.activePlan.global();
088      }
089    
090      /** @return The current trace instance. */
091      @Override
092      public final TraceLocal getCurrentTrace() {
093        return currentTrace;
094      }
095    }