src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.printer/src/org/graalvm/compiler/printer/IdealGraphPrinter.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot Sdiff src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.printer/src/org/graalvm/compiler/printer

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.printer/src/org/graalvm/compiler/printer/IdealGraphPrinter.java

Print this page




  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package org.graalvm.compiler.printer;
  24 
  25 import java.io.OutputStream;
  26 import java.util.ArrayList;
  27 import java.util.Arrays;
  28 import java.util.List;
  29 import java.util.Map;
  30 import java.util.Map.Entry;
  31 import java.util.Set;
  32 
  33 import org.graalvm.compiler.api.replacements.SnippetReflectionProvider;
  34 import org.graalvm.compiler.bytecode.BytecodeDisassembler;
  35 import org.graalvm.compiler.debug.GraalDebugConfig.Options;
  36 import org.graalvm.compiler.debug.internal.DebugScope;
  37 import org.graalvm.compiler.graph.Graph;
  38 import org.graalvm.compiler.graph.Node;
  39 import org.graalvm.compiler.graph.NodeMap;
  40 import org.graalvm.compiler.graph.Position;
  41 import org.graalvm.compiler.nodeinfo.Verbosity;
  42 import org.graalvm.compiler.nodes.AbstractMergeNode;
  43 import org.graalvm.compiler.nodes.BeginNode;
  44 import org.graalvm.compiler.nodes.ConstantNode;
  45 import org.graalvm.compiler.nodes.EndNode;
  46 import org.graalvm.compiler.nodes.ParameterNode;
  47 import org.graalvm.compiler.nodes.PhiNode;
  48 import org.graalvm.compiler.nodes.StateSplit;
  49 import org.graalvm.compiler.nodes.StructuredGraph;
  50 import org.graalvm.compiler.nodes.StructuredGraph.ScheduleResult;
  51 import org.graalvm.compiler.nodes.cfg.Block;
  52 import org.graalvm.compiler.nodes.cfg.ControlFlowGraph;

  53 import org.graalvm.compiler.phases.schedule.SchedulePhase;
  54 import org.graalvm.util.EconomicSet;
  55 import org.graalvm.util.Equivalence;
  56 
  57 import jdk.vm.ci.meta.ResolvedJavaMethod;
  58 
  59 /**
  60  * Generates a representation of {@link Graph Graphs} that can be visualized and inspected with the
  61  * <a href="http://kenai.com/projects/igv">Ideal Graph Visualizer</a>.
  62  */
  63 public class IdealGraphPrinter extends BasicIdealGraphPrinter implements GraphPrinter {
  64 
  65     private final boolean tryToSchedule;
  66     private SnippetReflectionProvider snippetReflection;
  67 
  68     /**
  69      * Creates a new {@link IdealGraphPrinter} that writes to the specified output stream.
  70      *
  71      * @param tryToSchedule If false, no scheduling is done, which avoids exceptions for
  72      *            non-schedulable graphs.
  73      */
  74     public IdealGraphPrinter(OutputStream stream, boolean tryToSchedule) {
  75         super(stream);

  76         this.begin();
  77         this.tryToSchedule = tryToSchedule;
  78     }
  79 
  80     @Override
  81     public void setSnippetReflectionProvider(SnippetReflectionProvider snippetReflection) {
  82         this.snippetReflection = snippetReflection;
  83     }
  84 
  85     @Override
  86     public SnippetReflectionProvider getSnippetReflectionProvider() {
  87         return snippetReflection;
  88     }
  89 
  90     /**
  91      * Starts a new group of graphs with the given name, short name and method byte code index (BCI)
  92      * as properties.
  93      */
  94     @Override
  95     public void beginGroup(String name, String shortName, ResolvedJavaMethod method, int bci, Map<Object, Object> properties) {
  96         beginGroup();
  97         beginProperties();
  98         printProperty("name", name);
  99         if (properties != null) {
 100             for (Entry<Object, Object> entry : properties.entrySet()) {
 101                 printProperty(entry.getKey().toString(), entry.getValue().toString());
 102             }
 103         }
 104         endProperties();
 105         beginMethod(name, shortName, bci);
 106         if (method != null && method.getCode() != null) {
 107             printBytecodes(new BytecodeDisassembler(false).disassemble(method));
 108         }
 109         endMethod();
 110     }
 111 
 112     /**
 113      * Prints an entire {@link Graph} with the specified title, optionally using short names for
 114      * nodes.
 115      */
 116     @Override
 117     public void print(Graph graph, Map<Object, Object> properties, int id, String format, Object... args) {
 118         String title = formatTitle(id, format, args);
 119         beginGraph(title);
 120         EconomicSet<Node> noBlockNodes = EconomicSet.create(Equivalence.IDENTITY);
 121         ScheduleResult schedule = null;
 122         if (graph instanceof StructuredGraph) {
 123             StructuredGraph structuredGraph = (StructuredGraph) graph;
 124             schedule = structuredGraph.getLastSchedule();
 125             if (schedule == null && tryToSchedule) {
 126                 if (Options.PrintGraphWithSchedule.getValue(DebugScope.getConfig().getOptions())) {

 127                     try {
 128                         SchedulePhase schedulePhase = new SchedulePhase(graph.getOptions());
 129                         schedulePhase.apply(structuredGraph);
 130                         schedule = structuredGraph.getLastSchedule();
 131                     } catch (Throwable t) {
 132                     }
 133                 }
 134             }
 135         }
 136         ControlFlowGraph cfg = schedule == null ? null : schedule.getCFG();
 137 
 138         if (properties != null) {
 139             beginProperties();
 140             for (Entry<Object, Object> entry : properties.entrySet()) {
 141                 printProperty(entry.getKey().toString(), entry.getValue().toString());
 142             }
 143             endProperties();
 144         }
 145 
 146         beginNodes();
 147         List<Edge> edges = printNodes(graph, cfg == null ? null : cfg.getNodeToBlock(), noBlockNodes);
 148         endNodes();




  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package org.graalvm.compiler.printer;
  24 
  25 import java.io.OutputStream;
  26 import java.util.ArrayList;
  27 import java.util.Arrays;
  28 import java.util.List;
  29 import java.util.Map;
  30 import java.util.Map.Entry;
  31 import java.util.Set;
  32 
  33 import org.graalvm.compiler.api.replacements.SnippetReflectionProvider;
  34 import org.graalvm.compiler.bytecode.BytecodeDisassembler;
  35 import org.graalvm.compiler.debug.DebugContext;
  36 import org.graalvm.compiler.debug.DebugOptions;
  37 import org.graalvm.compiler.graph.Graph;
  38 import org.graalvm.compiler.graph.Node;
  39 import org.graalvm.compiler.graph.NodeMap;
  40 import org.graalvm.compiler.graph.Position;
  41 import org.graalvm.compiler.nodeinfo.Verbosity;
  42 import org.graalvm.compiler.nodes.AbstractMergeNode;
  43 import org.graalvm.compiler.nodes.BeginNode;
  44 import org.graalvm.compiler.nodes.ConstantNode;
  45 import org.graalvm.compiler.nodes.EndNode;
  46 import org.graalvm.compiler.nodes.ParameterNode;
  47 import org.graalvm.compiler.nodes.PhiNode;
  48 import org.graalvm.compiler.nodes.StateSplit;
  49 import org.graalvm.compiler.nodes.StructuredGraph;
  50 import org.graalvm.compiler.nodes.StructuredGraph.ScheduleResult;
  51 import org.graalvm.compiler.nodes.cfg.Block;
  52 import org.graalvm.compiler.nodes.cfg.ControlFlowGraph;
  53 import org.graalvm.compiler.options.OptionValues;
  54 import org.graalvm.compiler.phases.schedule.SchedulePhase;
  55 import org.graalvm.util.EconomicSet;
  56 import org.graalvm.util.Equivalence;
  57 
  58 import jdk.vm.ci.meta.ResolvedJavaMethod;
  59 
  60 /**
  61  * Generates a representation of {@link Graph Graphs} that can be visualized and inspected with the
  62  * <a href="http://kenai.com/projects/igv">Ideal Graph Visualizer</a>.
  63  */
  64 public class IdealGraphPrinter extends BasicIdealGraphPrinter implements GraphPrinter {
  65 
  66     private final boolean tryToSchedule;
  67     private final SnippetReflectionProvider snippetReflection;
  68 
  69     /**
  70      * Creates a new {@link IdealGraphPrinter} that writes to the specified output stream.
  71      *
  72      * @param tryToSchedule If false, no scheduling is done, which avoids exceptions for
  73      *            non-schedulable graphs.
  74      */
  75     public IdealGraphPrinter(OutputStream stream, boolean tryToSchedule, SnippetReflectionProvider snippetReflection) {
  76         super(stream);
  77         this.snippetReflection = snippetReflection;
  78         this.begin();
  79         this.tryToSchedule = tryToSchedule;
  80     }
  81 
  82     @Override





  83     public SnippetReflectionProvider getSnippetReflectionProvider() {
  84         return snippetReflection;
  85     }
  86 
  87     /**
  88      * Starts a new group of graphs with the given name, short name and method byte code index (BCI)
  89      * as properties.
  90      */
  91     @Override
  92     public void beginGroup(DebugContext debug, String name, String shortName, ResolvedJavaMethod method, int bci, Map<Object, Object> properties) {
  93         beginGroup();
  94         beginProperties();
  95         printProperty("name", name);
  96         if (properties != null) {
  97             for (Entry<Object, Object> entry : properties.entrySet()) {
  98                 printProperty(entry.getKey().toString(), entry.getValue().toString());
  99             }
 100         }
 101         endProperties();
 102         beginMethod(name, shortName, bci);
 103         if (method != null && method.getCode() != null) {
 104             printBytecodes(new BytecodeDisassembler(false).disassemble(method));
 105         }
 106         endMethod();
 107     }
 108 
 109     /**
 110      * Prints an entire {@link Graph} with the specified title, optionally using short names for
 111      * nodes.
 112      */
 113     @Override
 114     public void print(DebugContext debug, Graph graph, Map<Object, Object> properties, int id, String format, Object... args) {
 115         String title = id + ": " + String.format(format, simplifyClassArgs(args));
 116         beginGraph(title);
 117         EconomicSet<Node> noBlockNodes = EconomicSet.create(Equivalence.IDENTITY);
 118         ScheduleResult schedule = null;
 119         if (graph instanceof StructuredGraph) {
 120             StructuredGraph structuredGraph = (StructuredGraph) graph;
 121             schedule = structuredGraph.getLastSchedule();
 122             if (schedule == null && tryToSchedule) {
 123                 OptionValues options = graph.getOptions();
 124                 if (DebugOptions.PrintGraphWithSchedule.getValue(options)) {
 125                     try {
 126                         SchedulePhase schedulePhase = new SchedulePhase(options);
 127                         schedulePhase.apply(structuredGraph);
 128                         schedule = structuredGraph.getLastSchedule();
 129                     } catch (Throwable t) {
 130                     }
 131                 }
 132             }
 133         }
 134         ControlFlowGraph cfg = schedule == null ? null : schedule.getCFG();
 135 
 136         if (properties != null) {
 137             beginProperties();
 138             for (Entry<Object, Object> entry : properties.entrySet()) {
 139                 printProperty(entry.getKey().toString(), entry.getValue().toString());
 140             }
 141             endProperties();
 142         }
 143 
 144         beginNodes();
 145         List<Edge> edges = printNodes(graph, cfg == null ? null : cfg.getNodeToBlock(), noBlockNodes);
 146         endNodes();


src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.printer/src/org/graalvm/compiler/printer/IdealGraphPrinter.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File