Summary
-------
To aid in testing, create a facility to serialize and deserialize the intermediate-representation (IR) graphs used in the HotSpot run-time compilers.
Non-Goals
---------
It is not a goal to provide a means to serialize IR graphs for purposes other than testing.
Motivation
----------
It is not possible, today, for HotSpot run-time compiler tests to test compiler optimizations directly. To test a specific optimization, they resort to manipulating the JVM into a state in which that optimization will be performed. These are [“gray box”][graybox] tests, since they depend upon HotSpot implementation details but do not have access to HotSpot internals. They are fragile, since a change in the implementation can render a test useless.
Most run-time compiler optimizations operate upon an IR graph. If we could load a graph into the JVM, perform a specific optimization on it, and then export it for analysis then we could write stable and robust optimizer tests that do not depend upon HotSpot implementation details. This would also simplify the development of optimizer regression tests.
Description
-----------
We propose to introduce new [HotSpot WhiteBox APIs][whitebox] to import an IR graph, perform a specific optimization on it, and then export it:
- `IRHandle import(InputStream)`
- `IRHandle optimize(IRHandle, OptimizationEnum)`
- `InputStream export(IRHandle)`
where `IRHandle` is a reference to an IR graph object and `OptimizationEnum` is an enumeration of all supported optimizations.
There is already a serial format for the C2 IR, namely the XML format used by the [Ideal Graph Visualizer (IGV)][igv]. We propose to use that format, extending it as necessary for the C1 IR. Using the IGV format will also allow us to enhance the IGV tool so that it can serve as a WSYIWYG-editor for IR graphs.
Risks and Assumptions
---------------------
Adding this code to product builds will slightly increase the size of `libjvm.so`. If that becomes an issue then we can move it into a separate dynamically-linked library.
[graybox]: https://en.wikipedia.org/wiki/Gray_box_testing
[whitebox]: https://wiki.openjdk.java.net/display/HotSpot/The+WhiteBox+testing+API
[igv]: https://wiki.openjdk.java.net/display/HotSpot/IdealGraphVisualizer