Mercurial > hg > graal-jvmci-8
comparison jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotJVMCIRuntime.java @ 23700:9e1235406b59
[Findbugs] various warnings reported for JVMCI sources (JDK-8159613)
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Sat, 18 Jun 2016 13:19:01 +0200 |
parents | b5557b757040 |
children | 5d149c67c230 |
comparison
equal
deleted
inserted
replaced
23699:8f9709f61cd4 | 23700:9e1235406b59 |
---|---|
25 import static jdk.vm.ci.common.InitTimer.timer; | 25 import static jdk.vm.ci.common.InitTimer.timer; |
26 | 26 |
27 import java.io.IOException; | 27 import java.io.IOException; |
28 import java.io.OutputStream; | 28 import java.io.OutputStream; |
29 import java.io.PrintStream; | 29 import java.io.PrintStream; |
30 import java.lang.reflect.Array; | |
31 import java.lang.reflect.Field; | |
32 import java.lang.reflect.Method; | |
33 import java.lang.reflect.Modifier; | |
34 import java.util.Collections; | 30 import java.util.Collections; |
35 import java.util.HashMap; | 31 import java.util.HashMap; |
36 import java.util.Map; | 32 import java.util.Map; |
37 import java.util.Objects; | 33 import java.util.Objects; |
38 import java.util.TreeMap; | 34 import java.util.TreeMap; |
42 import jdk.vm.ci.code.CompiledCode; | 38 import jdk.vm.ci.code.CompiledCode; |
43 import jdk.vm.ci.code.InstalledCode; | 39 import jdk.vm.ci.code.InstalledCode; |
44 import jdk.vm.ci.common.InitTimer; | 40 import jdk.vm.ci.common.InitTimer; |
45 import jdk.vm.ci.common.JVMCIError; | 41 import jdk.vm.ci.common.JVMCIError; |
46 import jdk.vm.ci.hotspot.services.HotSpotJVMCICompilerFactory; | 42 import jdk.vm.ci.hotspot.services.HotSpotJVMCICompilerFactory; |
43 import jdk.vm.ci.hotspot.services.HotSpotJVMCICompilerFactory.CompilationLevel; | |
47 import jdk.vm.ci.hotspot.services.HotSpotVMEventListener; | 44 import jdk.vm.ci.hotspot.services.HotSpotVMEventListener; |
48 import jdk.vm.ci.hotspot.services.HotSpotJVMCICompilerFactory.CompilationLevel; | |
49 import jdk.vm.ci.meta.JavaKind; | 45 import jdk.vm.ci.meta.JavaKind; |
50 import jdk.vm.ci.meta.JavaType; | 46 import jdk.vm.ci.meta.JavaType; |
51 import jdk.vm.ci.meta.ResolvedJavaType; | 47 import jdk.vm.ci.meta.ResolvedJavaType; |
52 import jdk.vm.ci.runtime.JVMCI; | 48 import jdk.vm.ci.runtime.JVMCI; |
53 import jdk.vm.ci.runtime.JVMCIBackend; | 49 import jdk.vm.ci.runtime.JVMCIBackend; |
93 public enum Option { | 89 public enum Option { |
94 Compiler(String.class, null, "Selects the system compiler."), | 90 Compiler(String.class, null, "Selects the system compiler."), |
95 // Note: The following one is not used (see InitTimer.ENABLED). It is added here | 91 // Note: The following one is not used (see InitTimer.ENABLED). It is added here |
96 // so that -Djvmci.PrintFlags=true shows the option. | 92 // so that -Djvmci.PrintFlags=true shows the option. |
97 InitTimer(boolean.class, false, "Specifies if initialization timing is enabled."), | 93 InitTimer(boolean.class, false, "Specifies if initialization timing is enabled."), |
98 PrintConfig(boolean.class, false, "Prints all HotSpotVMConfig fields."), | 94 PrintConfig(boolean.class, false, "Prints available VM configuration info."), |
99 PrintFlags(boolean.class, false, "Prints all JVMCI flags and exits."), | 95 PrintFlags(boolean.class, false, "Prints all JVMCI flags and exits."), |
100 ShowFlags(boolean.class, false, "Prints all JVMCI flags and continues."), | 96 ShowFlags(boolean.class, false, "Prints all JVMCI flags and continues."), |
101 TraceMethodDataFilter(String.class, null, ""); | 97 TraceMethodDataFilter(String.class, null, ""); |
102 | 98 |
103 /** | 99 /** |
223 * be read from the VM. | 219 * be read from the VM. |
224 */ | 220 */ |
225 @SuppressWarnings("unused") private final String[] trivialPrefixes; | 221 @SuppressWarnings("unused") private final String[] trivialPrefixes; |
226 | 222 |
227 @SuppressWarnings("try") | 223 @SuppressWarnings("try") |
224 @SuppressFBWarnings(value = "DM_EXIT", justification = "PrintFlags is meant to exit the VM") | |
228 private HotSpotJVMCIRuntime() { | 225 private HotSpotJVMCIRuntime() { |
229 compilerToVm = new CompilerToVM(); | 226 compilerToVm = new CompilerToVM(); |
230 | 227 |
231 try (InitTimer t = timer("HotSpotVMConfig<init>")) { | 228 try (InitTimer t = timer("HotSpotVMConfig<init>")) { |
232 configStore = new HotSpotVMConfigStore(compilerToVm); | 229 configStore = new HotSpotVMConfigStore(compilerToVm); |
255 System.exit(0); | 252 System.exit(0); |
256 } | 253 } |
257 } | 254 } |
258 | 255 |
259 if (Option.PrintConfig.getBoolean()) { | 256 if (Option.PrintConfig.getBoolean()) { |
260 printConfig(config, compilerToVm); | 257 printConfig(configStore, compilerToVm); |
261 } | 258 } |
262 | 259 |
263 compilerFactory = HotSpotJVMCICompilerConfig.getCompilerFactory(); | 260 compilerFactory = HotSpotJVMCICompilerConfig.getCompilerFactory(); |
264 if (compilerFactory instanceof HotSpotJVMCICompilerFactory) { | 261 if (compilerFactory instanceof HotSpotJVMCICompilerFactory) { |
265 hsCompilerFactory = (HotSpotJVMCICompilerFactory) compilerFactory; | 262 hsCompilerFactory = (HotSpotJVMCICompilerFactory) compilerFactory; |
446 for (HotSpotVMEventListener vmEventListener : vmEventListeners) { | 443 for (HotSpotVMEventListener vmEventListener : vmEventListeners) { |
447 vmEventListener.notifyInstall(hotSpotCodeCacheProvider, installedCode, compiledCode); | 444 vmEventListener.notifyInstall(hotSpotCodeCacheProvider, installedCode, compiledCode); |
448 } | 445 } |
449 } | 446 } |
450 | 447 |
451 private static void printConfig(HotSpotVMConfig config, CompilerToVM vm) { | 448 @SuppressFBWarnings(value = "DM_DEFAULT_ENCODING", justification = "no localization here please!") |
452 Field[] fields = config.getClass().getDeclaredFields(); | 449 private static void printConfigLine(CompilerToVM vm, String format, Object... args) { |
453 Map<String, Field> sortedFields = new TreeMap<>(); | 450 String line = String.format(format, args); |
454 for (Field f : fields) { | 451 byte[] lineBytes = line.getBytes(); |
455 if (!f.isSynthetic() && !Modifier.isStatic(f.getModifiers())) { | 452 vm.writeDebugOutput(lineBytes, 0, lineBytes.length); |
456 f.setAccessible(true); | 453 vm.flushDebugOutput(); |
457 sortedFields.put(f.getName(), f); | 454 } |
458 } | 455 |
459 } | 456 private static void printConfig(HotSpotVMConfigStore store, CompilerToVM vm) { |
460 for (Field f : sortedFields.values()) { | 457 TreeMap<String, VMField> fields = new TreeMap<>(store.getFields()); |
461 try { | 458 for (VMField field : fields.values()) { |
462 String line = String.format("%9s %-40s = %s%n", f.getType().getSimpleName(), f.getName(), pretty(f.get(config))); | 459 if (!field.isStatic()) { |
463 byte[] lineBytes = line.getBytes(); | 460 printConfigLine(vm, "[vmconfig:instance field] %s %s {offset=%d[0x%x]}%n", field.type, field.name, field.offset, field.offset); |
464 vm.writeDebugOutput(lineBytes, 0, lineBytes.length); | 461 } else { |
465 vm.flushDebugOutput(); | 462 String value = field.value == null ? "null" : String.format("%d[0x%x]", field.value, field.value); |
466 } catch (Exception e) { | 463 printConfigLine(vm, "[vmconfig:static field] %s %s = %s {address=0x%x}%n", field.type, field.name, value, field.address); |
467 } | 464 } |
468 } | 465 } |
469 } | 466 TreeMap<String, VMFlag> flags = new TreeMap<>(store.getFlags()); |
470 | 467 for (VMFlag flag : flags.values()) { |
471 private static String pretty(Object value) { | 468 printConfigLine(vm, "[vmconfig:flag] %s %s = %s%n", flag.type, flag.name, flag.value); |
472 if (value == null) { | 469 } |
473 return "null"; | 470 TreeMap<String, Long> addresses = new TreeMap<>(store.getAddresses()); |
474 } | 471 for (Map.Entry<String, Long> e : addresses.entrySet()) { |
475 | 472 printConfigLine(vm, "[vmconfig:address] %s = %d[0x%x]%n", e.getKey(), e.getValue(), e.getValue()); |
476 Class<?> klass = value.getClass(); | 473 } |
477 if (value instanceof String) { | 474 TreeMap<String, Long> constants = new TreeMap<>(store.getConstants()); |
478 return "\"" + value + "\""; | 475 for (Map.Entry<String, Long> e : constants.entrySet()) { |
479 } else if (value instanceof Method) { | 476 printConfigLine(vm, "[vmconfig:constant] %s = %d[0x%x]%n", e.getKey(), e.getValue(), e.getValue()); |
480 return "method \"" + ((Method) value).getName() + "\""; | 477 } |
481 } else if (value instanceof Class<?>) { | 478 TreeMap<String, Long> typeSizes = new TreeMap<>(store.getTypeSizes()); |
482 return "class \"" + ((Class<?>) value).getSimpleName() + "\""; | 479 for (Map.Entry<String, Long> e : typeSizes.entrySet()) { |
483 } else if (value instanceof Integer) { | 480 printConfigLine(vm, "[vmconfig:type size] %s = %d%n", e.getKey(), e.getValue()); |
484 if ((Integer) value < 10) { | 481 } |
485 return value.toString(); | |
486 } | |
487 return value + " (0x" + Integer.toHexString((Integer) value) + ")"; | |
488 } else if (value instanceof Long) { | |
489 if ((Long) value < 10 && (Long) value > -10) { | |
490 return value + "l"; | |
491 } | |
492 return value + "l (0x" + Long.toHexString((Long) value) + "l)"; | |
493 } else if (klass.isArray()) { | |
494 StringBuilder str = new StringBuilder(); | |
495 int dimensions = 0; | |
496 while (klass.isArray()) { | |
497 dimensions++; | |
498 klass = klass.getComponentType(); | |
499 } | |
500 int length = Array.getLength(value); | |
501 str.append(klass.getSimpleName()).append('[').append(length).append(']'); | |
502 for (int i = 1; i < dimensions; i++) { | |
503 str.append("[]"); | |
504 } | |
505 str.append(" {"); | |
506 for (int i = 0; i < length; i++) { | |
507 str.append(pretty(Array.get(value, i))); | |
508 if (i < length - 1) { | |
509 str.append(", "); | |
510 } | |
511 } | |
512 str.append('}'); | |
513 return str.toString(); | |
514 } | |
515 return value.toString(); | |
516 } | 482 } |
517 | 483 |
518 public OutputStream getLogStream() { | 484 public OutputStream getLogStream() { |
519 return new OutputStream() { | 485 return new OutputStream() { |
520 | 486 |