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

8269665: Clean-up toString() methods of some primitive wrappers #4633

Closed
wants to merge 4 commits into from

Conversation

stsypanov
Copy link
Contributor

@stsypanov stsypanov commented Jun 30, 2021

As of JDK 17 some of primitive wrappers, e.g. Long, Integer, Double and Float in their implementations of Object.toString() delegate to own utility toString(primitive) methods.

Unlike those, Boolean, Byte, Character and Short just duplicate the contents of utility methods in implementations of Object.toString().

Yet another issue is a tiny discrepancy in implementation related to Byte and Short (see the first):

public static String toString(byte b) {
    return Integer.toString((int)b, 10);
}

public String toString() {
    return Integer.toString((int)value);
}

Unlike in overriden method, In utility one they explicitly specify radix which can be skipped, as implementation of Integer.toString(int,int) has a fast-path for radix 10, ending in Integer.toString(int). This simplification gives tiny improvement, see benchmark:

@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@Fork(jvmArgsAppend = {"-Xms2g", "-Xmx2g"})
public class ByteToStringBenchmark {
    @Benchmark
    public String byteToString() {
        return Byte.toString((byte) 1);
    }
}

Results:

before

Benchmark                                                            Mode  Cnt     Score     Error   Units
ByteToStringBenchmark.byteToString                                   avgt   30    11,648 ±   1,906   ns/op
ByteToStringBenchmark.byteToString:·gc.alloc.rate                    avgt   30  3288,576 ± 418,119  MB/sec
ByteToStringBenchmark.byteToString:·gc.alloc.rate.norm               avgt   30    48,001 ±   0,001    B/op
ByteToStringBenchmark.byteToString:·gc.churn.G1_Eden_Space           avgt   30  3301,804 ± 455,932  MB/sec
ByteToStringBenchmark.byteToString:·gc.churn.G1_Eden_Space.norm      avgt   30    48,158 ±   2,085    B/op
ByteToStringBenchmark.byteToString:·gc.churn.G1_Survivor_Space       avgt   30     0,004 ±   0,001  MB/sec
ByteToStringBenchmark.byteToString:·gc.churn.G1_Survivor_Space.norm  avgt   30    ≈ 10⁻⁴              B/op
ByteToStringBenchmark.byteToString:·gc.count                         avgt   30   202,000            counts
ByteToStringBenchmark.byteToString:·gc.time                          avgt   30   413,000                ms

after

Benchmark                                                            Mode  Cnt     Score     Error   Units
ByteToStringBenchmark.byteToString                                   avgt   30    10,016 ±   0,530   ns/op
ByteToStringBenchmark.byteToString:·gc.alloc.rate                    avgt   30  3673,700 ± 167,450  MB/sec
ByteToStringBenchmark.byteToString:·gc.alloc.rate.norm               avgt   30    48,001 ±   0,001    B/op
ByteToStringBenchmark.byteToString:·gc.churn.G1_Eden_Space           avgt   30  3662,406 ± 205,978  MB/sec
ByteToStringBenchmark.byteToString:·gc.churn.G1_Eden_Space.norm      avgt   30    47,870 ±   1,750    B/op
ByteToStringBenchmark.byteToString:·gc.churn.G1_Survivor_Space       avgt   30     0,004 ±   0,002  MB/sec
ByteToStringBenchmark.byteToString:·gc.churn.G1_Survivor_Space.norm  avgt   30    ≈ 10⁻⁴              B/op
ByteToStringBenchmark.byteToString:·gc.count                         avgt   30   224,000            counts
ByteToStringBenchmark.byteToString:·gc.time                          avgt   30   358,000                ms

Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8269665: Clean-up toString() methods of some primitive wrappers

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/4633/head:pull/4633
$ git checkout pull/4633

Update a local copy of the PR:
$ git checkout pull/4633
$ git pull https://git.openjdk.java.net/jdk pull/4633/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 4633

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/4633.diff

@bridgekeeper
Copy link

bridgekeeper bot commented Jun 30, 2021

👋 Welcome back stsypanov! 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 Jun 30, 2021
@openjdk
Copy link

openjdk bot commented Jun 30, 2021

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

  • core-libs
  • i18n

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 core-libs core-libs-dev@openjdk.org i18n i18n-dev@openjdk.org labels Jun 30, 2021
@mlbridge
Copy link

mlbridge bot commented Jun 30, 2021

Webrevs

@bridgekeeper
Copy link

bridgekeeper bot commented Aug 1, 2021

@stsypanov 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!

@stsypanov
Copy link
Contributor Author

@stsypanov 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!

Not now

@@ -90,7 +90,7 @@
* @see java.lang.Integer#toString(int)
*/
public static String toString(byte b) {
return Integer.toString((int)b, 10);
return Integer.toString(b);
Copy link
Member

Choose a reason for hiding this comment

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

This change makes sense given the evidence that the radix tests in Integer.toString(int, int) are not elided. Same for the equivalent change in Short.java.

src/java.base/share/classes/java/lang/Byte.java Outdated Show resolved Hide resolved
@openjdk
Copy link

openjdk bot commented Aug 2, 2021

⚠️ @stsypanov the full name on your profile does not match the author name in this pull requests' HEAD commit. If this pull request gets integrated then the author name from this pull requests' HEAD commit will be used for the resulting commit. If you wish to push a new commit with a different author name, then please run the following commands in a local repository of your personal fork:

$ git checkout 8269665
$ git commit -c user.name='Preferred Full Name' --allow-empty -m 'Update full name'
$ git push

@openjdk
Copy link

openjdk bot commented Aug 2, 2021

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

8269665: Clean-up toString() methods of some primitive wrappers

Reviewed-by: redestad

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

  • 7cc1eb3: Merge
  • e351de3: 8271272: C2: assert(!had_error) failed: bad dominance
  • 6180cf1: 8271512: ProblemList serviceability/sa/sadebugd/DebugdConnectTest.java due to 8270326
  • a1b5b81: 8271507: ProblemList SA tests that are failing with ZGC due to JDK-8248912
  • 4bc9b04: 8263059: security/infra/java/security/cert/CertPathValidator/certification/ComodoCA.java fails due to revoked cert
  • d6bb846: 8248899: security/infra/java/security/cert/CertPathValidator/certification/QuoVadisCA.java fails, Certificate has been revoked
  • 71ca0c0: 8270848: Redundant unsafe opmask register allocation in some instruction patterns.
  • 6c68ce2: 8270947: AArch64: C1: use zero_words to initialize all objects
  • cd7e30e: 8271242: Add Arena regression tests
  • 5b3c418: 8270321: Startup regressions in 18-b5 caused by JDK-8266310
  • ... and 395 more: https://git.openjdk.java.net/jdk/compare/ee0247f056daea7a0afdd572d13fb30f5164e889...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 (@cl4es) 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).

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Aug 2, 2021
@stsypanov
Copy link
Contributor Author

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Aug 2, 2021
@openjdk
Copy link

openjdk bot commented Aug 2, 2021

@stsypanov
Your change (at version b9fb156) is now ready to be sponsored by a Committer.

@cl4es
Copy link
Member

cl4es commented Aug 2, 2021

/sponsor

@openjdk
Copy link

openjdk bot commented Aug 2, 2021

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

  • 7cc1eb3: Merge
  • e351de3: 8271272: C2: assert(!had_error) failed: bad dominance
  • 6180cf1: 8271512: ProblemList serviceability/sa/sadebugd/DebugdConnectTest.java due to 8270326
  • a1b5b81: 8271507: ProblemList SA tests that are failing with ZGC due to JDK-8248912
  • 4bc9b04: 8263059: security/infra/java/security/cert/CertPathValidator/certification/ComodoCA.java fails due to revoked cert
  • d6bb846: 8248899: security/infra/java/security/cert/CertPathValidator/certification/QuoVadisCA.java fails, Certificate has been revoked
  • 71ca0c0: 8270848: Redundant unsafe opmask register allocation in some instruction patterns.
  • 6c68ce2: 8270947: AArch64: C1: use zero_words to initialize all objects
  • cd7e30e: 8271242: Add Arena regression tests
  • 5b3c418: 8270321: Startup regressions in 18-b5 caused by JDK-8266310
  • ... and 395 more: https://git.openjdk.java.net/jdk/compare/ee0247f056daea7a0afdd572d13fb30f5164e889...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot closed this Aug 2, 2021
@openjdk openjdk bot added integrated Pull request has been integrated and 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 Aug 2, 2021
@openjdk
Copy link

openjdk bot commented Aug 2, 2021

@cl4es @stsypanov Pushed as commit 72145f3.

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

@stsypanov stsypanov deleted the 8269665 branch August 2, 2021 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-libs core-libs-dev@openjdk.org i18n i18n-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

2 participants