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.Log;
016 import org.mmtk.vm.VM;
017
018 import org.vmmagic.pragma.*;
019
020 /**
021 * This class (and its sub-classes) implement <i>per-mutator thread</i>
022 * behavior and state.
023 *
024 * MMTk assumes that the VM instantiates instances of MutatorContext
025 * in thread local storage (TLS) for each application thread. Accesses
026 * to this state are therefore assumed to be low-cost during mutator
027 * time.<p>
028 *
029 * @see MutatorContext
030 */
031 @Uninterruptible
032 public abstract class SimpleMutator extends MutatorContext {
033
034 /****************************************************************************
035 *
036 * Collection.
037 */
038
039 /**
040 * Perform a per-mutator collection phase. This is executed by
041 * one collector thread on behalf of a mutator thread.
042 *
043 * @param phaseId The unique phase identifier
044 * @param primary Should this thread be used to execute any single-threaded
045 * local operations?
046 */
047 @Inline
048 public void collectionPhase(short phaseId, boolean primary) {
049 if (phaseId == Simple.PREPARE_STACKS) {
050 if (!Plan.stacksPrepared()) {
051 VM.collection.prepareMutator(this);
052 }
053 flushRememberedSets();
054 return;
055 }
056
057 if (phaseId == Simple.PREPARE) {
058 los.prepare(true);
059 lgcode.prepare(true);
060 smcode.prepare();
061 nonmove.prepare();
062 VM.memory.collectorPrepareVMSpace();
063 return;
064 }
065
066 if (phaseId == Simple.RELEASE) {
067 los.release(true);
068 lgcode.release(true);
069 smcode.release();
070 nonmove.release();
071 VM.memory.collectorReleaseVMSpace();
072 return;
073 }
074
075 Log.write("Per-mutator phase \""); Phase.getPhase(phaseId).logPhase();
076 Log.writeln("\" not handled.");
077 VM.assertions.fail("Per-mutator phase not handled!");
078 }
079 }