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

8342650: Move getChars to DecimalDigits #21593

Closed
wants to merge 13 commits into from

Conversation

wenshao
Copy link
Contributor

@wenshao wenshao commented Oct 20, 2024

Move getChars methods of StringLatin1 and StringUTF16 to DecimalDigits to reduce duplication

  1. HexDigits and OctalDigits also include getCharsLatin1 and getCharsUTF16
  2. Putting these two methods into DecimalDigits can avoid the need to expose them in JavaLangAccess
  3. Eliminate duplicate code in BigDecimal

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-8342650: Move getChars to DecimalDigits (Enhancement - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 21593

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Oct 20, 2024

👋 Welcome back swen! 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 Oct 20, 2024

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

8342650: Move getChars to DecimalDigits

Reviewed-by: liach

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

  • 423e8e0: 8339162: [REDO] JDK-8338440 Parallel: Improve fragmentation mitigation in Full GC
  • f400896: 8342442: Static ACVP sample tests
  • 325a2c3: 8343848: Fix typo of property name in TestOAEPPadding after 8341927
  • 2614c99: 8343793: Test java/foreign/TestMemorySession.java is timing out
  • 8a69893: 8343819: Link Float.NaN and Double.NaN to equivalence discussion in Double
  • 52c0b09: 8277240: java/awt/Graphics2D/ScaledTransform/ScaledTransform.java dialog does not get disposed
  • 0329855: 8343804: Show the default time zone with -XshowSettings option
  • 44ec501: 8305895: Implement JEP 450: Compact Object Headers (Experimental)
  • 6053962: 8343684: Test KDFDelayedProviderSyncTest.java intermittent fails didn't finish within the time-out 150
  • 2fb0c1d: 8343844: Add benchmarks for superword/autovectorization in FFM BulkOperations
  • ... and 62 more: https://git.openjdk.org/jdk/compare/5890d9438bbde88b89070052926a2eafe13d7b42...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
Copy link

openjdk bot commented Oct 20, 2024

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

  • core-libs
  • security

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.

@wenshao wenshao changed the title Move getChars methods of StringLatin1 and StringUTF16 to DecimalDigits to reduce duplication Move getChars to DecimalDigits to reduce duplication Oct 20, 2024
@wenshao wenshao changed the title Move getChars to DecimalDigits to reduce duplication Move getChars to DecimalDigits Oct 20, 2024
@wenshao wenshao changed the title Move getChars to DecimalDigits 8342650: Move getChars to DecimalDigits Oct 20, 2024
@openjdk openjdk bot added the rfr Pull request is ready for review label Oct 20, 2024
@mlbridge
Copy link

mlbridge bot commented Oct 20, 2024

Webrevs

char[] coeff;
int offset; // offset is the starting index for coeff array
// Get the significand as an absolute value
if (intCompact != INFLATED) {
offset = sbHelper.putIntCompact(Math.abs(intCompact));
coeff = sbHelper.getCompactCharArray();
coeff = new char[19];
Copy link

@j3graham j3graham Oct 20, 2024

Choose a reason for hiding this comment

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

A possibility here would be to change coeff to be a String. The “else” branch already creates a string and has to additionally create a char array from it. If this is the only place where the DecimalDigits.getChars(… char[]) is used, some extra code duplication could be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If this PR can be merged, we can continue to complete PR #16006, which can also remove DecimalDigits.getChars(… char[])

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@j3graham I have submitted PR #22009

@wenshao
Copy link
Contributor Author

wenshao commented Oct 22, 2024

/label remove security

@openjdk
Copy link

openjdk bot commented Oct 22, 2024

@wenshao
The security label was successfully removed.

public static void putPairLatin1(byte[] buf, int charPos, int v) {
int packed = DIGITS[v];
putCharLatin1(buf, charPos, packed & 0xFF);
putCharLatin1(buf, charPos + 1, packed >> 8);
Copy link
Member

Choose a reason for hiding this comment

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

Does merge store work here? Original code in StringLatin1 uses direct array writes, not sure about this version.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tests show that the current version of MergeStore also works

[TraceMergeStores] found:
    0-->  114  StoreB  === 80 91 113 95  [[ 18 ]]  @byte[int:>=0] (java/lang/Cloneable,java/io/Serializable):exact+any *, idx=5; unsafe  Memory: @byte[int:>=0] (java/lang/Cloneable,java/io/Serializable):NotNull:exact+any *, idx=5; !jvms: DecimalDigits::putCharLatin1 @ bci:12 (line 430) DecimalDigits::putPairLatin1 @ bci:24 (line 413)
    1-->   91  StoreB  === 80 7 90 51  [[ 114 ]]  @byte[int:>=0] (java/lang/Cloneable,java/io/Serializable):exact+any *, idx=5; unsafe  Memory: @byte[int:>=0] (java/lang/Cloneable,java/io/Serializable):NotNull:exact+any *, idx=5; !jvms: DecimalDigits::putCharLatin1 @ bci:12 (line 430) DecimalDigits::putPairLatin1 @ bci:13 (line 412)
[TraceMergeStores] truncated:
    0-->  114  StoreB  === 80 91 113 95  [[ 18 ]]  @byte[int:>=0] (java/lang/Cloneable,java/io/Serializable):exact+any *, idx=5; unsafe  Memory: @byte[int:>=0] (java/lang/Cloneable,java/io/Serializable):NotNull:exact+any *, idx=5; !jvms: DecimalDigits::putCharLatin1 @ bci:12 (line 430) DecimalDigits::putPairLatin1 @ bci:24 (line 413)
    1-->   91  StoreB  === 80 7 90 51  [[ 114 ]]  @byte[int:>=0] (java/lang/Cloneable,java/io/Serializable):exact+any *, idx=5; unsafe  Memory: @byte[int:>=0] (java/lang/Cloneable,java/io/Serializable):NotNull:exact+any *, idx=5; !jvms: DecimalDigits::putCharLatin1 @ bci:12 (line 430) DecimalDigits::putPairLatin1 @ bci:13 (line 412)
[TraceMergeStores]: Replace
  91  StoreB  === 80 7 90 51  [[ 114 ]]  @byte[int:>=0] (java/lang/Cloneable,java/io/Serializable):exact+any *, idx=5; unsafe  Memory: @byte[int:>=0] (java/lang/Cloneable,java/io/Serializable):NotNull:exact+any *, idx=5; !jvms: DecimalDigits::putCharLatin1 @ bci:12 (line 430) DecimalDigits::putPairLatin1 @ bci:13 (line 412)
 114  StoreB  === 80 91 113 95  [[ 18 ]]  @byte[int:>=0] (java/lang/Cloneable,java/io/Serializable):exact+any *, idx=5; unsafe  Memory: @byte[int:>=0] (java/lang/Cloneable,java/io/Serializable):NotNull:exact+any *, idx=5; !jvms: DecimalDigits::putCharLatin1 @ bci:12 (line 430) DecimalDigits::putPairLatin1 @ bci:24 (line 413)
[TraceMergeStores]: with
  51  LoadS  === 33 7 49  [[ 91 85 95 70 118 ]]  @short[int:>=0] (java/lang/Cloneable,java/io/Serializable):exact+any *, idx=4; #short !jvms: DecimalDigits::putPairLatin1 @ bci:4 (line 411)
 118  StoreC  === 80 7 90 51  [[ ]]  @byte[int:>=0] (java/lang/Cloneable,java/io/Serializable):NotNull:exact+any *, idx=5; mismatched  Memory: @byte[int:>=0] (java/lang/Cloneable,java/io/Serializable):NotNull:exact+any *, idx=5;
[TraceMergeStores] MergePrimitiveStores::run:  118  StoreC  === 80 7 90 51  [[ 18 ]]  @byte[int:>=0] (java/lang/Cloneable,java/io/Serializable):NotNull:exact+any *, idx=5; mismatched  Memory: @byte[int:>=0] (java/lang/Cloneable,java/io/Serializable):NotNull:exact+any *, idx=5; !orig=[114] !jvms: DecimalDigits::putCharLatin1 @ bci:12 (line 430) DecimalDigits::putPairLatin1 @ bci:24 (line 413)

Copy link
Member

@liach liach 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. Tier 1-3 tests pass.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Nov 10, 2024
@wenshao
Copy link
Contributor Author

wenshao commented Nov 11, 2024

This PR will improve the performance of Integer/Long.toString and StringBuilder.append(int/long) scenarios. This is because Unsafe.putByte is used to eliminate array bounds checks, and of course this elimination is safe.

In previous versions, in Integer/Long.toString and StringBuilder.append(int/long) scenarios, -COMPACT_STRING performed better than +COMPACT_STRING. This is because StringUTF16.getChars uses StringUTF16.putChar, which is similar to Unsafe.putChar, and there is no bounds check.

@wenshao
Copy link
Contributor Author

wenshao commented Nov 11, 2024

/integrate

@openjdk
Copy link

openjdk bot commented Nov 11, 2024

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

  • ca69a53: 8211033: Clean up the processing -classpath argument not to set LM_CLASS
  • 7b0f273: 8343894: ProblemList javax/management/remote/mandatory/notif/EmptyDomainNotificationTest.java
  • 74ae3c6: 8343650: Reuse StringLatin1::putCharsAt and StringUTF16::putCharsAt
  • 423e8e0: 8339162: [REDO] JDK-8338440 Parallel: Improve fragmentation mitigation in Full GC
  • f400896: 8342442: Static ACVP sample tests
  • 325a2c3: 8343848: Fix typo of property name in TestOAEPPadding after 8341927
  • 2614c99: 8343793: Test java/foreign/TestMemorySession.java is timing out
  • 8a69893: 8343819: Link Float.NaN and Double.NaN to equivalence discussion in Double
  • 52c0b09: 8277240: java/awt/Graphics2D/ScaledTransform/ScaledTransform.java dialog does not get disposed
  • 0329855: 8343804: Show the default time zone with -XshowSettings option
  • ... and 65 more: https://git.openjdk.org/jdk/compare/5890d9438bbde88b89070052926a2eafe13d7b42...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Nov 11, 2024

@wenshao Pushed as commit e1d684c.

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

@TobiHartmann
Copy link
Member

This caused a regression, see JDK-8343925. You might want to consider a quick backout.

@AlanBateman
Copy link
Contributor

I see Shaojin has created an issue to exclude the test but I think better to back this out quickly.

@liach
Copy link
Member

liach commented Nov 11, 2024

I think the fix is easy: Unsafe calls are using a bad offset which should be cast to long. Will submit a PR, but since I cannot reproduce the original issue locally or on internal CI, need others review first.

@wenshao
Copy link
Contributor Author

wenshao commented Nov 11, 2024

I submitted a rollback PR #22012. I can't reproduce the problem on a MacBook M1 Max, but I agree that more testing is needed, so let's roll it back first.

@wenshao
Copy link
Contributor Author

wenshao commented Nov 12, 2024

/open

@openjdk
Copy link

openjdk bot commented Nov 12, 2024

@wenshao The command open can only be used in open pull requests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-libs [email protected] integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

5 participants