Skip to content

8341471: Reversed field layout caused by unstable sorting #21382

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

Closed
wants to merge 4 commits into from

Conversation

fg1417
Copy link

@fg1417 fg1417 commented Oct 7, 2024

For class Test:

    public class Test {
        char a000;
        char a001;
        char a002;
        char a003;
        char a004;
        char a005;
        char a006;
        char a007;
        char a008;
        char a009;
        char a00a;
        char a00b;
    }

We found its field layout on macOS was:

Layout of class Test
  Instance fields:
   @0 12/- RESERVED
   @12 "a00b" C 2/2 REGULAR
   @14 "a001" C 2/2 REGULAR
   @16 "a002" C 2/2 REGULAR
   @18 "a003" C 2/2 REGULAR
   @20 "a004" C 2/2 REGULAR
   @22 "a005" C 2/2 REGULAR
   @24 "a006" C 2/2 REGULAR
   @26 "a007" C 2/2 REGULAR
   @28 "a008" C 2/2 REGULAR
   @30 "a009" C 2/2 REGULAR
   @32 "a00a" C 2/2 REGULAR
   @34 "a000" C 2/2 REGULAR

a000 was put in the end while a00b was put in the beginning.

Fields get sorted according to size in [1]. qsort() on macOS reverses the order of fields with the same size. We should extend the comparison function to preserve the order on macOS, as we did on Windows.

Tier 1-3 passed on macOS.

[1]

void FieldGroup::sort_by_size() {


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-8341471: Reversed field layout caused by unstable sorting (Bug - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 21382

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

Using diff file

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

Webrev

Link to Webrev Comment

…ting

For class Test:
```
    public class Test {
        char a000;
        char a001;
        char a002;
        char a003;
        char a004;
        char a005;
        char a006;
        char a007;
        char a008;
        char a009;
        char a00a;
        char a00b;
    }
```

We found its field layout on macOS was:

Layout of class Test
  Instance fields:
   @0 12/- RESERVED
   @12 "a00b" C 2/2 REGULAR
   @14 "a001" C 2/2 REGULAR
   @16 "a002" C 2/2 REGULAR
   @18 "a003" C 2/2 REGULAR
   @20 "a004" C 2/2 REGULAR
   @22 "a005" C 2/2 REGULAR
   @24 "a006" C 2/2 REGULAR
   @26 "a007" C 2/2 REGULAR
   @28 "a008" C 2/2 REGULAR
   @30 "a009" C 2/2 REGULAR
   @32 "a00a" C 2/2 REGULAR
   @34 "a000" C 2/2 REGULAR

`a000` was put in the end while `a00b` was put in the beginning.

Fields get sorted according to size in [1]. `qsort()` on macOS
reverses the order of fields with the same size. We should extend
the comparison function to preserve the order on macOS, as we
did on Windows.

Tier 1-3 passed on macOS.

[1] https://github.com/openjdk/jdk/blob/3ee94e040a7395d11a294a6b660d707c97f188f8/src/hotspot/share/classfile/fieldLayoutBuilder.cpp#L102
@bridgekeeper
Copy link

bridgekeeper bot commented Oct 7, 2024

👋 Welcome back fgao! 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 7, 2024

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

8341471: Reversed field layout caused by unstable sorting

Reviewed-by: jwaters, jsjolen

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

  • d3f3c6a: 8330157: C2: Add a stress flag for bailouts
  • d809bc0: 8341658: RISC-V: Test DateFormatProviderTest.java run timeouted
  • de90204: 8341588: Remove CollectionUsageThreshold.java from ProblemList-Xcomp for debugging
  • f276f58: 8341803: ProblemList containers/docker/TestJcmdWithSideCar.java on linux-x64
  • 7eab0a5: 8337066: Repeated call of StringBuffer.reverse with double byte string returns wrong result
  • 62acc9c: 8341548: More concise use of classfile API
  • 7312eea: 8341131: Some jdk/jfr/event/compiler tests shouldn't be executed with Xcomp
  • 966eb72: 8341447: Open source closed frame tests # 5
  • b9db74a: 8341378: Open source few TrayIcon tests - Set8
  • 6546353: 8340203: Link color is hard to distinguish from text color in API documentation
  • ... and 20 more: https://git.openjdk.org/jdk/compare/28977972a0129892543222eada4dc99f4cd62574...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 rfr Pull request is ready for review label Oct 7, 2024
@openjdk
Copy link

openjdk bot commented Oct 7, 2024

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

  • hotspot-runtime

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 hotspot-runtime hotspot-runtime-dev@openjdk.org label Oct 7, 2024
@mlbridge
Copy link

mlbridge bot commented Oct 7, 2024

Webrevs

Copy link
Contributor

@TheShermanTanker TheShermanTanker left a comment

Choose a reason for hiding this comment

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

Not usually my domain, but this looks good since it's not that big of a change

#ifdef _WINDOWS
// qsort() on Windows reverse the order of fields with the same size
#if defined (_WINDOWS) || defined (__APPLE__)
// qsort() on Windows/macOS reverse the order of fields with the same size
// the extension of the comparison function below preserves this order
Copy link
Contributor

Choose a reason for hiding this comment

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

qsort() isn't defined to be stable anywhere. I can't see any reason to restrict thus bug fix to Windows and MacOS.

Copy link
Author

Choose a reason for hiding this comment

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

@theRealAph thanks for your review. The new commit removed the macro and applied the extension of the comparison function to all platforms. Tier 1 - 3 passed on both linux-aarch64 and x86 platforms.

@fg1417 fg1417 changed the title 8341471: [macOS_aarch64] Reversed field layout caused by unstable sorting 8341471: Reversed field layout caused by unstable sorting Oct 8, 2024
Copy link
Contributor

@jdksjolen jdksjolen left a comment

Choose a reason for hiding this comment

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

Please add a comment that mentions the reason for the branch, for example

// ensure stable sort
if (...) {

}

@fg1417
Copy link
Author

fg1417 commented Oct 8, 2024

Please add a comment that mentions the reason for the branch, for example

// ensure stable sort
if (...) {

}

Thanks for your review @jdksjolen . Updated it with comments.

Copy link
Contributor

@jdksjolen jdksjolen left a comment

Choose a reason for hiding this comment

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

LGTM

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Oct 8, 2024
@fg1417
Copy link
Author

fg1417 commented Oct 9, 2024

May I have a review for the latest commit? @theRealAph @TheShermanTanker

Thanks!

Copy link
Contributor

@TheShermanTanker TheShermanTanker left a comment

Choose a reason for hiding this comment

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

In my opinion it was sufficient to use it only for macOS and Windows, but I don't mind it for all platforms

@fg1417
Copy link
Author

fg1417 commented Oct 14, 2024

Thanks for your review @theRealAph @TheShermanTanker @jdksjolen .

I'll integrate it.

/integrate

@openjdk
Copy link

openjdk bot commented Oct 14, 2024

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

  • e3f6503: 8341893: AArch64: Micro-optimize compressed ptr decoding
  • 037f11b: 8341708: Optimize safepoint poll encoding with smaller poll data offset
  • 8d0975a: 8336726: C2: assert(!do_asserts || projs->fallthrough_ioproj != nullptr) failed: must be found
  • fe98f86: 8226938: [TEST_BUG]GTK L&F: There is no Details button in FileChooser Dialog
  • 5c4f1ef: 8226933: [TEST_BUG]GTK L&F: There is no swatches or RGB tab in JColorChooser
  • 41ee582: 8341138: Rename jtreg property docker.support as container.support
  • 2e1c193: 8342003: ProblemList sun/security/tools/keytool/GenKeyPairSigner.java
  • 2db3397: 8341797: Fix ExceptionOccurred in jdk.jdi
  • c4965d9: 8341794: Fix ExceptionOccurred in jdk.attach
  • 3f53d57: 8340327: A common framework to support public key algorithms with standard parameter sets
  • ... and 82 more: https://git.openjdk.org/jdk/compare/28977972a0129892543222eada4dc99f4cd62574...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Oct 14, 2024

@fg1417 Pushed as commit dcac4b0.

💡 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
hotspot-runtime hotspot-runtime-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

4 participants