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

8313564: Fix -Wconversion warnings in classfile code #15111

Closed
wants to merge 14 commits into from

Conversation

coleenp
Copy link
Contributor

@coleenp coleenp commented Aug 1, 2023

This patch fixes various -Wconversion warnings in classfile code. I broke the change into commits so the changes are easier to see.
Tested with tier1-4.


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-8313564: Fix -Wconversion warnings in classfile code (Enhancement - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 15111

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Aug 1, 2023

👋 Welcome back coleenp! 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 Aug 1, 2023
@openjdk
Copy link

openjdk bot commented Aug 1, 2023

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

  • graal
  • 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 graal graal-dev@openjdk.org hotspot hotspot-dev@openjdk.org labels Aug 1, 2023
@mlbridge
Copy link

mlbridge bot commented Aug 1, 2023

Webrevs

…h. prefetch_data_size() returns uint, so added a checked_cast<> to catch the case where it would return greater than signed int max.
Copy link
Contributor

@matias9927 matias9927 left a comment

Choose a reason for hiding this comment

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

Thanks for this! I have a few questions and potential improvements, but overall this looks good!

src/hotspot/share/classfile/altHashing.cpp Show resolved Hide resolved
src/hotspot/share/classfile/symbolTable.cpp Show resolved Hide resolved
@@ -923,14 +923,14 @@ void SymbolTable::print_histogram() {
tty->print_cr(" Total removed " SIZE_FORMAT_W(7), _symbols_removed);
if (_symbols_counted > 0) {
tty->print_cr(" Percent removed %3.2f",
((float)_symbols_removed / _symbols_counted) * 100);
((float)_symbols_removed / (float)_symbols_counted) * 100);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can also just cast once here.

Copy link
Member

Choose a reason for hiding this comment

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

These should probably be double rather than float - the float result will be promoted to double to be passed as an argument anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to double.

}
tty->print_cr(" Reference counts " SIZE_FORMAT_W(7), Symbol::_total_count);
tty->print_cr(" Symbol arena used " SIZE_FORMAT_W(7) "K", arena()->used() / K);
tty->print_cr(" Symbol arena size " SIZE_FORMAT_W(7) "K", arena()->size_in_bytes() / K);
tty->print_cr(" Total symbol length " SIZE_FORMAT_W(7), hi.total_length);
tty->print_cr(" Maximum symbol length " SIZE_FORMAT_W(7), hi.max_length);
tty->print_cr(" Average symbol length %7.2f", ((float)hi.total_length / hi.total_count));
tty->print_cr(" Average symbol length %7.2f", ((float)hi.total_length / (float)hi.total_count));
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think each value needs to be cast to get the correct result.

Copy link
Member

Choose a reason for hiding this comment

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

Yes size_t values must be cast to float/double. Again I think double should be used here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also changed to double.

Copy link
Contributor Author

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

Thanks for looking at this in detail Matias and for asking questions. I hope I've answered them sufficiently.

src/hotspot/share/classfile/altHashing.cpp Show resolved Hide resolved
src/hotspot/share/classfile/symbolTable.cpp Show resolved Hide resolved
}
tty->print_cr(" Reference counts " SIZE_FORMAT_W(7), Symbol::_total_count);
tty->print_cr(" Symbol arena used " SIZE_FORMAT_W(7) "K", arena()->used() / K);
tty->print_cr(" Symbol arena size " SIZE_FORMAT_W(7) "K", arena()->size_in_bytes() / K);
tty->print_cr(" Total symbol length " SIZE_FORMAT_W(7), hi.total_length);
tty->print_cr(" Maximum symbol length " SIZE_FORMAT_W(7), hi.max_length);
tty->print_cr(" Average symbol length %7.2f", ((float)hi.total_length / hi.total_count));
tty->print_cr(" Average symbol length %7.2f", ((float)hi.total_length / (float)hi.total_count));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think each value needs to be cast to get the correct result.

Copy link
Contributor

@matias9927 matias9927 left a comment

Choose a reason for hiding this comment

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

Thank you for addressing my questions, it looks like everything is good then!

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.

A couple of queries/comments but overall seems reasonable.

Thanbks.

src/hotspot/share/classfile/loaderConstraints.cpp Outdated Show resolved Hide resolved
src/hotspot/share/classfile/stringTable.cpp Show resolved Hide resolved
@openjdk
Copy link

openjdk bot commented Aug 2, 2023

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

8313564: Fix -Wconversion warnings in classfile code

Reviewed-by: matsaave, dholmes

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 44 new commits pushed to the master branch:

  • 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
  • e8c325d: 8313394: Array Elements in OldObjectSample event has the incorrect description
  • d60352e: 8311006: missing @SInCE info in jdk.xml.dom
  • 4577147: 8313712: [BACKOUT] 8313632: ciEnv::dump_replay_data use fclose
  • bb3aac6: 8301606: JFileChooser file chooser details view "size" label cut off in Metal Look&Feel
  • ... and 34 more: https://git.openjdk.org/jdk/compare/ee3e0917b393b879a543060ace2537be84f20e82...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 2, 2023
Copy link
Contributor Author

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

Thanks for reviewing, David. Reran with -Wconversion and now tier1 on your suggestions.

src/hotspot/share/classfile/loaderConstraints.cpp Outdated Show resolved Hide resolved
src/hotspot/share/classfile/stringTable.cpp Show resolved Hide resolved
@@ -923,14 +923,14 @@ void SymbolTable::print_histogram() {
tty->print_cr(" Total removed " SIZE_FORMAT_W(7), _symbols_removed);
if (_symbols_counted > 0) {
tty->print_cr(" Percent removed %3.2f",
((float)_symbols_removed / _symbols_counted) * 100);
((float)_symbols_removed / (float)_symbols_counted) * 100);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to double.

}
tty->print_cr(" Reference counts " SIZE_FORMAT_W(7), Symbol::_total_count);
tty->print_cr(" Symbol arena used " SIZE_FORMAT_W(7) "K", arena()->used() / K);
tty->print_cr(" Symbol arena size " SIZE_FORMAT_W(7) "K", arena()->size_in_bytes() / K);
tty->print_cr(" Total symbol length " SIZE_FORMAT_W(7), hi.total_length);
tty->print_cr(" Maximum symbol length " SIZE_FORMAT_W(7), hi.max_length);
tty->print_cr(" Average symbol length %7.2f", ((float)hi.total_length / hi.total_count));
tty->print_cr(" Average symbol length %7.2f", ((float)hi.total_length / (float)hi.total_count));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also changed to double.

src/hotspot/share/classfile/stringTable.cpp Outdated Show resolved Hide resolved
src/hotspot/share/classfile/symbolTable.cpp Outdated Show resolved Hide resolved
src/hotspot/share/classfile/symbolTable.cpp Show resolved Hide resolved
@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Aug 3, 2023
Copy link
Contributor Author

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

I reverted the items_count change.

src/hotspot/cpu/x86/vm_version_x86.cpp Show resolved Hide resolved
src/hotspot/share/classfile/stringTable.cpp Show resolved Hide resolved
src/hotspot/share/classfile/symbolTable.cpp Outdated Show resolved Hide resolved
src/hotspot/share/classfile/symbolTable.cpp Outdated Show resolved Hide resolved
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.

Okay on reverting the item_count changes - but we should look at a follow up RFE to get these types sorted out.

Thanks

src/hotspot/share/classfile/stringTable.cpp Outdated Show resolved Hide resolved
@@ -825,7 +825,7 @@ void StringTable::allocate_shared_strings_array(TRAPS) {
// This can only happen if you have an extremely large number of classes that
// refer to more than 16384 * 16384 = 26M interned strings! Not a practical concern
// but bail out for safety.
log_error(cds)("Too many strings to be archived: %d", _items_count);
log_error(cds)("Too many strings to be archived: " SIZE_FORMAT, _items_count);
Copy link
Member

Choose a reason for hiding this comment

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

Ditto %zu?

@@ -657,11 +657,14 @@ void SymbolTable::copy_shared_symbol_table(GrowableArray<Symbol*>* symbols,
}

size_t SymbolTable::estimate_size_for_archive() {
return CompactHashtableWriter::estimate_size(_items_count);
if (_items_count > (size_t)max_jint) {
fatal("Too many symbols to be archived: " SIZE_FORMAT, _items_count);
Copy link
Member

Choose a reason for hiding this comment

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

Ditto %zu?

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Aug 4, 2023
@coleenp
Copy link
Contributor Author

coleenp commented Aug 4, 2023

Okay on reverting the item_count changes - but we should look at a follow up RFE to get these types sorted out.

In this case, I think we need items_count to be size_t so that we can do an explicit bounds check for CDS, so this type is correct.

Thanks for reviewing, Matias, Dean and David.
/integrate

@openjdk
Copy link

openjdk bot commented Aug 4, 2023

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

  • 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
  • e8c325d: 8313394: Array Elements in OldObjectSample event has the incorrect description
  • d60352e: 8311006: missing @SInCE info in jdk.xml.dom
  • 4577147: 8313712: [BACKOUT] 8313632: ciEnv::dump_replay_data use fclose
  • bb3aac6: 8301606: JFileChooser file chooser details view "size" label cut off in Metal Look&Feel
  • ... and 34 more: https://git.openjdk.org/jdk/compare/ee3e0917b393b879a543060ace2537be84f20e82...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

@coleenp Pushed as commit f66cd50.

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

@coleenp coleenp deleted the classfile-conversion branch August 4, 2023 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
graal graal-dev@openjdk.org hotspot hotspot-dev@openjdk.org integrated Pull request has been integrated
4 participants