Skip to content

Conversation

@ruben-arm
Copy link
Contributor

@ruben-arm ruben-arm commented Nov 7, 2025

The original fix JDK-8365047 was backed out by JDK-8371388, this is the REDO.

The C2 exception handler stub code is only a trampoline to the generated exception handler blob. This change removes the extra step on the way to the generated blob.

According to some comments in the source code, the exception handler stub code used to be patched upon deoptimization, however presumably these comments are outdated as the patching upon deoptimization happens for post-call NOPs only.


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed (2 reviews required, with at least 2 Reviewers)

Issue

  • JDK-8371458: [REDO] Remove exception handler stub code in C2 (Enhancement - P4)

Reviewers

Contributors

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/28192/head:pull/28192
$ git checkout pull/28192

Update a local copy of the PR:
$ git checkout pull/28192
$ git pull https://git.openjdk.org/jdk.git pull/28192/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 28192

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/28192.diff

Using Webrev

Link to Webrev Comment

The C2 exception handler stub code is only a trampoline to the
generated exception handler blob. This change removes the extra
step on the way to the generated blob.

According to some comments in the source code, the exception handler
stub code used to be patched upon deoptimization, however presumably
these comments are outdated as the patching upon deoptimization happens
for post-call NOPs only.
Change-Id: I596317ec6a364b341e4642636fa5cf08f87ed722
Change-Id: I9ef51b426d34e9b44a3891f6a45307232f900e5a
Change-Id: I5f5fd681ba699f96859180d984841dd6df8524b5
@ruben-arm
Copy link
Contributor Author

/contributor add @TheRealMDoerr

@bridgekeeper
Copy link

bridgekeeper bot commented Nov 7, 2025

👋 Welcome back ruben-arm! 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 Nov 7, 2025

@ruben-arm 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:

8371458: [REDO] Remove exception handler stub code in C2

Co-authored-by: Martin Doerr <[email protected]>
Reviewed-by: mdoerr, dlong

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 306 new commits pushed to 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.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@TheRealMDoerr, @dean-long) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk
Copy link

openjdk bot commented Nov 7, 2025

@ruben-arm
Contributor Martin Doerr <[email protected]> successfully added.

@openjdk
Copy link

openjdk bot commented Nov 7, 2025

@ruben-arm The following labels will be automatically applied to this pull request:

  • hotspot
  • serviceability

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

@openjdk openjdk bot added the rfr Pull request is ready for review label Nov 7, 2025
@mlbridge
Copy link

mlbridge bot commented Nov 7, 2025

Webrevs

@ruben-arm
Copy link
Contributor Author

Thanks @ruben-arm. Let's go with this clean back out for now - testing just came back clean. Once you have the REDO ready, I can submit some more sophisticated testing to make sure it addresses the issues we're seeing.

@TobiHartmann, I would appreciate it if you could initiate the extended testing for this PR.

@TobiHartmann
Copy link
Member

Sure, I submitted testing.

@ruben-arm ruben-arm changed the title 8371458: [REDO] - Remove exception handler stub code in C2 8371458: [REDO] Remove exception handler stub code in C2 Nov 7, 2025
@vnkozlov
Copy link
Contributor

vnkozlov commented Nov 7, 2025

@ruben-arm what was the issue in the original changes?

@ruben-arm
Copy link
Contributor Author

@vnkozlov, the NativePostCallNop::check

bool check() const { return int_at(0) == 0x841f0f; }
was reading 4 bytes from the perceived call site.

That works when the check happens for an actual call site, as the post-call NOP sequence is always longer than 4 bytes.
However, it fails in case the return address in the stack frame, during deoptimization, is patched to point to the deoptimization stub code entry point.

With the change, the distance between the entry point and end of code blob can now be just 2 bytes - consequently the 4-bytes read would read outside the code blob.
The proposed fix is to split the read in the post-call NOP check into two 2-byte reads. If first read+comparison doesn't confirm it might be a post-call NOP sequence (it never will for the deoptimization stub code entry point) the second read wouldn't happen.

I initially missed this issue - having incorrectly concluded that the jmp at the entry point will take 5 bytes in size instead of 2 bytes.

7bb4352 should address this issue by splitting the faulting read into two. It also adjusts the expected size of deoptimization handler stub code to 7 bytes in total instead of the incorrect estimate of 10 bytes.

@TobiHartmann
Copy link
Member

Sure, I submitted testing.

All testing passed. I leave it to the original reviewers to re-review.

Copy link
Contributor

@TheRealMDoerr TheRealMDoerr left a comment

Choose a reason for hiding this comment

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

I haven't checked the deopt handler size on x86. Otherwise, it still looks good to me.

};

bool check() const { return int_at(0) == 0x841f0f; }
bool check() const { return short_at(0) == 0x1f0f && short_at(2) == 0x0084; }
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe a comment would be nice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestion. Would the comments added at 20cc58a be suitable?

@openjdk
Copy link

openjdk bot commented Nov 10, 2025

⚠️ @ruben-arm the full name on your profile does not match the author name in this pull requests' HEAD commit. If this pull request gets integrated then the author name from this pull requests' HEAD commit will be used for the resulting commit. If you wish to push a new commit with a different author name, then please run the following commands in a local repository of your personal fork:

$ git checkout pr-8365047
$ git commit --author='Preferred Full Name <[email protected]>' --allow-empty -m 'Update full name'
$ git push

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Nov 10, 2025
@ruben-arm
Copy link
Contributor Author

Thanks, @TobiHartmann, for the extra tests, and apologies for missing this in the original PR.

@TheRealMDoerr, I will update the PR to add comments.

I am exploring a possibility to add a unit test for this issue, but I have not identified a deterministic way to make the deopt handler stub end at a page boundary.

@TobiHartmann
Copy link
Member

/reviewers 2 reviewer

@openjdk
Copy link

openjdk bot commented Nov 13, 2025

@TobiHartmann
The total number of required reviews for this PR (including the jcheck configuration and the last /reviewers command) is now set to 2 (with at least 2 Reviewers).

@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Nov 13, 2025
@ruben-arm
Copy link
Contributor Author

I am planning to update this PR today to include the comments.
However, I still have not identified a way to ensure the deopt handler stub ends at a page boundary in a unit test.

@ruben-arm
Copy link
Contributor Author

However, I still have not identified a way to ensure the deopt handler stub ends at a page boundary in a unit test.

The latest update implements an alternative way to detect the failure early during testing - via the newly added assertion in the emit_deopt_handler.

@adinn, @dean-long, @TheRealMDoerr, would it be possible for you to review the latest version of the PR?

Is there any additional testing you would recommend to perform before this can be integrated?

Copy link
Contributor

@TheRealMDoerr TheRealMDoerr left a comment

Choose a reason for hiding this comment

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

I think assertions would be sufficient in C1 instead of guarantee. But, ok. I'll put it into our test queue.

@TheRealMDoerr
Copy link
Contributor

Our tests haven't revealed any new issues related to this PR.

@ruben-arm
Copy link
Contributor Author

Thank you, @TheRealMDoerr,

I think assertions would be sufficient in C1 instead of guarantee.

Sure, I will change these to assertions.

// The two parts should be checked separately to prevent out of bounds access in case
// the return address points to the deopt handler stub code entry point which could be
// at the end of page.
first_check_size = 4
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
first_check_size = 4
first_check_size = instruction_size

// read. If the check would read beyond size of the instruction at the deopt handler stub
// code entry point, then it has to happen in two stages - to prevent out of bounds access
// in case the return address points to the entry point which could be at the end of page.
first_check_size = 0
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
first_check_size = 0
first_check_size = 0 // check is unimplemented

@dean-long
Copy link
Member

Is there any additional testing you would recommend to perform before this can be integrated?

Oracle likes to make sure the final version passes in our CI. I got burned last time testing an earlier version and not the final version.

@adinn
Copy link
Contributor

adinn commented Nov 19, 2025

@ruben-arm I'm ok with this version assuming it passes tests.

@ruben-arm
Copy link
Contributor Author

Thank you for the reviews, @dean-long, @adinn, @TheRealMDoerr.
@dean-long, I've updated the patch according to your suggestions - also applied the same to other nativeInst_* files except nativeInst_x86.hpp as the instruction size is not fixed in this case.

the final version passes in our CI

If this version of the patch looks suitable, would it be possible to start the CI testing please?

Copy link
Contributor

@TheRealMDoerr TheRealMDoerr left a comment

Choose a reason for hiding this comment

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

Still good.

Copy link
Member

@dean-long dean-long left a comment

Choose a reason for hiding this comment

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

CI testing results are good.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Nov 21, 2025
@ruben-arm
Copy link
Contributor Author

Thank you both. I am planning to submit the /integrate request in a few hours.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hotspot [email protected] ready Pull request is ready to be integrated rfr Pull request is ready for review serviceability [email protected]

Development

Successfully merging this pull request may close these issues.

6 participants