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.utility.options;
014
015 /**
016 * The number of GC threads to use for parallel collection.
017 *
018 * This is slightly unclean as the default value is not known at build time.
019 */
020 public final class Threads extends org.vmutil.options.IntOption {
021
022 /** Has a value been set? */
023 private boolean valueSet;
024
025 /**
026 * Create the option.
027 */
028 public Threads() {
029 super(Options.set, "Threads",
030 "Number of GC threads to use",
031 1);
032 valueSet = false;
033 }
034
035 /**
036 * Update the default value, only overriding value if no explicit value was set.
037 *
038 * @param defaultValue The actual default value.
039 */
040 public void updateDefaultValue(int defaultValue) {
041 this.defaultValue = defaultValue;
042 if (!valueSet) {
043 this.value = defaultValue;
044 }
045 }
046
047 /**
048 * Return the number of threads to use, or delegate to the runtime if this has not been set.
049 */
050 @Override
051 public void setValue(int value) {
052 super.setValue(value);
053 valueSet = true;
054 }
055
056 /**
057 * Only accept values of 1 or higher.
058 */
059 @Override
060 protected void validate() {
061 failIf(this.value < 1, "Must have at least one gc thread");
062 }
063 }