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

Recursive method that was compiled by C1 is unable to catch StackOverflowError

XMLWordPrintable

    • 8
    • b29
    • generic
    • generic

        Starting from JDK8-FCS following method will throw StackOverflowError when it compiled by C1:

        void run() {
            try {
                run();
            } catch (Throwable t) {
                // StackOverflowError expected to be caught here
            }
        }

        Issue happens when StackOverflowError is thrown during constraint class resolution (in this case j.l.Throwable and it is unresolved for some reason) in Method::fast_exception_handler_bci_for.
        In that case SharedRuntime::compute_compiled_exc_handler will return address of unwind handler and C1's Runtime1::exception_handler_for_pc_helper will store in ExceptionCache as handler for StackOverflowError @ run() bci.
        As a result, at every further attempt to find exception handler during unwinding Runtime1::exception_handler_for_pc_helper will return unwind handler from cache and method will never catch StackOverflowError.

        For C2 StackOverflowError is also occurring during Throwable resolution, but in that case stack will be unwound until there will be enough stack space to resolve Throwable and actual exception handler will be returned.

        Issue could be reproduced starting from 8 FCS. It is also reproducible with latest JDK9 build (b25).
        Issue could be reproduced only with C1.

              roland Roland Westrelin
              fzhinkin Filipp Zhinkin
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: