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;
014    
015    import org.mmtk.vm.VM;
016    
017    import org.vmmagic.pragma.*;
018    
019    /**
020     * TODO: Documentation.
021     */
022    @Uninterruptible
023    public abstract class ParallelCollector extends CollectorContext {
024    
025      /****************************************************************************
026       * Instance fields
027       */
028    
029      /** The group that this collector context is running in (may be null) */
030      protected ParallelCollectorGroup group;
031    
032      /** Last group trigger index (see CollectorContextGroup) */
033      int lastTriggerCount;
034    
035      /** The index of this thread in the collector context group. */
036      int workerOrdinal;
037    
038      /****************************************************************************
039       * Collection.
040       */
041    
042      /**
043       * {@inheritDoc}
044       */
045      @Override
046      @Unpreemptible
047      public void run() {
048        while(true) {
049          park();
050          collect();
051        }
052      }
053    
054      /** Perform a single garbage collection */
055      public void collect() {
056        VM.assertions.fail("Collector has not implemented collectionPhase");
057      }
058    
059      /**
060       * Perform a (local, i.e.per-collector) collection phase.
061       *
062       * @param phaseId The unique phase identifier
063       * @param primary Should this thread be used to execute any single-threaded
064       * local operations?
065       */
066      public void collectionPhase(short phaseId, boolean primary) {
067        VM.assertions.fail("Collector has not implemented collectionPhase");
068      }
069    
070      /**
071       * @return The current trace instance.
072       */
073      public TraceLocal getCurrentTrace() {
074        VM.assertions.fail("Collector has not implemented getCurrentTrace");
075        return null;
076      }
077    
078      /**
079       * Park this thread into the group, waiting for a request.
080       */
081      public final void park() {
082        if (VM.VERIFY_ASSERTIONS) VM.assertions._assert(this.group != null);
083        group.park(this);
084      }
085    
086      @Override
087      public int parallelWorkerCount() {
088        return group.activeWorkerCount();
089      }
090    
091      @Override
092      public int parallelWorkerOrdinal() {
093        return workerOrdinal;
094      }
095    
096      @Override
097      public int rendezvous() {
098        return group.rendezvous();
099      }
100    }