enso/tools/enso4igv
Jaroslav Tulach 402ebb2f8e
Upgrade to GraalVM 22.3.0 (#3663)
Upgrading to GraalVM 22.3.0.

# Important Notes
- Removed all deprecated `FrameSlot`, and replaced them with frame indexes - integers.
- Add more information to `AliasAnalysis` so that it also gathers these indexes.
- Add quick build mode option to `native-image` as default for non-release builds
- `graaljs` and `native-image` should now be downloaded via `gu` automatically, as dependencies.
- Remove `engine-runner-native` project - native image is now build straight from `engine-runner`.
- We used to have `engine-runner-native` without `sqldf` in classpath as a workaround for an internal native image bug.
- Fixed chrome inspector integration, such that it shows values of local variables both for current stack frame and caller stack frames.
- There are still many issues with the debugging in general, for example, when there is a polyglot value among local variables, a `NullPointerException` is thrown and no values are displayed.
- Removed some deprecated `native-image` options
- Remove some deprecated Truffle API method calls.
2022-11-23 14:30:48 +00:00
..
src/main Proper classpath of engine sources in Enso4Igv plugin (#3810) 2022-11-15 07:05:53 +00:00
pom.xml Proper classpath of engine sources in Enso4Igv plugin (#3810) 2022-11-15 07:05:53 +00:00
README.md Upgrade to GraalVM 22.3.0 (#3663) 2022-11-23 14:30:48 +00:00

Enso Language Support for NetBeans & Ideal Graph Visualizer

Enso Language Support for IGV

Enso language runtime engine is built on top of GraalVM and its Truffle framework. Enso, as a good citizen of the GraalVM ecosystem, benefits from polyglot capabilities of GraalVM as well as its rich tooling offering. One of such tools is IGV - the Ideal Graph Visualizer - an excellent tool to get insights into behavior of Graal compiler.

This document shows how to use IGV with the Enso language. The command line instructions format is Unix oriented. Use instructions appropriate for your operating system to perform the same on different OS. IGV itself as well as the Enso language support are platform neutral with launch scripts for all major operating systems.

Installation

Visit GraalVM.org download page and continue towards enterprise edition option. There is an Ideal Graph Visualizer option. After clicking through the confirmation dialogs you should get a ZIP - I've just got idealgraphvisualizer-22.1.0.zip and then:

$ unzip idealgraphvisualizer-22.1.0.zip
$ ./idealgraphvisualizer/bin/idealgraphvisualizer --userdir /tmp/emptyuserdir

launches the IGV application. One doesn't have to use the --userdir option, but doing so ensures the newly running IGV process is isolated from any settings left around by previous usage of IGV.

IGV understands Enso when Enso Language Support module is installed. Login to GitHub, follow the GitHub actions link and select a build. Unless you have some special needs choose the latest one. The build summary page provides various information as well as list of artifacts at the bottom. Download the Enso IGV Plugin ZIP file (make sure you are logged into GitHub - artifacts are only available to those logged in). Unzip it and get enso*.nbm file. This file can be installed into IGV (or any other NetBeans based application). Go to Tools/Plugins/Downloaded/Add Plugins and select the NBM file.

Tools/Plugins/Downloaded

Proceed by clicking Install. You may be asked to download TextMate Lexer - a necessary dependency of the Enso support module. Continue through the wizard to finish the installation.

Tools/Plugins/Downloaded

Using the IGV

Build an instance of the Enso runtime engine (see Running Enso) using:

enso$ sbt buildEngineDistribution

and then launch it with special --dump-graphs option:

enso$ ./built-distribution/enso-engine-0.0.0-dev-linux-amd64/enso-0.0.0-dev/bin/enso --dump-graphs --run yourprogram.enso

When executed on GraalVM 22.3.0 these options instruct the Graal/Truffle compiler to dump files into graal_dumps/_sometimestamp_ directory. Generating these files takes a while - make sure yourprogram.enso runs long enough for the system to warmup, compile the code and run at full speed.

Sieve of Eratosthenes Example

As an example you can download sieve.enso which computes hundred thousand of prime numbers repeatedly and measures time of each round. Download the file and launch Enso with --dump-graphs argument:

enso$ ./built-distribution/enso-engine-0.0.0-dev-linux-amd64/enso-0.0.0-dev/bin/enso --dump-graphs --run sieve.enso

Bunch of files in graal_dumps/* subdirectory is going to be generated:

enso$ ls graal_dumps/*/Truffle* | tail -n5
graal_dumps/2022.06.20.06.18.21.733/TruffleHotSpotCompilation-9889[argument<2>].bgv
graal_dumps/2022.06.20.06.18.21.733/TruffleHotSpotCompilation-9896[IfThenElseMethodGen@3af870b9_<split-62b6b4f3>]_1.bgv
graal_dumps/2022.06.20.06.18.21.733/TruffleHotSpotCompilation-9896[IfThenElseMethodGen@3af870b9_<split-62b6b4f3>].bgv
graal_dumps/2022.06.20.06.18.21.733/TruffleHotSpotCompilation-9935[Primes.next_<split-717d5bdf>]_1.bgv
graal_dumps/2022.06.20.06.18.21.733/TruffleHotSpotCompilation-9935[Primes.next_<split-717d5bdf>].bgv

Let's launch IGV with Enso integration. Locate the engine/runtime directory and open it as "project" in IGV:

Open Project in IGV

The project directories (not only runtime, but also other like runtime-language-epb, etc.) are recognized only if you have built the Enso engine sources with sbt buildEngineDistribution.

With such setup let's open graph for one of the top-most functions: TruffleHotSpotCompilation*Primes*next*.bgv. Choose compilation phase "Before lowering":

Before Lowering Graph

Now you can inspect the compiler graphs the regular IGV way. Let's locate for example LoadField#FunctionSchema.isFullyApplied node and let's check how it got inlined(you can use search box in the top-right corner)

Inlining Stacktrace

The stack trace shows what methods of the Enso interpreter and Truffle runtime are "inlined on stack" when this node is being compiled. However thanks to integration with engine/runtime sources one can directly jump to the sources of the interpreter that represent certain graph nodes:

Associated Engine Sources

Not only that, but one we can also switch to Enso view:

Enso Source

By choosing the Enso language icon in front of the stack trace combo, the source code of our .enso program is opened and we can analyze what compiler nodes refer to what lines in the our Enso program. Click Navigate to Source icon in the Stack View to get from graph node to source. Select a drop down widget in the editor toolbar to show you what compiler nodes as associated with currently selected line.

Building

The plugin can be rebuilt using Apache Maven. The build is platform independent. The following instructions are for Unix like environment. Switch to this directory and invoke:

enso/tools/enso4igv$ mvn clean install
enso/tools/enso4igv$ ls target/*.nbm
target/enso4igv-1.0-SNAPSHOT.nbm

an NBM file is generated which can be installed into IGV, NetBeans or any other NetBeans based application.