Severe Performance Regression Caused by Excessive Deoptimization in Exception Handling

XMLWordPrintable

      ADDITIONAL SYSTEM INFORMATION :
      Property settings:
          file.encoding = UTF-8
          file.separator = /
          java.class.path =
          java.class.version = 65.0
          java.io.tmpdir = /tmp
          java.library.path = /usr/java/packages/lib
              /usr/lib64
              /lib64
              /lib
              /usr/lib
          java.runtime.name = Java(TM) SE Runtime Environment
          java.runtime.version = 21.0.10+8-LTS-217
          java.specification.name = Java Platform API Specification
          java.specification.vendor = Oracle Corporation
          java.specification.version = 21
          java.vendor = Oracle Corporation
          java.vendor.url = https://java.oracle.com/
          java.vendor.url.bug = https://bugreport.java.com/bugreport/
          java.version = 21.0.10
          java.version.date = 2026-01-20
          java.vm.compressedOopsMode = Zero based
          java.vm.info = mixed mode, sharing
          java.vm.name = Java HotSpot(TM) 64-Bit Server VM
          java.vm.specification.name = Java Virtual Machine Specification
          java.vm.specification.vendor = Oracle Corporation
          java.vm.specification.version = 21
          java.vm.vendor = Oracle Corporation
          java.vm.version = 21.0.10+8-LTS-217
          jdk.debug = release
          line.separator = \n
          native.encoding = ANSI_X3.4-1968
          os.arch = amd64
          os.name = Linux
          os.version = 5.15.0-60-generic
          path.separator = :
          stderr.encoding = ANSI_X3.4-1968
          stdout.encoding = ANSI_X3.4-1968
          sun.arch.data.model = 64
          sun.cpu.endian = little
          sun.io.unicode.encoding = UnicodeLittle
          sun.java.launcher = SUN_STANDARD
          sun.jnu.encoding = ANSI_X3.4-1968
          sun.management.compiler = HotSpot 64-Bit Tiered Compilers
          user.country = US
          user.language = en
          user.name = root

      java version "21.0.10" 2026-01-20 LTS
      Java(TM) SE Runtime Environment (build 21.0.10+8-LTS-217)
      Java HotSpot(TM) 64-Bit Server VM (build 21.0.10+8-LTS-217, mixed mode, sharing)

      A DESCRIPTION OF THE PROBLEM :
      HotSpot 21 exhibits a severe performance regression when executing code that repeatedly invokes Math.multiplyExact() within a hot loop that includes exception handling. The root cause appears to be excessive compilation and deoptimization cycles triggered by overly aggressive speculative optimization of exception paths.

      Evidence:
      + Using -Xint (interpreter only) is faster than default JIT, which proves the JIT optimization is counterproductive.
      + CPU profiling with async-profiler shows that a significant amount of execution time in HotSpot 21 is spent in deoptimization, whereas this behavior is not observed in GraalVM 21.
      + Compilation logs obtained with -XX:+PrintCompilation indicate repeated recompilation of the same method: Math.multiplyExact() is compiled four times (Tier 3 → Tier 4 → Tier 3 → Tier 4), and the associated exception handling code is compiled nine times.

      ---------- BEGIN SOURCE ----------
      public class Test {
          public static void main(String[] args) {
              long checksum = 0;
              for (int i = 1; i < 20_000_000; i++) {
                  checksum += hotPath(i);
              }
              System.out.println(checksum);
          }

          private static long hotPath(int i) {
              try {
                  return Math.multiplyExact(i, -i);
              } catch (ArithmeticException ex) {
                  return 0;
              }
          }
      }
      ---------- END SOURCE ----------

      FREQUENCY :
      ALWAYS

            Assignee:
            Unassigned
            Reporter:
            Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: