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

8299677: Formatter.format might take a long time to format an integer or floating-point #459

Closed
wants to merge 4 commits into from

Conversation

chadrako
Copy link
Contributor

@chadrako chadrako commented Feb 26, 2024

Backport of JDK-8299677

Backport was not clean. Rewrote test to not include junit ParameterizedTest. Rewrote fix since String.repeat is not in JDK8


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
  • JDK-8299677 needs maintainer approval

Issue

  • JDK-8299677: Formatter.format might take a long time to format an integer or floating-point (Bug - P4 - Approved)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk8u-dev.git pull/459/head:pull/459
$ git checkout pull/459

Update a local copy of the PR:
$ git checkout pull/459
$ git pull https://git.openjdk.org/jdk8u-dev.git pull/459/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 459

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk8u-dev/pull/459.diff

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Feb 26, 2024

👋 Welcome back chadrako! 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 changed the title Backport 33412c102ce799ff2de3512df77e6e07d76acd36 8299677: Formatter.format might take a long time to format an integer or floating-point Feb 26, 2024
@openjdk
Copy link

openjdk bot commented Feb 26, 2024

This backport pull request has now been updated with issue from the original commit.

@openjdk openjdk bot added backport rfr Pull request is ready for review labels Feb 26, 2024
@mlbridge
Copy link

mlbridge bot commented Feb 26, 2024

Webrevs

for (int k = 0; k < width - len; k++)
sb.insert(begin, zero);
if (width > len && f.contains(Flags.ZERO_PAD)) {
String zeros = new String(new char[width - len]).replace("\0", "0");
Copy link
Member

Choose a reason for hiding this comment

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

In the original patch, we use the locale-dependent zero variable here. I don't think we can just use 0, although I struggle to imagine the case where that would matter. Plus, given we are changing char->char, we can use String.replace(char,char) instead of String.replace(CharSequence,CharSequence).

I think we can hit these two birds with one stone by doing:

 char[] zeros = new char[width - len];
 Arrays.fill(zeros, zero);
 sb.insert(begin, new String(zeros));

It is still awkward because String constructor copies the array. For extreme use cases, there is a package-private String(char[] array, boolean share) constructor that might be accessible through SharedSecrets.getJavaLangAccess().newSharedString(...) (needs a new method). But that might be moot point since AbstractStringBuilder.insert already does a lot of copies.

if (width > len && f.contains(Flags.ZERO_PAD)) {
char[] zeros = new char[width - len];
Arrays.fill(zeros, zero);
sb.insert(begin, new String(zeros));
Copy link
Member

@shipilev shipilev Feb 27, 2024

Choose a reason for hiding this comment

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

Oh wait, we actually have StringBuilder.insert(char[],int)! That's useful, we don't need to do new String() then?

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.

More comments.

jdk/test/java/util/Formatter/Padding.java Outdated Show resolved Hide resolved
jdk/test/java/util/Formatter/Padding.java Outdated Show resolved Hide resolved
Copy link
Member

@phohensee phohensee 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, except please change the Formatter.java copyright end date to 2023 to match the original commit.

@chadrako
Copy link
Contributor Author

Looks good, except please change the Formatter.java copyright end date to 2023 to match the original commit.

Should the test Padding.java also be 2023 to match the original commit?

@phohensee
Copy link
Member

Yes, I overlooked that.

@openjdk
Copy link

openjdk bot commented Mar 13, 2024

@chadrako This change now passes all automated pre-integration checks.

After integration, the commit message for the final commit will be:

8299677: Formatter.format might take a long time to format an integer or floating-point

Reviewed-by: shade, phh, andrew

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

  • c8eb027: 8075511: Enable -Woverloaded-virtual C++ warning for HotSpot build
  • 16ea85b: 8335552: [8u] JDK-8303466 backport to 8u requires 3 ::Identity signature fixes
  • 54f7734: 8303466: C2: failed: malformed control flow. Limit type made precise with MaxL/MinL
  • 385e34d: 8262017: C2: assert(n != __null) failed: Bad immediate dominator info.
  • 44eac48: 8137329: [windows] Build broken on VS2010 after "8046148: JEP 158: Unified JVM Logging"
  • a0715ab: 8238274: (sctp) JDK-7118373 is not fixed for SctpChannel
  • b499ea7: 8030204: com/sun/jdi/JdbExprTest.sh: Required output "Can\'t convert 2147483648 to int" not found
  • b1e2ea8: 8279164: Disable TLS_ECDH_* cipher suites
  • 6abb3f2: 8035395: sun/management/jmxremote/startstop/JMXStartStopTest.java fails intermittently: Port already in use
  • 6838605: 8311666: Disabled tests in test/jdk/sun/java2d/marlin
  • ... and 45 more: https://git.openjdk.org/jdk8u-dev/compare/d7ad5bf5583bed023558c5bb9eaba12ded4987e2...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.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@shipilev, @phohensee, @gnu-andrew) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

Copy link
Member

@phohensee phohensee left a comment

Choose a reason for hiding this comment

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

Lgtm, but you need Aleksey to also re-review.

@openjdk
Copy link

openjdk bot commented Mar 13, 2024

⚠️ @chadrako This change is now ready for you to apply for maintainer approval. This can be done directly in each associated issue or by using the /approval command.

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 good to me.

@chadrako
Copy link
Contributor Author

chadrako commented Apr 3, 2024

/approval Backport for fix that improves String.format for large number of zero padding. Backport was not clean since String.repeat and ParameterizedTest are not in JDK8. Users ran into issues with other versions so would like to backport for completeness. Change is simple but medium risk as it touches String.format code

@openjdk
Copy link

openjdk bot commented Apr 3, 2024

@chadrako usage: /approval [<id>] (request|cancel) [<text>]

@chadrako
Copy link
Contributor Author

chadrako commented Apr 3, 2024

/approval 8299677 request Backport for fix that improves String.format for large number of zero padding. Backport was not clean since String.repeat and ParameterizedTest are not in JDK8. Users ran into issues with other versions so would like to backport for completeness. Change is simple but medium risk as it touches String.format code

@openjdk
Copy link

openjdk bot commented Apr 3, 2024

@chadrako
8299677: The approval request has been created successfully.

@openjdk openjdk bot added the approval label Apr 3, 2024
@bridgekeeper
Copy link

bridgekeeper bot commented May 1, 2024

@chadrako This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@chadrako
Copy link
Contributor Author

chadrako commented May 1, 2024

Commenting to keep PR open. Can a maintainer take a look at this request?

@bridgekeeper
Copy link

bridgekeeper bot commented May 29, 2024

@chadrako This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@bridgekeeper
Copy link

bridgekeeper bot commented Jun 27, 2024

@chadrako This pull request has been inactive for more than 8 weeks and will now be automatically closed. If you would like to continue working on this pull request in the future, feel free to reopen it! This can be done using the /open pull request command.

@bridgekeeper bridgekeeper bot closed this Jun 27, 2024
@chadrako
Copy link
Contributor Author

/open

@openjdk openjdk bot reopened this Jun 27, 2024
@openjdk
Copy link

openjdk bot commented Jun 27, 2024

@chadrako This pull request is now open

Copy link
Member

@gnu-andrew gnu-andrew left a comment

Choose a reason for hiding this comment

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

Sorry for the delay. Final version looks good. I appreciate the work done to largely rewirte the test for the older JTreg in 8u.

@gnu-andrew
Copy link
Member

/approve yes

@openjdk
Copy link

openjdk bot commented Jul 5, 2024

@gnu-andrew
8299677: The approval request has been approved.

@openjdk openjdk bot added ready Pull request is ready to be integrated and removed approval labels Jul 5, 2024
@chadrako
Copy link
Contributor Author

chadrako commented Jul 8, 2024

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Jul 8, 2024
@openjdk
Copy link

openjdk bot commented Jul 8, 2024

@chadrako
Your change (at version 3c86b6f) is now ready to be sponsored by a Committer.

@phohensee
Copy link
Member

/sponsor

@openjdk
Copy link

openjdk bot commented Jul 8, 2024

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

  • c8eb027: 8075511: Enable -Woverloaded-virtual C++ warning for HotSpot build
  • 16ea85b: 8335552: [8u] JDK-8303466 backport to 8u requires 3 ::Identity signature fixes
  • 54f7734: 8303466: C2: failed: malformed control flow. Limit type made precise with MaxL/MinL
  • 385e34d: 8262017: C2: assert(n != __null) failed: Bad immediate dominator info.
  • 44eac48: 8137329: [windows] Build broken on VS2010 after "8046148: JEP 158: Unified JVM Logging"
  • a0715ab: 8238274: (sctp) JDK-7118373 is not fixed for SctpChannel
  • b499ea7: 8030204: com/sun/jdi/JdbExprTest.sh: Required output "Can\'t convert 2147483648 to int" not found
  • b1e2ea8: 8279164: Disable TLS_ECDH_* cipher suites
  • 6abb3f2: 8035395: sun/management/jmxremote/startstop/JMXStartStopTest.java fails intermittently: Port already in use
  • 6838605: 8311666: Disabled tests in test/jdk/sun/java2d/marlin
  • ... and 45 more: https://git.openjdk.org/jdk8u-dev/compare/d7ad5bf5583bed023558c5bb9eaba12ded4987e2...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Jul 8, 2024

@phohensee @chadrako Pushed as commit ddce2b5.

💡 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
backport integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

4 participants