> ### Mismatching Stack Sizes During Late Inlining > The re-enabled assert and some tests in `TestNullableInlineTypes` fail with a > stack mismatch assert when trying to combine exception states when replacing > the non-static `CallStaticJava` node in `GraphKit::replace_call()` for a just > late inlined call with the actual result . In `test84()`, for example, we > have one exception state with the JVM expression stack pointer (later > referred to as just "stack pointer") set to 1 and the other set to 0. This > means that we throw from two different paths with unequal stack sizes which > is a problem. > > ### Reason for Stack Size Mismatch > At the time of the assertion failure, we compare two states from two > exception safepoints: > 1. `builtin_throw()` from a null check from an ordinary field access in the > callee (currently being late inlined): > https://github.com/openjdk/valhalla/blob/4c23f0ed5d6a89cd1e7ab8550b367bca296a9f30/src/hotspot/share/opto/graphKit.cpp#L1543-L1544 > We clear the stack due to not having an exception handler: > https://github.com/openjdk/valhalla/blob/931493bdedd35731569225e1a5c644fbeeea6372/src/hotspot/share/opto/graphKit.cpp#L614-L619 > 2. `builtin_throw()` from the receiver null check before the non-static call > to the callee (i.e. still in the caller). We have an exception handler and > thus do not clear the stack as for `1.`. We have all the arguments on the > stack: > https://github.com/openjdk/valhalla/blob/4c23f0ed5d6a89cd1e7ab8550b367bca296a9f30/src/hotspot/share/opto/graphKit.hpp#L692-L694 > > This explains the different stack sizes. > > When we have an exception handler in the callee, we would already handle the > exception states in `Parse::do_exceptions()` and do not need to combine them > in the caller after the callee was late inlined. > > ### Why Is this not Causing more Problems? > This seems to be quite a common case to have different stack size, so why > don't we hit more problems? First, we notice that when we normally add a new > exception state, we combine states only when stack sizes are equal: > https://github.com/openjdk/valhalla/blob/931493bdedd35731569225e1a5c644fbeeea6372/src/hotspot/share/opto/graphKit.cpp#L304-L308 > > We only combine exception states with different stack sizes when calling > `combine_exception_states()` from `combine_and_pop_all_exception_states()`. > This happens at two places: > - `Compile::rethrow_exceptions()`: When we still have exceptions states when > calling this method, it means that there is no exception handler in the > current method. Therefore...
Christian Hagedorn has updated the pull request incrementally with one additional commit since the last revision: Apply suggestion from @TobiHartmann Co-authored-by: Tobias Hartmann <[email protected]> ------------- Changes: - all: https://git.openjdk.org/valhalla/pull/2486/files - new: https://git.openjdk.org/valhalla/pull/2486/files/23a173eb..2f59416b Webrevs: - full: https://webrevs.openjdk.org/?repo=valhalla&pr=2486&range=01 - incr: https://webrevs.openjdk.org/?repo=valhalla&pr=2486&range=00-01 Stats: 1 line in 1 file changed: 0 ins; 1 del; 0 mod Patch: https://git.openjdk.org/valhalla/pull/2486.diff Fetch: git fetch https://git.openjdk.org/valhalla.git pull/2486/head:pull/2486 PR: https://git.openjdk.org/valhalla/pull/2486
