Mercurial > hg > graal-jvmci-8
annotate src/share/tools/IdealGraphVisualizer/Data/src/com/sun/hotspot/igv/data/serialization/Printer.java @ 23355:135acd2dead4
Import actual changes from JDK9 IGV which is mostly copyright related
author | Tom Rodriguez <tom.rodriguez@oracle.com> |
---|---|
date | Thu, 28 Apr 2016 09:29:22 -0700 |
parents | 3c78119de0cd |
children | a95267ab6955 |
rev | line source |
---|---|
220 | 1 /* |
23355
135acd2dead4
Import actual changes from JDK9 IGV which is mostly copyright related
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
19986
diff
changeset
|
2 * Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved. |
220 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
417
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
417
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
417
diff
changeset
|
21 * questions. |
220 | 22 * |
23 */ | |
24 package com.sun.hotspot.igv.data.serialization; | |
25 | |
4372
2e66f6fd4bc9
IGV clean up. Allow groups with subgroups.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
2898
diff
changeset
|
26 import com.sun.hotspot.igv.data.*; |
220 | 27 import java.io.IOException; |
2898
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
2766
diff
changeset
|
28 import java.io.InputStream; |
220 | 29 import java.io.Writer; |
30 import java.util.HashSet; | |
31 import java.util.Set; | |
32 | |
33 /** | |
34 * | |
35 * @author Thomas Wuerthinger | |
36 */ | |
37 public class Printer { | |
38 | |
2898
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
2766
diff
changeset
|
39 private InputStream in; |
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
2766
diff
changeset
|
40 |
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
2766
diff
changeset
|
41 public Printer() { |
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
2766
diff
changeset
|
42 this(null); |
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
2766
diff
changeset
|
43 } |
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
2766
diff
changeset
|
44 |
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
2766
diff
changeset
|
45 public Printer(InputStream inputStream) { |
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
2766
diff
changeset
|
46 this.in = inputStream; |
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
2766
diff
changeset
|
47 } |
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
2766
diff
changeset
|
48 |
220 | 49 public void export(Writer writer, GraphDocument document) { |
50 | |
51 XMLWriter xmlWriter = new XMLWriter(writer); | |
52 | |
53 try { | |
54 export(xmlWriter, document); | |
55 } catch (IOException ex) { | |
56 } | |
57 } | |
58 | |
59 private void export(XMLWriter xmlWriter, GraphDocument document) throws IOException { | |
60 xmlWriter.startTag(Parser.ROOT_ELEMENT); | |
61 xmlWriter.writeProperties(document.getProperties()); | |
4372
2e66f6fd4bc9
IGV clean up. Allow groups with subgroups.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
2898
diff
changeset
|
62 for (FolderElement e : document.getElements()) { |
2e66f6fd4bc9
IGV clean up. Allow groups with subgroups.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
2898
diff
changeset
|
63 if (e instanceof Group) { |
2e66f6fd4bc9
IGV clean up. Allow groups with subgroups.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
2898
diff
changeset
|
64 export(xmlWriter, (Group) e); |
2e66f6fd4bc9
IGV clean up. Allow groups with subgroups.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
2898
diff
changeset
|
65 } else if (e instanceof InputGraph) { |
2e66f6fd4bc9
IGV clean up. Allow groups with subgroups.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
2898
diff
changeset
|
66 export(xmlWriter, (InputGraph)e, null, false); |
2e66f6fd4bc9
IGV clean up. Allow groups with subgroups.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
2898
diff
changeset
|
67 } |
220 | 68 } |
69 | |
70 xmlWriter.endTag(); | |
71 xmlWriter.flush(); | |
72 } | |
73 | |
74 private void export(XMLWriter writer, Group g) throws IOException { | |
75 Properties attributes = new Properties(); | |
417 | 76 attributes.setProperty("difference", Boolean.toString(true)); |
220 | 77 writer.startTag(Parser.GROUP_ELEMENT, attributes); |
78 writer.writeProperties(g.getProperties()); | |
79 | |
2898
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
2766
diff
changeset
|
80 boolean shouldExport = true; |
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
2766
diff
changeset
|
81 if (in != null) { |
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
2766
diff
changeset
|
82 char c = (char) in.read(); |
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
2766
diff
changeset
|
83 if (c != 'y') { |
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
2766
diff
changeset
|
84 shouldExport = false; |
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
2766
diff
changeset
|
85 } |
220 | 86 } |
87 | |
2898
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
2766
diff
changeset
|
88 if (shouldExport) { |
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
2766
diff
changeset
|
89 if (g.getMethod() != null) { |
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
2766
diff
changeset
|
90 export(writer, g.getMethod()); |
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
2766
diff
changeset
|
91 } |
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
2766
diff
changeset
|
92 |
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
2766
diff
changeset
|
93 InputGraph previous = null; |
4372
2e66f6fd4bc9
IGV clean up. Allow groups with subgroups.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
2898
diff
changeset
|
94 for (FolderElement e : g.getElements()) { |
2e66f6fd4bc9
IGV clean up. Allow groups with subgroups.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
2898
diff
changeset
|
95 if (e instanceof InputGraph) { |
2e66f6fd4bc9
IGV clean up. Allow groups with subgroups.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
2898
diff
changeset
|
96 InputGraph graph = (InputGraph) e; |
2e66f6fd4bc9
IGV clean up. Allow groups with subgroups.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
2898
diff
changeset
|
97 export(writer, graph, previous, true); |
2e66f6fd4bc9
IGV clean up. Allow groups with subgroups.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
2898
diff
changeset
|
98 previous = graph; |
2e66f6fd4bc9
IGV clean up. Allow groups with subgroups.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
2898
diff
changeset
|
99 } else if (e instanceof Group) { |
2e66f6fd4bc9
IGV clean up. Allow groups with subgroups.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
2898
diff
changeset
|
100 export(writer, (Group) e); |
2e66f6fd4bc9
IGV clean up. Allow groups with subgroups.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
2898
diff
changeset
|
101 } |
2898
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
2766
diff
changeset
|
102 } |
220 | 103 } |
104 | |
105 writer.endTag(); | |
106 } | |
107 | |
108 public void export(XMLWriter writer, InputGraph graph, InputGraph previous, boolean difference) throws IOException { | |
109 | |
110 writer.startTag(Parser.GRAPH_ELEMENT); | |
111 writer.writeProperties(graph.getProperties()); | |
112 writer.startTag(Parser.NODES_ELEMENT); | |
113 | |
4382
f22dc0a63f03
Removed old hierarchical layout manager; start removing cluster layout. apply diamond operator to whole source.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
4372
diff
changeset
|
114 Set<InputNode> removed = new HashSet<>(); |
f22dc0a63f03
Removed old hierarchical layout manager; start removing cluster layout. apply diamond operator to whole source.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
4372
diff
changeset
|
115 Set<InputNode> equal = new HashSet<>(); |
220 | 116 |
117 if (previous != null) { | |
118 for (InputNode n : previous.getNodes()) { | |
119 int id = n.getId(); | |
120 InputNode n2 = graph.getNode(id); | |
121 if (n2 == null) { | |
122 removed.add(n); | |
123 } else if (n.equals(n2)) { | |
124 equal.add(n); | |
125 } | |
126 } | |
127 } | |
128 | |
129 if (difference) { | |
130 for (InputNode n : removed) { | |
131 writer.simpleTag(Parser.REMOVE_NODE_ELEMENT, new Properties(Parser.NODE_ID_PROPERTY, Integer.toString(n.getId()))); | |
132 } | |
133 } | |
134 | |
135 for (InputNode n : graph.getNodes()) { | |
136 if (!difference || !equal.contains(n)) { | |
137 writer.startTag(Parser.NODE_ELEMENT, new Properties(Parser.NODE_ID_PROPERTY, Integer.toString(n.getId()))); | |
138 writer.writeProperties(n.getProperties()); | |
139 writer.endTag(); | |
140 } | |
141 } | |
142 | |
143 writer.endTag(); | |
144 | |
145 writer.startTag(Parser.EDGES_ELEMENT); | |
4382
f22dc0a63f03
Removed old hierarchical layout manager; start removing cluster layout. apply diamond operator to whole source.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
4372
diff
changeset
|
146 Set<InputEdge> removedEdges = new HashSet<>(); |
f22dc0a63f03
Removed old hierarchical layout manager; start removing cluster layout. apply diamond operator to whole source.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
4372
diff
changeset
|
147 Set<InputEdge> equalEdges = new HashSet<>(); |
220 | 148 |
149 if (previous != null) { | |
150 for (InputEdge e : previous.getEdges()) { | |
151 if (graph.getEdges().contains(e)) { | |
152 equalEdges.add(e); | |
153 } else { | |
154 removedEdges.add(e); | |
155 } | |
156 } | |
157 } | |
158 | |
159 if (difference) { | |
160 for (InputEdge e : removedEdges) { | |
161 writer.simpleTag(Parser.REMOVE_EDGE_ELEMENT, createProperties(e)); | |
162 } | |
163 } | |
164 | |
165 for (InputEdge e : graph.getEdges()) { | |
166 if (!difference || !equalEdges.contains(e)) { | |
167 if (!equalEdges.contains(e)) { | |
168 writer.simpleTag(Parser.EDGE_ELEMENT, createProperties(e)); | |
169 } | |
170 } | |
171 } | |
172 | |
173 writer.endTag(); | |
174 | |
175 writer.startTag(Parser.CONTROL_FLOW_ELEMENT); | |
176 for (InputBlock b : graph.getBlocks()) { | |
177 writer.startTag(Parser.BLOCK_ELEMENT, new Properties(Parser.BLOCK_NAME_PROPERTY, b.getName())); | |
2898
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
2766
diff
changeset
|
178 |
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
2766
diff
changeset
|
179 if (b.getSuccessors().size() > 0) { |
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
2766
diff
changeset
|
180 writer.startTag(Parser.SUCCESSORS_ELEMENT); |
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
2766
diff
changeset
|
181 for (InputBlock s : b.getSuccessors()) { |
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
2766
diff
changeset
|
182 writer.simpleTag(Parser.SUCCESSOR_ELEMENT, new Properties(Parser.BLOCK_NAME_PROPERTY, s.getName())); |
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
2766
diff
changeset
|
183 } |
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
2766
diff
changeset
|
184 writer.endTag(); |
220 | 185 } |
186 | |
2898
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
2766
diff
changeset
|
187 if (b.getNodes().size() > 0) { |
220 | 188 writer.startTag(Parser.NODES_ELEMENT); |
2898
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
2766
diff
changeset
|
189 for (InputNode n : b.getNodes()) { |
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
2766
diff
changeset
|
190 writer.simpleTag(Parser.NODE_ELEMENT, new Properties(Parser.NODE_ID_PROPERTY, n.getId() + "")); |
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
2766
diff
changeset
|
191 } |
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
2766
diff
changeset
|
192 writer.endTag(); |
220 | 193 } |
2898
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
2766
diff
changeset
|
194 |
220 | 195 writer.endTag(); |
196 } | |
197 | |
198 writer.endTag(); | |
199 writer.endTag(); | |
200 } | |
201 | |
202 private void export(XMLWriter w, InputMethod method) throws IOException { | |
203 | |
204 w.startTag(Parser.METHOD_ELEMENT, new Properties(Parser.METHOD_BCI_PROPERTY, method.getBci() + "", Parser.METHOD_NAME_PROPERTY, method.getName(), Parser.METHOD_SHORT_NAME_PROPERTY, method.getShortName())); | |
205 | |
206 w.writeProperties(method.getProperties()); | |
207 | |
208 if (method.getInlined().size() > 0) { | |
209 w.startTag(Parser.INLINE_ELEMENT); | |
210 for (InputMethod m : method.getInlined()) { | |
211 export(w, m); | |
212 } | |
213 w.endTag(); | |
214 } | |
215 | |
216 w.startTag(Parser.BYTECODES_ELEMENT); | |
217 | |
218 StringBuilder b = new StringBuilder(); | |
219 b.append("<![CDATA[\n"); | |
220 for (InputBytecode code : method.getBytecodes()) { | |
221 b.append(code.getBci()); | |
222 b.append(" "); | |
223 b.append(code.getName()); | |
224 b.append("\n"); | |
225 } | |
2898
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
2766
diff
changeset
|
226 |
220 | 227 b.append("]]>"); |
228 w.write(b.toString()); | |
229 w.endTag(); | |
230 w.endTag(); | |
231 } | |
232 | |
233 private Properties createProperties(InputEdge edge) { | |
234 Properties p = new Properties(); | |
2898
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
2766
diff
changeset
|
235 if (edge.getToIndex() != 0) { |
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
2766
diff
changeset
|
236 p.setProperty(Parser.TO_INDEX_PROPERTY, Integer.toString(edge.getToIndex())); |
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
2766
diff
changeset
|
237 } |
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
2766
diff
changeset
|
238 if (edge.getFromIndex() != 0) { |
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
2766
diff
changeset
|
239 p.setProperty(Parser.FROM_INDEX_PROPERTY, Integer.toString(edge.getFromIndex())); |
53ddfe305645
IdealGraphVisualizer: merge changes from the IGV project on Kenai and add Oracle copyright notices where necessary
Peter Hofer <peter.hofer@jku.at>
parents:
2766
diff
changeset
|
240 } |
220 | 241 p.setProperty(Parser.TO_PROPERTY, Integer.toString(edge.getTo())); |
242 p.setProperty(Parser.FROM_PROPERTY, Integer.toString(edge.getFrom())); | |
19986
3c78119de0cd
Layout and display improvements and bug fixes for IdealGraphVisualizer.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
4382
diff
changeset
|
243 p.setProperty(Parser.TYPE_PROPERTY, edge.getType()); |
220 | 244 return p; |
245 } | |
246 } |