JDK-8043472 : JEP 399: Intermediate-Representation Graph Serialization
  • Type: JEP
  • Component: hotspot
  • Sub-Component: compiler
  • Priority: P4
  • Status: Candidate
  • Resolution: Unresolved
  • Submitted: 2014-05-19
  • Updated: 2024-06-07
Related Reports
Relates :  
Relates :  
Description
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

Comments
Thanks Cesar for offering your help! I appreciate that but I agree with what Tobias says here. I would also rather opt to improve the IR framework to cover some of the use cases mentioned. I'm not sure though how easy this will be and if it really justified the required (hard to estimate) work given that we will only cover some special cases that currently cannot be checked otherwise. Regarding the IR framework in general, I think there are probably some other more promising tasks that could be done (if looking to contribute to the IR framework).
07-06-2024

We think that the IR Test Framework (JDK-8254129) solves the vast majority of use cases described in this JEP with a much simpler and more robust implementation. There are certainly use cases (for example, checking placement of a node in a loop) where the IR Test Framework reaches its limitations but I'd prefer improving that framework instead of introducing graph serialization.
07-06-2024

Hi Cesar, as far as I know, no one from Oracle is currently working on this or planning to in the near future.
07-06-2024

[~epavlova] I'd love to help you with this work. Is there anything that I could help with? /cc [~kvn] [~thartmann]
07-06-2024

Hi folks, I'm from the JVM Engineering team at Microsoft, we would like to offer assistance to get this work done. Is there anything that we could help you with? Thank you!
09-07-2021

[~mr] thanks for your edits, it looks good.
05-03-2021

[~iignatyev] I’ve rewritten this to smooth out and tighten up the wording, and to add a few informational links. If this looks okay to you then I’ll move it to Candidate.
03-03-2021

I believe security risks should also be considered.
05-10-2015