changeset 22470:eaf97ec55a78

Merge
author Christian Wimmer <christian.wimmer@oracle.com>
date Wed, 26 Aug 2015 15:06:50 -0700
parents f58e7b5fe0ab (current diff) a6adaf9c330d (diff)
children a69a8d96ee6e
files
diffstat 6 files changed, 46 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/jvmci/jdk.internal.jvmci.options.processor/src/jdk/internal/jvmci/options/processor/OptionProcessor.java	Tue Aug 25 22:58:03 2015 +0200
+++ b/jvmci/jdk.internal.jvmci.options.processor/src/jdk/internal/jvmci/options/processor/OptionProcessor.java	Wed Aug 26 15:06:50 2015 -0700
@@ -191,9 +191,9 @@
                 String declaringClass = option.declaringClass;
                 Name fieldName = option.field.getSimpleName();
                 if (info.options.size() == 1) {
-                    out.printf("            return new %s(\"%s\", %s.class, \"%s\", %s.class, \"%s\", %s);\n", desc, name, type, help, declaringClass, fieldName, optionValue);
+                    out.printf("            return %s.create(\"%s\", %s.class, \"%s\", %s.class, \"%s\", %s);\n", desc, name, type, help, declaringClass, fieldName, optionValue);
                 } else {
-                    out.printf("            case \"" + name + "\": return new %s(\"%s\", %s.class, \"%s\", %s.class, \"%s\", %s);\n", desc, name, type, help, declaringClass, fieldName, optionValue);
+                    out.printf("            case \"" + name + "\": return %s.create(\"%s\", %s.class, \"%s\", %s.class, \"%s\", %s);\n", desc, name, type, help, declaringClass, fieldName, optionValue);
                 }
             }
             out.println("        }");
@@ -219,7 +219,7 @@
                 String declaringClass = option.declaringClass;
                 Name fieldName = option.field.getSimpleName();
                 String comma = i == info.options.size() - 1 ? "" : ",";
-                out.printf("            new %s(\"%s\", %s.class, \"%s\", %s.class, \"%s\", %s)%s\n", desc, name, type, help, declaringClass, fieldName, optionValue, comma);
+                out.printf("            %s.create(\"%s\", %s.class, \"%s\", %s.class, \"%s\", %s)%s\n", desc, name, type, help, declaringClass, fieldName, optionValue, comma);
                 i++;
             }
             out.println("        );");
--- a/jvmci/jdk.internal.jvmci.options.test/src/jdk/internal/jvmci/options/test/NestedBooleanOptionValueTest.java	Tue Aug 25 22:58:03 2015 +0200
+++ b/jvmci/jdk.internal.jvmci.options.test/src/jdk/internal/jvmci/options/test/NestedBooleanOptionValueTest.java	Wed Aug 26 15:06:50 2015 -0700
@@ -40,12 +40,12 @@
         public static final OptionValue<Boolean> NestedOption2 = new NestedBooleanOptionValue(Master2, false);
     }
 
-    static final OptionDescriptor master0 = new OptionDescriptor("Master0", Boolean.class, "", Options.class, "Master0", Master0);
-    static final OptionDescriptor nestedOption0 = new OptionDescriptor("NestedOption0", Boolean.class, "", Options.class, "NestedOption0", NestedOption0);
-    static final OptionDescriptor master1 = new OptionDescriptor("Master1", Boolean.class, "", Options.class, "Master1", Master1);
-    static final OptionDescriptor nestedOption1 = new OptionDescriptor("NestedOption1", Boolean.class, "", Options.class, "NestedOption1", NestedOption1);
-    static final OptionDescriptor master2 = new OptionDescriptor("Master2", Boolean.class, "", Options.class, "Master2", Master2);
-    static final OptionDescriptor nestedOption2 = new OptionDescriptor("NestedOption2", Boolean.class, "", Options.class, "NestedOption2", NestedOption2);
+    static final OptionDescriptor master0 = OptionDescriptor.create("Master0", Boolean.class, "", Options.class, "Master0", Master0);
+    static final OptionDescriptor nestedOption0 = OptionDescriptor.create("NestedOption0", Boolean.class, "", Options.class, "NestedOption0", NestedOption0);
+    static final OptionDescriptor master1 = OptionDescriptor.create("Master1", Boolean.class, "", Options.class, "Master1", Master1);
+    static final OptionDescriptor nestedOption1 = OptionDescriptor.create("NestedOption1", Boolean.class, "", Options.class, "NestedOption1", NestedOption1);
+    static final OptionDescriptor master2 = OptionDescriptor.create("Master2", Boolean.class, "", Options.class, "Master2", Master2);
+    static final OptionDescriptor nestedOption2 = OptionDescriptor.create("NestedOption2", Boolean.class, "", Options.class, "NestedOption2", NestedOption2);
 
     @Test
     public void runOverrides() {
--- a/jvmci/jdk.internal.jvmci.options.test/src/jdk/internal/jvmci/options/test/TestOptionValue.java	Tue Aug 25 22:58:03 2015 +0200
+++ b/jvmci/jdk.internal.jvmci.options.test/src/jdk/internal/jvmci/options/test/TestOptionValue.java	Wed Aug 26 15:06:50 2015 -0700
@@ -40,9 +40,9 @@
         public static final OptionValue<String> SecondMutable = new OptionValue<>("second");
     }
 
-    static final OptionDescriptor stable = new OptionDescriptor("Stable", Boolean.class, "", Options.class, "Stable", Stable);
-    static final OptionDescriptor mutable = new OptionDescriptor("Mutable", String.class, "", Options.class, "Mutable", Mutable);
-    static final OptionDescriptor secondMutable = new OptionDescriptor("SecondMutable", String.class, "", Options.class, "SecondMutable", SecondMutable);
+    static final OptionDescriptor stable = OptionDescriptor.create("Stable", Boolean.class, "", Options.class, "Stable", Stable);
+    static final OptionDescriptor mutable = OptionDescriptor.create("Mutable", String.class, "", Options.class, "Mutable", Mutable);
+    static final OptionDescriptor secondMutable = OptionDescriptor.create("SecondMutable", String.class, "", Options.class, "SecondMutable", SecondMutable);
 
     @Test
     public void testMutable() {
--- a/jvmci/jdk.internal.jvmci.options/src/jdk/internal/jvmci/options/OptionDescriptor.java	Tue Aug 25 22:58:03 2015 +0200
+++ b/jvmci/jdk.internal.jvmci.options/src/jdk/internal/jvmci/options/OptionDescriptor.java	Wed Aug 26 15:06:50 2015 -0700
@@ -26,7 +26,7 @@
  * Describes the attributes of a static field {@linkplain Option option} and provides access to its
  * {@linkplain OptionValue value}.
  */
-public class OptionDescriptor {
+public final class OptionDescriptor {
 
     protected final String name;
     protected final Class<?> type;
@@ -35,7 +35,17 @@
     protected final Class<?> declaringClass;
     protected final String fieldName;
 
-    public OptionDescriptor(String name, Class<?> type, String help, Class<?> declaringClass, String fieldName, OptionValue<?> option) {
+    public static OptionDescriptor create(String name, Class<?> type, String help, Class<?> declaringClass, String fieldName, OptionValue<?> option) {
+        OptionDescriptor result = option.getDescriptor();
+        if (result == null) {
+            result = new OptionDescriptor(name, type, help, declaringClass, fieldName, option);
+            option.setDescriptor(result);
+        }
+        assert result.name.equals(name) && result.type == type && result.declaringClass == declaringClass && result.fieldName.equals(fieldName) && result.option == option;
+        return result;
+    }
+
+    private OptionDescriptor(String name, Class<?> type, String help, Class<?> declaringClass, String fieldName, OptionValue<?> option) {
         this.name = name;
         this.type = type;
         this.help = help;
@@ -43,7 +53,6 @@
         this.declaringClass = declaringClass;
         this.fieldName = fieldName;
         assert !type.isPrimitive() : "must used boxed type instead of " + type;
-        option.setDescriptor(this);
     }
 
     /**
--- a/jvmci/jdk.internal.jvmci.options/src/jdk/internal/jvmci/options/OptionValue.java	Tue Aug 25 22:58:03 2015 +0200
+++ b/jvmci/jdk.internal.jvmci.options/src/jdk/internal/jvmci/options/OptionValue.java	Wed Aug 26 15:06:50 2015 -0700
@@ -193,6 +193,7 @@
      * Sets the descriptor for this option.
      */
     public void setDescriptor(OptionDescriptor descriptor) {
+        assert this.descriptor == null : "Overwriting existing descriptor";
         this.descriptor = descriptor;
     }
 
@@ -234,7 +235,9 @@
      * Returns true if the option has the same value that was set in the source code.
      */
     public boolean hasDefaultValue() {
-        getValue(); // ensure initialized
+        if (!(this instanceof StableOptionValue)) {
+            getValue(); // ensure initialized
+        }
         return value == DEFAULT || Objects.equals(value, getDefaultValue());
     }
 
--- a/jvmci/jdk.internal.jvmci.options/src/jdk/internal/jvmci/options/OptionsParser.java	Tue Aug 25 22:58:03 2015 +0200
+++ b/jvmci/jdk.internal.jvmci.options/src/jdk/internal/jvmci/options/OptionsParser.java	Wed Aug 26 15:06:50 2015 -0700
@@ -24,6 +24,7 @@
 
 import static jdk.internal.jvmci.inittimer.InitTimer.*;
 
+import java.io.*;
 import java.util.*;
 
 import jdk.internal.jvmci.inittimer.*;
@@ -88,6 +89,10 @@
         return Boolean.TRUE;
     }
 
+    public static void parseOption(String option, OptionConsumer setter, OptionDescriptorsProvider odp) {
+        parseOption(OptionsLoader.options, option, setter, odp);
+    }
+
     /**
      * Parses a given option value specification.
      *
@@ -95,7 +100,7 @@
      * @param setter the object to notify of the parsed option and value
      * @throws IllegalArgumentException if there's a problem parsing {@code option}
      */
-    public static void parseOption(String option, OptionConsumer setter, OptionDescriptorsProvider odp) {
+    public static void parseOption(SortedMap<String, OptionDescriptor> options, String option, OptionConsumer setter, OptionDescriptorsProvider odp) {
         if (option.length() == 0) {
             return;
         }
@@ -119,19 +124,19 @@
             }
         }
 
-        OptionDescriptor desc = odp == null ? OptionsLoader.options.get(optionName) : odp.get(optionName);
+        OptionDescriptor desc = odp == null ? options.get(optionName) : odp.get(optionName);
         if (desc == null && value != null) {
             int index = option.indexOf('=');
             if (index != -1) {
                 optionName = option.substring(1, index);
-                desc = odp == null ? OptionsLoader.options.get(optionName) : odp.get(optionName);
+                desc = odp == null ? options.get(optionName) : odp.get(optionName);
             }
             if (desc == null && optionName.equals("PrintFlags")) {
-                desc = new OptionDescriptor("PrintFlags", Boolean.class, "Prints all JVMCI flags and exits", OptionsParser.class, "PrintFlags", PrintFlags);
+                desc = OptionDescriptor.create("PrintFlags", Boolean.class, "Prints all JVMCI flags and exits", OptionsParser.class, "PrintFlags", PrintFlags);
             }
         }
         if (desc == null) {
-            List<OptionDescriptor> matches = fuzzyMatch(optionName);
+            List<OptionDescriptor> matches = fuzzyMatch(options, optionName);
             Formatter msg = new Formatter();
             msg.format("Could not find option %s", optionName);
             if (!matches.isEmpty()) {
@@ -180,7 +185,8 @@
         }
 
         if (PrintFlags.getValue()) {
-            printFlags();
+            printFlags(options, "JVMCI", System.out);
+            System.exit(0);
         }
     }
 
@@ -247,21 +253,18 @@
         return lines;
     }
 
-    public static void printFlags() {
-        System.out.println("[List of JVMCI options]");
-        SortedMap<String, OptionDescriptor> sortedOptions = OptionsLoader.options;
+    public static void printFlags(SortedMap<String, OptionDescriptor> sortedOptions, String prefix, PrintStream out) {
+        out.println("[List of " + prefix + " options]");
         for (Map.Entry<String, OptionDescriptor> e : sortedOptions.entrySet()) {
             e.getKey();
             OptionDescriptor desc = e.getValue();
             Object value = desc.getOptionValue().getValue();
             List<String> helpLines = wrap(desc.getHelp(), 70);
-            System.out.println(String.format("%9s %-40s = %-14s %s", desc.getType().getSimpleName(), e.getKey(), value, helpLines.get(0)));
+            out.println(String.format("%9s %-40s = %-14s %s", desc.getType().getSimpleName(), e.getKey(), value, helpLines.get(0)));
             for (int i = 1; i < helpLines.size(); i++) {
-                System.out.println(String.format("%67s %s", " ", helpLines.get(i)));
+                out.println(String.format("%67s %s", " ", helpLines.get(i)));
             }
         }
-
-        System.exit(0);
     }
 
     /**
@@ -287,9 +290,9 @@
     /**
      * Returns the set of options that fuzzy match a given option name.
      */
-    private static List<OptionDescriptor> fuzzyMatch(String optionName) {
+    private static List<OptionDescriptor> fuzzyMatch(SortedMap<String, OptionDescriptor> options, String optionName) {
         List<OptionDescriptor> matches = new ArrayList<>();
-        for (Map.Entry<String, OptionDescriptor> e : OptionsLoader.options.entrySet()) {
+        for (Map.Entry<String, OptionDescriptor> e : options.entrySet()) {
             float score = stringSimiliarity(e.getKey(), optionName);
             if (score >= FUZZY_MATCH_THRESHOLD) {
                 matches.add(e.getValue());