Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8273563

Improve performance of implicit exceptions with -XX:-OmitStackTraceInFastThrow

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: In Progress
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 18, 19
    • Fix Version/s: tbd
    • Component/s: hotspot
    • Labels:
      None
    • Subcomponent:
    • Understanding:
      Fix Understood
    • CPU:
      generic
    • OS:
      generic

      Description

      Currently, if running with -XX:-OmitStackTraceInFastThrow, C2 has no possibility to create implicit exceptions like AIOOBE, NullPointerExceptions, etc. in compiled code with the effect that these methods will always be deoptimized and reexecuted in the interpreter if such an exception is happening.

      If such implicit exceptions are used for normal control flow, that can have a dramatic impact on performance. A prominent example for such code is Tomcat's HttpParser::isAlpha() method[1]:

          public static boolean isAlpha(int c) {
              try {
                  return IS_ALPHA[c];
              } catch (ArrayIndexOutOfBoundsException ex) {
                  return false;
              }
          }

      Instead of deoptimizing and resorting to the interpreter, we can generate code which allocates and initializes the corresponding exceptions right in compiled code.

      A prototype which implements this idea shows a ten-times performance improvement for the above code:

      -XX:-OmitStackTraceInFastThrow
      Benchmark (exceptionProbability) Mode Cnt Score Error Units
      ImplicitExceptions.bench 0.0 avgt 5 1.430 ± 0.353 ns/op
      ImplicitExceptions.bench 0.33 avgt 5 3563.038 ± 77.358 ns/op
      ImplicitExceptions.bench 0.66 avgt 5 8609.693 ± 1205.104 ns/op
      ImplicitExceptions.bench 1.00 avgt 5 12842.401 ± 1022.728 ns/op

      -XX:-OmitStackTraceInFastThrow -XX:+OptimizeImplicitExceptions
      Benchmark (exceptionProbability) Mode Cnt Score Error Units
      ImplicitExceptions.bench 0.0 avgt 5 1.432 ± 0.352 ns/op
      ImplicitExceptions.bench 0.33 avgt 5 355.723 ± 16.641 ns/op
      ImplicitExceptions.bench 0.66 avgt 5 887.068 ± 166.728 ns/op
      ImplicitExceptions.bench 1.00 avgt 5 1274.418 ± 88.235 ns/op

      [1] https://github.com/apache/tomcat/blob/26ba86cdbd40ca718e43b82e62b3eb49d004c3d6/java/org/apache/tomcat/util/http/parser/HttpParser.java#L266-L274

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              simonis Volker Simonis
              Reporter:
              simonis Volker Simonis
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated: