Table of Contents
Fetching ...

Pattern-Based Peephole Optimizations with Java JIT Tests

Zhiqiang Zang, Aditya Thimmaiah, Milos Gligoric

TL;DR

JOG enables developers to write a pattern, in Java itself, that specifies desired code transformations by writing code before and after the optimization, as well as any necessary preconditions, in the same way that tests of the optimization are already written in OpenJDK.

Abstract

We present JOG, a framework that facilitates developing Java JIT peephole optimizations alongside JIT tests. JOG enables developers to write a pattern, in Java itself, that specifies desired code transformations by writing code before and after the optimization, as well as any necessary preconditions. Such patterns can be written in the same way that tests of the optimization are already written in OpenJDK. JOG translates each pattern into C/C++ code that can be integrated as a JIT optimization pass. JOG also generates Java tests for optimizations from patterns. Furthermore, JOG can automatically detect possible shadow relation between a pair of optimizations where the effect of the shadowed optimization is overridden by another. Our evaluation shows that JOG makes it easier to write readable JIT optimizations alongside tests without decreasing the effectiveness of JIT optimizations. We wrote 162 patterns, including 68 existing optimizations in OpenJDK, 92 new optimizations adapted from LLVM, and two new optimizations that we proposed. We opened eight pull requests (PRs) for OpenJDK, including six for new optimizations, one on removing shadowed optimizations, and one for newly generated JIT tests; seven PRs have already been integrated into the master branch of OpenJDK.

Pattern-Based Peephole Optimizations with Java JIT Tests

TL;DR

JOG enables developers to write a pattern, in Java itself, that specifies desired code transformations by writing code before and after the optimization, as well as any necessary preconditions, in the same way that tests of the optimization are already written in OpenJDK.

Abstract

We present JOG, a framework that facilitates developing Java JIT peephole optimizations alongside JIT tests. JOG enables developers to write a pattern, in Java itself, that specifies desired code transformations by writing code before and after the optimization, as well as any necessary preconditions. Such patterns can be written in the same way that tests of the optimization are already written in OpenJDK. JOG translates each pattern into C/C++ code that can be integrated as a JIT optimization pass. JOG also generates Java tests for optimizations from patterns. Furthermore, JOG can automatically detect possible shadow relation between a pair of optimizations where the effect of the shadowed optimization is overridden by another. Our evaluation shows that JOG makes it easier to write readable JIT optimizations alongside tests without decreasing the effectiveness of JIT optimizations. We wrote 162 patterns, including 68 existing optimizations in OpenJDK, 92 new optimizations adapted from LLVM, and two new optimizations that we proposed. We opened eight pull requests (PRs) for OpenJDK, including six for new optimizations, one on removing shadowed optimizations, and one for newly generated JIT tests; seven PRs have already been integrated into the master branch of OpenJDK.
Paper Structure (17 sections, 5 equations, 9 figures, 3 tables)

This paper contains 17 sections, 5 equations, 9 figures, 3 tables.

Figures (9)

  • Figure 1: An example JIT test available in OpenJDK.
  • Figure 2: An example of a peephole optimization as implemented in OpenJDK and JOG, and associated test.
  • Figure 3: JOG Syntax. The non-terminals that are not defined in the figure share the same definition as Java JavaLangSpecification.
  • Figure 4: eASTs for pattern ADD8 in Figure \ref{['fig:example:pattern-code']}.
  • Figure 5: Illustration of shadow detecting algorithm on pattern ADD2 ($X$) shadowing ADD7 ($Y$). Every eAST node is represented by a variable, and the dashed lines connect equivalent nodes (e.g., $x_1$ is equivalent to $y_1$). The formula $F$ shows the final SMT formula that specifies the shadow relation.
  • ...and 4 more figures