Mercurial > hg > graal-jvmci-8
diff 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 |
line wrap: on
line diff
--- a/jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotJVMCIRuntime.java Fri Jun 17 19:13:02 2016 +0200 +++ b/jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotJVMCIRuntime.java Sat Jun 18 13:19:01 2016 +0200 @@ -27,10 +27,6 @@ import java.io.IOException; import java.io.OutputStream; import java.io.PrintStream; -import java.lang.reflect.Array; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -44,8 +40,8 @@ import jdk.vm.ci.common.InitTimer; import jdk.vm.ci.common.JVMCIError; import jdk.vm.ci.hotspot.services.HotSpotJVMCICompilerFactory; +import jdk.vm.ci.hotspot.services.HotSpotJVMCICompilerFactory.CompilationLevel; import jdk.vm.ci.hotspot.services.HotSpotVMEventListener; -import jdk.vm.ci.hotspot.services.HotSpotJVMCICompilerFactory.CompilationLevel; import jdk.vm.ci.meta.JavaKind; import jdk.vm.ci.meta.JavaType; import jdk.vm.ci.meta.ResolvedJavaType; @@ -95,7 +91,7 @@ // Note: The following one is not used (see InitTimer.ENABLED). It is added here // so that -Djvmci.PrintFlags=true shows the option. InitTimer(boolean.class, false, "Specifies if initialization timing is enabled."), - PrintConfig(boolean.class, false, "Prints all HotSpotVMConfig fields."), + PrintConfig(boolean.class, false, "Prints available VM configuration info."), PrintFlags(boolean.class, false, "Prints all JVMCI flags and exits."), ShowFlags(boolean.class, false, "Prints all JVMCI flags and continues."), TraceMethodDataFilter(String.class, null, ""); @@ -225,6 +221,7 @@ @SuppressWarnings("unused") private final String[] trivialPrefixes; @SuppressWarnings("try") + @SuppressFBWarnings(value = "DM_EXIT", justification = "PrintFlags is meant to exit the VM") private HotSpotJVMCIRuntime() { compilerToVm = new CompilerToVM(); @@ -257,7 +254,7 @@ } if (Option.PrintConfig.getBoolean()) { - printConfig(config, compilerToVm); + printConfig(configStore, compilerToVm); } compilerFactory = HotSpotJVMCICompilerConfig.getCompilerFactory(); @@ -448,71 +445,40 @@ } } - private static void printConfig(HotSpotVMConfig config, CompilerToVM vm) { - Field[] fields = config.getClass().getDeclaredFields(); - Map<String, Field> sortedFields = new TreeMap<>(); - for (Field f : fields) { - if (!f.isSynthetic() && !Modifier.isStatic(f.getModifiers())) { - f.setAccessible(true); - sortedFields.put(f.getName(), f); - } - } - for (Field f : sortedFields.values()) { - try { - String line = String.format("%9s %-40s = %s%n", f.getType().getSimpleName(), f.getName(), pretty(f.get(config))); - byte[] lineBytes = line.getBytes(); - vm.writeDebugOutput(lineBytes, 0, lineBytes.length); - vm.flushDebugOutput(); - } catch (Exception e) { - } - } + @SuppressFBWarnings(value = "DM_DEFAULT_ENCODING", justification = "no localization here please!") + private static void printConfigLine(CompilerToVM vm, String format, Object... args) { + String line = String.format(format, args); + byte[] lineBytes = line.getBytes(); + vm.writeDebugOutput(lineBytes, 0, lineBytes.length); + vm.flushDebugOutput(); } - private static String pretty(Object value) { - if (value == null) { - return "null"; - } - - Class<?> klass = value.getClass(); - if (value instanceof String) { - return "\"" + value + "\""; - } else if (value instanceof Method) { - return "method \"" + ((Method) value).getName() + "\""; - } else if (value instanceof Class<?>) { - return "class \"" + ((Class<?>) value).getSimpleName() + "\""; - } else if (value instanceof Integer) { - if ((Integer) value < 10) { - return value.toString(); - } - return value + " (0x" + Integer.toHexString((Integer) value) + ")"; - } else if (value instanceof Long) { - if ((Long) value < 10 && (Long) value > -10) { - return value + "l"; + private static void printConfig(HotSpotVMConfigStore store, CompilerToVM vm) { + TreeMap<String, VMField> fields = new TreeMap<>(store.getFields()); + for (VMField field : fields.values()) { + if (!field.isStatic()) { + printConfigLine(vm, "[vmconfig:instance field] %s %s {offset=%d[0x%x]}%n", field.type, field.name, field.offset, field.offset); + } else { + String value = field.value == null ? "null" : String.format("%d[0x%x]", field.value, field.value); + printConfigLine(vm, "[vmconfig:static field] %s %s = %s {address=0x%x}%n", field.type, field.name, value, field.address); } - return value + "l (0x" + Long.toHexString((Long) value) + "l)"; - } else if (klass.isArray()) { - StringBuilder str = new StringBuilder(); - int dimensions = 0; - while (klass.isArray()) { - dimensions++; - klass = klass.getComponentType(); - } - int length = Array.getLength(value); - str.append(klass.getSimpleName()).append('[').append(length).append(']'); - for (int i = 1; i < dimensions; i++) { - str.append("[]"); - } - str.append(" {"); - for (int i = 0; i < length; i++) { - str.append(pretty(Array.get(value, i))); - if (i < length - 1) { - str.append(", "); - } - } - str.append('}'); - return str.toString(); + } + TreeMap<String, VMFlag> flags = new TreeMap<>(store.getFlags()); + for (VMFlag flag : flags.values()) { + printConfigLine(vm, "[vmconfig:flag] %s %s = %s%n", flag.type, flag.name, flag.value); + } + TreeMap<String, Long> addresses = new TreeMap<>(store.getAddresses()); + for (Map.Entry<String, Long> e : addresses.entrySet()) { + printConfigLine(vm, "[vmconfig:address] %s = %d[0x%x]%n", e.getKey(), e.getValue(), e.getValue()); } - return value.toString(); + TreeMap<String, Long> constants = new TreeMap<>(store.getConstants()); + for (Map.Entry<String, Long> e : constants.entrySet()) { + printConfigLine(vm, "[vmconfig:constant] %s = %d[0x%x]%n", e.getKey(), e.getValue(), e.getValue()); + } + TreeMap<String, Long> typeSizes = new TreeMap<>(store.getTypeSizes()); + for (Map.Entry<String, Long> e : typeSizes.entrySet()) { + printConfigLine(vm, "[vmconfig:type size] %s = %d%n", e.getKey(), e.getValue()); + } } public OutputStream getLogStream() {