Mercurial > hg > graal-jvmci-8
annotate jvmci/jdk.vm.ci.options/src/jdk/vm/ci/options/OptionsParser.java @ 22685:3039e5bb94cb
initialize JVMCI eagerly if either the PrintFlags or ShowFlags JVMCI option is present
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Thu, 15 Oct 2015 17:32:19 +0200 |
parents | 1bbd4a7c274b |
children | d43f6d932ad5 |
rev | line source |
---|---|
18684
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
1 /* |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
4 * |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
8 * |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
14 * |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
18 * |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
21 * questions. |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
22 */ |
22672
1bbd4a7c274b
Rename jdk.internal.jvmci to jdk.vm.ci
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
22649
diff
changeset
|
23 package jdk.vm.ci.options; |
18684
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
24 |
22672
1bbd4a7c274b
Rename jdk.internal.jvmci to jdk.vm.ci
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
22649
diff
changeset
|
25 import static jdk.vm.ci.inittimer.InitTimer.timer; |
22398
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
26 |
22569
ec96f33a101d
updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents:
22534
diff
changeset
|
27 import java.io.BufferedReader; |
ec96f33a101d
updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents:
22534
diff
changeset
|
28 import java.io.File; |
ec96f33a101d
updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents:
22534
diff
changeset
|
29 import java.io.FileReader; |
ec96f33a101d
updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents:
22534
diff
changeset
|
30 import java.io.IOException; |
ec96f33a101d
updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents:
22534
diff
changeset
|
31 import java.io.PrintStream; |
ec96f33a101d
updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents:
22534
diff
changeset
|
32 import java.util.ArrayList; |
ec96f33a101d
updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents:
22534
diff
changeset
|
33 import java.util.Collections; |
ec96f33a101d
updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents:
22534
diff
changeset
|
34 import java.util.Formatter; |
ec96f33a101d
updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents:
22534
diff
changeset
|
35 import java.util.List; |
ec96f33a101d
updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents:
22534
diff
changeset
|
36 import java.util.Map; |
ec96f33a101d
updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents:
22534
diff
changeset
|
37 import java.util.ServiceLoader; |
ec96f33a101d
updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents:
22534
diff
changeset
|
38 import java.util.SortedMap; |
18684
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
39 |
22672
1bbd4a7c274b
Rename jdk.internal.jvmci to jdk.vm.ci
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
22649
diff
changeset
|
40 import jdk.vm.ci.inittimer.InitTimer; |
22398
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
41 |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
42 /** |
22399
fb3940232214
revived support for PrintFlags option
Doug Simon <doug.simon@oracle.com>
parents:
22398
diff
changeset
|
43 * This class contains methods for parsing JVMCI options and matching them against a set of |
fb3940232214
revived support for PrintFlags option
Doug Simon <doug.simon@oracle.com>
parents:
22398
diff
changeset
|
44 * {@link OptionDescriptors}. The {@link OptionDescriptors} are loaded from JVMCI jars, either |
fb3940232214
revived support for PrintFlags option
Doug Simon <doug.simon@oracle.com>
parents:
22398
diff
changeset
|
45 * {@linkplain JVMCIJarsOptionDescriptorsProvider directly} or via a {@link ServiceLoader}. |
22398
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
46 */ |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
47 public class OptionsParser { |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
48 |
22399
fb3940232214
revived support for PrintFlags option
Doug Simon <doug.simon@oracle.com>
parents:
22398
diff
changeset
|
49 private static final OptionValue<Boolean> PrintFlags = new OptionValue<>(false); |
22685
3039e5bb94cb
initialize JVMCI eagerly if either the PrintFlags or ShowFlags JVMCI option is present
Doug Simon <doug.simon@oracle.com>
parents:
22672
diff
changeset
|
50 private static final OptionValue<Boolean> ShowFlags = new OptionValue<>(false); |
22399
fb3940232214
revived support for PrintFlags option
Doug Simon <doug.simon@oracle.com>
parents:
22398
diff
changeset
|
51 |
22398
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
52 /** |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
53 * A service for looking up {@link OptionDescriptor}s. |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
54 */ |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
55 public interface OptionDescriptorsProvider { |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
56 /** |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
57 * Gets the {@link OptionDescriptor} matching a given option {@linkplain Option#name() name} |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
58 * or null if no option of that name is provided by this object. |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
59 */ |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
60 OptionDescriptor get(String name); |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
61 } |
18684
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
62 |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
63 public interface OptionConsumer { |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
64 void set(OptionDescriptor desc, Object value); |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
65 } |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
66 |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
67 /** |
22511
df5a7841f92a
revived support for specifying JVMCI options in <jre>/lib/jvmci/options
Doug Simon <doug.simon@oracle.com>
parents:
22509
diff
changeset
|
68 * Parses the options in {@code <jre>/lib/jvmci/options} if {@code parseOptionsFile == true} and |
22601
bc2d4dac0cd3
JVMCI options are now passed as individual -Djvmci.option.<name>=<value> arguments on the command line instead of -Djvmci.options=<multiple options settings separated by spaces>
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
69 * the file exists followed by the JVMCI options in {@code options} if {@code options != null}. |
22398
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
70 * |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
71 * Called from VM. This method has an object return type to allow it to be called with a VM |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
72 * utility function used to call other static initialization methods. |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
73 * |
22601
bc2d4dac0cd3
JVMCI options are now passed as individual -Djvmci.option.<name>=<value> arguments on the command line instead of -Djvmci.options=<multiple options settings separated by spaces>
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
74 * @param options JVMCI options as serialized (name, value) pairs |
22511
df5a7841f92a
revived support for specifying JVMCI options in <jre>/lib/jvmci/options
Doug Simon <doug.simon@oracle.com>
parents:
22509
diff
changeset
|
75 * @param parseOptionsFile specifies whether to look for and parse |
df5a7841f92a
revived support for specifying JVMCI options in <jre>/lib/jvmci/options
Doug Simon <doug.simon@oracle.com>
parents:
22509
diff
changeset
|
76 * {@code <jre>/lib/jvmci.options} |
22398
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
77 */ |
22509
267eecd6d92a
suppressed -Xlint:try warnings
Doug Simon <doug.simon@oracle.com>
parents:
22469
diff
changeset
|
78 @SuppressWarnings("try") |
22601
bc2d4dac0cd3
JVMCI options are now passed as individual -Djvmci.option.<name>=<value> arguments on the command line instead of -Djvmci.options=<multiple options settings separated by spaces>
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
79 public static Boolean parseOptionsFromVM(String[] options, boolean parseOptionsFile) { |
22398
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
80 try (InitTimer t = timer("ParseOptions")) { |
22649
5cd42bb63fad
made initialization of OptionsLoader lazy again
Doug Simon <doug.simon@oracle.com>
parents:
22601
diff
changeset
|
81 JVMCIJarsOptionDescriptorsProvider odp = JVMCIJarsOptionDescriptorsProvider.create(); |
22511
df5a7841f92a
revived support for specifying JVMCI options in <jre>/lib/jvmci/options
Doug Simon <doug.simon@oracle.com>
parents:
22509
diff
changeset
|
82 |
df5a7841f92a
revived support for specifying JVMCI options in <jre>/lib/jvmci/options
Doug Simon <doug.simon@oracle.com>
parents:
22509
diff
changeset
|
83 if (parseOptionsFile) { |
df5a7841f92a
revived support for specifying JVMCI options in <jre>/lib/jvmci/options
Doug Simon <doug.simon@oracle.com>
parents:
22509
diff
changeset
|
84 File javaHome = new File(System.getProperty("java.home")); |
df5a7841f92a
revived support for specifying JVMCI options in <jre>/lib/jvmci/options
Doug Simon <doug.simon@oracle.com>
parents:
22509
diff
changeset
|
85 File lib = new File(javaHome, "lib"); |
df5a7841f92a
revived support for specifying JVMCI options in <jre>/lib/jvmci/options
Doug Simon <doug.simon@oracle.com>
parents:
22509
diff
changeset
|
86 File jvmci = new File(lib, "jvmci"); |
df5a7841f92a
revived support for specifying JVMCI options in <jre>/lib/jvmci/options
Doug Simon <doug.simon@oracle.com>
parents:
22509
diff
changeset
|
87 File jvmciOptions = new File(jvmci, "options"); |
df5a7841f92a
revived support for specifying JVMCI options in <jre>/lib/jvmci/options
Doug Simon <doug.simon@oracle.com>
parents:
22509
diff
changeset
|
88 if (jvmciOptions.exists()) { |
df5a7841f92a
revived support for specifying JVMCI options in <jre>/lib/jvmci/options
Doug Simon <doug.simon@oracle.com>
parents:
22509
diff
changeset
|
89 try (BufferedReader br = new BufferedReader(new FileReader(jvmciOptions))) { |
22601
bc2d4dac0cd3
JVMCI options are now passed as individual -Djvmci.option.<name>=<value> arguments on the command line instead of -Djvmci.options=<multiple options settings separated by spaces>
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
90 String optionSetting = null; |
bc2d4dac0cd3
JVMCI options are now passed as individual -Djvmci.option.<name>=<value> arguments on the command line instead of -Djvmci.options=<multiple options settings separated by spaces>
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
91 int lineNo = 1; |
bc2d4dac0cd3
JVMCI options are now passed as individual -Djvmci.option.<name>=<value> arguments on the command line instead of -Djvmci.options=<multiple options settings separated by spaces>
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
92 while ((optionSetting = br.readLine()) != null) { |
bc2d4dac0cd3
JVMCI options are now passed as individual -Djvmci.option.<name>=<value> arguments on the command line instead of -Djvmci.options=<multiple options settings separated by spaces>
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
93 if (!optionSetting.isEmpty() && optionSetting.charAt(0) != '#') { |
bc2d4dac0cd3
JVMCI options are now passed as individual -Djvmci.option.<name>=<value> arguments on the command line instead of -Djvmci.options=<multiple options settings separated by spaces>
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
94 try { |
bc2d4dac0cd3
JVMCI options are now passed as individual -Djvmci.option.<name>=<value> arguments on the command line instead of -Djvmci.options=<multiple options settings separated by spaces>
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
95 parseOptionSetting(optionSetting, null, odp); |
bc2d4dac0cd3
JVMCI options are now passed as individual -Djvmci.option.<name>=<value> arguments on the command line instead of -Djvmci.options=<multiple options settings separated by spaces>
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
96 } catch (Throwable e) { |
bc2d4dac0cd3
JVMCI options are now passed as individual -Djvmci.option.<name>=<value> arguments on the command line instead of -Djvmci.options=<multiple options settings separated by spaces>
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
97 throw new InternalError("Error parsing " + jvmciOptions + ", line " + lineNo, e); |
bc2d4dac0cd3
JVMCI options are now passed as individual -Djvmci.option.<name>=<value> arguments on the command line instead of -Djvmci.options=<multiple options settings separated by spaces>
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
98 } |
22511
df5a7841f92a
revived support for specifying JVMCI options in <jre>/lib/jvmci/options
Doug Simon <doug.simon@oracle.com>
parents:
22509
diff
changeset
|
99 } |
22601
bc2d4dac0cd3
JVMCI options are now passed as individual -Djvmci.option.<name>=<value> arguments on the command line instead of -Djvmci.options=<multiple options settings separated by spaces>
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
100 lineNo++; |
22511
df5a7841f92a
revived support for specifying JVMCI options in <jre>/lib/jvmci/options
Doug Simon <doug.simon@oracle.com>
parents:
22509
diff
changeset
|
101 } |
df5a7841f92a
revived support for specifying JVMCI options in <jre>/lib/jvmci/options
Doug Simon <doug.simon@oracle.com>
parents:
22509
diff
changeset
|
102 } catch (IOException e) { |
df5a7841f92a
revived support for specifying JVMCI options in <jre>/lib/jvmci/options
Doug Simon <doug.simon@oracle.com>
parents:
22509
diff
changeset
|
103 throw new InternalError("Error reading " + jvmciOptions, e); |
df5a7841f92a
revived support for specifying JVMCI options in <jre>/lib/jvmci/options
Doug Simon <doug.simon@oracle.com>
parents:
22509
diff
changeset
|
104 } |
df5a7841f92a
revived support for specifying JVMCI options in <jre>/lib/jvmci/options
Doug Simon <doug.simon@oracle.com>
parents:
22509
diff
changeset
|
105 } |
df5a7841f92a
revived support for specifying JVMCI options in <jre>/lib/jvmci/options
Doug Simon <doug.simon@oracle.com>
parents:
22509
diff
changeset
|
106 } |
df5a7841f92a
revived support for specifying JVMCI options in <jre>/lib/jvmci/options
Doug Simon <doug.simon@oracle.com>
parents:
22509
diff
changeset
|
107 |
df5a7841f92a
revived support for specifying JVMCI options in <jre>/lib/jvmci/options
Doug Simon <doug.simon@oracle.com>
parents:
22509
diff
changeset
|
108 if (options != null) { |
22601
bc2d4dac0cd3
JVMCI options are now passed as individual -Djvmci.option.<name>=<value> arguments on the command line instead of -Djvmci.options=<multiple options settings separated by spaces>
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
109 assert options.length % 2 == 0; |
bc2d4dac0cd3
JVMCI options are now passed as individual -Djvmci.option.<name>=<value> arguments on the command line instead of -Djvmci.options=<multiple options settings separated by spaces>
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
110 for (int i = 0; i < options.length / 2; i++) { |
bc2d4dac0cd3
JVMCI options are now passed as individual -Djvmci.option.<name>=<value> arguments on the command line instead of -Djvmci.options=<multiple options settings separated by spaces>
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
111 String name = options[i * 2]; |
bc2d4dac0cd3
JVMCI options are now passed as individual -Djvmci.option.<name>=<value> arguments on the command line instead of -Djvmci.options=<multiple options settings separated by spaces>
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
112 String value = options[i * 2 + 1]; |
22649
5cd42bb63fad
made initialization of OptionsLoader lazy again
Doug Simon <doug.simon@oracle.com>
parents:
22601
diff
changeset
|
113 parseOption(name, value, null, odp, null); |
22511
df5a7841f92a
revived support for specifying JVMCI options in <jre>/lib/jvmci/options
Doug Simon <doug.simon@oracle.com>
parents:
22509
diff
changeset
|
114 } |
22398
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
115 } |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
116 } |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
117 return Boolean.TRUE; |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
118 } |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
119 |
22601
bc2d4dac0cd3
JVMCI options are now passed as individual -Djvmci.option.<name>=<value> arguments on the command line instead of -Djvmci.options=<multiple options settings separated by spaces>
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
120 /** |
bc2d4dac0cd3
JVMCI options are now passed as individual -Djvmci.option.<name>=<value> arguments on the command line instead of -Djvmci.options=<multiple options settings separated by spaces>
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
121 * Parses a given option setting. |
bc2d4dac0cd3
JVMCI options are now passed as individual -Djvmci.option.<name>=<value> arguments on the command line instead of -Djvmci.options=<multiple options settings separated by spaces>
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
122 * |
bc2d4dac0cd3
JVMCI options are now passed as individual -Djvmci.option.<name>=<value> arguments on the command line instead of -Djvmci.options=<multiple options settings separated by spaces>
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
123 * @param optionSetting a string matching the pattern {@code <name>=<value>} |
bc2d4dac0cd3
JVMCI options are now passed as individual -Djvmci.option.<name>=<value> arguments on the command line instead of -Djvmci.options=<multiple options settings separated by spaces>
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
124 * @param setter the object to notify of the parsed option and value |
bc2d4dac0cd3
JVMCI options are now passed as individual -Djvmci.option.<name>=<value> arguments on the command line instead of -Djvmci.options=<multiple options settings separated by spaces>
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
125 */ |
bc2d4dac0cd3
JVMCI options are now passed as individual -Djvmci.option.<name>=<value> arguments on the command line instead of -Djvmci.options=<multiple options settings separated by spaces>
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
126 public static void parseOptionSetting(String optionSetting, OptionConsumer setter, OptionDescriptorsProvider odp) { |
bc2d4dac0cd3
JVMCI options are now passed as individual -Djvmci.option.<name>=<value> arguments on the command line instead of -Djvmci.options=<multiple options settings separated by spaces>
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
127 int eqIndex = optionSetting.indexOf('='); |
bc2d4dac0cd3
JVMCI options are now passed as individual -Djvmci.option.<name>=<value> arguments on the command line instead of -Djvmci.options=<multiple options settings separated by spaces>
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
128 if (eqIndex == -1) { |
bc2d4dac0cd3
JVMCI options are now passed as individual -Djvmci.option.<name>=<value> arguments on the command line instead of -Djvmci.options=<multiple options settings separated by spaces>
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
129 throw new InternalError("Option setting has does not match the pattern <name>=<value>: " + optionSetting); |
bc2d4dac0cd3
JVMCI options are now passed as individual -Djvmci.option.<name>=<value> arguments on the command line instead of -Djvmci.options=<multiple options settings separated by spaces>
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
130 } |
bc2d4dac0cd3
JVMCI options are now passed as individual -Djvmci.option.<name>=<value> arguments on the command line instead of -Djvmci.options=<multiple options settings separated by spaces>
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
131 String name = optionSetting.substring(0, eqIndex); |
bc2d4dac0cd3
JVMCI options are now passed as individual -Djvmci.option.<name>=<value> arguments on the command line instead of -Djvmci.options=<multiple options settings separated by spaces>
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
132 String value = optionSetting.substring(eqIndex + 1); |
22649
5cd42bb63fad
made initialization of OptionsLoader lazy again
Doug Simon <doug.simon@oracle.com>
parents:
22601
diff
changeset
|
133 parseOption(name, value, setter, odp, null); |
5cd42bb63fad
made initialization of OptionsLoader lazy again
Doug Simon <doug.simon@oracle.com>
parents:
22601
diff
changeset
|
134 } |
5cd42bb63fad
made initialization of OptionsLoader lazy again
Doug Simon <doug.simon@oracle.com>
parents:
22601
diff
changeset
|
135 |
5cd42bb63fad
made initialization of OptionsLoader lazy again
Doug Simon <doug.simon@oracle.com>
parents:
22601
diff
changeset
|
136 /** |
5cd42bb63fad
made initialization of OptionsLoader lazy again
Doug Simon <doug.simon@oracle.com>
parents:
22601
diff
changeset
|
137 * Resolves {@code options} to a non-null value. This ensures {@link OptionsLoader#options} is |
5cd42bb63fad
made initialization of OptionsLoader lazy again
Doug Simon <doug.simon@oracle.com>
parents:
22601
diff
changeset
|
138 * only loaded if necessary. |
5cd42bb63fad
made initialization of OptionsLoader lazy again
Doug Simon <doug.simon@oracle.com>
parents:
22601
diff
changeset
|
139 */ |
5cd42bb63fad
made initialization of OptionsLoader lazy again
Doug Simon <doug.simon@oracle.com>
parents:
22601
diff
changeset
|
140 private static SortedMap<String, OptionDescriptor> resolveOptions(SortedMap<String, OptionDescriptor> options) { |
5cd42bb63fad
made initialization of OptionsLoader lazy again
Doug Simon <doug.simon@oracle.com>
parents:
22601
diff
changeset
|
141 return options != null ? options : OptionsLoader.options; |
22469
a6adaf9c330d
Ensure only one OptionDescriptor is created per option; allow custom lists of options passed to OptionParser
Christian Wimmer <christian.wimmer@oracle.com>
parents:
22399
diff
changeset
|
142 } |
a6adaf9c330d
Ensure only one OptionDescriptor is created per option; allow custom lists of options passed to OptionParser
Christian Wimmer <christian.wimmer@oracle.com>
parents:
22399
diff
changeset
|
143 |
22398
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
144 /** |
22601
bc2d4dac0cd3
JVMCI options are now passed as individual -Djvmci.option.<name>=<value> arguments on the command line instead of -Djvmci.options=<multiple options settings separated by spaces>
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
145 * Parses a given option name and value. |
18684
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
146 * |
22601
bc2d4dac0cd3
JVMCI options are now passed as individual -Djvmci.option.<name>=<value> arguments on the command line instead of -Djvmci.options=<multiple options settings separated by spaces>
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
147 * @param name the option name |
bc2d4dac0cd3
JVMCI options are now passed as individual -Djvmci.option.<name>=<value> arguments on the command line instead of -Djvmci.options=<multiple options settings separated by spaces>
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
148 * @param valueString the option value as a string |
22398
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
149 * @param setter the object to notify of the parsed option and value |
22649
5cd42bb63fad
made initialization of OptionsLoader lazy again
Doug Simon <doug.simon@oracle.com>
parents:
22601
diff
changeset
|
150 * @param odp if non-null, the service to use for looking up {@link OptionDescriptor}s |
5cd42bb63fad
made initialization of OptionsLoader lazy again
Doug Simon <doug.simon@oracle.com>
parents:
22601
diff
changeset
|
151 * @param options the options database to use if {@code odp} is null |
22398
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
152 * @throws IllegalArgumentException if there's a problem parsing {@code option} |
18684
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
153 */ |
22649
5cd42bb63fad
made initialization of OptionsLoader lazy again
Doug Simon <doug.simon@oracle.com>
parents:
22601
diff
changeset
|
154 public static void parseOption(String name, String valueString, OptionConsumer setter, OptionDescriptorsProvider odp, SortedMap<String, OptionDescriptor> options) { |
18684
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
155 |
22649
5cd42bb63fad
made initialization of OptionsLoader lazy again
Doug Simon <doug.simon@oracle.com>
parents:
22601
diff
changeset
|
156 OptionDescriptor desc = odp != null ? odp.get(name) : resolveOptions(options).get(name); |
22685
3039e5bb94cb
initialize JVMCI eagerly if either the PrintFlags or ShowFlags JVMCI option is present
Doug Simon <doug.simon@oracle.com>
parents:
22672
diff
changeset
|
157 if (desc == null) { |
3039e5bb94cb
initialize JVMCI eagerly if either the PrintFlags or ShowFlags JVMCI option is present
Doug Simon <doug.simon@oracle.com>
parents:
22672
diff
changeset
|
158 if (name.equals("PrintFlags")) { |
3039e5bb94cb
initialize JVMCI eagerly if either the PrintFlags or ShowFlags JVMCI option is present
Doug Simon <doug.simon@oracle.com>
parents:
22672
diff
changeset
|
159 desc = OptionDescriptor.create("PrintFlags", Boolean.class, "Prints all JVMCI flags and exits", OptionsParser.class, "PrintFlags", PrintFlags); |
3039e5bb94cb
initialize JVMCI eagerly if either the PrintFlags or ShowFlags JVMCI option is present
Doug Simon <doug.simon@oracle.com>
parents:
22672
diff
changeset
|
160 } else if (name.equals("ShowFlags")) { |
3039e5bb94cb
initialize JVMCI eagerly if either the PrintFlags or ShowFlags JVMCI option is present
Doug Simon <doug.simon@oracle.com>
parents:
22672
diff
changeset
|
161 desc = OptionDescriptor.create("ShowFlags", Boolean.class, "Prints all JVMCI flags and continues", OptionsParser.class, "ShowFlags", ShowFlags); |
3039e5bb94cb
initialize JVMCI eagerly if either the PrintFlags or ShowFlags JVMCI option is present
Doug Simon <doug.simon@oracle.com>
parents:
22672
diff
changeset
|
162 } |
22398
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
163 } |
18684
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
164 if (desc == null) { |
22649
5cd42bb63fad
made initialization of OptionsLoader lazy again
Doug Simon <doug.simon@oracle.com>
parents:
22601
diff
changeset
|
165 List<OptionDescriptor> matches = fuzzyMatch(resolveOptions(options), name); |
22398
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
166 Formatter msg = new Formatter(); |
22601
bc2d4dac0cd3
JVMCI options are now passed as individual -Djvmci.option.<name>=<value> arguments on the command line instead of -Djvmci.options=<multiple options settings separated by spaces>
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
167 msg.format("Could not find option %s", name); |
22398
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
168 if (!matches.isEmpty()) { |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
169 msg.format("%nDid you mean one of the following?"); |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
170 for (OptionDescriptor match : matches) { |
22601
bc2d4dac0cd3
JVMCI options are now passed as individual -Djvmci.option.<name>=<value> arguments on the command line instead of -Djvmci.options=<multiple options settings separated by spaces>
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
171 msg.format("%n %s=<value>", match.getName()); |
22398
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
172 } |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
173 } |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
174 throw new IllegalArgumentException(msg.toString()); |
18684
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
175 } |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
176 |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
177 Class<?> optionType = desc.getType(); |
22601
bc2d4dac0cd3
JVMCI options are now passed as individual -Djvmci.option.<name>=<value> arguments on the command line instead of -Djvmci.options=<multiple options settings separated by spaces>
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
178 Object value; |
bc2d4dac0cd3
JVMCI options are now passed as individual -Djvmci.option.<name>=<value> arguments on the command line instead of -Djvmci.options=<multiple options settings separated by spaces>
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
179 if (optionType == Boolean.class) { |
bc2d4dac0cd3
JVMCI options are now passed as individual -Djvmci.option.<name>=<value> arguments on the command line instead of -Djvmci.options=<multiple options settings separated by spaces>
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
180 if ("true".equals(valueString)) { |
bc2d4dac0cd3
JVMCI options are now passed as individual -Djvmci.option.<name>=<value> arguments on the command line instead of -Djvmci.options=<multiple options settings separated by spaces>
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
181 value = Boolean.TRUE; |
bc2d4dac0cd3
JVMCI options are now passed as individual -Djvmci.option.<name>=<value> arguments on the command line instead of -Djvmci.options=<multiple options settings separated by spaces>
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
182 } else if ("false".equals(valueString)) { |
bc2d4dac0cd3
JVMCI options are now passed as individual -Djvmci.option.<name>=<value> arguments on the command line instead of -Djvmci.options=<multiple options settings separated by spaces>
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
183 value = Boolean.FALSE; |
bc2d4dac0cd3
JVMCI options are now passed as individual -Djvmci.option.<name>=<value> arguments on the command line instead of -Djvmci.options=<multiple options settings separated by spaces>
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
184 } else { |
bc2d4dac0cd3
JVMCI options are now passed as individual -Djvmci.option.<name>=<value> arguments on the command line instead of -Djvmci.options=<multiple options settings separated by spaces>
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
185 throw new IllegalArgumentException("Boolean option '" + name + "' must have value \"true\" or \"false\", not \"" + valueString + "\""); |
18684
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
186 } |
22601
bc2d4dac0cd3
JVMCI options are now passed as individual -Djvmci.option.<name>=<value> arguments on the command line instead of -Djvmci.options=<multiple options settings separated by spaces>
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
187 } else if (optionType == Float.class) { |
bc2d4dac0cd3
JVMCI options are now passed as individual -Djvmci.option.<name>=<value> arguments on the command line instead of -Djvmci.options=<multiple options settings separated by spaces>
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
188 value = Float.parseFloat(valueString); |
bc2d4dac0cd3
JVMCI options are now passed as individual -Djvmci.option.<name>=<value> arguments on the command line instead of -Djvmci.options=<multiple options settings separated by spaces>
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
189 } else if (optionType == Double.class) { |
bc2d4dac0cd3
JVMCI options are now passed as individual -Djvmci.option.<name>=<value> arguments on the command line instead of -Djvmci.options=<multiple options settings separated by spaces>
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
190 value = Double.parseDouble(valueString); |
bc2d4dac0cd3
JVMCI options are now passed as individual -Djvmci.option.<name>=<value> arguments on the command line instead of -Djvmci.options=<multiple options settings separated by spaces>
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
191 } else if (optionType == Integer.class) { |
bc2d4dac0cd3
JVMCI options are now passed as individual -Djvmci.option.<name>=<value> arguments on the command line instead of -Djvmci.options=<multiple options settings separated by spaces>
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
192 value = Integer.valueOf((int) parseLong(valueString)); |
bc2d4dac0cd3
JVMCI options are now passed as individual -Djvmci.option.<name>=<value> arguments on the command line instead of -Djvmci.options=<multiple options settings separated by spaces>
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
193 } else if (optionType == Long.class) { |
bc2d4dac0cd3
JVMCI options are now passed as individual -Djvmci.option.<name>=<value> arguments on the command line instead of -Djvmci.options=<multiple options settings separated by spaces>
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
194 value = Long.valueOf(parseLong(valueString)); |
bc2d4dac0cd3
JVMCI options are now passed as individual -Djvmci.option.<name>=<value> arguments on the command line instead of -Djvmci.options=<multiple options settings separated by spaces>
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
195 } else if (optionType == String.class) { |
bc2d4dac0cd3
JVMCI options are now passed as individual -Djvmci.option.<name>=<value> arguments on the command line instead of -Djvmci.options=<multiple options settings separated by spaces>
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
196 value = valueString; |
18684
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
197 } else { |
22601
bc2d4dac0cd3
JVMCI options are now passed as individual -Djvmci.option.<name>=<value> arguments on the command line instead of -Djvmci.options=<multiple options settings separated by spaces>
Doug Simon <doug.simon@oracle.com>
parents:
22569
diff
changeset
|
198 throw new IllegalArgumentException("Wrong value for option '" + name + "'"); |
18684
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
199 } |
22398
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
200 if (setter == null) { |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
201 desc.getOptionValue().setValue(value); |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
202 } else { |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
203 setter.set(desc, value); |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
204 } |
22399
fb3940232214
revived support for PrintFlags option
Doug Simon <doug.simon@oracle.com>
parents:
22398
diff
changeset
|
205 |
22685
3039e5bb94cb
initialize JVMCI eagerly if either the PrintFlags or ShowFlags JVMCI option is present
Doug Simon <doug.simon@oracle.com>
parents:
22672
diff
changeset
|
206 if (PrintFlags.getValue() || ShowFlags.getValue()) { |
22649
5cd42bb63fad
made initialization of OptionsLoader lazy again
Doug Simon <doug.simon@oracle.com>
parents:
22601
diff
changeset
|
207 printFlags(resolveOptions(options), "JVMCI", System.out); |
22685
3039e5bb94cb
initialize JVMCI eagerly if either the PrintFlags or ShowFlags JVMCI option is present
Doug Simon <doug.simon@oracle.com>
parents:
22672
diff
changeset
|
208 if (PrintFlags.getValue()) { |
3039e5bb94cb
initialize JVMCI eagerly if either the PrintFlags or ShowFlags JVMCI option is present
Doug Simon <doug.simon@oracle.com>
parents:
22672
diff
changeset
|
209 System.exit(0); |
3039e5bb94cb
initialize JVMCI eagerly if either the PrintFlags or ShowFlags JVMCI option is present
Doug Simon <doug.simon@oracle.com>
parents:
22672
diff
changeset
|
210 } |
22399
fb3940232214
revived support for PrintFlags option
Doug Simon <doug.simon@oracle.com>
parents:
22398
diff
changeset
|
211 } |
18684
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
212 } |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
213 |
20822
8ad82587f08d
Allow scaling factors in integer options; add support for Long values in addition to Integer values
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18684
diff
changeset
|
214 private static long parseLong(String v) { |
8ad82587f08d
Allow scaling factors in integer options; add support for Long values in addition to Integer values
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18684
diff
changeset
|
215 String valueString = v.toLowerCase(); |
8ad82587f08d
Allow scaling factors in integer options; add support for Long values in addition to Integer values
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18684
diff
changeset
|
216 long scale = 1; |
8ad82587f08d
Allow scaling factors in integer options; add support for Long values in addition to Integer values
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18684
diff
changeset
|
217 if (valueString.endsWith("k")) { |
8ad82587f08d
Allow scaling factors in integer options; add support for Long values in addition to Integer values
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18684
diff
changeset
|
218 scale = 1024L; |
8ad82587f08d
Allow scaling factors in integer options; add support for Long values in addition to Integer values
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18684
diff
changeset
|
219 } else if (valueString.endsWith("m")) { |
8ad82587f08d
Allow scaling factors in integer options; add support for Long values in addition to Integer values
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18684
diff
changeset
|
220 scale = 1024L * 1024L; |
8ad82587f08d
Allow scaling factors in integer options; add support for Long values in addition to Integer values
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18684
diff
changeset
|
221 } else if (valueString.endsWith("g")) { |
8ad82587f08d
Allow scaling factors in integer options; add support for Long values in addition to Integer values
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18684
diff
changeset
|
222 scale = 1024L * 1024L * 1024L; |
8ad82587f08d
Allow scaling factors in integer options; add support for Long values in addition to Integer values
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18684
diff
changeset
|
223 } else if (valueString.endsWith("t")) { |
8ad82587f08d
Allow scaling factors in integer options; add support for Long values in addition to Integer values
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18684
diff
changeset
|
224 scale = 1024L * 1024L * 1024L * 1024L; |
8ad82587f08d
Allow scaling factors in integer options; add support for Long values in addition to Integer values
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18684
diff
changeset
|
225 } |
8ad82587f08d
Allow scaling factors in integer options; add support for Long values in addition to Integer values
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18684
diff
changeset
|
226 |
8ad82587f08d
Allow scaling factors in integer options; add support for Long values in addition to Integer values
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18684
diff
changeset
|
227 if (scale != 1) { |
8ad82587f08d
Allow scaling factors in integer options; add support for Long values in addition to Integer values
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18684
diff
changeset
|
228 /* Remove trailing scale character. */ |
8ad82587f08d
Allow scaling factors in integer options; add support for Long values in addition to Integer values
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18684
diff
changeset
|
229 valueString = valueString.substring(0, valueString.length() - 1); |
8ad82587f08d
Allow scaling factors in integer options; add support for Long values in addition to Integer values
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18684
diff
changeset
|
230 } |
8ad82587f08d
Allow scaling factors in integer options; add support for Long values in addition to Integer values
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18684
diff
changeset
|
231 |
8ad82587f08d
Allow scaling factors in integer options; add support for Long values in addition to Integer values
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18684
diff
changeset
|
232 return Long.parseLong(valueString) * scale; |
8ad82587f08d
Allow scaling factors in integer options; add support for Long values in addition to Integer values
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18684
diff
changeset
|
233 } |
8ad82587f08d
Allow scaling factors in integer options; add support for Long values in addition to Integer values
Christian Wimmer <christian.wimmer@oracle.com>
parents:
18684
diff
changeset
|
234 |
18684
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
235 /** |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
236 * Wraps some given text to one or more lines of a given maximum width. |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
237 * |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
238 * @param text text to wrap |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
239 * @param width maximum width of an output line, exception for words in {@code text} longer than |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
240 * this value |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
241 * @return {@code text} broken into lines |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
242 */ |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
243 private static List<String> wrap(String text, int width) { |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
244 List<String> lines = Collections.singletonList(text); |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
245 if (text.length() > width) { |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
246 String[] chunks = text.split("\\s+"); |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
247 lines = new ArrayList<>(); |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
248 StringBuilder line = new StringBuilder(); |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
249 for (String chunk : chunks) { |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
250 if (line.length() + chunk.length() > width) { |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
251 lines.add(line.toString()); |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
252 line.setLength(0); |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
253 } |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
254 if (line.length() != 0) { |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
255 line.append(' '); |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
256 } |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
257 String[] embeddedLines = chunk.split("%n", -2); |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
258 if (embeddedLines.length == 1) { |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
259 line.append(chunk); |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
260 } else { |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
261 for (int i = 0; i < embeddedLines.length; i++) { |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
262 line.append(embeddedLines[i]); |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
263 if (i < embeddedLines.length - 1) { |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
264 lines.add(line.toString()); |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
265 line.setLength(0); |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
266 } |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
267 } |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
268 } |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
269 } |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
270 if (line.length() != 0) { |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
271 lines.add(line.toString()); |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
272 } |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
273 } |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
274 return lines; |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
275 } |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
276 |
22469
a6adaf9c330d
Ensure only one OptionDescriptor is created per option; allow custom lists of options passed to OptionParser
Christian Wimmer <christian.wimmer@oracle.com>
parents:
22399
diff
changeset
|
277 public static void printFlags(SortedMap<String, OptionDescriptor> sortedOptions, String prefix, PrintStream out) { |
a6adaf9c330d
Ensure only one OptionDescriptor is created per option; allow custom lists of options passed to OptionParser
Christian Wimmer <christian.wimmer@oracle.com>
parents:
22399
diff
changeset
|
278 out.println("[List of " + prefix + " options]"); |
18684
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
279 for (Map.Entry<String, OptionDescriptor> e : sortedOptions.entrySet()) { |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
280 e.getKey(); |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
281 OptionDescriptor desc = e.getValue(); |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
282 Object value = desc.getOptionValue().getValue(); |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
283 List<String> helpLines = wrap(desc.getHelp(), 70); |
22469
a6adaf9c330d
Ensure only one OptionDescriptor is created per option; allow custom lists of options passed to OptionParser
Christian Wimmer <christian.wimmer@oracle.com>
parents:
22399
diff
changeset
|
284 out.println(String.format("%9s %-40s = %-14s %s", desc.getType().getSimpleName(), e.getKey(), value, helpLines.get(0))); |
18684
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
285 for (int i = 1; i < helpLines.size(); i++) { |
22469
a6adaf9c330d
Ensure only one OptionDescriptor is created per option; allow custom lists of options passed to OptionParser
Christian Wimmer <christian.wimmer@oracle.com>
parents:
22399
diff
changeset
|
286 out.println(String.format("%67s %s", " ", helpLines.get(i))); |
18684
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
287 } |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
288 } |
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
289 } |
22398
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
290 |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
291 /** |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
292 * Compute string similarity based on Dice's coefficient. |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
293 * |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
294 * Ported from str_similar() in globals.cpp. |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
295 */ |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
296 static float stringSimiliarity(String str1, String str2) { |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
297 int hit = 0; |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
298 for (int i = 0; i < str1.length() - 1; ++i) { |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
299 for (int j = 0; j < str2.length() - 1; ++j) { |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
300 if ((str1.charAt(i) == str2.charAt(j)) && (str1.charAt(i + 1) == str2.charAt(j + 1))) { |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
301 ++hit; |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
302 break; |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
303 } |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
304 } |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
305 } |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
306 return 2.0f * hit / (str1.length() + str2.length()); |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
307 } |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
308 |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
309 private static final float FUZZY_MATCH_THRESHOLD = 0.7F; |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
310 |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
311 /** |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
312 * Returns the set of options that fuzzy match a given option name. |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
313 */ |
22469
a6adaf9c330d
Ensure only one OptionDescriptor is created per option; allow custom lists of options passed to OptionParser
Christian Wimmer <christian.wimmer@oracle.com>
parents:
22399
diff
changeset
|
314 private static List<OptionDescriptor> fuzzyMatch(SortedMap<String, OptionDescriptor> options, String optionName) { |
22398
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
315 List<OptionDescriptor> matches = new ArrayList<>(); |
22469
a6adaf9c330d
Ensure only one OptionDescriptor is created per option; allow custom lists of options passed to OptionParser
Christian Wimmer <christian.wimmer@oracle.com>
parents:
22399
diff
changeset
|
316 for (Map.Entry<String, OptionDescriptor> e : options.entrySet()) { |
22398
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
317 float score = stringSimiliarity(e.getKey(), optionName); |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
318 if (score >= FUZZY_MATCH_THRESHOLD) { |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
319 matches.add(e.getValue()); |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
320 } |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
321 } |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
322 return matches; |
4f6caa445b92
moved JVMCI option parsing back into Java
Doug Simon <doug.simon@oracle.com>
parents:
22054
diff
changeset
|
323 } |
18684
137773e5250c
Factor out VM-independent parts of option parsing
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
324 } |