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.<p>
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 @Override
044 @Inline
045 public void collectionPhase(short phaseId, boolean primary) {
046 if (phaseId == Simple.PREPARE_STACKS) {
047 if (!Plan.stacksPrepared()) {
048 VM.collection.prepareMutator(this);
049 }
050 flushRememberedSets();
051 return;
052 }
053
054 if (phaseId == Simple.PREPARE) {
055 los.prepare(true);
056 lgcode.prepare(true);
057 smcode.prepare();
058 nonmove.prepare();
059 VM.memory.collectorPrepareVMSpace();
060 return;
061 }
062
063 if (phaseId == Simple.RELEASE) {
064 los.release(true);
065 lgcode.release(true);
066 smcode.release();
067 nonmove.release();
068 VM.memory.collectorReleaseVMSpace();
069 return;
070 }
071
072 Log.write("Per-mutator phase \""); Phase.getPhase(phaseId).logPhase();
073 Log.writeln("\" not handled.");
074 VM.assertions.fail("Per-mutator phase not handled!");
075 }
076 }