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.jikesrvm.mm.mmtk; 014 015import org.mmtk.plan.Plan; 016import org.mmtk.plan.CollectorContext; 017import org.mmtk.plan.MutatorContext; 018import org.mmtk.plan.PlanConstraints; 019import org.mmtk.utility.Log; 020import org.mmtk.utility.options.Options; 021 022import org.jikesrvm.VM; 023import org.jikesrvm.mm.mminterface.Selected; 024import org.jikesrvm.scheduler.RVMThread; 025 026import org.vmmagic.pragma.*; 027 028/** 029 * This class contains interfaces to access the current plan, plan local and 030 * plan constraints instances. 031 */ 032@Uninterruptible public final class ActivePlan extends org.mmtk.vm.ActivePlan { 033 034 private static SynchronizedCounter mutatorCounter = new SynchronizedCounter(); 035 036 @Override 037 @Inline 038 public Plan global() { 039 return Selected.Plan.get(); 040 } 041 042 @Override 043 @Inline 044 public PlanConstraints constraints() { 045 return Selected.Constraints.get(); 046 } 047 048 @Override 049 @Inline 050 public int collectorCount() { 051 return Options.threads.getValue(); 052 } 053 054 @Override 055 @Inline 056 public CollectorContext collector() { 057 return RVMThread.getCurrentThread().getCollectorContext(); 058 } 059 060 @Override 061 @Inline 062 public boolean isMutator() { 063 return !RVMThread.getCurrentThread().isCollectorThread(); 064 } 065 066 @Override 067 @Inline 068 public MutatorContext mutator() { 069 return Selected.Mutator.get(); 070 } 071 072 @Override 073 public Log log() { 074 if (VM.runningVM) { 075 return Selected.Mutator.get().getLog(); 076 } else { 077 return buildLog; 078 } 079 } 080 081 /** Log instance used at build time */ 082 private static final Log buildLog = new Log(); 083 084 @Override 085 public void resetMutatorIterator() { 086 mutatorCounter.reset(); 087 } 088 089 @Override 090 public MutatorContext getNextMutator() { 091 for (;;) { 092 int idx = mutatorCounter.increment(); 093 if (idx >= RVMThread.numThreads) { 094 return null; 095 } else { 096 RVMThread t = RVMThread.threads[idx]; 097 if (t.activeMutatorContext) { 098 return t; 099 } 100 } 101 } 102 } 103}