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

8315970: Big-endian issues after JDK-8310929 #15652

Closed
wants to merge 2 commits into from

Conversation

wenshao
Copy link
Contributor

@wenshao wenshao commented Sep 10, 2023

https://bugs.openjdk.org/browse/JDK-8310929

@TheRealMDoerr Feedback:

We're getting test failures on AIX:
compiler/intrinsics/Test8215792.java
compiler/intrinsics/string/TestStringIntrinsics.java
runtime/CompactStrings/TestMethodNames.java
runtime/StringIntrinsic/StringIndexOfChar.java
Is there a problem with Big Endian?

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-8315970: Big-endian issues after JDK-8310929 (Enhancement - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 15652

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Sep 10, 2023

👋 Welcome back wenshao! 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 Sep 10, 2023

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

  • core-libs

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the core-libs core-libs-dev@openjdk.org label Sep 10, 2023
@cl4es
Copy link
Member

cl4es commented Sep 10, 2023

Filed https://bugs.openjdk.org/browse/JDK-8315970 for this.

@wenshao wenshao changed the title fix PR 14699 big endian problem 8315970: Big-endian issues after JDK-8310929 Sep 10, 2023
@openjdk openjdk bot added the rfr Pull request is ready for review label Sep 10, 2023
@mlbridge
Copy link

mlbridge bot commented Sep 10, 2023

Webrevs

Copy link
Contributor

@RogerRiggs RogerRiggs left a comment

Choose a reason for hiding this comment

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

I'd suggest backing out the whole commit and resumitting after the fix and more complete testing.

@wenshao
Copy link
Contributor Author

wenshao commented Sep 10, 2023

I don't have a big endian environment so I can't test it. I need help from @TheRealMDoerr


private static int inflatePacked(int v) {
int packed = (int) StringLatin1.PACKED_DIGITS[v];
return ((packed & 0xFF) << HI_BYTE_SHIFT)
Copy link
Member

@cl4es cl4es Sep 10, 2023

Choose a reason for hiding this comment

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

I'm not sure this is correct.

Compare StringUTF16::putChar where these constants are used to shift right to extract the equivalent byte from a value:

        val[index++] = (byte)(c >> HI_BYTE_SHIFT);
        val[index]   = (byte)(c >> LO_BYTE_SHIFT);

I.e., when inflating a byte 0xaa to a char encoded into a byte[] we end up with 0xaa00 on big-endian. Inflating a short literal 0xaabb encoding two chars logically I think will need to consider each byte in isolation, ending up with 0xaa00bb00 (in little-endian notation). Or maybe it's 0xbb00aa00. Ugh..

Since HI_BYTE_SHIFT is 8 on big-endian and 0 on little-endian I guess this might just work:

return ((packed & 0xFF) << 16 + HI_BYTE_SHIFT) | ((packed & 0xFF00) << HI_BYTE_SHIFT)

.. but we really need to re-examine, prototype and test this out thoroughly on a big-endian system. I second @RogerRiggs notion that the best course of action right now is to back out #14699 and redo it with big-endianness issues resolved.

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'm also not sure if this PR is correct.

@wenshao
Copy link
Contributor Author

wenshao commented Sep 10, 2023

Could it be caused by using VarHandle/ByteArrayLittleEndian?

@TheRealMDoerr
Copy link
Contributor

This helps. I'll run more tests.

Copy link
Contributor

@TheRealMDoerr TheRealMDoerr 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 reasonable. The tests have passed on linux Big Endian and AIX. Thanks for fixing it so quickly. (Otherwise, backout and re-do would have been a good option as well.)

@openjdk
Copy link

openjdk bot commented Sep 11, 2023

⚠️ @wenshao 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 fix_14699_big_endian
$ git commit --author='Preferred Full Name <you@example.com>' --allow-empty -m 'Update full name'
$ git push

@openjdk
Copy link

openjdk bot commented Sep 11, 2023

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

8315970: Big-endian issues after JDK-8310929

Reviewed-by: mdoerr

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

  • ae08143: 8315611: Open source swing text/html and tree test
  • 7b3e697: 8315855: G1: Revise signature of set_humongous_candidate
  • 1941290: 8315942: Sort platform enums and definitions after JDK-8304913 follow-ups
  • 996b336: 8315781: Reduce the max value of GCDrainStackTargetSize
  • 35bccac: 8315841: RISC-V: Check for hardware TSO support
  • a04c6c1: 8315609: Open source few more swing text/html tests
  • dab1c21: 8314491: Linux: jexec launched via PATH fails to find java
  • 9a83d55: 8315373: Change VirtualThread to unmount after freezing, re-mount before thawing
  • 68f6941: 8314452: Explicitly indicate inlining success/failure in PrintInlining
  • b482e6d: 8315580: Remove unused java_lang_String::set_value_raw()
  • ... and 18 more: https://git.openjdk.org/jdk/compare/4b43c25fe382b5ee805a2d1b173fdd32d8da7fad...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 (@RogerRiggs, @TheRealMDoerr) 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 Sep 11, 2023
@wenshao
Copy link
Contributor Author

wenshao commented Sep 11, 2023

@TheRealMDoerr
Can you also help test the version Webrevs 00: Full (911bbce8) ?

@TheRealMDoerr
Copy link
Contributor

Your earlier version didn't work. The one which I have successfully tested is after 2nd commit.

@wenshao
Copy link
Contributor Author

wenshao commented Sep 11, 2023

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Sep 11, 2023
@openjdk
Copy link

openjdk bot commented Sep 11, 2023

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

@TheRealMDoerr
Copy link
Contributor

GHA Pre-submit test results look good. Tests on AIX as well. Let's ship it!
/sponsor

@openjdk
Copy link

openjdk bot commented Sep 11, 2023

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

  • ae08143: 8315611: Open source swing text/html and tree test
  • 7b3e697: 8315855: G1: Revise signature of set_humongous_candidate
  • 1941290: 8315942: Sort platform enums and definitions after JDK-8304913 follow-ups
  • 996b336: 8315781: Reduce the max value of GCDrainStackTargetSize
  • 35bccac: 8315841: RISC-V: Check for hardware TSO support
  • a04c6c1: 8315609: Open source few more swing text/html tests
  • dab1c21: 8314491: Linux: jexec launched via PATH fails to find java
  • 9a83d55: 8315373: Change VirtualThread to unmount after freezing, re-mount before thawing
  • 68f6941: 8314452: Explicitly indicate inlining success/failure in PrintInlining
  • b482e6d: 8315580: Remove unused java_lang_String::set_value_raw()
  • ... and 18 more: https://git.openjdk.org/jdk/compare/4b43c25fe382b5ee805a2d1b173fdd32d8da7fad...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Sep 11, 2023

@TheRealMDoerr @wenshao Pushed as commit 4cb4637.

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

@cl4es
Copy link
Member

cl4es commented Sep 11, 2023

Your earlier version didn't work. The one which I have successfully tested is after 2nd commit.

I think this looks OK.

This patch probably reverts performance numbers on little-endian on some measures to pre-JDK-8310929 levels. A follow-up could examine if we can recuperate, e.g. differentiate the logic on big-endian, e.g. something like:

        charPos -= 2;
        if (BIG_ENDIAN) {
            putPair(..);
        } else {
            int packed = (int) StringLatin1.PACKED_DIGITS[-i];
            int inflated = ((packed & 0xFF00) << 8) | (packed & 0xFF);
            ByteArrayLittleEndian.setInt(buf, charPos << 1, inflated);
        }

It might also work generally if we made int inflated = ((packed & 0xFF) << (16 + HI_BYTE_SHIFT)) | ((packed & 0xFF00) << HI_BYTE_SHIFT), but I have no way to test that and the performance of ByteArrayLittleEndian might be poor on AIX.

@TheRealMDoerr
Copy link
Contributor

Shouldn't this get optimized by the JIT compilers? Why is ByteArrayLittleEndian supposed to be faster?
Note that there are still several Big Endian platforms: AIX, s390x and old linux ppc64 (still kept alive)

@wenshao
Copy link
Contributor Author

wenshao commented Sep 11, 2023

It will be faster to use ByteArrayLittle or ByteArrayLittleEndian. ByteArrayLittleEndian has an Integer.reverseBytes operation under the bigendian endian platform.

@cl4es
Copy link
Member

cl4es commented Sep 11, 2023

Shouldn't this get optimized by the JIT compilers? Why is ByteArrayLittleEndian supposed to be faster? Note that there are still several Big Endian platforms: AIX, s390x and old linux ppc64 (still kept alive)

And none of these are covered by Oracle-internal or GHA testing, sadly.

It'd be interesting to see performance numbers for putPair vs ByteArrayLittleEndian.setInt in isolation on x86. I.e. before and after this PR. When I've tested a similar thing for #15591 I saw a slight win on a two-byte pair (that might be due improved inlining decisions) but regressions on 4-byte or larger writes.

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 integrated Pull request has been integrated
4 participants