Revision: 15731
http://jikesrvm.svn.sourceforge.net/jikesrvm/?rev=15731&view=revAuthor: rgarner
Date: 2009-07-21 04:20:25 +0000 (Tue, 21 Jul 2009)
Log Message:
-----------
Allow for set-valued options in the Harness
Modified Paths:
--------------
rvmroot/trunk/MMTk/harness/src/org/mmtk/harness/lang/Trace.java
rvmroot/trunk/MMTk/harness/src/org/mmtk/harness/options/HarnessOptionSet.java
rvmroot/trunk/MMTk/harness/src/org/mmtk/harness/options/Trace.java
Added Paths:
-----------
rvmroot/trunk/MMTk/harness/src/org/mmtk/harness/options/EnumSetOption.java
rvmroot/trunk/MMTk/harness/src/org/mmtk/harness/options/IntSetOption.java
Modified: rvmroot/trunk/MMTk/harness/src/org/mmtk/harness/lang/Trace.java
===================================================================
--- rvmroot/trunk/MMTk/harness/src/org/mmtk/harness/lang/Trace.java 2009-07-21 04:11:55 UTC (rev 15730)
+++ rvmroot/trunk/MMTk/harness/src/org/mmtk/harness/lang/Trace.java 2009-07-21 04:20:25 UTC (rev 15731)
@@ -27,22 +27,27 @@
*/
public enum Item {
/** Object allocation */ ALLOC,
+ /** Available byte operations */ AVBYTE,
/** Procedure calls in the harness language */ CALL,
- /** Object reads and writes */ OBJECT,
+ /** Harness language semantic checker */ CHECKER,
+ /** Garbage collection */ COLLECT,
+ /** P-code compiler */ COMPILER,
+ /** Environment (stack frame) loads/stores */ ENV,
+ /** P-code evaluation */ EVAL,
+ /** Hashcode operations */ HASH,
/** Calls to intrinsic methods in the harness language */ INTRINSIC,
/** Load operations in the harness language */ LOAD,
+ /** Memory operations (mmap, zero etc) */ MEMORY,
+ /** Object reads and writes */ OBJECT,
+ /** Harness language parser */ PARSER,
+ /** Reference type processing */ REFERENCES,
+ /** Remset */ REMSET,
+ /** Tracing of roots */ ROOTS,
+ /** Sanity checker - verbose output */ SANITY,
+ /** Harness language thread scheduler */ SCHEDULER,
+ /** Harness language simplifier */ SIMPLIFIER,
/** Store operations in the harness language */ STORE,
- /** Hashcode operations */ HASH,
- /** Environment (stack frame) loads/stores */ ENV,
- /** Tracing of roots */ ROOTS,
- /** Garbage collection */ COLLECT,
- /** Available byte operations */ AVBYTE,
- /** P-code evaluation */ EVAL,
- /** P-code compiler */ COMPILER,
- /** Harness language semantic checker */ CHECKER,
- /** Harness language thread scheduler */ SCHEDULER,
- /** Harness language parser */ PARSER,
- /** Harness language simplifier */ SIMPLIFIER
+ /** calls to traceObject during GC */ TRACEOBJECT,
}
private static EnumSet<Item> enabled = EnumSet.noneOf(Item.class);
@@ -88,21 +93,44 @@
return enabled.contains(item);
}
+ /**
+ * Print a message iff tracing for the given item is enabled.
+ * @param item The trace item
+ * @param pattern String pattern (as per java.lang.String#format(...))
+ * @param args Format arguments
+ */
public static synchronized void trace(Item item, String pattern, Object...args) {
if (isEnabled(item)) {
- printf(item, pattern, args);
+ printf(item, pattern + "%n", args);
}
}
+ /**
+ * Message prefix for messages enabled by a given trace item
+ * @param item The trace item
+ * @return The string prefix
+ */
public static String prefix(Item item) {
return "["+item+"] ";
}
+ /**
+ * Print a message as trace output.
+ * @param item The trace item
+ * @param pattern String pattern (as per java.lang.String#format(...))
+ * @param args Format arguments
+ */
public static void printf(Item item, String pattern, Object... args) {
- printf(prefix(item) + pattern + "%n",args);
+ printf(prefix(item) + pattern ,args);
}
+ /**
+ * Print a raw message as trace output.
+ * @param pattern String pattern (as per java.lang.String#format(...))
+ * @param args Format arguments
+ */
public static void printf(String pattern, Object...args) {
System.err.printf(pattern,args);
+ System.err.flush();
}
}
Added: rvmroot/trunk/MMTk/harness/src/org/mmtk/harness/options/EnumSetOption.java
===================================================================
--- rvmroot/trunk/MMTk/harness/src/org/mmtk/harness/options/EnumSetOption.java (rev 0)
+++ rvmroot/trunk/MMTk/harness/src/org/mmtk/harness/options/EnumSetOption.java 2009-07-21 04:20:25 UTC (rev 15731)
@@ -0,0 +1,142 @@
+/*
+ * This file is part of the Jikes RVM project (
http://jikesrvm.org).
+ *
+ * This file is licensed to You under the Eclipse Public License (EPL);
+ * You may not use this file except in compliance with the License. You
+ * may obtain a copy of the License at
+ *
+ *
http://www.opensource.org/licenses/eclipse-1.0.php+ *
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership.
+ */
+package org.mmtk.harness.options;
+
+import static org.mmtk.harness.options.HarnessOptionSet.ENUM_SET_OPTION;
+
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.vmmagic.pragma.Uninterruptible;
+import org.vmutil.options.Option;
+import org.vmutil.options.OptionSet;
+
+/**
+ * A set-valued option, eg opt=v1,v2,v3
+ * The values of the set come from an enumeration
+ */
+public class EnumSetOption extends Option {
+
+ // values
+ protected Set<Integer> defaultValues;
+ protected Set<Integer> values;
+ protected String[] options;
+
+ /**
+ * Create a new enumeration option.
+ *
+ * @param set The option set this option belongs to.
+ * @param name The space separated name for the option.
+ * @param description The purpose of the option.
+ * @param values A mapping of int to string for the enum.
+ * @param defaultValue The default value of the option.
+ */
+ protected EnumSetOption(OptionSet set, String name, String description, String[] options, String defaultValues) {
+ super(set, ENUM_SET_OPTION, name, description);
+ this.options = options;
+ this.values = this.defaultValues = findValues(defaultValues);
+ }
+
+ /**
+ * Search for a string in the enumeration.
+ *
+ * @return The index of the passed string.
+ */
+ private int findValue(String string) {
+ for (int i = 0; i < options.length; i++) {
+ if (options[i].equals(string)) {
+ return i;
+ }
+ }
+ fail("Invalid Enumeration Value, \""+string+"\"");
+ return -1;
+ }
+
+ /**
+ * Search for a string in the enumeration.
+ *
+ * @return The index of the passed string.
+ */
+ private Set<Integer> findValues(String string) {
+ Set<Integer> results = new TreeSet<Integer>();
+ for (String str : string.split(",")) {
+ if (!str.equals("")) {
+ results.add(findValue(str));
+ }
+ }
+ return results;
+ }
+
+ /**
+ * Read the current value of the option.
+ *
+ * @return The option value.
+ */
+ @Uninterruptible
+ public Set<Integer> getValue() {
+ return this.values;
+ }
+
+ /**
+ * Read the default value of the option.
+ *
+ * @return The default value.
+ */
+ @Uninterruptible
+ public Set<Integer> getDefaultValue() {
+ return this.defaultValues;
+ }
+
+ /**
+ * Update the value of the option, echoing the change if the echoOptions
+ * option is set. This method also calls the validate method to allow
+ * subclasses to perform any required validation.
+ *
+ * @param values The new value for the option.
+ */
+ public void setValue(Set<Integer> values) {
+ this.values = values;
+ validate();
+ set.logChange(this);
+ }
+
+ /**
+ * Look up the value for a string and update the value of the option
+ * accordingly, echoing the change if the echoOptions option is set.
+ * This method also calls the validate method to allow subclasses to
+ * perform any required validation.
+ *
+ * @param value The new value for the option.
+ */
+ public void setValue(String value) {
+ setValue(findValues(value));
+ }
+
+ /**
+ * Modify the default value of the option.
+ *
+ * @param values The new default value for the option.
+ */
+ public void setDefaultValue(String values) {
+ this.values = this.defaultValues = findValues(values);
+ }
+
+ /**
+ * Return the array of allowed enumeration values.
+ *
+ * @return The values array.
+ */
+ public String[] getValues() {
+ return this.options;
+ }
+}
Modified: rvmroot/trunk/MMTk/harness/src/org/mmtk/harness/options/HarnessOptionSet.java
===================================================================
--- rvmroot/trunk/MMTk/harness/src/org/mmtk/harness/options/HarnessOptionSet.java 2009-07-21 04:11:55 UTC (rev 15730)
+++ rvmroot/trunk/MMTk/harness/src/org/mmtk/harness/options/HarnessOptionSet.java 2009-07-21 04:20:25 UTC (rev 15731)
@@ -12,8 +12,12 @@
*/
package org.mmtk.harness.options;
+import java.util.TreeSet;
+
import org.vmmagic.pragma.Uninterruptible;
-import org.vmmagic.unboxed.*;
+import org.vmmagic.unboxed.Extent;
+import org.vmmagic.unboxed.Word;
+import org.vmmagic.unboxed.SimulatedMemory;
import org.vmutil.options.AddressOption;
import org.vmutil.options.BooleanOption;
import org.vmutil.options.EnumOption;
@@ -29,6 +33,16 @@
*/
public final class HarnessOptionSet extends org.vmutil.options.OptionSet {
+ /*
+ * The following 2 option types are used only by the MMTk Harness,
+ * since they are hard to implement without allocating.
+ */
+ /** A Set<Enum> valued option */
+ public static final int ENUM_SET_OPTION = 1001;
+
+ /** A multi-valued integer valued option */
+ public static final int INT_SET_OPTION = 1011;
+
/**
* Take a string (most likely a command-line argument) and try to proccess it
* as an option command. Return true if the string was understood, false
@@ -129,12 +143,34 @@
return true;
} catch (NumberFormatException nfe) {}
return false;
+ case ENUM_SET_OPTION:
+ ((EnumSetOption)o).setValue(value);
+ return true;
+ case INT_SET_OPTION:
+ try {
+ ((IntSetOption)o).setValue(parseIntSet(value));
+ } catch (NumberFormatException nfe) {
+ return false;
+ }
+ return true;
}
// None of the above tests matched, so this wasn't an option
return false;
}
+ private int[] parseIntSet(String value) {
+ TreeSet<Integer> intSetValues = new TreeSet<Integer>();
+ for (String element : value.split(",")) {
+ intSetValues.add(Integer.valueOf(element));
+ }
+ int[] intValues = new int[intSetValues.size()];
+ for (int i=0; i < intValues.length; i++) {
+ intValues[i] = intSetValues.pollFirst();
+ }
+ return intValues;
+ }
+
/**
* Print a short description of every option
*/
@@ -277,6 +313,7 @@
* @param o The option.
* @param forXml Is this part of xml output?
*/
+ @Override
protected void logValue(Option o, boolean forXml) {
switch (o.getType()) {
case Option.BOOLEAN_OPTION:
@@ -311,6 +348,7 @@
/**
* Log a string.
*/
+ @Override
protected void logString(String s) {
System.err.print(s);
}
@@ -318,6 +356,7 @@
/**
* Print a new line.
*/
+ @Override
protected void logNewLine() {
System.err.println();
}
@@ -329,6 +368,7 @@
* @param name The option name.
* @return The VM specific key.
*/
+ @Override
protected String computeKey(String name) {
int space = name.indexOf(' ');
if (space < 0) return name.toLowerCase();
@@ -354,6 +394,7 @@
* @param o The responsible option.
* @param message The message associated with the warning.
*/
+ @Override
protected void warn(Option o, String message) {
System.err.println("WARNING: Option '" + o.getKey() + "' : " + message);
}
@@ -365,6 +406,7 @@
* @param o The responsible option.
* @param message The error message associated with the failure.
*/
+ @Override
protected void fail(Option o, String message) {
throw new RuntimeException("Option '" + o.getKey() + "' : " + message);
}
@@ -375,6 +417,7 @@
* @param bytes The number of bytes.
* @return The corresponding number of pages.
*/
+ @Override
@Uninterruptible
protected int bytesToPages(Extent bytes) {
return bytes.plus(SimulatedMemory.BYTES_IN_PAGE-1).toWord().rshl(SimulatedMemory.LOG_BYTES_IN_PAGE).toInt();
@@ -385,6 +428,7 @@
* @param pages the number of pages.
* @return The corresponding number of bytes.
*/
+ @Override
@Uninterruptible
protected Extent pagesToBytes(int pages) {
return Word.fromIntZeroExtend(pages).lsh(SimulatedMemory.LOG_BYTES_IN_PAGE).toExtent();
Added: rvmroot/trunk/MMTk/harness/src/org/mmtk/harness/options/IntSetOption.java
===================================================================
--- rvmroot/trunk/MMTk/harness/src/org/mmtk/harness/options/IntSetOption.java (rev 0)
+++ rvmroot/trunk/MMTk/harness/src/org/mmtk/harness/options/IntSetOption.java 2009-07-21 04:20:25 UTC (rev 15731)
@@ -0,0 +1,76 @@
+/*
+ * This file is part of the Jikes RVM project (
http://jikesrvm.org).
+ *
+ * This file is licensed to You under the Eclipse Public License (EPL);
+ * You may not use this file except in compliance with the License. You
+ * may obtain a copy of the License at
+ *
+ *
http://www.opensource.org/licenses/eclipse-1.0.php+ *
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership.
+ */
+package org.mmtk.harness.options;
+
+import static org.mmtk.harness.options.HarnessOptionSet.INT_SET_OPTION;
+
+import org.vmmagic.pragma.Uninterruptible;
+import org.vmutil.options.Option;
+import org.vmutil.options.OptionSet;
+
+/**
+ * A set-valued option, eg opt=v1,v2,v3
+ * The values of the set are integers
+ */
+public class IntSetOption extends Option {
+
+ // values
+ protected int[] defaultValues;
+ protected int[] values;
+
+ /**
+ * Create a new enumeration option.
+ *
+ * @param set The option set this option belongs to.
+ * @param name The space separated name for the option.
+ * @param description The purpose of the option.
+ * @param values A mapping of int to string for the enum.
+ * @param defaultValue The default value of the option.
+ */
+ protected IntSetOption(OptionSet set, String name, String description, int[] defaultValues) {
+ super(set, INT_SET_OPTION, name, description);
+ this.values = this.defaultValues = defaultValues;
+ }
+ /**
+ * Read the current value of the option.
+ *
+ * @return The option value.
+ */
+ @Uninterruptible
+ public int[] getValue() {
+ return this.values;
+ }
+
+ /**
+ * Read the default value of the option.
+ *
+ * @return The default value.
+ */
+ @Uninterruptible
+ public int[] getDefaultValue() {
+ return this.defaultValues;
+ }
+
+ /**
+ * Update the value of the option, echoing the change if the echoOptions
+ * option is set. This method also calls the validate method to allow
+ * subclasses to perform any required validation.
+ *
+ * @param values The new value for the option.
+ */
+ public void setValue(int[] values) {
+ this.values = values;
+ validate();
+ set.logChange(this);
+ }
+}
Modified: rvmroot/trunk/MMTk/harness/src/org/mmtk/harness/options/Trace.java
===================================================================
--- rvmroot/trunk/MMTk/harness/src/org/mmtk/harness/options/Trace.java 2009-07-21 04:11:55 UTC (rev 15730)
+++ rvmroot/trunk/MMTk/harness/src/org/mmtk/harness/options/Trace.java 2009-07-21 04:20:25 UTC (rev 15731)
@@ -17,7 +17,7 @@
/**
* Number of collector threads.
*/
-public final class Trace extends org.vmutil.options.EnumOption {
+public final class Trace extends EnumSetOption {
/**
* Create the option.
*/
@@ -25,16 +25,21 @@
super(Harness.options, "Trace",
"Harness debugging trace options",
org.mmtk.harness.lang.Trace.itemNames(),
- System.getProperty("mmtk.harness.trace", "NONE"));
+ System.getProperty("mmtk.harness.trace", ""));
}
+ /**
+ * Apply the effects of this option
+ */
public void apply() {
- switch(getValue()) {
- case 0:
- break;
- default: {
- org.mmtk.harness.lang.Trace.enable(values[getValue()]);
- break;
+ for (int value : getValue()) {
+ switch(value) {
+ case 0:
+ break;
+ default: {
+ org.mmtk.harness.lang.Trace.enable(options[value]);
+ break;
+ }
}
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge
This is your chance to win up to $100,000 in prizes! For a limited time,
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize
details at:
http://p.sf.net/sfu/Challenge_______________________________________________
Jikesrvm-commits mailing list
Jikesrvm-commits@...
https://lists.sourceforge.net/lists/listinfo/jikesrvm-commits