Skip to content

Ideal Graph Visualizer

Thomas E Enebo edited this page Apr 17, 2024 · 1 revision

Ideal Graph Visualizer (IGV) is a tool shipped with OpenJDK. It allows you do see a graph of internal representations of Java. JRuby also has the ability to visualize JRuby's IR using this tool. This page talks about how to use it.

First you need IGV which can be retrieved by checking out OpenJDK source (there may be other links to pre-built version but I have not seen one). You cd into the igv directory and do mvn package. This will create a zip file and also a subdirectory with the contents of that file. I just do cp -rp application/target/idealgraphvisualizer ~/Applications/ and that directory has a bin directory containing idealgraphvisualizer.

To see some JRuby IR you are interested in you need to have IGV running. This running process is listening to localhost:4444. Then it is as simple as running your application with the option -Xir.debug.igv=. The value for this option is either the filename as it will be required/loaded and optionally the linenumber where the scope you want to see begins.

For whole file I would run a command line like: jruby -Xir.debug.igv=../snippets/while2.rb ../snippets/while2.rb. If I only cared about a single scope this would look like jruby -Xir.debug.igv=../snippets/while2.rb:2 ../snippets/while2.rb.

Once you have run the command you will see an entry show up on the left side which can be expanded. Once expanded you will see all compiler passes we execute on the IR. If you click on the first one in the list this is the initial CFG. The middle section of IGV will show you the instructions. Be sure to select the button 'Cluster nodes into blocks' This will visually wrap the instructions into their BasicBlocks. Now if you select the right arrow in the middle ('Expand the difference selection') you will go to next compiler pass. This will also show removed instrs in red and new instrs in green.

This should be enough info for people to be able to examine the IR we generate.

Clone this wiki locally