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.jikesrvm.mm.mmtk;
014
015 import org.mmtk.plan.Plan;
016 import org.mmtk.plan.CollectorContext;
017 import org.mmtk.plan.MutatorContext;
018 import org.mmtk.plan.PlanConstraints;
019 import org.mmtk.utility.Log;
020
021 import org.jikesrvm.mm.mminterface.Selected;
022 import org.jikesrvm.scheduler.RVMThread;
023
024 import org.vmmagic.pragma.*;
025
026 /**
027 * This class contains interfaces to access the current plan, plan local and
028 * plan constraints instances.
029 */
030 @Uninterruptible public final class ActivePlan extends org.mmtk.vm.ActivePlan {
031
032 private static SynchronizedCounter mutatorCounter = new SynchronizedCounter();
033
034 /** @return The active Plan instance. */
035 @Inline
036 public Plan global() {
037 return Selected.Plan.get();
038 }
039
040 /** @return The active PlanConstraints instance. */
041 @Inline
042 public PlanConstraints constraints() {
043 return Selected.Constraints.get();
044 }
045
046 /** @return The number of registered CollectorContext instances. */
047 @Inline
048 public int collectorCount() {
049 return RVMThread.numProcessors;
050 }
051
052 /** @return The active CollectorContext instance. */
053 @Inline
054 public CollectorContext collector() {
055 return Selected.Collector.get();
056 }
057
058 /** @return The active MutatorContext instance. */
059 @Inline
060 public MutatorContext mutator() {
061 return Selected.Mutator.get();
062 }
063
064 /** @return The log for the active thread */
065 public Log log() {
066 return Selected.Mutator.get().getLog();
067 }
068
069 /** Reset the mutator iterator */
070 public void resetMutatorIterator() {
071 mutatorCounter.reset();
072 }
073
074 /**
075 * Return the next <code>MutatorContext</code> in a
076 * synchronized iteration of all mutators.
077 *
078 * @return The next <code>MutatorContext</code> in a
079 * synchronized iteration of all mutators, or
080 * <code>null</code> when all mutators have been done.
081 */
082 public MutatorContext getNextMutator() {
083 for (;;) {
084 int idx = mutatorCounter.increment();
085 if (idx >= RVMThread.numThreads) {
086 return null;
087 } else {
088 RVMThread t=RVMThread.threads[idx];
089 if (t.activeMutatorContext) {
090 return t;
091 }
092 }
093 }
094 }
095 }