Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8261837: SIGSEGV in ciVirtualCallTypeData::translate_from #16750

Closed
wants to merge 8 commits into from

Conversation

dean-long
Copy link
Member

@dean-long dean-long commented Nov 20, 2023

Type profiling code based on the x86 implementation uses XOR to check if the MDO value matches the klass, then later stores that XORed value into the MDO if the MDO value was 0. However, there is a race here if we reload the MDO value to check for 0, resulting in storing OBJ_KLASS XOR MDO_KLASS back to the MDO.

I took a stab at riscv, but I don't have a way to test it.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8261837: SIGSEGV in ciVirtualCallTypeData::translate_from (Bug - P3)

Reviewers

Contributors

  • Fei Yang <fyang@openjdk.org>

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 16750

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Nov 20, 2023

👋 Welcome back dlong! 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 openjdk bot added the rfr Pull request is ready for review label Nov 20, 2023
@openjdk
Copy link

openjdk bot commented Nov 20, 2023

@dean-long 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.org label Nov 20, 2023
@mlbridge
Copy link

mlbridge bot commented Nov 20, 2023

Webrevs

@dean-long dean-long marked this pull request as draft November 20, 2023 23:17
@openjdk openjdk bot removed the rfr Pull request is ready for review label Nov 20, 2023
@dean-long
Copy link
Member Author

Moved to Draft. There is no rscratch1 register on 32-bit x86.

Comment on lines 86 to 87
xorptr(obj, rscratch1); // get back original value before XOR
xorptr(obj, mdo_addr);
Copy link
Contributor

Choose a reason for hiding this comment

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

Was it bug here originally? We had 2 xors (including this) and now 3 for obj.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, there was a bug here originally. obj could have contained a bad value. The code wants to store the Klass* from load_klass with the low TypeEntries::null_seen bit from mdo_addr ORed in. However, because the low bits of the Klass* are 0, XOR was used to both OR the low bits and SET the high bits, assuming the high bits from mdo_addr are 0.
The problem comes from assuming the mdo_addr memory value is stable and reloading the value from memory to compare against 0 and TypeEntries::null_seen. A transient 0 can appear because of non-atomic updates like this:
orptr(mdo_addr, TypeEntries::null_seen);
An alternative fix would be to get rid of the races and use atomic compare-and-swap to write new values.

The new 2nd XOR is an optimization, instead of calling load_klass() again, or saving the original obj value somewhere else. The 3nd XOR is a repeat of the 1st XOR. I don't think this slow path retry is that useful, and not all platforms do it, but I left it in because I wanted to minimize changes.

@dean-long
Copy link
Member Author

@vnkozlov, you might want to wait until the 32-bit x86 code is fixed before reviewing. If I can't find an extra temp register to use, I'll need to make more significant changes.

@dean-long
Copy link
Member Author

pseudo-code of the bug:

klass = obj->klass();
mdo_klass = *mdo_addr;
// low 2 bits: null_seen, unknown_type
// case 1: klass unset
// we want (klass | (mdo_klass & 3)) if md_addr is empty or null_seen,
// XOR gives same result as OR if klass has low bits 0 and md_addr has
// high bits 0.
// case 2: klass already set and matches obj klass
// (klass ^ mdo_klass) & ~3 == 0 means klasses match 
new_klass = klass ^ mdo_klass;
if ((new_klass & ~3) == 0) {
  // match, do nothing
} else if (*mdo_addr == 0 || *mdo_addr == null_seen) {
  // XXX Oops, *mdo_addr could have changed, which means instead of the value
  // (klass | (mdo_klass & 3))
  // we might have instead
  // klass ^ mdo_klass
  *mdo_addr = new_klass;
}

Copy link
Contributor

@veresov veresov left a comment

Choose a reason for hiding this comment

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

Great find! Thank you for getting to the bottom of it!

@dean-long
Copy link
Member Author

Thanks @veresov. I had to push a different fix for x86 because of a lack of scratch registers. Please take another look.

@dean-long dean-long marked this pull request as ready for review November 21, 2023 23:28
@openjdk
Copy link

openjdk bot commented Nov 21, 2023

@dean-long 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:

8261837: SIGSEGV in ciVirtualCallTypeData::translate_from

Co-authored-by: Fei Yang <fyang@openjdk.org>
Reviewed-by: iveresov, vlivanov, 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 99 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.

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

@openjdk openjdk bot added ready Pull request is ready to be integrated rfr Pull request is ready for review labels Nov 21, 2023
@dean-long
Copy link
Member Author

/label hotspot-runtime

@openjdk openjdk bot added the hotspot-runtime hotspot-runtime-dev@openjdk.org label Nov 21, 2023
@openjdk
Copy link

openjdk bot commented Nov 21, 2023

@dean-long
The hotspot-runtime label was successfully added.

@dean-long
Copy link
Member Author

Can I get a RISC-V developer to test this for me, please?
@feilongjiang @RealFYang @luhenry

Copy link
Contributor

@iwanowww iwanowww left a comment

Choose a reason for hiding this comment

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

Nice catch, Dean!

@RealFYang
Copy link
Member

RealFYang commented Nov 22, 2023

@dean-long : Hi Dean, thanks for adding handling for riscv.
But seems that we need several more changes for this platform. Would you mind apply following small add-on patch please?
(Tier1 tested on sifive unmatched board. Also run non-trivial benchmark workloads.)

16750-riscv.diff.txt

@dean-long
Copy link
Member Author

/contributor @RealFYang

@dean-long
Copy link
Member Author

Thanks @RealFYang

@openjdk
Copy link

openjdk bot commented Nov 23, 2023

@dean-long Syntax: /contributor (add|remove) [@user | openjdk-user | Full Name <email@address>]. For example:

  • /contributor add @openjdk-bot
  • /contributor add duke
  • /contributor add J. Duke <duke@openjdk.org>

User names can only be used for users in the census associated with this repository. For other contributors you need to supply the full name and email address.

@dean-long
Copy link
Member Author

/contributor add fyang

@openjdk
Copy link

openjdk bot commented Nov 23, 2023

@dean-long
Contributor Fei Yang <fyang@openjdk.org> successfully added.

Copy link
Contributor

@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.

Latest changes looks good.

@dean-long
Copy link
Member Author

Thanks @iwanowww , @veresov , and @vnkozlov .

@dean-long
Copy link
Member Author

/integrate

@openjdk
Copy link

openjdk bot commented Nov 27, 2023

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

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Nov 27, 2023

@dean-long Pushed as commit 1bb250c.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot-compiler hotspot-compiler-dev@openjdk.org hotspot-runtime hotspot-runtime-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

5 participants