47798
|
1 |
/*
|
58299
|
2 |
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
|
47798
|
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 |
*
|
|
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 |
|
|
24 |
/**
|
|
25 |
* Send your graphs to <b>IGV</b> via a socket or a file. This package allows one to easily encode
|
48861
|
26 |
* any graph-like data structure and send it for visualization to <em>OracleLab's Ideal Graph
|
|
27 |
* Visualizer</em> tool. Assuming you already have your own data structure that contains
|
|
28 |
* <b>nodes</b> and <b>edges</b> among them, creating a {@link org.graalvm.graphio.GraphOutput}
|
|
29 |
* specialized for your data is a matter of implementing a single interface:
|
47798
|
30 |
*
|
48861
|
31 |
* {@link org.graalvm.graphio.GraphJavadocSnippets#acmeGraphStructure}
|
47798
|
32 |
*
|
|
33 |
* The {@link org.graalvm.graphio.GraphStructure} interface defines the set of operations that are
|
|
34 |
* needed by the <em>graph protocol</em> to encode a graph into the <b>IGV</b> expected format. The
|
|
35 |
* graph structure is implemented as a so called
|
|
36 |
* <a href="http://wiki.apidesign.org/wiki/Singletonizer">singletonizer</a> API pattern: there is no
|
|
37 |
* need to change your data structures or implement some special interfaces - everything needed is
|
|
38 |
* provided by implementing the {@link org.graalvm.graphio.GraphStructure} operations.
|
|
39 |
* <p>
|
|
40 |
* The next step is to turn this graph structure into an instance of
|
|
41 |
* {@link org.graalvm.graphio.GraphOutput}. To do so use the associated
|
|
42 |
* {@link org.graalvm.graphio.GraphOutput.Builder builder} just like shown in the following method:
|
|
43 |
*
|
48861
|
44 |
* {@link org.graalvm.graphio.GraphJavadocSnippets#buildOutput}
|
47798
|
45 |
*
|
|
46 |
* Now you are ready to dump your graph into <b>IGV</b>. Where to obtain the right channel? One
|
|
47 |
* option is to create a {@link java.nio.channels.FileChannel} and dump the data into a file
|
|
48 |
* (preferrably with <code>.bgv</code> extension). The other is to open a socket to port
|
|
49 |
* <code>4445</code> (the default port <b>IGV</b> listens to) and dump the data there. Here is an
|
|
50 |
* example:
|
|
51 |
*
|
48861
|
52 |
* {@link org.graalvm.graphio.GraphJavadocSnippets#dump}
|
47798
|
53 |
*
|
|
54 |
* Call the {@code dump} method with pointer to file {@code diamond.bgv} and then you can open the
|
|
55 |
* file in <b>IGV</b>. The result will look like this:
|
|
56 |
* <p>
|
|
57 |
* <img src="doc-files/diamond.png">
|
|
58 |
* <p>
|
|
59 |
* You can verify the behavior directly in the <b>IGV</b> by downloading
|
|
60 |
* <a href="doc-files/diamond.bgv">diamond.bgv</a> file generated from the above diamond structure
|
|
61 |
* graph.
|
|
62 |
* <p>
|
55509
|
63 |
* The primary <b>IGV</b> focus is on graphs used by the compiler. As such they aren't plain graphs,
|
|
64 |
* but contain various compiler oriented attributes:
|
47798
|
65 |
* <ul>
|
|
66 |
* <li>{@linkplain org.graalvm.graphio.GraphBlocks code blocks} information</li>
|
|
67 |
* <li>{@linkplain org.graalvm.graphio.GraphElements method and fields} information</li>
|
|
68 |
* <li>Advanced support for {@linkplain org.graalvm.graphio.GraphTypes recognizing types}</li>
|
|
69 |
* </ul>
|
|
70 |
* all these additional interfaces ({@link org.graalvm.graphio.GraphBlocks},
|
|
71 |
* {@link org.graalvm.graphio.GraphElements} and {@link org.graalvm.graphio.GraphTypes}) are
|
|
72 |
* optional - they don't have to be provided. As such they can be specified via
|
|
73 |
* {@link org.graalvm.graphio.GraphOutput.Builder} instance methods, which may, but need not be
|
|
74 |
* called at all. Here is an example:
|
|
75 |
*
|
48861
|
76 |
* {@link org.graalvm.graphio.GraphJavadocSnippets#buildAll}
|
47798
|
77 |
*
|
|
78 |
* All these interfaces follow the
|
|
79 |
* <a href="http://wiki.apidesign.org/wiki/Singletonizer">singletonizer</a> API pattern again - e.g.
|
|
80 |
* no need to change your existing data structures, just implement the operations provided by the
|
|
81 |
* interfaces you pass into the builder. By combining these interfaces together you can get as rich,
|
55509
|
82 |
* colorful, source linked graphs as the compiler produces to describe its optimizations.
|
47798
|
83 |
*/
|
50858
|
84 |
|
|
85 |
|
47798
|
86 |
package org.graalvm.graphio;
|