annotate graal/com.oracle.graal.printer/src/com/oracle/graal/printer/GraphPrinterDumpHandler.java @ 7032:5a1f6e96e163

close() method for dump handlers should not throw IOException
author Christian Wimmer <christian.wimmer@oracle.com>
date Mon, 26 Nov 2012 18:24:08 -0800
parents dc7cd6885f07
children c421c19b7bf8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5810
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
1 /*
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
4 *
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
7 * published by the Free Software Foundation.
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
8 *
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
13 * accompanied this code).
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
14 *
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
18 *
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
21 * questions.
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
22 */
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
23 package com.oracle.graal.printer;
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
24
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
25 import java.io.*;
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
26 import java.net.*;
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
27 import java.nio.channels.*;
5819
8fd81d0e3acf Make DebugDumpHandler closable, close them on compiler thread when compiler threads finish
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5817
diff changeset
28 import java.nio.file.*;
5815
272f9da7ce78 Put Binary and xml dumpers behing a common interface and use the same dumphandler for them
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5810
diff changeset
29 import java.text.*;
5810
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
30 import java.util.*;
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
31
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
32 import com.oracle.graal.api.meta.*;
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
33 import com.oracle.graal.debug.*;
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
34 import com.oracle.graal.graph.*;
6525
2c913b643422 rename packages in graal.phases to match project name
Doug Simon <doug.simon@oracle.com>
parents: 6500
diff changeset
35 import com.oracle.graal.phases.*;
5810
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
36
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
37 /**
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
38 * Observes compilation events and uses {@link IdealGraphPrinter} to generate a graph representation that can be
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
39 * inspected with the <a href="http://kenai.com/projects/igv">Ideal Graph Visualizer</a>.
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
40 */
5815
272f9da7ce78 Put Binary and xml dumpers behing a common interface and use the same dumphandler for them
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5810
diff changeset
41 public class GraphPrinterDumpHandler implements DebugDumpHandler {
272f9da7ce78 Put Binary and xml dumpers behing a common interface and use the same dumphandler for them
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5810
diff changeset
42 private static final SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-dd-HHmm");
5810
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
43
5815
272f9da7ce78 Put Binary and xml dumpers behing a common interface and use the same dumphandler for them
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5810
diff changeset
44 private GraphPrinter printer;
5817
74eb5feba8dc Make sure the right port is used for dumping
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5815
diff changeset
45 private List<String> previousInlineContext;
5810
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
46 private int failuresCount;
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
47
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
48 /**
5817
74eb5feba8dc Make sure the right port is used for dumping
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5815
diff changeset
49 * Creates a new {@link GraphPrinterDumpHandler}.
5810
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
50 */
5815
272f9da7ce78 Put Binary and xml dumpers behing a common interface and use the same dumphandler for them
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5810
diff changeset
51 public GraphPrinterDumpHandler() {
5817
74eb5feba8dc Make sure the right port is used for dumping
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5815
diff changeset
52 previousInlineContext = new ArrayList<>();
5810
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
53 }
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
54
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
55 private void ensureInitialized() {
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
56 if (printer == null) {
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
57 if (failuresCount > 8) {
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
58 return;
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
59 }
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
60 previousInlineContext.clear();
5819
8fd81d0e3acf Make DebugDumpHandler closable, close them on compiler thread when compiler threads finish
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5817
diff changeset
61 if (GraalOptions.PrintIdealGraphFile) {
5810
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
62 initializeFilePrinter();
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
63 } else {
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
64 initializeNetworkPrinter();
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
65 }
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
66 }
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
67 }
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
68
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
69 private void initializeFilePrinter() {
5819
8fd81d0e3acf Make DebugDumpHandler closable, close them on compiler thread when compiler threads finish
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5817
diff changeset
70 String ext;
8fd81d0e3acf Make DebugDumpHandler closable, close them on compiler thread when compiler threads finish
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5817
diff changeset
71 if (GraalOptions.PrintBinaryGraphs) {
8fd81d0e3acf Make DebugDumpHandler closable, close them on compiler thread when compiler threads finish
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5817
diff changeset
72 ext = ".bgv";
8fd81d0e3acf Make DebugDumpHandler closable, close them on compiler thread when compiler threads finish
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5817
diff changeset
73 } else {
8fd81d0e3acf Make DebugDumpHandler closable, close them on compiler thread when compiler threads finish
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5817
diff changeset
74 ext = ".gv.xml";
8fd81d0e3acf Make DebugDumpHandler closable, close them on compiler thread when compiler threads finish
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5817
diff changeset
75 }
8fd81d0e3acf Make DebugDumpHandler closable, close them on compiler thread when compiler threads finish
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5817
diff changeset
76 String fileName = "Graphs-" + Thread.currentThread().getName() + "-" + sdf.format(new Date()) + ext;
5810
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
77 try {
5815
272f9da7ce78 Put Binary and xml dumpers behing a common interface and use the same dumphandler for them
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5810
diff changeset
78 if (GraalOptions.PrintBinaryGraphs) {
5819
8fd81d0e3acf Make DebugDumpHandler closable, close them on compiler thread when compiler threads finish
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5817
diff changeset
79 printer = new BinaryGraphPrinter(FileChannel.open(new File(fileName).toPath(), StandardOpenOption.WRITE, StandardOpenOption.CREATE_NEW));
5815
272f9da7ce78 Put Binary and xml dumpers behing a common interface and use the same dumphandler for them
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5810
diff changeset
80 } else {
272f9da7ce78 Put Binary and xml dumpers behing a common interface and use the same dumphandler for them
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5810
diff changeset
81 printer = new IdealGraphPrinter(new FileOutputStream(fileName));
272f9da7ce78 Put Binary and xml dumpers behing a common interface and use the same dumphandler for them
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5810
diff changeset
82 }
272f9da7ce78 Put Binary and xml dumpers behing a common interface and use the same dumphandler for them
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5810
diff changeset
83 TTY.println("Dumping IGV graphs to %s", fileName);
5810
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
84 } catch (IOException e) {
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 5819
diff changeset
85 TTY.println("Failed to open %s to dump IGV graphs : %s", fileName, e);
5810
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
86 failuresCount++;
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
87 printer = null;
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
88 }
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
89 }
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
90
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
91 private void initializeNetworkPrinter() {
5817
74eb5feba8dc Make sure the right port is used for dumping
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5815
diff changeset
92 String host = GraalOptions.PrintIdealGraphAddress;
74eb5feba8dc Make sure the right port is used for dumping
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5815
diff changeset
93 int port = GraalOptions.PrintBinaryGraphs ? GraalOptions.PrintBinaryGraphPort : GraalOptions.PrintIdealGraphPort;
5810
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
94 try {
5815
272f9da7ce78 Put Binary and xml dumpers behing a common interface and use the same dumphandler for them
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5810
diff changeset
95 if (GraalOptions.PrintBinaryGraphs) {
272f9da7ce78 Put Binary and xml dumpers behing a common interface and use the same dumphandler for them
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5810
diff changeset
96 printer = new BinaryGraphPrinter(SocketChannel.open(new InetSocketAddress(host, port)));
272f9da7ce78 Put Binary and xml dumpers behing a common interface and use the same dumphandler for them
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5810
diff changeset
97 } else {
272f9da7ce78 Put Binary and xml dumpers behing a common interface and use the same dumphandler for them
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5810
diff changeset
98 IdealGraphPrinter xmlPrinter = new IdealGraphPrinter(new Socket(host, port).getOutputStream());
272f9da7ce78 Put Binary and xml dumpers behing a common interface and use the same dumphandler for them
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5810
diff changeset
99 printer = xmlPrinter;
272f9da7ce78 Put Binary and xml dumpers behing a common interface and use the same dumphandler for them
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5810
diff changeset
100 }
272f9da7ce78 Put Binary and xml dumpers behing a common interface and use the same dumphandler for them
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5810
diff changeset
101 TTY.println("Connected to the IGV on %s:%d", host, port);
5810
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
102 } catch (IOException e) {
5819
8fd81d0e3acf Make DebugDumpHandler closable, close them on compiler thread when compiler threads finish
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5817
diff changeset
103 TTY.println("Could not connect to the IGV on %s:%d : %s", host, port, e);
5810
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
104 failuresCount++;
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
105 printer = null;
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
106 }
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
107 }
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
108
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
109 @Override
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
110 public void dump(Object object, final String message) {
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
111 if (object instanceof Graph) {
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
112 ensureInitialized();
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
113 if (printer == null) {
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
114 return;
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
115 }
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
116 final Graph graph = (Graph) object;
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
117
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
118 if (printer != null) {
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
119 // Get all current RiResolvedMethod instances in the context.
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
120 List<String> inlineContext = getInlineContext();
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
121
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
122 // Reverse list such that inner method comes after outer method.
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
123 Collections.reverse(inlineContext);
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
124
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
125 // Check for method scopes that must be closed since the previous dump.
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
126 for (int i = 0; i < previousInlineContext.size(); ++i) {
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
127 if (i >= inlineContext.size() || !inlineContext.get(i).equals(previousInlineContext.get(i))) {
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
128 for (int j = previousInlineContext.size() - 1; j >= i; --j) {
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
129 closeScope();
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
130 }
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
131 break;
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
132 }
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
133 }
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
134
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
135 // Check for method scopes that must be opened since the previous dump.
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
136 for (int i = 0; i < inlineContext.size(); ++i) {
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
137 if (i >= previousInlineContext.size() || !inlineContext.get(i).equals(previousInlineContext.get(i))) {
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
138 for (int j = i; j < inlineContext.size(); ++j) {
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
139 openScope(inlineContext.get(j), j == 0);
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
140 }
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
141 break;
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
142 }
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
143 }
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
144
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
145 // Save inline context for next dump.
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
146 previousInlineContext = inlineContext;
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
147
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
148 Debug.sandbox("PrintingGraph", new Runnable() {
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
149
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
150 @Override
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
151 public void run() {
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
152 // Finally, output the graph.
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
153 try {
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
154 printer.print(graph, message, null);
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
155 } catch (IOException e) {
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
156 failuresCount++;
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
157 printer = null;
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
158 }
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
159 }
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
160 });
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
161 }
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
162 }
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
163 }
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
164
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
165 private static List<String> getInlineContext() {
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
166 List<String> result = new ArrayList<>();
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
167 for (Object o : Debug.context()) {
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
168 if (o instanceof ResolvedJavaMethod) {
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
169 ResolvedJavaMethod method = (ResolvedJavaMethod) o;
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
170 result.add(MetaUtil.format("%H::%n(%p)", method));
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
171 } else if (o instanceof DebugDumpScope) {
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
172 DebugDumpScope debugDumpScope = (DebugDumpScope) o;
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
173 if (debugDumpScope.decorator && !result.isEmpty()) {
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
174 result.set(result.size() - 1, debugDumpScope.name + ":" + result.get(result.size() - 1));
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
175 } else {
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
176 result.add(debugDumpScope.name);
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
177 }
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
178 }
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
179 }
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
180 return result;
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
181 }
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
182
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
183 private void openScope(String name, boolean showThread) {
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
184 String prefix = showThread ? Thread.currentThread().getName() + ":" : "";
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
185 try {
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
186 printer.beginGroup(prefix + name, name, Debug.contextLookup(ResolvedJavaMethod.class), -1);
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
187 } catch (IOException e) {
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
188 failuresCount++;
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
189 printer = null;
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
190 }
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
191 }
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
192
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
193 private void closeScope() {
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
194 try {
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
195 printer.endGroup();
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
196 } catch (IOException e) {
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
197 failuresCount++;
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
198 printer = null;
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
199 }
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
200 }
5819
8fd81d0e3acf Make DebugDumpHandler closable, close them on compiler thread when compiler threads finish
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5817
diff changeset
201
8fd81d0e3acf Make DebugDumpHandler closable, close them on compiler thread when compiler threads finish
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5817
diff changeset
202 @Override
7032
5a1f6e96e163 close() method for dump handlers should not throw IOException
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6695
diff changeset
203 public void close() {
5819
8fd81d0e3acf Make DebugDumpHandler closable, close them on compiler thread when compiler threads finish
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5817
diff changeset
204 for (int i = 0; i < previousInlineContext.size(); i++) {
8fd81d0e3acf Make DebugDumpHandler closable, close them on compiler thread when compiler threads finish
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5817
diff changeset
205 closeScope();
8fd81d0e3acf Make DebugDumpHandler closable, close them on compiler thread when compiler threads finish
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5817
diff changeset
206 }
6695
dc7cd6885f07 Avoid NullPointerException
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6525
diff changeset
207 if (printer != null) {
dc7cd6885f07 Avoid NullPointerException
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6525
diff changeset
208 printer.close();
dc7cd6885f07 Avoid NullPointerException
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6525
diff changeset
209 }
5819
8fd81d0e3acf Make DebugDumpHandler closable, close them on compiler thread when compiler threads finish
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5817
diff changeset
210 }
5810
bc237d8b6f99 Add binary graph dumping to compiler (-G:+PrintBinaryGraphs)
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
diff changeset
211 }