一句话:提出 JOG 框架,用 Java 模式同时编写 JIT 窥孔优化与其测试,并自动检测优化间的遮蔽关系。
Java JIT 的窥孔优化通常以 C/C++ 手工编写,测试则分散在 Java 测试中,二者难以同步维护。本文提出 JOG 框架,允许开发者直接在 Java 中以模式形式描述优化:写出优化前后的代码以及必要的前置条件,其写法与 OpenJDK 中已有的优化测试一致。JOG 将每个模式翻译为可集成到 JIT 优化管线中的 C/C++ 代码,同时从模式自动生成对应的 Java 测试;此外,JOG 还能自动检测一对优化之间可能存在的遮蔽(shadow)关系,即某个优化的效果被另一个优化覆盖。评估中作者编写了 162 个模式,包括 68 个 OpenJDK 已有优化、92 个改编自 LLVM 的新优化以及 2 个自行提出的新优化,并向 OpenJDK 提交 8 个 PR,其中 7 个已被合入主分支。结果表明 JOG 在不降低 JIT 优化效果的前提下,使优化与测试的编写更易读、更易维护。
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.