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; 014 015import org.mmtk.utility.deque.SharedDeque; 016import org.mmtk.policy.RawPageSpace; 017 018import org.vmmagic.pragma.*; 019 020/** 021 * This abstract class implements the core functionality for a transitive 022 * closure over the heap. This class holds the global state, TraceLocal 023 * and its super-classes handle per-thread state. 024 */ 025@Uninterruptible 026public class Trace { 027 028 // Global pools for load-balancing deques 029 final SharedDeque valuePool; 030 final SharedDeque rootLocationPool; 031 032 /** 033 * @param metaDataSpace the space to use for allocation for this 034 * instance 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 * @return whether there is any work outstanding in this trace. 068 * That is are there any pages in the pools. 069 */ 070 public boolean hasWork() { 071 return (valuePool.enqueuedPages() + rootLocationPool.enqueuedPages()) > 0; 072 } 073}