1 
   2 /*
   3  * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
   4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5  *
   6  * This code is free software; you can redistribute it and/or modify it
   7  * under the terms of the GNU General Public License version 2 only, as
   8  * published by the Free Software Foundation.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  */
  24 
  25 /**
  26  * Send your graphs to <b>IGV</b> via a socket or a file. This package allows one to easily encode
  27  * any graph-like data structure and send it for visualization to
  28  * <em>OracleLab's Ideal Graph Visualizer</em> tool. Assuming you already have your own data
  29  * structure that contains <b>nodes</b> and <b>edges</b> among them, creating a
  30  * {@link org.graalvm.graphio.GraphOutput} specialized for your data is a matter of implementing a
  31  * single interface:
  32  *
  33  * {@link org.graalvm.graphio.GraphSnippets#acmeGraphStructure}
  34  *
  35  * The {@link org.graalvm.graphio.GraphStructure} interface defines the set of operations that are
  36  * needed by the <em>graph protocol</em> to encode a graph into the <b>IGV</b> expected format. The
  37  * graph structure is implemented as a so called
  38  * <a href="http://wiki.apidesign.org/wiki/Singletonizer">singletonizer</a> API pattern: there is no
  39  * need to change your data structures or implement some special interfaces - everything needed is
  40  * provided by implementing the {@link org.graalvm.graphio.GraphStructure} operations.
  41  * <p>
  42  * The next step is to turn this graph structure into an instance of
  43  * {@link org.graalvm.graphio.GraphOutput}. To do so use the associated
  44  * {@link org.graalvm.graphio.GraphOutput.Builder builder} just like shown in the following method:
  45  *
  46  * {@link org.graalvm.graphio.GraphSnippets#buildOutput}
  47  *
  48  * Now you are ready to dump your graph into <b>IGV</b>. Where to obtain the right channel? One
  49  * option is to create a {@link java.nio.channels.FileChannel} and dump the data into a file
  50  * (preferrably with <code>.bgv</code> extension). The other is to open a socket to port
  51  * <code>4445</code> (the default port <b>IGV</b> listens to) and dump the data there. Here is an
  52  * example:
  53  *
  54  * {@link org.graalvm.graphio.GraphSnippets#dump}
  55  *
  56  * Call the {@code dump} method with pointer to file {@code diamond.bgv} and then you can open the
  57  * file in <b>IGV</b>. The result will look like this:
  58  * <p>
  59  * <img src="doc-files/diamond.png">
  60  * <p>
  61  * You can verify the behavior directly in the <b>IGV</b> by downloading
  62  * <a href="doc-files/diamond.bgv">diamond.bgv</a> file generated from the above diamond structure
  63  * graph.
  64  * <p>
  65  * The primary <b>IGV</b> focus is on graphs used by Graal compiler. As such they aren't plain
  66  * graphs, but contain various compiler oriented attributes:
  67  * <ul>
  68  * <li>{@linkplain org.graalvm.graphio.GraphBlocks code blocks} information</li>
  69  * <li>{@linkplain org.graalvm.graphio.GraphElements method and fields} information</li>
  70  * <li>Advanced support for {@linkplain org.graalvm.graphio.GraphTypes recognizing types}</li>
  71  * </ul>
  72  * all these additional interfaces ({@link org.graalvm.graphio.GraphBlocks},
  73  * {@link org.graalvm.graphio.GraphElements} and {@link org.graalvm.graphio.GraphTypes}) are
  74  * optional - they don't have to be provided. As such they can be specified via
  75  * {@link org.graalvm.graphio.GraphOutput.Builder} instance methods, which may, but need not be
  76  * called at all. Here is an example:
  77  *
  78  * {@link org.graalvm.graphio.GraphSnippets#buildAll}
  79  *
  80  * All these interfaces follow the
  81  * <a href="http://wiki.apidesign.org/wiki/Singletonizer">singletonizer</a> API pattern again - e.g.
  82  * no need to change your existing data structures, just implement the operations provided by the
  83  * interfaces you pass into the builder. By combining these interfaces together you can get as rich,
  84  * colorful, source linked graphs as Graal compiler produces to describe its optimizations.
  85  */
  86 package org.graalvm.graphio;