# HG changeset patch # User Doug Simon # Date 1412152404 -7200 # Node ID db0ee78b1ad5918111feea0fbf386390ff15c129 # Parent 0f8b1fb632df82a19fd0631c782c5506ba700108 prevent deadlock in HotSpotGraalRuntime.shutdown() by loading DebugValuesPrinter class eagerly diff -r 0f8b1fb632df -r db0ee78b1ad5 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/DebugValuesPrinter.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/DebugValuesPrinter.java Tue Sep 30 18:56:28 2014 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/DebugValuesPrinter.java Wed Oct 01 10:33:24 2014 +0200 @@ -38,75 +38,73 @@ public class DebugValuesPrinter { public void printDebugValues(String phase, boolean reset) throws GraalInternalError { - if (Debug.areUnconditionalMetricsEnabled() || Debug.areUnconditionalTimersEnabled() || (Debug.isEnabled() && areMetricsOrTimersEnabled())) { - TTY.println(); - if (phase != null) { - TTY.println(""); - } else { - TTY.println(""); - } - List topLevelMaps = DebugValueMap.getTopLevelMaps(); - List debugValues = KeyRegistry.getDebugValues(); - if (debugValues.size() > 0) { - try { - ArrayList sortedValues = new ArrayList<>(debugValues); - Collections.sort(sortedValues); + TTY.println(); + if (phase != null) { + TTY.println(""); + } else { + TTY.println(""); + } + List topLevelMaps = DebugValueMap.getTopLevelMaps(); + List debugValues = KeyRegistry.getDebugValues(); + if (debugValues.size() > 0) { + try { + ArrayList sortedValues = new ArrayList<>(debugValues); + Collections.sort(sortedValues); - String summary = DebugValueSummary.getValue(); - if (summary == null) { - summary = "Complete"; - } - switch (summary) { - case "Name": - printSummary(topLevelMaps, sortedValues); - break; - case "Partial": { - DebugValueMap globalMap = new DebugValueMap("Global"); - for (DebugValueMap map : topLevelMaps) { - flattenChildren(map, globalMap); - } - globalMap.normalize(); - printMap(new DebugValueScope(null, globalMap), sortedValues); - break; + String summary = DebugValueSummary.getValue(); + if (summary == null) { + summary = "Complete"; + } + switch (summary) { + case "Name": + printSummary(topLevelMaps, sortedValues); + break; + case "Partial": { + DebugValueMap globalMap = new DebugValueMap("Global"); + for (DebugValueMap map : topLevelMaps) { + flattenChildren(map, globalMap); } - case "Complete": { - DebugValueMap globalMap = new DebugValueMap("Global"); - for (DebugValueMap map : topLevelMaps) { - globalMap.addChild(map); - } - globalMap.group(); - globalMap.normalize(); - printMap(new DebugValueScope(null, globalMap), sortedValues); - break; + globalMap.normalize(); + printMap(new DebugValueScope(null, globalMap), sortedValues); + break; + } + case "Complete": { + DebugValueMap globalMap = new DebugValueMap("Global"); + for (DebugValueMap map : topLevelMaps) { + globalMap.addChild(map); + } + globalMap.group(); + globalMap.normalize(); + printMap(new DebugValueScope(null, globalMap), sortedValues); + break; + } + case "Thread": + for (DebugValueMap map : topLevelMaps) { + TTY.println("Showing the results for thread: " + map.getName()); + map.group(); + map.normalize(); + printMap(new DebugValueScope(null, map), sortedValues); } - case "Thread": - for (DebugValueMap map : topLevelMaps) { - TTY.println("Showing the results for thread: " + map.getName()); - map.group(); - map.normalize(); - printMap(new DebugValueScope(null, map), sortedValues); - } - break; - default: - throw new GraalInternalError("Unknown summary type: %s", summary); + break; + default: + throw new GraalInternalError("Unknown summary type: %s", summary); + } + if (reset) { + for (DebugValueMap topLevelMap : topLevelMaps) { + topLevelMap.reset(); } - if (reset) { - for (DebugValueMap topLevelMap : topLevelMaps) { - topLevelMap.reset(); - } - } - } catch (Throwable e) { - // Don't want this to change the exit status of the VM - PrintStream err = System.err; - err.println("Error while printing debug values:"); - e.printStackTrace(); } + } catch (Throwable e) { + // Don't want this to change the exit status of the VM + PrintStream err = System.err; + err.println("Error while printing debug values:"); + e.printStackTrace(); } - if (phase != null) { - TTY.println(""); - } else { - TTY.println(""); - } + } + if (phase != null) { + TTY.println(""); + } else { + TTY.println(""); } } diff -r 0f8b1fb632df -r db0ee78b1ad5 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java Tue Sep 30 18:56:28 2014 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java Wed Oct 01 10:33:24 2014 +0200 @@ -132,6 +132,11 @@ throw new GraalInternalError("Unsupported value for DebugSummaryValue: %s", summary); } } + if (Debug.areUnconditionalMetricsEnabled() || Debug.areUnconditionalTimersEnabled() || (Debug.isEnabled() && areMetricsOrTimersEnabled())) { + // This must be created here to avoid loading the DebugValuesPrinter class + // during shutdown() which in turn can cause a deadlock + debugValuesPrinter = new DebugValuesPrinter(); + } } // Complete initialization of backends @@ -247,6 +252,7 @@ protected final HotSpotVMConfig config; private final HotSpotBackend hostBackend; + private DebugValuesPrinter debugValuesPrinter; /** * Graal mirrors are stored as a {@link ClassValue} associated with the {@link Class} of the @@ -581,7 +587,9 @@ */ @SuppressWarnings("unused") private void shutdown() throws Exception { - new DebugValuesPrinter().printDebugValues(ResetDebugValuesAfterBootstrap.getValue() ? "application" : null, false); + if (debugValuesPrinter != null) { + debugValuesPrinter.printDebugValues(ResetDebugValuesAfterBootstrap.getValue() ? "application" : null, false); + } phaseTransition("final"); SnippetCounter.printGroups(TTY.out().out());