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

8313554: Fix -Wconversion warnings for ResolvedFieldEntry #15126

Closed

Conversation

matias9927
Copy link
Contributor

@matias9927 matias9927 commented Aug 2, 2023

The recent change in JDK-8301996 added more -Wconversion warnings that are addressed in this patch. The aforementioned change has overlooked inconsistencies with the types used by ResolvedFieldEntry and the method fill_in(). Verified with tier 1-4 tests.


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-8313554: Fix -Wconversion warnings for ResolvedFieldEntry (Bug - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 15126

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Aug 2, 2023

👋 Welcome back matsaave! 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 Aug 2, 2023

@matias9927 The following labels will be automatically applied to this pull request:

  • build
  • hotspot

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 build build-dev@openjdk.org hotspot hotspot-dev@openjdk.org labels Aug 2, 2023
@matias9927 matias9927 marked this pull request as ready for review August 2, 2023 20:14
@openjdk openjdk bot added the rfr Pull request is ready for review label Aug 2, 2023
@mlbridge
Copy link

mlbridge bot commented Aug 2, 2023

Webrevs

Copy link
Contributor

@coleenp coleenp 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 to me, thank you for fixing these.

@openjdk
Copy link

openjdk bot commented Aug 3, 2023

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

8313554: Fix -Wconversion warnings for ResolvedFieldEntry

Reviewed-by: coleenp, 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 45 new commits pushed to the master branch:

  • b2add96: 8159527: Collections mutator methods should all be marked as optional operations
  • 873d117: 8312623: SA add NestHost and NestMembers attributes when dumping class
  • 017e0c7: 8310388: Shenandoah: Auxiliary bitmap is not madvised for THP
  • f66cd50: 8313564: Fix -Wconversion warnings in classfile code
  • e8a37b9: 8313248: C2: setScopedValueCache intrinsic exposes nullptr pre-values to store barriers
  • 29f1d8e: 8313707: GHA: Bootstrap sysroots with --variant=minbase
  • 61c58fd: 8312976: MatchResult produces StringIndexOutOfBoundsException for groups outside match
  • 5d23295: 8313251: Add NativeLibraryLoad event
  • c4b8574: 8311938: Add default cups include location for configure on AIX
  • 10a2605: 8294979: test/jdk/tools/jlink 3 test classes use ASM library
  • ... and 35 more: https://git.openjdk.org/jdk/compare/ec2f38fd389dc51dc4d8925e037a8bf2e64a3722...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 Aug 3, 2023
Copy link
Member

@dholmes-ora dholmes-ora left a comment

Choose a reason for hiding this comment

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

I'm still not seeing the pattern, in these Wconversion changes, of when to use checked_cast, when to use static_cast and when to use a raw C-style cast??

u1 new_flags = (static_cast<u1>(is_final) << static_cast<u1>(is_final_shift)) | static_cast<u1>(is_volatile);
_flags = new_flags;
int new_flags = (is_final << is_final_shift) | static_cast<int>(is_volatile);
_flags = (u1)new_flags;
Copy link
Member

Choose a reason for hiding this comment

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

Why isn't this using checked_cast?

Copy link
Contributor

@coleenp coleenp Aug 3, 2023

Choose a reason for hiding this comment

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

I still don't see the point of using checked_cast if we know that this is only two bits.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As far as I've designed it, only the last two bits of the flags are ever set or used. C++ booleans are either 0 or 1 so the higher bits should never be set.

Copy link
Contributor

Choose a reason for hiding this comment

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

It is only two bits and the only variable here "is_final_shift" is 1. This could use 1 to make it obvious but the variable is used in the templateInterpreter code. Again, I think this is good. This is never going to be a bug.

Copy link
Member

Choose a reason for hiding this comment

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

It's fine unless the shift values get changed so the value no longer fits in u1. Then it fails silently.
As an alternative to checked_cast, how about something like:

assert(is_final() == is_final, "");
assert(is_volatile() == is_volatile, "");

} else {
int field_entry_index = Bytes::get_native_u2(p);
int pool_index = _initialized_field_entries.at(field_entry_index).constant_pool_index();
Bytes::put_Java_u2(p, pool_index);
Bytes::put_Java_u2(p, (u2)pool_index);
Copy link
Member

Choose a reason for hiding this comment

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

I guess this isn't using checked_cast because similar code elsewhere in this file uses this style, but it means we can silently do the wrong thing. Is there a separate RFE to remove as many of these unchecked casts as possible?

Copy link
Contributor

Choose a reason for hiding this comment

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

We could rewrite _initialized_field_entries to be an array of u2 and not need the cast, but that changed felt out of scope for this fix.

Copy link
Contributor

@coleenp coleenp left a comment

Choose a reason for hiding this comment

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

The checked_cast<> change is fine. Hopefully appeases other reviewers.

@@ -185,11 +185,11 @@ void Rewriter::rewrite_field_reference(address bcp, int offset, bool reverse) {
if (!reverse) {
int cp_index = Bytes::get_Java_u2(p);
int field_entry_index = _cp_map.at(cp_index);
Bytes::put_native_u2(p, field_entry_index);
Bytes::put_native_u2(p, checked_cast<u2>(field_entry_index));
Copy link
Member

Choose a reason for hiding this comment

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

I would have put the checked_cast on the initialization and not the use, but this is OK too.

Copy link
Contributor

@coleenp coleenp left a comment

Choose a reason for hiding this comment

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

This looks good.

@matias9927
Copy link
Contributor Author

Thank you for the reviews @coleenp, @dean-long, and @dholmes-ora!
/integrate

@openjdk
Copy link

openjdk bot commented Aug 4, 2023

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

  • b463c6d: 8311517: Add performance information to ArrayList javadoc
  • b2add96: 8159527: Collections mutator methods should all be marked as optional operations
  • 873d117: 8312623: SA add NestHost and NestMembers attributes when dumping class
  • 017e0c7: 8310388: Shenandoah: Auxiliary bitmap is not madvised for THP
  • f66cd50: 8313564: Fix -Wconversion warnings in classfile code
  • e8a37b9: 8313248: C2: setScopedValueCache intrinsic exposes nullptr pre-values to store barriers
  • 29f1d8e: 8313707: GHA: Bootstrap sysroots with --variant=minbase
  • 61c58fd: 8312976: MatchResult produces StringIndexOutOfBoundsException for groups outside match
  • 5d23295: 8313251: Add NativeLibraryLoad event
  • c4b8574: 8311938: Add default cups include location for configure on AIX
  • ... and 36 more: https://git.openjdk.org/jdk/compare/ec2f38fd389dc51dc4d8925e037a8bf2e64a3722...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Aug 4, 2023

@matias9927 Pushed as commit ad6e9e7.

💡 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
build build-dev@openjdk.org hotspot hotspot-dev@openjdk.org integrated Pull request has been integrated
4 participants