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.marksweep; 014 015import org.mmtk.plan.*; 016import org.mmtk.vm.VM; 017 018import 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. 030 * 031 * @see MS 032 * @see MSMutator 033 * @see StopTheWorldCollector 034 * @see CollectorContext 035 */ 036@Uninterruptible 037public class MSCollector extends StopTheWorldCollector { 038 039 /**************************************************************************** 040 * Instance fields 041 */ 042 043 /** 044 * 045 */ 046 protected MSTraceLocal fullTrace = new MSTraceLocal(global().msTrace, null);; 047 protected TraceLocal currentTrace = fullTrace; 048 049 050 /**************************************************************************** 051 * Collection 052 */ 053 054 /** 055 * {@inheritDoc} 056 */ 057 @Inline 058 @Override 059 public void collectionPhase(short phaseId, boolean primary) { 060 if (phaseId == MS.PREPARE) { 061 super.collectionPhase(phaseId, primary); 062 fullTrace.prepare(); 063 return; 064 } 065 066 if (phaseId == MS.CLOSURE) { 067 fullTrace.completeTrace(); 068 return; 069 } 070 071 if (phaseId == MS.RELEASE) { 072 fullTrace.release(); 073 super.collectionPhase(phaseId, primary); 074 return; 075 } 076 077 super.collectionPhase(phaseId, primary); 078 } 079 080 081 /**************************************************************************** 082 * Miscellaneous 083 */ 084 085 /** @return The active global plan as an <code>MS</code> instance. */ 086 @Inline 087 private static MS global() { 088 return (MS) VM.activePlan.global(); 089 } 090 091 @Override 092 public final TraceLocal getCurrentTrace() { 093 return currentTrace; 094 } 095}