< prev index next >

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

Print this page




   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  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 static org.graalvm.compiler.debug.DebugOptions.CanonicalGraphStringsCheckConstants;
  26 import static org.graalvm.compiler.debug.DebugOptions.CanonicalGraphStringsExcludeVirtuals;
  27 import static org.graalvm.compiler.debug.DebugOptions.CanonicalGraphStringsRemoveIdentities;
  28 import static org.graalvm.compiler.debug.DebugOptions.PrintCanonicalGraphStringFlavor;
  29 import static org.graalvm.compiler.printer.GraalDebugHandlersFactory.sanitizedFileName;
  30 
  31 import java.io.BufferedWriter;
  32 import java.io.FileWriter;
  33 import java.io.IOException;
  34 import java.io.PrintWriter;
  35 import java.io.StringWriter;
  36 import java.nio.file.Path;
  37 import java.util.ArrayList;
  38 import java.util.Collections;
  39 import java.util.Iterator;
  40 import java.util.List;
  41 import java.util.Map;
  42 import java.util.regex.Pattern;
  43 
  44 import org.graalvm.compiler.api.replacements.SnippetReflectionProvider;
  45 import org.graalvm.compiler.core.common.Fields;
  46 import org.graalvm.compiler.debug.DebugContext;

  47 import org.graalvm.compiler.graph.Graph;
  48 import org.graalvm.compiler.graph.Node;
  49 import org.graalvm.compiler.graph.NodeMap;
  50 import org.graalvm.compiler.graph.Position;
  51 import org.graalvm.compiler.nodeinfo.Verbosity;
  52 import org.graalvm.compiler.nodes.ConstantNode;
  53 import org.graalvm.compiler.nodes.FixedNode;
  54 import org.graalvm.compiler.nodes.FixedWithNextNode;
  55 import org.graalvm.compiler.nodes.FrameState;
  56 import org.graalvm.compiler.nodes.FullInfopointNode;
  57 import org.graalvm.compiler.nodes.PhiNode;
  58 import org.graalvm.compiler.nodes.ProxyNode;
  59 import org.graalvm.compiler.nodes.StructuredGraph;
  60 import org.graalvm.compiler.nodes.ValueNode;
  61 import org.graalvm.compiler.nodes.cfg.Block;
  62 import org.graalvm.compiler.nodes.cfg.ControlFlowGraph;
  63 import org.graalvm.compiler.nodes.virtual.VirtualObjectNode;
  64 import org.graalvm.compiler.options.OptionValues;
  65 
  66 import jdk.vm.ci.meta.ResolvedJavaMethod;


 243 
 244     public static String getCanonicalGraphString(StructuredGraph graph, boolean excludeVirtual, boolean checkConstants) {
 245         StringWriter stringWriter = new StringWriter();
 246         PrintWriter writer = new PrintWriter(stringWriter);
 247         writeCanonicalGraphString(graph, excludeVirtual, checkConstants, writer);
 248         writer.flush();
 249         return stringWriter.toString();
 250     }
 251 
 252     private static int filteredUsageCount(Node node) {
 253         return node.usages().filter(n -> !(n instanceof FrameState)).count();
 254     }
 255 
 256     @Override
 257     public void beginGroup(DebugContext debug, String name, String shortName, ResolvedJavaMethod method, int bci, Map<Object, Object> properties) throws IOException {
 258     }
 259 
 260     private StructuredGraph currentGraph;
 261     private Path currentDirectory;
 262 
 263     private Path getDirectory(StructuredGraph graph) throws IOException {
 264         if (graph == currentGraph) {
 265             return currentDirectory;
 266         }
 267         currentDirectory = GraalDebugHandlersFactory.createDumpPath(graph.getOptions(), graph, "graph-strings", true);
 268         currentGraph = graph;
 269         return currentDirectory;
 270     }
 271 
 272     @Override
 273     public void print(DebugContext debug, Graph graph, Map<Object, Object> properties, int id, String format, Object... args) throws IOException {
 274         if (graph instanceof StructuredGraph) {
 275             OptionValues options = graph.getOptions();
 276             StructuredGraph structuredGraph = (StructuredGraph) graph;
 277             Path outDirectory = getDirectory(structuredGraph);
 278             String title = String.format("%03d-%s.txt", id, String.format(format, simplifyClassArgs(args)));
 279             Path filePath = outDirectory.resolve(sanitizedFileName(title));
 280             try (PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(filePath.toFile())))) {
 281                 switch (PrintCanonicalGraphStringFlavor.getValue(options)) {
 282                     case 1:
 283                         writeCanonicalExpressionCFGString(structuredGraph, CanonicalGraphStringsCheckConstants.getValue(options), CanonicalGraphStringsRemoveIdentities.getValue(options), writer);
 284                         break;
 285                     case 0:
 286                     default:
 287                         writeCanonicalGraphString(structuredGraph, CanonicalGraphStringsExcludeVirtuals.getValue(options), CanonicalGraphStringsCheckConstants.getValue(options), writer);
 288                         break;
 289                 }
 290             }
 291         }
 292     }
 293 
 294     @Override
 295     public void endGroup() throws IOException {
 296     }
 297 
 298     @Override
 299     public void close() {


   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  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 static org.graalvm.compiler.debug.DebugOptions.CanonicalGraphStringsCheckConstants;
  26 import static org.graalvm.compiler.debug.DebugOptions.CanonicalGraphStringsExcludeVirtuals;
  27 import static org.graalvm.compiler.debug.DebugOptions.CanonicalGraphStringsRemoveIdentities;
  28 import static org.graalvm.compiler.debug.DebugOptions.PrintCanonicalGraphStringFlavor;

  29 
  30 import java.io.BufferedWriter;
  31 import java.io.FileWriter;
  32 import java.io.IOException;
  33 import java.io.PrintWriter;
  34 import java.io.StringWriter;
  35 import java.nio.file.Path;
  36 import java.util.ArrayList;
  37 import java.util.Collections;
  38 import java.util.Iterator;
  39 import java.util.List;
  40 import java.util.Map;
  41 import java.util.regex.Pattern;
  42 
  43 import org.graalvm.compiler.api.replacements.SnippetReflectionProvider;
  44 import org.graalvm.compiler.core.common.Fields;
  45 import org.graalvm.compiler.debug.DebugContext;
  46 import org.graalvm.compiler.debug.PathUtilities;
  47 import org.graalvm.compiler.graph.Graph;
  48 import org.graalvm.compiler.graph.Node;
  49 import org.graalvm.compiler.graph.NodeMap;
  50 import org.graalvm.compiler.graph.Position;
  51 import org.graalvm.compiler.nodeinfo.Verbosity;
  52 import org.graalvm.compiler.nodes.ConstantNode;
  53 import org.graalvm.compiler.nodes.FixedNode;
  54 import org.graalvm.compiler.nodes.FixedWithNextNode;
  55 import org.graalvm.compiler.nodes.FrameState;
  56 import org.graalvm.compiler.nodes.FullInfopointNode;
  57 import org.graalvm.compiler.nodes.PhiNode;
  58 import org.graalvm.compiler.nodes.ProxyNode;
  59 import org.graalvm.compiler.nodes.StructuredGraph;
  60 import org.graalvm.compiler.nodes.ValueNode;
  61 import org.graalvm.compiler.nodes.cfg.Block;
  62 import org.graalvm.compiler.nodes.cfg.ControlFlowGraph;
  63 import org.graalvm.compiler.nodes.virtual.VirtualObjectNode;
  64 import org.graalvm.compiler.options.OptionValues;
  65 
  66 import jdk.vm.ci.meta.ResolvedJavaMethod;


 243 
 244     public static String getCanonicalGraphString(StructuredGraph graph, boolean excludeVirtual, boolean checkConstants) {
 245         StringWriter stringWriter = new StringWriter();
 246         PrintWriter writer = new PrintWriter(stringWriter);
 247         writeCanonicalGraphString(graph, excludeVirtual, checkConstants, writer);
 248         writer.flush();
 249         return stringWriter.toString();
 250     }
 251 
 252     private static int filteredUsageCount(Node node) {
 253         return node.usages().filter(n -> !(n instanceof FrameState)).count();
 254     }
 255 
 256     @Override
 257     public void beginGroup(DebugContext debug, String name, String shortName, ResolvedJavaMethod method, int bci, Map<Object, Object> properties) throws IOException {
 258     }
 259 
 260     private StructuredGraph currentGraph;
 261     private Path currentDirectory;
 262 
 263     private Path getDirectory(DebugContext debug, StructuredGraph graph) {
 264         if (graph == currentGraph) {
 265             return currentDirectory;
 266         }
 267         currentDirectory = debug.getDumpPath(".graph-strings", true);
 268         currentGraph = graph;
 269         return currentDirectory;
 270     }
 271 
 272     @Override
 273     public void print(DebugContext debug, Graph graph, Map<Object, Object> properties, int id, String format, Object... args) throws IOException {
 274         if (graph instanceof StructuredGraph) {
 275             OptionValues options = graph.getOptions();
 276             StructuredGraph structuredGraph = (StructuredGraph) graph;
 277             Path outDirectory = getDirectory(debug, structuredGraph);
 278             String title = String.format("%03d-%s.txt", id, String.format(format, simplifyClassArgs(args)));
 279             Path filePath = outDirectory.resolve(PathUtilities.sanitizeFileName(title));
 280             try (PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(filePath.toFile())))) {
 281                 switch (PrintCanonicalGraphStringFlavor.getValue(options)) {
 282                     case 1:
 283                         writeCanonicalExpressionCFGString(structuredGraph, CanonicalGraphStringsCheckConstants.getValue(options), CanonicalGraphStringsRemoveIdentities.getValue(options), writer);
 284                         break;
 285                     case 0:
 286                     default:
 287                         writeCanonicalGraphString(structuredGraph, CanonicalGraphStringsExcludeVirtuals.getValue(options), CanonicalGraphStringsCheckConstants.getValue(options), writer);
 288                         break;
 289                 }
 290             }
 291         }
 292     }
 293 
 294     @Override
 295     public void endGroup() throws IOException {
 296     }
 297 
 298     @Override
 299     public void close() {
< prev index next >