src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.printer/src/org/graalvm/compiler/printer/CanonicalStringGraphPrinter.java
Index
Unified diffs
Context diffs
Sdiffs
Patch
New
Old
Previous File
Next File
hotspot Cdiff src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.printer/src/org/graalvm/compiler/printer/CanonicalStringGraphPrinter.java
src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.printer/src/org/graalvm/compiler/printer/CanonicalStringGraphPrinter.java
Print this page
*** 20,33 ****
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package org.graalvm.compiler.printer;
! import static org.graalvm.compiler.debug.GraalDebugConfig.Options.CanonicalGraphStringsCheckConstants;
! import static org.graalvm.compiler.debug.GraalDebugConfig.Options.CanonicalGraphStringsExcludeVirtuals;
! import static org.graalvm.compiler.debug.GraalDebugConfig.Options.CanonicalGraphStringsRemoveIdentities;
! import static org.graalvm.compiler.debug.GraalDebugConfig.Options.PrintCanonicalGraphStringFlavor;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
--- 20,34 ----
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package org.graalvm.compiler.printer;
! import static org.graalvm.compiler.debug.DebugOptions.CanonicalGraphStringsCheckConstants;
! import static org.graalvm.compiler.debug.DebugOptions.CanonicalGraphStringsExcludeVirtuals;
! import static org.graalvm.compiler.debug.DebugOptions.CanonicalGraphStringsRemoveIdentities;
! import static org.graalvm.compiler.debug.DebugOptions.PrintCanonicalGraphStringFlavor;
! import static org.graalvm.compiler.printer.GraalDebugHandlersFactory.sanitizedFileName;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
*** 40,50 ****
import java.util.Map;
import java.util.regex.Pattern;
import org.graalvm.compiler.api.replacements.SnippetReflectionProvider;
import org.graalvm.compiler.core.common.Fields;
! import org.graalvm.compiler.debug.TTY;
import org.graalvm.compiler.graph.Graph;
import org.graalvm.compiler.graph.Node;
import org.graalvm.compiler.graph.NodeMap;
import org.graalvm.compiler.graph.Position;
import org.graalvm.compiler.nodeinfo.Verbosity;
--- 41,51 ----
import java.util.Map;
import java.util.regex.Pattern;
import org.graalvm.compiler.api.replacements.SnippetReflectionProvider;
import org.graalvm.compiler.core.common.Fields;
! import org.graalvm.compiler.debug.DebugContext;
import org.graalvm.compiler.graph.Graph;
import org.graalvm.compiler.graph.Node;
import org.graalvm.compiler.graph.NodeMap;
import org.graalvm.compiler.graph.Position;
import org.graalvm.compiler.nodeinfo.Verbosity;
*** 59,107 ****
import org.graalvm.compiler.nodes.ValueNode;
import org.graalvm.compiler.nodes.cfg.Block;
import org.graalvm.compiler.nodes.cfg.ControlFlowGraph;
import org.graalvm.compiler.nodes.virtual.VirtualObjectNode;
import org.graalvm.compiler.options.OptionValues;
- import org.graalvm.compiler.phases.schedule.SchedulePhase;
import jdk.vm.ci.meta.ResolvedJavaMethod;
public class CanonicalStringGraphPrinter implements GraphPrinter {
private static final Pattern IDENTITY_PATTERN = Pattern.compile("([A-Za-z0-9$_]+)@[0-9a-f]+");
! private Path currentDirectory;
! private Path root;
! private SnippetReflectionProvider snippetReflection;
!
! public CanonicalStringGraphPrinter(Path directory) {
! this.currentDirectory = directory;
! this.root = directory;
! }
! @Override
! public void setSnippetReflectionProvider(SnippetReflectionProvider snippetReflection) {
this.snippetReflection = snippetReflection;
}
@Override
public SnippetReflectionProvider getSnippetReflectionProvider() {
return snippetReflection;
}
- protected static String escapeFileName(String name) {
- byte[] bytes = name.getBytes();
- StringBuilder sb = new StringBuilder();
- for (byte b : bytes) {
- if ((b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z') || (b >= '0' && b <= '9') || b == '.' || b == '-' || b == '_') {
- sb.append((char) b);
- } else {
- sb.append('%');
- sb.append(Integer.toHexString(b));
- }
- }
- return sb.toString();
- }
-
private static String removeIdentities(String str) {
return IDENTITY_PATTERN.matcher(str).replaceAll("$1");
}
protected static void writeCanonicalGraphExpressionString(ValueNode node, boolean checkConstants, boolean removeIdentities, PrintWriter writer) {
--- 60,85 ----
import org.graalvm.compiler.nodes.ValueNode;
import org.graalvm.compiler.nodes.cfg.Block;
import org.graalvm.compiler.nodes.cfg.ControlFlowGraph;
import org.graalvm.compiler.nodes.virtual.VirtualObjectNode;
import org.graalvm.compiler.options.OptionValues;
import jdk.vm.ci.meta.ResolvedJavaMethod;
public class CanonicalStringGraphPrinter implements GraphPrinter {
private static final Pattern IDENTITY_PATTERN = Pattern.compile("([A-Za-z0-9$_]+)@[0-9a-f]+");
! private final SnippetReflectionProvider snippetReflection;
! public CanonicalStringGraphPrinter(SnippetReflectionProvider snippetReflection) {
this.snippetReflection = snippetReflection;
}
@Override
public SnippetReflectionProvider getSnippetReflectionProvider() {
return snippetReflection;
}
private static String removeIdentities(String str) {
return IDENTITY_PATTERN.matcher(str).replaceAll("$1");
}
protected static void writeCanonicalGraphExpressionString(ValueNode node, boolean checkConstants, boolean removeIdentities, PrintWriter writer) {
*** 142,152 ****
}
writer.print(")");
}
protected static void writeCanonicalExpressionCFGString(StructuredGraph graph, boolean checkConstants, boolean removeIdentities, PrintWriter writer) {
! ControlFlowGraph controlFlowGraph = ControlFlowGraph.compute(graph, true, true, false, false);
for (Block block : controlFlowGraph.getBlocks()) {
writer.print("Block ");
writer.print(block);
writer.print(" ");
if (block == controlFlowGraph.getStartBlock()) {
--- 120,134 ----
}
writer.print(")");
}
protected static void writeCanonicalExpressionCFGString(StructuredGraph graph, boolean checkConstants, boolean removeIdentities, PrintWriter writer) {
! ControlFlowGraph controlFlowGraph = getControlFlowGraph(graph);
! if (controlFlowGraph == null) {
! return;
! }
! try {
for (Block block : controlFlowGraph.getBlocks()) {
writer.print("Block ");
writer.print(block);
writer.print(" ");
if (block == controlFlowGraph.getStartBlock()) {
*** 167,182 ****
} else {
node = null;
}
}
}
}
protected static void writeCanonicalGraphString(StructuredGraph graph, boolean excludeVirtual, boolean checkConstants, PrintWriter writer) {
! SchedulePhase schedule = new SchedulePhase(SchedulePhase.SchedulingStrategy.EARLIEST);
! schedule.apply(graph);
! StructuredGraph.ScheduleResult scheduleResult = graph.getLastSchedule();
NodeMap<Integer> canonicalId = graph.createNodeMap();
int nextId = 0;
List<String> constantsLines = null;
--- 149,179 ----
} else {
node = null;
}
}
}
+ } catch (Throwable e) {
+ writer.println();
+ e.printStackTrace(writer);
+ }
+ }
+
+ protected static ControlFlowGraph getControlFlowGraph(StructuredGraph graph) {
+ try {
+ return ControlFlowGraph.compute(graph, true, true, false, false);
+ } catch (Throwable e) {
+ // Ignore a non-well formed graph
+ return null;
+ }
}
protected static void writeCanonicalGraphString(StructuredGraph graph, boolean excludeVirtual, boolean checkConstants, PrintWriter writer) {
! StructuredGraph.ScheduleResult scheduleResult = GraphPrinter.getScheduleOrNull(graph);
! if (scheduleResult == null) {
! return;
! }
! try {
NodeMap<Integer> canonicalId = graph.createNodeMap();
int nextId = 0;
List<String> constantsLines = null;
*** 236,245 ****
--- 233,246 ----
Collections.sort(constantsLines);
for (String s : constantsLines) {
writer.println(s);
}
}
+ } catch (Throwable t) {
+ writer.println();
+ t.printStackTrace(writer);
+ }
}
public static String getCanonicalGraphString(StructuredGraph graph, boolean excludeVirtual, boolean checkConstants) {
StringWriter stringWriter = new StringWriter();
PrintWriter writer = new PrintWriter(stringWriter);
*** 251,276 ****
private static int filteredUsageCount(Node node) {
return node.usages().filter(n -> !(n instanceof FrameState)).count();
}
@Override
! public void beginGroup(String name, String shortName, ResolvedJavaMethod method, int bci, Map<Object, Object> properties) throws IOException {
! currentDirectory = currentDirectory.resolve(escapeFileName(name));
}
@Override
! public void print(Graph graph, Map<Object, Object> properties, int id, String format, Object... args) throws IOException {
if (graph instanceof StructuredGraph) {
OptionValues options = graph.getOptions();
StructuredGraph structuredGraph = (StructuredGraph) graph;
! currentDirectory.toFile().mkdirs();
! if (this.root != null) {
! TTY.println("Dumping string graphs in %s", this.root);
! this.root = null;
! }
! String title = formatTitle(id, format, args);
! Path filePath = currentDirectory.resolve(escapeFileName(title));
try (PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(filePath.toFile())))) {
switch (PrintCanonicalGraphStringFlavor.getValue(options)) {
case 1:
writeCanonicalExpressionCFGString(structuredGraph, CanonicalGraphStringsCheckConstants.getValue(options), CanonicalGraphStringsRemoveIdentities.getValue(options), writer);
break;
--- 252,284 ----
private static int filteredUsageCount(Node node) {
return node.usages().filter(n -> !(n instanceof FrameState)).count();
}
@Override
! public void beginGroup(DebugContext debug, String name, String shortName, ResolvedJavaMethod method, int bci, Map<Object, Object> properties) throws IOException {
! }
!
! private StructuredGraph currentGraph;
! private Path currentDirectory;
!
! private Path getDirectory(StructuredGraph graph) throws IOException {
! if (graph == currentGraph) {
! return currentDirectory;
! }
! currentDirectory = GraalDebugHandlersFactory.createDumpPath(graph.getOptions(), graph, "graph-strings", true);
! currentGraph = graph;
! return currentDirectory;
}
@Override
! public void print(DebugContext debug, Graph graph, Map<Object, Object> properties, int id, String format, Object... args) throws IOException {
if (graph instanceof StructuredGraph) {
OptionValues options = graph.getOptions();
StructuredGraph structuredGraph = (StructuredGraph) graph;
! Path outDirectory = getDirectory(structuredGraph);
! String title = String.format("%03d-%s.txt", id, String.format(format, simplifyClassArgs(args)));
! Path filePath = outDirectory.resolve(sanitizedFileName(title));
try (PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(filePath.toFile())))) {
switch (PrintCanonicalGraphStringFlavor.getValue(options)) {
case 1:
writeCanonicalExpressionCFGString(structuredGraph, CanonicalGraphStringsCheckConstants.getValue(options), CanonicalGraphStringsRemoveIdentities.getValue(options), writer);
break;
*** 283,294 ****
}
}
@Override
public void endGroup() throws IOException {
- currentDirectory = currentDirectory.getParent();
- assert currentDirectory != null;
}
@Override
public void close() {
}
--- 291,300 ----
src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.printer/src/org/graalvm/compiler/printer/CanonicalStringGraphPrinter.java
Index
Unified diffs
Context diffs
Sdiffs
Patch
New
Old
Previous File
Next File