Mercurial > hg > graal-jvmci-8
comparison jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotJVMCIRuntime.java @ 23777:6c8eaf47db9a
added -XX:+JVMCIPrintFlags to support printing of JVMCI flags without having to know how to trigger JVMCI initialization
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Tue, 04 Oct 2016 22:14:32 +0200 |
parents | 724fbad94ee3 |
children | a2051f3fe76b |
comparison
equal
deleted
inserted
replaced
23776:450e0bafd83d | 23777:6c8eaf47db9a |
---|---|
87 | 87 |
88 /** | 88 /** |
89 * A list of all supported JVMCI options. | 89 * A list of all supported JVMCI options. |
90 */ | 90 */ |
91 public enum Option { | 91 public enum Option { |
92 // @formatter:off | |
92 Compiler(String.class, null, "Selects the system compiler."), | 93 Compiler(String.class, null, "Selects the system compiler."), |
93 // Note: The following one is not used (see InitTimer.ENABLED). It is added here | 94 // Note: The following one is not used (see InitTimer.ENABLED). It is added here |
94 // so that -Djvmci.PrintFlags=true shows the option. | 95 // so that -XX:JVMCIPrintFlags shows the option. |
95 InitTimer(boolean.class, false, "Specifies if initialization timing is enabled."), | 96 InitTimer(Boolean.class, false, "Specifies if initialization timing is enabled."), |
96 PrintConfig(boolean.class, false, "Prints VM configuration available via JVMCI and exits."), | 97 PrintConfig(Boolean.class, false, "Prints VM configuration available via JVMCI and exits."), |
97 PrintFlags(boolean.class, false, "Prints all JVMCI flags and exits."), | 98 TraceMethodDataFilter(String.class, null, |
98 ShowFlags(boolean.class, false, "Prints all JVMCI flags and continues."), | 99 "Enables tracing of profiling info when read by JVMCI.", |
99 TraceMethodDataFilter(String.class, null, ""); | 100 "Empty value: trace all methods", |
101 "Non-empty value: trace methods whose fully qualified name contains the value."); | |
102 // @formatter:on | |
100 | 103 |
101 /** | 104 /** |
102 * The prefix for system properties that are JVMCI options. | 105 * The prefix for system properties that are JVMCI options. |
103 */ | 106 */ |
104 private static final String JVMCI_OPTION_PROPERTY_PREFIX = "jvmci."; | 107 private static final String JVMCI_OPTION_PROPERTY_PREFIX = "jvmci."; |
110 | 113 |
111 private final Class<?> type; | 114 private final Class<?> type; |
112 private Object value; | 115 private Object value; |
113 private final Object defaultValue; | 116 private final Object defaultValue; |
114 private boolean isDefault; | 117 private boolean isDefault; |
115 private final String help; | 118 private final String[] helpLines; |
116 | 119 |
117 Option(Class<?> type, Object defaultValue, String help) { | 120 Option(Class<?> type, Object defaultValue, String... helpLines) { |
118 assert Character.isUpperCase(name().charAt(0)) : "Option name must start with upper-case letter: " + name(); | 121 assert Character.isUpperCase(name().charAt(0)) : "Option name must start with upper-case letter: " + name(); |
119 this.type = type; | 122 this.type = type; |
120 this.value = UNINITIALIZED; | 123 this.value = UNINITIALIZED; |
121 this.defaultValue = defaultValue; | 124 this.defaultValue = defaultValue; |
122 this.help = help; | 125 this.helpLines = helpLines; |
123 } | 126 } |
124 | 127 |
125 @SuppressFBWarnings(value = "ES_COMPARING_STRINGS_WITH_EQ", justification = "sentinel must be String since it's a static final in an enum") | 128 @SuppressFBWarnings(value = "ES_COMPARING_STRINGS_WITH_EQ", justification = "sentinel must be String since it's a static final in an enum") |
126 private Object getValue() { | 129 private Object getValue() { |
127 if (value == UNINITIALIZED) { | 130 if (value == UNINITIALIZED) { |
128 String propertyValue = VM.getSavedProperty(JVMCI_OPTION_PROPERTY_PREFIX + name()); | 131 String propertyValue = VM.getSavedProperty(JVMCI_OPTION_PROPERTY_PREFIX + name()); |
129 if (propertyValue == null) { | 132 if (propertyValue == null) { |
130 this.value = defaultValue; | 133 this.value = defaultValue; |
131 this.isDefault = true; | 134 this.isDefault = true; |
132 } else { | 135 } else { |
133 if (type == boolean.class) { | 136 if (type == Boolean.class) { |
134 this.value = Boolean.parseBoolean(propertyValue); | 137 this.value = Boolean.parseBoolean(propertyValue); |
135 } else if (type == String.class) { | 138 } else if (type == String.class) { |
136 this.value = propertyValue; | 139 this.value = propertyValue; |
137 } else { | 140 } else { |
138 throw new JVMCIError("Unexpected option type " + type); | 141 throw new JVMCIError("Unexpected option type " + type); |
167 * Prints all option flags to {@code out}. | 170 * Prints all option flags to {@code out}. |
168 * | 171 * |
169 * @param out stream to print to | 172 * @param out stream to print to |
170 */ | 173 */ |
171 public static void printFlags(PrintStream out) { | 174 public static void printFlags(PrintStream out) { |
172 out.println("[List of JVMCI options]"); | 175 out.println("[List of JVMCI options. Set with \"jvmci.\" prefixed system property (e.g., -Djvmci." + InitTimer.name() + "=true)"); |
173 for (Option option : values()) { | 176 int typeWidth = 0; |
177 int nameWidth = 0; | |
178 Option[] values = values(); | |
179 for (Option option : values) { | |
180 typeWidth = Math.max(typeWidth, option.type.getSimpleName().length()); | |
181 nameWidth = Math.max(nameWidth, option.name().length()); | |
182 } | |
183 for (Option option : values) { | |
174 Object value = option.getValue(); | 184 Object value = option.getValue(); |
175 String assign = option.isDefault ? ":=" : " ="; | 185 if (value instanceof String) { |
176 out.printf("%9s %-40s %s %-14s %s%n", option.type.getSimpleName(), option, assign, value, option.help); | 186 value = '"' + String.valueOf(value) + '"'; |
187 } | |
188 String assign = option.isDefault ? " =" : ":="; | |
189 String format = "%" + (typeWidth + 1) + "s %-" + (nameWidth + 1) + "s %s %s%n"; | |
190 out.printf(format, option.type.getSimpleName(), option.name(), assign, value); | |
191 String helpFormat = "%" + (typeWidth + 1) + "s %s%n"; | |
192 for (String line : option.helpLines) { | |
193 out.printf(helpFormat, "", line); | |
194 } | |
177 } | 195 } |
178 } | 196 } |
179 } | 197 } |
180 | 198 |
181 public static HotSpotJVMCIBackendFactory findFactory(String architecture) { | 199 public static HotSpotJVMCIBackendFactory findFactory(String architecture) { |
257 try (InitTimer t = timer("create JVMCI backend:", hostArchitecture)) { | 275 try (InitTimer t = timer("create JVMCI backend:", hostArchitecture)) { |
258 hostBackend = registerBackend(factory.createJVMCIBackend(this, null)); | 276 hostBackend = registerBackend(factory.createJVMCIBackend(this, null)); |
259 } | 277 } |
260 | 278 |
261 metaAccessContext = new HotSpotJVMCIMetaAccessContext(); | 279 metaAccessContext = new HotSpotJVMCIMetaAccessContext(); |
262 | |
263 boolean printFlags = Option.PrintFlags.getBoolean(); | |
264 boolean showFlags = Option.ShowFlags.getBoolean(); | |
265 if (printFlags || showFlags) { | |
266 Option.printFlags(System.out); | |
267 if (printFlags) { | |
268 System.exit(0); | |
269 } | |
270 } | |
271 | |
272 if (Option.PrintConfig.getBoolean()) { | |
273 printConfig(configStore, compilerToVm); | |
274 System.exit(0); | |
275 } | |
276 | 280 |
277 compilerFactory = HotSpotJVMCICompilerConfig.getCompilerFactory(); | 281 compilerFactory = HotSpotJVMCICompilerConfig.getCompilerFactory(); |
278 if (compilerFactory instanceof HotSpotJVMCICompilerFactory) { | 282 if (compilerFactory instanceof HotSpotJVMCICompilerFactory) { |
279 hsCompilerFactory = (HotSpotJVMCICompilerFactory) compilerFactory; | 283 hsCompilerFactory = (HotSpotJVMCICompilerFactory) compilerFactory; |
280 trivialPrefixes = hsCompilerFactory.getTrivialPrefixes(); | 284 trivialPrefixes = hsCompilerFactory.getTrivialPrefixes(); |
295 } else { | 299 } else { |
296 hsCompilerFactory = null; | 300 hsCompilerFactory = null; |
297 trivialPrefixes = null; | 301 trivialPrefixes = null; |
298 compilationLevelAdjustment = config.compLevelAdjustmentNone; | 302 compilationLevelAdjustment = config.compLevelAdjustmentNone; |
299 } | 303 } |
304 | |
305 if (config.getFlag("JVMCIPrintFlags", Boolean.class)) { | |
306 PrintStream out = new PrintStream(getLogStream()); | |
307 Option.printFlags(out); | |
308 compilerFactory.printFlags(out); | |
309 System.exit(0); | |
310 } | |
311 | |
312 if (Option.PrintConfig.getBoolean()) { | |
313 printConfig(configStore, compilerToVm); | |
314 System.exit(0); | |
315 } | |
300 } | 316 } |
301 | 317 |
302 private JVMCIBackend registerBackend(JVMCIBackend backend) { | 318 private JVMCIBackend registerBackend(JVMCIBackend backend) { |
303 Class<? extends Architecture> arch = backend.getCodeCache().getTarget().arch.getClass(); | 319 Class<? extends Architecture> arch = backend.getCodeCache().getTarget().arch.getClass(); |
304 JVMCIBackend oldValue = backends.put(arch, backend); | 320 JVMCIBackend oldValue = backends.put(arch, backend); |