Pattern-Based Peephole Optimizations with Java JIT Tests (2403.11283v1)
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.
- Gergö Barany. 2018. Finding Missed Compiler Optimizations by Differential Testing. In International Conference on Compiler Construction. ACM, 82–92. https://doi.org/10.1145/3178372.3179521
- Formal Verification of an SSA-Based Middle-End for CompCert. In Programming Language Design and Implementation. Association for Computing Machinery, 4:1–4:35. https://doi.org/10.1145/2579080
- Richard Biener and Prathamesh Kulkarni. 2022. gcc/match.pd at master - gcc-mirror/gcc. https://github.com/gcc-mirror/gcc/blob/dcb4bd0/gcc/match.pd.
- The DaCapo Benchmarks: Java Benchmarking Development and Analysis. In International Conference on Object-Oriented Programming, Systems, Languages, and Applications. ACM, 169–190. https://doi.org/10.1145/1167473.1167488
- Sebastian Buchwald. 2015. Optgen: A Generator for Local Optimizations. In International Conference on Compiler Construction. Springer, Berlin, Heidelberg, 171–189. https://doi.org/10.1007/978-3-662-46663-6_9
- Raymond P.L. Buse and Westley R. Weimer. 2010. Learning a Metric for Code Readability. IEEE Transactions on Software Engineering 36, 4 (2010), 546–558. https://doi.org/10.1109/TSE.2009.70
- Nathanaël Courant and Xavier Leroy. 2021. Verified Code Generation for the Polyhedral Model. In Symposium on Principles of Programming Languages. ACM, 40:1–40:24. https://doi.org/10.1145/3434321
- Leonardo De Moura and Nikolaj Bjørner. 2008. Z3: An Efficient SMT Solver. In International Conference on Tools and Algorithms for the Construction and Analysis of Systems. Springer, 337–340. https://doi.org/10.1007/978-3-540-78800-3_24
- Bradley Efron and Robert J. Tibshirani. 1994. An Introduction to the Bootstrap. CRC Press. https://books.google.com/books?id=MWC1DwAAQBAJ
- CAnDL: A Domain Specific Language for Compiler Analysis. In International Conference on Compiler Construction. ACM, 151–162. https://doi.org/10.1145/3178372.3179515
- The Java® Language Specification. https://docs.oracle.com/javase/specs/jls/se17/jls17.pdf.
- CTOS: Compiler Testing for Optimization Sequences of LLVM. IEEE Transactions on Software Engineering 48, 7 (2022), 2339–2358. https://doi.org/10.1109/TSE.2021.3058671
- Proving Optimizations Correct Using Parameterized Program Equivalence. In Programming Language Design and Implementation. ACM, 327–337. https://doi.org/10.1145/1542476.1542513
- Automatically Proving the Correctness of Compiler Optimizations. In Programming Language Design and Implementation. ACM, 220–231. https://doi.org/10.1145/781131.781156
- Automated Soundness Proofs for Dataflow Analyses and Transformations via Local Rules. In Symposium on Principles of Programming Languages. ACM, 364–377. https://doi.org/10.1145/1040305.1040335
- Xavier Leroy. 2009. Formal Verification of a Realistic Compiler. Commun. ACM 52, 7 (2009), 107–115. https://doi.org/10.1145/1538788.1538814
- LLVM Project. 2022. llvm-project/llvm/lib/Transforms/InstCombine at main - llvm/llvm-project. https://github.com/llvm/llvm-project/tree/b26e44e/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp.
- LLVM Project. 2023. llvm/llvm-project: The LLVM Project is a collection of modular and reusable compiler and toolchain technologies. Note: the repository does not accept github pull requests at this moment. Please submit your patches at http://reviews.llvm.org. https://github.com/llvm/llvm-project.
- Provably Correct Peephole Optimizations with Alive. In Programming Language Design and Implementation. ACM, 22–32. https://doi.org/10.1145/2737924.2737965
- Nuno P. Lopes and John Regehr. 2018. Future Directions for Optimizing Compilers. https://doi.org/10.48550/ARXIV.1809.02161
- W. M. McKeeman. 1965. Peephole Optimization. Commun. ACM 8, 7 (1965), 443–444. https://doi.org/10.1145/364995.365000
- David Menendez and Santosh Nagarakatte. 2016. Termination-Checking for LLVM Peephole Optimizations. In International Conference on Software Engineering. ACM, 191–202. https://doi.org/10.1145/2884781.2884809
- Alive-FP: Automated Verification of Floating Point Based Peephole Optimizations in LLVM. In Static Analysis. Springer, 317–337. https://doi.org/10.1007/978-3-662-53413-7_16
- Steven S. Muchnick. 1997. Advanced Compiler Design and Implementation. Morgan Kaufmann Publishers.
- Verified Peephole Optimizations for CompCert. In Programming Language Design and Implementation. ACM, 448–461. https://doi.org/10.1145/2908080.2908109
- Naoki Nishida and Sarah Winkler. 2018. Loop Detection by Logically Constrained Term Rewriting. In Verified Software. Theories, Tools, and Experiments. Springer, 309–321. https://doi.org/10.1007/978-3-030-03592-1_18
- Andres Nötzli and Fraser Brown. 2016. LifeJacket: Verifying Precise Floating-Point Optimizations in LLVM. In International Workshop on State Of the Art in Program Analysis. ACM, 24–29. https://doi.org/10.1145/2931021.2931024
- Oracle and/or its affiliates. 2022a. jdk/AddINodeIdealizationTests.java at master - openjdk/jdk - GitHub. https://github.com/openjdk/jdk/blob/master/test/hotspot/jtreg/compiler/c2/irTests/AddINodeIdealizationTests.java.
- Oracle and/or its affiliates. 2022b. jdk/subnode.cpp at b334d96 - openjdk/jdk - GitHub. https://github.com/openjdk/jdk/blob/b334d96/src/hotspot/share/opto/subnode.cpp#L163.
- Oracle and/or its affiliates. 2022c. jdk/test/hotspot/jtreg/compiler/lib/ir_framework at master - openjdk/jdk - GitHub. https://github.com/openjdk/jdk/tree/master/test/hotspot/jtreg/compiler/lib/ir_framework.
- Oracle and/or its affiliates. 2023a. 8277882: New subnode ideal optimization: converting ”c0 - (x + c1)” into ”(c0 - c1) - x” - Pull Request #6441 - openjdk/jdk. https://github.com/openjdk/jdk/pull/6441.
- Oracle and/or its affiliates. 2023b. 8278114: New addnode ideal optimization: converting ”x + x” into ”x ¡¡ 1” - Pull Request #6675 - openjdk/jdk. https://github.com/openjdk/jdk/pull/6675.
- Oracle and/or its affiliates. 2023c. 8278471: Remove unreached rules in AddNode::IdealIL - Pull Request #6752 - openjdk/jdk. https://github.com/openjdk/jdk/pull/6752.
- Oracle and/or its affiliates. 2023d. 8279607: Existing optimization ”~x+1” -¿ ”-x” can be generalized to ”~x+c” -¿ ”(c-1)-x”. - Pull Request #6858 - openjdk/jdk. https://github.com/openjdk/jdk/pull/6858.
- Oracle and/or its affiliates. 2023e. 8281453: New optimization: convert ~x into -1-x when ~x is used in an arithmetic expression - Pull Request #7376 - openjdk/jdk. https://github.com/openjdk/jdk/pull/7376.
- Oracle and/or its affiliates. 2023f. 8281518: New optimization: convert ”(x—y)-(x^y)” into ”x&y” - Pull Request #7395 - openjdk/jdk. https://github.com/openjdk/jdk/pull/7395.
- Oracle and/or its affiliates. 2023g. 8283094: Add Ideal transformation: x + (con - y) -¿ (x - y) + con - Pull Request #7795 - openjdk/jdk. https://github.com/openjdk/jdk/pull/7795.
- Oracle and/or its affiliates. 2023h. 8297384: Add IR tests for existing idealizations of arithmetic nodes by CptGit - Pull Request #11049 - openjdk/jdk. https://github.com/openjdk/jdk/pull/11049.
- Oracle and/or its affiliates. 2023i. jdk/addnode.cpp at b334d96 - openjdk/jdk - GitHub. https://github.com/openjdk/jdk/blob/b334d96/src/hotspot/share/opto/addnode.cpp#L358.
- Oracle and/or its affiliates. 2023j. jdk/subnode.cpp at b334d96 - openjdk/jdk - GitHub. https://github.com/openjdk/jdk/blob/b334d96/src/hotspot/share/opto/subnode.cpp#L243.
- Oracle Corporation and/or its affiliates. 2023a. JDK Bug System. https://bugs.openjdk.java.net/browse/JDK-8266601.
- Oracle Corporation and/or its affiliates. 2023b. openjdk/jdk: JDK main-line development. https://github.com/openjdk/jdk.
- Renaissance: Benchmarking Suite for Parallel Applications on the JVM. In Programming Language Design and Implementation. ACM, 31–47. https://doi.org/10.1145/3314221.3314637
- Standard Performance Evaluation Corporation. 2022. SPECjvm2008. https://www.spec.org/jvm2008/.
- the GCC Developer Community. 2022. Match and Simplify. https://gcc.gnu.org/onlinedocs/gccint/match-and-simplify.html.
- Finding Missed Optimizations through the Lens of Dead Code Elimination. In International Conference on Architectural Support for Programming Languages and Operating Systems. ACM, 697–709. https://doi.org/10.1145/3503222.3507764
- Sruthi Venkat and Preet Kanwal. 2018. COpt: A High Level Domain-Specific Language to Generate Compiler Optimizers. In International Conference on Advanced Computation and Telecommunication. IEEE, 1–6. https://doi.org/10.1109/ICACAT.2018.8933593
- Deborah L. Whitfield and Mary Lou Soffa. 1997. An Approach for Exploring Code Improving Transformations. ACM Trans. Program. Lang. Syst. 19, 6 (1997), 1053–1084. https://doi.org/10.1145/267959.267960
- Zhiqiang Zang (3 papers)
- Aditya Thimmaiah (3 papers)
- Milos Gligoric (23 papers)