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

Reduce Throwable.getStackTrace() calls to the JVM

    XMLWordPrintable

Details

    • Enhancement
    • Resolution: Fixed
    • P3
    • 9
    • 9
    • hotspot
    • b115

    Description


      In Throwable.getOurStackTrace(), the JDK makes an downcall to the JVM to get the stack trace depth, and once for each element of the stacktrace element. On the vm side, we have to traverse the backtrace chunks for each element.

                      int depth = getStackTraceDepth();
                      stackTrace = new StackTraceElement[depth];
                      for (int i = 0; i < depth; i++)
                          stackTrace[i] = getStackTraceElement(i);

      If we add a depth field in the Throwable object when creating the stack trace, getStackTraceDepth can use that to create an array of StackTraceElement and call the JVM to fill in all the elements:

                      int depth = getStackTraceDepth();
                      stackTrace = new StackTraceElement[depth];
                      for (int i = 0; i < depth; i++) {
                          stackTrace[i] = new StackTraceElement();
                      }
                      getStackTraceElements(stackTrace);

      This would clean out the native code and allow some sharing with code that's being prototyped in the StackWalk API code using a simplified StackTraceElement::fill_in(). Also walking the internal format for Throwable.backtrace in the jvm can be simplified.

      It also improves performance of Throwable.getStackTrace() and printStackTrace.

      Using 100 stack trace elements in the microbenchmark for throwable:

      JDK8Benchmarks.testThrowableGetStackTrace 100 avgt 20 66830.815 ± 474.345 ns/op
      vs.
      JDK8Benchmarks.testThrowableGetStackTrace 100 avgt 20 59471.911 ± 540.100 ns/op

      Attachments

        Issue Links

          Activity

            People

              coleenp Coleen Phillimore
              coleenp Coleen Phillimore
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: