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

8340620: Fix -Wzero-as-null-pointer-constant warnings for CompressedOops #21172

Closed
wants to merge 5 commits into from

Conversation

kimbarrett
Copy link

@kimbarrett kimbarrett commented Sep 24, 2024

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

  • 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-8340620: Fix -Wzero-as-null-pointer-constant warnings for CompressedOops (Enhancement - P4)

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

@bridgekeeper
Copy link

bridgekeeper bot commented Sep 24, 2024

👋 Welcome back kbarrett! 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 Sep 24, 2024

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

8340620: Fix -Wzero-as-null-pointer-constant warnings for CompressedOops

Reviewed-by: shade, stefank, mli, amitkumar

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 master branch:

  • 6587909: 8341015: OopStorage location decoder crashes accessing non-initalized OopStorage
  • 9003e2c: 8341027: Crash in java/runtime/Unsafe/InternalErrorTest when running with -XX:-UseCompressedClassPointers
  • 2a2ecc9: 8339475: Clean up return code handling for pthread calls in library coding
  • 85dba47: 8325090: javadoc fails when -subpackages option is used with non-modular -source
  • 1bc13a1: 8340552: Harden TzdbZoneRulesCompiler against missing zone names
  • e6373b5: 8340679: Misc tests fail assert(!set || SafepointSynchronize::is_at_safepoint()) failed: set once or at safepoint
  • 2349bb7: 8340974: Ambiguous name of jtreg property vm.libgraal.enabled
  • 5d062e2: 8340576: Some JVMCI flags are inconsistent
  • 1447967: 8339261: Logs truncated in test javax/net/ssl/DTLS/DTLSRehandshakeTest.java
  • a02d895: 8333403: Write a test to check various components events are triggered properly
  • ... and 79 more: https://git.openjdk.org/jdk/compare/dd498794f20df0ac1a73d84e54591905c8a5a5c7...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 rfr Pull request is ready for review label Sep 24, 2024
@openjdk
Copy link

openjdk bot commented Sep 24, 2024

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

  • hotspot

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 hotspot-dev@openjdk.org label Sep 24, 2024
@mlbridge
Copy link

mlbridge bot commented Sep 24, 2024

Webrevs

Copy link
Member

@stefank stefank left a 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?");
Copy link
Member

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?

Copy link
Member

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.

Copy link
Member

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.

Copy link
Author

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

Copy link
Member

@shipilev shipilev Sep 26, 2024

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.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Sep 25, 2024
Copy link
Member

@shipilev shipilev left a 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?");
Copy link
Member

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.

@stefank
Copy link
Member

stefank commented Sep 26, 2024

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.

@kimbarrett
Copy link
Author

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
assumption here, and allow removal of the assertions currently proposed here.
And I generally prefer placing asserts with the expecting code. OTOH, I think
it's nearly certain there are other places where we make the same assumption.
(And I'd forgotten we have some assumption checks in globalDefinitions.cpp.)
I don't have a strong opinion in this area.

@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Sep 27, 2024
@kimbarrett
Copy link
Author

@stefank wrote:

FWIW, I think these asserts adds extra noise to these functions [...]

@kimbarrett replied

Implementing option 2 (making base() an integral offset) would remove that assumption here, and allow removal of the assertions currently proposed here. And I generally prefer placing asserts with the expecting code. OTOH, I think it's nearly certain there are other places where we make the same assumption. (And I'd forgotten we have some assumption checks in globalDefinitions.cpp.) I don't have a strong opinion in this area.

@stefank and I discussed this offline. I've removed the asserts, as they are just kind of executable comments that
aren't going to help catch any bugs. As a separate task we're going to consider adding a file that checks various
assumptions like this, as a way of documenting assumptions we make.

Copy link
Member

@shipilev shipilev 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, ship it.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Sep 27, 2024
@kimbarrett
Copy link
Author

Thanks for all the reviews.

@kimbarrett
Copy link
Author

/integrate

@openjdk
Copy link

openjdk bot commented Sep 27, 2024

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

  • 6587909: 8341015: OopStorage location decoder crashes accessing non-initalized OopStorage
  • 9003e2c: 8341027: Crash in java/runtime/Unsafe/InternalErrorTest when running with -XX:-UseCompressedClassPointers
  • 2a2ecc9: 8339475: Clean up return code handling for pthread calls in library coding
  • 85dba47: 8325090: javadoc fails when -subpackages option is used with non-modular -source
  • 1bc13a1: 8340552: Harden TzdbZoneRulesCompiler against missing zone names
  • e6373b5: 8340679: Misc tests fail assert(!set || SafepointSynchronize::is_at_safepoint()) failed: set once or at safepoint
  • 2349bb7: 8340974: Ambiguous name of jtreg property vm.libgraal.enabled
  • 5d062e2: 8340576: Some JVMCI flags are inconsistent
  • 1447967: 8339261: Logs truncated in test javax/net/ssl/DTLS/DTLSRehandshakeTest.java
  • a02d895: 8333403: Write a test to check various components events are triggered properly
  • ... and 79 more: https://git.openjdk.org/jdk/compare/dd498794f20df0ac1a73d84e54591905c8a5a5c7...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Sep 27, 2024

@kimbarrett Pushed as commit 25e8929.

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

@kimbarrett kimbarrett deleted the fix-CompressedOops branch September 27, 2024 11:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot hotspot-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

6 participants