--- old/src/jdk.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotJVMCIRuntime.java 2016-06-21 23:03:51.000000000 +0200 +++ new/src/jdk.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotJVMCIRuntime.java 2016-06-21 23:03:50.000000000 +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.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -48,8 +44,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.HotSpotVMEventListener; import jdk.vm.ci.hotspot.services.HotSpotJVMCICompilerFactory.CompilationLevel; +import jdk.vm.ci.hotspot.services.HotSpotVMEventListener; import jdk.vm.ci.meta.JavaKind; import jdk.vm.ci.meta.JavaType; import jdk.vm.ci.meta.ResolvedJavaType; @@ -95,9 +91,10 @@ */ public enum Option { Compiler(String.class, null, "Selects the system compiler."), - // Note: The following one is not used (see InitTimer.ENABLED). + // 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 VM configuration available via JVMCI and exits."), PrintFlags(boolean.class, false, "Prints all JVMCI flags and exits."), ShowFlags(boolean.class, false, "Prints all JVMCI flags and continues."), TraceMethodDataFilter(String.class, null, ""); @@ -242,6 +239,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(); @@ -273,7 +271,8 @@ } if (Option.PrintConfig.getBoolean()) { - printConfig(config, compilerToVm); + printConfig(configStore, compilerToVm); + System.exit(0); } compilerFactory = HotSpotJVMCICompilerConfig.getCompilerFactory(); @@ -464,71 +463,40 @@ } } - private static void printConfig(HotSpotVMConfig config, CompilerToVM vm) { - Field[] fields = config.getClass().getDeclaredFields(); - Map 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"; - } - 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(", "); - } + private static void printConfig(HotSpotVMConfigStore store, CompilerToVM vm) { + TreeMap 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); } - str.append('}'); - return str.toString(); } - return value.toString(); + TreeMap 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 addresses = new TreeMap<>(store.getAddresses()); + for (Map.Entry e : addresses.entrySet()) { + printConfigLine(vm, "[vmconfig:address] %s = %d[0x%x]%n", e.getKey(), e.getValue(), e.getValue()); + } + TreeMap constants = new TreeMap<>(store.getConstants()); + for (Map.Entry e : constants.entrySet()) { + printConfigLine(vm, "[vmconfig:constant] %s = %d[0x%x]%n", e.getKey(), e.getValue(), e.getValue()); + } + TreeMap typeSizes = new TreeMap<>(store.getTypeSizes()); + for (Map.Entry e : typeSizes.entrySet()) { + printConfigLine(vm, "[vmconfig:type size] %s = %d%n", e.getKey(), e.getValue()); + } } public OutputStream getLogStream() {