-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
8340620: Fix -Wzero-as-null-pointer-constant warnings for CompressedOops #21172
Conversation
👋 Welcome back kbarrett! A progress list of the required criteria for merging this PR into |
@kimbarrett 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:
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 89 new commits pushed to the
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 |
@kimbarrett The following label will be automatically applied to this pull request:
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. |
Webrevs
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. One inquiry below.
@@ -48,6 +48,9 @@ inline oop CompressedOops::decode_raw_not_null(narrowOop v) { | |||
} | |||
|
|||
inline oop CompressedOops::decode_raw(narrowOop v) { | |||
// Assume a null base casts to zero. Otherwise we need more complexity that | |||
// we can't test, since this is true for all currently supported platforms. | |||
assert(0 == reinterpret_cast<uintptr_t>(nullptr), "null pointer value not zero?"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this be a static_assert?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1. Although I would expect any sane compiler to fold it, maybe it is still not optimized with something like -O0
. Or maybe just move these asserts to CompressedOops::initialize
, so whatever happens, happens once.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This cannot be used in static_assert
because reinterpret_cast
is not allowed here.
I believe reinterpret_cast<uintptr_t>(nullptr)
will always return 0. You may need to do it the other way around.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct that static_assert can't be used, because of the reinterpret_cast.
I considered putting the assert in CompressedOops::set_base, with comments to
connect encode/decode with that assertion, but prefer putting the assert near
the code that is actually relying on the property. Even with -O0 gcc seems to
constant fold the expression and (pretty much?) compile away the assertion.
A null pointer value is not guaranteed to have a zero representation. The
conversion of a literal 0 to a null pointer value is syntactic sugar. The
bit pattern of the result might be something else. There's some good
discussion of this here:
https://stackoverflow.com/questions/2761360/could-i-ever-want-to-access-the-address-zero
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All right, if this assert folds even on lowest optimization level, this all is just nitpicking then. Ship it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine, modulo assert comment:
@@ -48,6 +48,9 @@ inline oop CompressedOops::decode_raw_not_null(narrowOop v) { | |||
} | |||
|
|||
inline oop CompressedOops::decode_raw(narrowOop v) { | |||
// Assume a null base casts to zero. Otherwise we need more complexity that | |||
// we can't test, since this is true for all currently supported platforms. | |||
assert(0 == reinterpret_cast<uintptr_t>(nullptr), "null pointer value not zero?"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1. Although I would expect any sane compiler to fold it, maybe it is still not optimized with something like -O0
. Or maybe just move these asserts to CompressedOops::initialize
, so whatever happens, happens once.
FWIW, I think these asserts adds extra noise to these functions and I don't think we will be much more happy about having to read them over and over again when we read this functions / debug code through these functions. I would have preferred if this was one of those things that we require from our platforms and place a check in globalDefinitions, or some other prominent place that checks HotSpot's assumptions of the compilers / platforms. |
Implementing option 2 (making base() an integral offset) would remove that |
@stefank wrote:
@kimbarrett replied
@stefank and I discussed this offline. I've removed the asserts, as they are just kind of executable comments that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still good, ship it.
Thanks for all the reviews. |
/integrate |
Going to push as commit 25e8929.
Your commit was automatically rebased without conflicts. |
@kimbarrett Pushed as commit 25e8929. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
Please review this change that fixes -Wzero-as-null-pointer-constant warnings
in CompressedOops code. These all relate to CompressedOops::base().
I also added a couple of asserts to verify our assumptions about null pointer
constants being representationally zero. That isn't a Standard-conforming
assumption, but holds for all platforms we currently support. I considered,
and even explored, a couple of different options.
(1) Continue to have CompressedOops::base() be a pointer, but avoid that
assumption, being more careful about how zero-valued pointers are treated. But
that adds significant complexity that we can't test, since we don't support
any platforms needing that extra work.
(2) Change CompressedOops::base() to an integral adjustment. This is probably
the correct approach, but is much more intrusive and wide ranging in the
changes required. Maybe something for the future.
Testing: mach5 tier1-5
GHA testing, verifying builds on some platforms not supported by Oracle.
There are some simple changes to s390 and ppc code that I haven't tested,
beyond verifying compilation.
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/21172/head:pull/21172
$ git checkout pull/21172
Update a local copy of the PR:
$ git checkout pull/21172
$ git pull https://git.openjdk.org/jdk.git pull/21172/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 21172
View PR using the GUI difftool:
$ git pr show -t 21172
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/21172.diff
Webrev
Link to Webrev Comment