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

8289060: Undefined Behaviour in class VMReg #9276

Closed
wants to merge 7 commits into from

Conversation

theRealAph
Copy link
Contributor

@theRealAph theRealAph commented Jun 24, 2022

Like class Register, class VMReg exhibits undefined behaviour, in particular null pointer dereferences.

The right way to fix this is simple: make instances of VMReg point to reified instances of VMRegImpl. We do this by creating a static array of VMRegImpl, and making all VMReg instances point into it, making the code well defined.

However, while VMReg instances are no longer null, and so do not generate compile warnings or errors, there is still a problem in that higher-numbered VMReg instances point outside the static array of VMRegImpl. This is hard to avoid, given that (as far as I can tell) there is no upper limit on the number of stack slots that can be allocated as VMReg instances. While this is in theory UB, it's not likely to cause problems. We could fix this by creating a much larger static array of VMRegImpl, up to the largest plausible size of stack offsets.

We could instead make VMReg instances objects with a single numeric field rather than pointers, but some C++ compilers pass all such objects by reference, so I don't think we should.


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

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 9276

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

Using diff file

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

@theRealAph theRealAph changed the title 8289060: Undefined Behaviour in class VMReg' src/hotspot/ 8289060: Undefined Behaviour in class VMReg Jun 24, 2022
@bridgekeeper
Copy link

bridgekeeper bot commented Jun 24, 2022

👋 Welcome back aph! 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 Jun 24, 2022
@openjdk
Copy link

openjdk bot commented Jun 24, 2022

@theRealAph 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 Jun 24, 2022
@mlbridge
Copy link

mlbridge bot commented Jun 24, 2022

Webrevs

@JornVernee
Copy link
Member

We could instead make VMReg instances objects with a single numeric field rather than pointers, but some C++ compilers pass all such objects by reference, so I don't think we should.

I've been thinking about this some more after you fixed the same issue for Register on AArch64 [1]. I think the issue is out-of-line calls to member functions. Since this is a pointer, the compiler is forced to spill the value on the stack to comply with the ABI. i.e. what we'd really want is some way to say "pass this by value". (On x64 Windows, as long as a struct fits in a register, it is not passed by reference).

To avoid that, I think we could theoretically convert every member function to a static function that takes a VMReg as it's first argument. That's an option, but not a very nice one... (just mentioning it for the record).

[1] : #6280 (comment)


I think the patch looks good overall, but it looks like there are some failures in some of the SA tests.

@theRealAph
Copy link
Contributor Author

I've been thinking about this some more after you fixed the same issue for Register on AArch64 [1]. I think the issue is out-of-line calls to member functions. Since this is a pointer, the compiler is forced to spill the value on the stack to comply with the ABI. i.e. what we'd really want is some way to say "pass this by value". (On x64 Windows, as long as a struct fits in a register, it is not passed by reference).

Ah, I see. That makes sense.

I think the patch looks good overall, but it looks like there are some failures in some of the SA tests.

Right. I'll start digging.

@theRealAph
Copy link
Contributor Author

I think the patch looks good overall, but it looks like there are some failures in some of the SA tests.

Right. I'll start digging.

Fixed now.

Copy link
Member

@JornVernee JornVernee left a comment

Choose a reason for hiding this comment

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

LGTM

@openjdk
Copy link

openjdk bot commented Jun 30, 2022

@theRealAph 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:

8289060: Undefined Behaviour in class VMReg

Reviewed-by: jvernee, 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:

  • feb223a: 8288707: javax/swing/JToolBar/4529206/bug4529206.java: setFloating does not work correctly
  • c3addbb: 8288895: LdapContext doesn't honor set referrals limit
  • 1305fb5: 8287984: AArch64: [vector] Make all bits set vector sharable for match rules
  • 7b5bd25: 8286397: Address possibly lossy conversions in jdk.hotspot.agent
  • 28c5e48: 8287094: IGV: show node input numbers in edge tooltips
  • da6d1fc: 8289477: Memory corruption with CPU_ALLOC, CPU_FREE on muslc
  • 31e50f2: 8286104: use aggressive liveness for unstable_if traps
  • dddd4e7: 8289291: HttpServer sets incorrect value for "max" parameter in Keep-Alive header value
  • 048bffa: Merge
  • cf71544: 8289252: Recommend Locale.of() method instead of the constructor
  • ... and 89 more: https://git.openjdk.org/jdk/compare/a802b9816ac5c0cb0fd236cc7f25ed4fdb1349ef...master

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 Jun 30, 2022
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.

Looks reasonable. Let me test it.

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.

My testing passed.

@theRealAph
Copy link
Contributor Author

/integrate

@openjdk
Copy link

openjdk bot commented Jul 6, 2022

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

  • 82a8bd7: 8287596: Reorg jdk.test.lib.util.ForceGC
  • cc2b792: 8288992: AArch64: CMN should be handled the same way as CMP
  • 75c0a5b: 8288824: [arm32] Display isetstate in register output
  • 83a5d59: 8278479: RunThese test failure with +UseHeavyMonitors and +VerifyHeavyMonitors
  • cbaf6e8: 8288022: c2: Transform (CastLL (AddL into (AddL (CastLL when possible
  • 8341895: 8289739: Add G1 specific GC breakpoints for testing
  • ac6be16: 8289695: [TESTBUG] TestMemoryAwareness.java fails on cgroups v2 and crun
  • 4ad18cf: 8289730: Deprecated code sample in java.lang.ClassCastException
  • d8f4e97: 8289146: containers/docker/TestMemoryWithCgroupV1.java fails on linux ppc64le machine with missing Memory and Swap Limit output
  • f783244: 8289706: (cs) Avoid redundant TreeMap.containsKey call in AbstractCharsetProvider
  • ... and 143 more: https://git.openjdk.org/jdk/compare/a802b9816ac5c0cb0fd236cc7f25ed4fdb1349ef...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Jul 6, 2022

@theRealAph Pushed as commit dfb24ae.

💡 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 integrated Pull request has been integrated
3 participants