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.semispace.gctrace;
014    
015    import org.mmtk.plan.*;
016    import org.mmtk.plan.semispace.*;
017    import org.mmtk.vm.VM;
018    
019    import org.vmmagic.pragma.*;
020    
021    
022    /**
023     * This class implements <i>per-collector thread</i> behavior and state for the
024     * <i>GCTrace</i> plan, which implements a GC tracing algorithm.<p>
025     *
026     * Specifically, this class defines <i>SS</i> collection behavior
027     * (through <code>inducedTrace</code> and the <code>collectionPhase</code>
028     * method), and collection-time allocation (copying of objects).<p>
029     *
030     * See {@link GCTrace} for an overview of the GC trace algorithm.<p>
031     *
032     * @see SSCollector
033     * @see GCTrace
034     * @see GCTraceMutator
035     * @see org.mmtk.plan.StopTheWorldCollector
036     * @see org.mmtk.plan.CollectorContext
037     */
038    @Uninterruptible public class GCTraceCollector extends SSCollector {
039      /****************************************************************************
040       * Instance fields
041       */
042      protected final GCTraceTraceLocal inducedTrace;
043    
044      /****************************************************************************
045       *
046       * Initialization
047       */
048    
049      /**
050       * Constructor
051       */
052      public GCTraceCollector() {
053        inducedTrace = new GCTraceTraceLocal(global().ssTrace);
054      }
055    
056      /****************************************************************************
057       *
058       * Collection
059       */
060    
061      /**
062       * Perform a per-collector collection phase.
063       *
064       * @param phaseId The collection phase to perform
065       * @param primary perform any single-threaded local activities.
066       */
067      public void collectionPhase(short phaseId, boolean primary) {
068        if (phaseId == GCTrace.CLOSURE) {
069          inducedTrace.completeTrace();
070          return;
071        }
072    
073        if (phaseId == GCTrace.RELEASE) {
074          inducedTrace.release();
075          if (!GCTrace.traceInducedGC) {
076            super.collectionPhase(phaseId, primary);
077          }
078          return;
079        }
080    
081        /* fall through case */
082        if (!GCTrace.traceInducedGC ||
083            ((phaseId != StopTheWorld.SOFT_REFS) &&
084             (phaseId != StopTheWorld.WEAK_REFS) &&
085             (phaseId != StopTheWorld.PHANTOM_REFS) &&
086             (phaseId != StopTheWorld.FINALIZABLE) &&
087             (phaseId != SS.PREPARE))) {
088          // Delegate up.
089          super.collectionPhase(phaseId, primary);
090        }
091      }
092    
093      /****************************************************************************
094       *
095       * Miscellaneous
096       */
097    
098      /** @return The active global plan as a <code>GCTrace</code> instance. */
099      @Inline
100      private static GCTrace global() {
101        return (GCTrace) VM.activePlan.global();
102      }
103    
104      /** @return The current trace instance */
105      public TraceLocal getCurrentTrace() {
106        return inducedTrace;
107      }
108    }