Navigation Menu

Skip to content
This repository has been archived by the owner on Sep 19, 2023. It is now read-only.

8275638: GraphKit::combine_exception_states fails with "matching stack sizes" assert #29

Closed
wants to merge 7 commits into from

Conversation

rwestrel
Copy link
Contributor

@rwestrel rwestrel commented Dec 15, 2021

The bug and fix were discussed in a previous PR:

openjdk/jdk#6572

I pushed all commits from that PR on top of jdk 18 and added a couple
extra tests as suggested in:

openjdk/jdk#6572 (comment)


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8275638: GraphKit::combine_exception_states fails with "matching stack sizes" assert

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk18 pull/29/head:pull/29
$ git checkout pull/29

Update a local copy of the PR:
$ git checkout pull/29
$ git pull https://git.openjdk.java.net/jdk18 pull/29/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 29

View PR using the GUI difftool:
$ git pr show -t 29

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jdk18/pull/29.diff

@bridgekeeper
Copy link

bridgekeeper bot commented Dec 15, 2021

👋 Welcome back roland! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Dec 15, 2021

@rwestrel The following label will be automatically applied to this pull request:

  • hotspot-compiler

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the hotspot-compiler hotspot-compiler-dev@openjdk.java.net label Dec 15, 2021
@openjdk openjdk bot added the rfr Pull request is ready for review label Dec 15, 2021
@mlbridge
Copy link

mlbridge bot commented Dec 15, 2021

Webrevs

@openjdk
Copy link

openjdk bot commented Dec 15, 2021

@rwestrel This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8275638: GraphKit::combine_exception_states fails with "matching stack sizes" assert

Reviewed-by: dlong, kvn

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 5 new commits pushed to the master branch:

  • 69b5d49: 8272064: test/jdk/jdk/jfr/api/consumer/TestHiddenMethod.java needs update for JEP 416
  • d6b5544: 8278607: Misc issues in foreign API javadoc
  • 918e339: 8278233: [macos] tools/jpackage tests timeout due to /usr/bin/osascript
  • f48a3e8: 8278758: runtime/BootstrapMethod/BSMCalledTwice.java fails with release VMs after JDK-8262134
  • 0cc989b: 8278744: KeyStore:getAttributes() not returning unmodifiable Set

Please see this link for an up-to-date comparison between the source branch of this pull request and the master branch.
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Dec 15, 2021
Copy link

@vnkozlov vnkozlov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with this conservative fix. John agreed with it too.
@dean-long please run testing for it before Roland pushed it. Also file RFE to clean these up - we will assign an engineer to look on it later.

@dean-long
Copy link
Member

I filed JDK-8278873 and started testing.

@dean-long
Copy link
Member

Test results look good.

@rwestrel
Copy link
Contributor Author

@dean-long @vnkozlov thanks for the reviews.

@rwestrel
Copy link
Contributor Author

/integrate

@openjdk
Copy link

openjdk bot commented Dec 17, 2021

Going to push as commit b9a477b.
Since your change was applied there have been 12 commits pushed to the master branch:

  • bb7efb3: 8278790: Inner loop of long loop nest runs for too few iterations
  • 8494fec: 8278796: Incorrect behavior of FloatVector.withLane on X86
  • f5d7c77: 8276826: Clarify the ModuleDescriptor.Version specification’s treatment of repeated punctuation characters
  • be6b90d: 8278574: update --help-extra message to include default value of --finalization option
  • aec1b03: 8278389: SuspendibleThreadSet::_suspend_all should be volatile/atomic
  • e82310f: 8278575: update jcmd GC.finalizer_info to list finalization status
  • d3408a4: 8277964: ClassCastException with no stack trace is thrown with -Xcomp in method handle invocation
  • 69b5d49: 8272064: test/jdk/jdk/jfr/api/consumer/TestHiddenMethod.java needs update for JEP 416
  • d6b5544: 8278607: Misc issues in foreign API javadoc
  • 918e339: 8278233: [macos] tools/jpackage tests timeout due to /usr/bin/osascript
  • ... and 2 more: https://git.openjdk.java.net/jdk18/compare/475ec8e6c5abc3431344d69bd46395e8c4b46e4c...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Dec 17, 2021
@openjdk openjdk bot closed this Dec 17, 2021
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Dec 17, 2021
@openjdk
Copy link

openjdk bot commented Dec 17, 2021

@rwestrel Pushed as commit b9a477b.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@iwanowww
Copy link

iwanowww commented Dec 23, 2021

I'm late to the party, but still would like to clarify one thing.

It seems the root cause of the bug comes from the fact that the same JVM state is used by both GraphKit::uncommon_trap() and GraphKit::builtin_throw() while GraphKit::null_check_receiver_before_call() deliberately adjusts the state to please the former case. If the original state (after the call) is used for GraphKit::builtin_throw(), it should fix the bug as well, shouldn't it?

  // Do a null check on the receiver as it would happen before the call to
  // callee (with all arguments still on the stack).
  Node* null_check_receiver_before_call(ciMethod* callee) {
    assert(!callee->is_static(), "must be a virtual method");
    // Callsite signature can be different from actual method being called (i.e _linkTo* sites).
    // Use callsite signature always.
    ciMethod* declared_method = method()->get_method_at_bci(bci());
    const int nargs = declared_method->arg_size();
    inc_sp(nargs);
    Node* n = null_check_receiver();
    dec_sp(nargs);
    return n;
  }

@rwestrel
Copy link
Contributor Author

rwestrel commented Jan 3, 2022

It seems the root cause of the bug comes from the fact that the same JVM state is used by both GraphKit::uncommon_trap() and GraphKit::builtin_throw() while GraphKit::null_check_receiver_before_call() deliberately adjusts the state to please the former case. If the original state (after the call) is used for GraphKit::builtin_throw(), it should fix the bug as well, shouldn't it?

Wouldn't that only work if there's no uncommon trap in GraphKit::builtin_throw()?

@iwanowww
Copy link

iwanowww commented Jan 3, 2022

Wouldn't that only work if there's no uncommon trap in GraphKit::builtin_throw()?

Good point. I overlooked the uncommon trap logic there.

But my original point still stands: why can't GraphKit::builtin_throw() be taught to distinguish between throwing and uncommon trap cases and adjust JVM state accordingly? In this particular case, it seems simpler to start with the JVM state for re-execution (before call) and switch to the JVM state after the call (pop arguments from the stack) when an exception is thrown.

So, instead of checking for local exception handlers and wiping the stack [1], the effects of null_check_receiver_before_call() [2] can be undone unconditionally. That should make all possible exception states uniform and, hence, mergeable, shouldn't it?

[1]

       if (!method()->has_exception_handlers()) {
        // We don't need to preserve the stack if there's no handler as the entire frame is going to be popped anyway.
        // This prevents issues with exception handling and late inlining.
        set_sp(0);
        clean_stack(0);
      }

[2]

  // Do a null check on the receiver as it would happen before the call to
  // callee (with all arguments still on the stack).
  Node* null_check_receiver_before_call(ciMethod* callee) {
    assert(!callee->is_static(), "must be a virtual method");
    // Callsite signature can be different from actual method being called (i.e _linkTo* sites).
    // Use callsite signature always.
    ciMethod* declared_method = method()->get_method_at_bci(bci());
    const int nargs = declared_method->arg_size();
    inc_sp(nargs);
    Node* n = null_check_receiver();
    dec_sp(nargs);
    return n;
  }

@rwestrel
Copy link
Contributor Author

rwestrel commented Jan 5, 2022

But my original point still stands: why can't GraphKit::builtin_throw() be taught to distinguish between throwing and uncommon trap cases and adjust JVM state accordingly? In this particular case, it seems simpler to start with the JVM state for re-execution (before call) and switch to the JVM state after the call (pop arguments from the stack) when an exception is thrown.

Then what's on the stack doesn't matter so why not pop the stack instead?
There's some discussion about that in the initial PR (before the jdk18 fork): openjdk/jdk#6572
And a follow up bug: https://bugs.openjdk.java.net/browse/JDK-8278846

@iwanowww
Copy link

iwanowww commented Jan 5, 2022

Then what's on the stack doesn't matter so why not pop the stack instead?

Yes, that's also an option. (And, probably, the cleanest one.)

I agree with the summary in JDK-8278846. I don't see any reason why exception state should include stack state.

Thanks for the clarifications.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
hotspot-compiler hotspot-compiler-dev@openjdk.java.net integrated Pull request has been integrated
4 participants