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.utility.Constants;
016    import org.mmtk.utility.deque.SharedDeque;
017    import org.mmtk.policy.RawPageSpace;
018    
019    import org.vmmagic.pragma.*;
020    
021    /**
022     * This abstract class implements the core functionality for a transitive
023     * closure over the heap.  This class holds the global state, TraceLocal
024     * and its super-classes handle per-thread state.
025     */
026    @Uninterruptible
027    public class Trace implements Constants {
028    
029      // Global pools for load-balancing deques
030      final SharedDeque valuePool;
031      final SharedDeque rootLocationPool;
032    
033      /**
034       * Constructor
035       */
036      public Trace(RawPageSpace metaDataSpace) {
037        valuePool = new SharedDeque("valuePool",metaDataSpace, 1);
038        rootLocationPool = new SharedDeque("rootLocations", metaDataSpace, 1);
039      }
040    
041      /**
042       * Prepare for a new collection pass.
043       */
044      public void prepareNonBlocking() {
045        valuePool.prepareNonBlocking();
046        rootLocationPool.prepareNonBlocking();
047      }
048    
049      /**
050       * Prepare for a new collection pass.
051       * All active GC threads take part.
052       */
053      public void prepare() {
054        valuePool.prepare();
055        rootLocationPool.prepareNonBlocking();
056      }
057    
058      /**
059       * Release resources after completing a collection pass.
060       */
061      public void release() {
062        valuePool.reset();
063        rootLocationPool.reset();
064      }
065    
066      /**
067       * Is there any work outstanding in this trace. That is are there any pages in the pools.
068       */
069      public boolean hasWork() {
070        return (valuePool.enqueuedPages() + rootLocationPool.enqueuedPages()) > 0;
071      }
072    }