-
Notifications
You must be signed in to change notification settings - Fork 6.1k
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
Conversation
…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
👋 Welcome back fgao! A progress list of the required criteria for merging this PR into |
@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:
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
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 |
Webrevs
|
There was a problem hiding this 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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 (...) {
}
Thanks for your review @jdksjolen . Updated it with comments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
May I have a review for the latest commit? @theRealAph @TheShermanTanker Thanks! |
There was a problem hiding this 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
Thanks for your review @theRealAph @TheShermanTanker @jdksjolen . I'll integrate it. /integrate |
Going to push as commit dcac4b0.
Your commit was automatically rebased without conflicts. |
For class Test:
We found its field layout on macOS was:
a000
was put in the end whilea00b
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]
jdk/src/hotspot/share/classfile/fieldLayoutBuilder.cpp
Line 102 in 3ee94e0
Progress
Issue
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