-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8371667: Shenandoah: Re-design alloc request type enum for better efficiency and cleaner code #28247
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
…iciency and cleaner code
|
👋 Welcome back xpeng! A progress list of the required criteria for merging this PR into |
|
@pengxiaolong 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 184 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 |
|
@pengxiaolong The following labels will be automatically applied to this pull request:
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. |
Webrevs
|
shipilev
left a comment
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.
Honestly, I don't believe switching from explicit switch cases to bit manipulation is that much readable here. If you want to pursue this, then maybe do the proper bitmask manipulation, something like:
// bit 0: mutator (0) or GC (1) alloc
// bit 1: LAB (0) or shared (1) alloc
// bit 2: if LAB, then GCLAB (0) or PLAB (1)
// bit 3: if mutator, then normal (0) or CDS (1)
typedef int AllocType;
constexpr int bit_gc_alloc = 1 << 1;
constexpr int bit_lab_alloc = 1 << 2;
constexpr int bit_plab_alloc = 1 << 3;
constexpr int bit_cds_alloc = 1 << 4;
...
const bool is_lab_alloc(AllocType type) {
return (type & bit_lab_alloc) != 0;
}
constexpr AllocType _alloc_tlab = bit_lab_alloc;
constexpr AllocType _alloc_plab = bit_gc_alloc | bit_lab_alloc | bit_plab_alloc;
...
Remains to be seen what is the most sensible encoding scheme here.
Thanks you for the suggestion. I didn't think about changing the enum to constexpr int for alloc request type, just wanted to re-shuffle the values of current enum, so I only used bit manipulation when test if it lab allocation. I'll update the PR and use proper bitmask manipulation as you suggested. In terms of readability, explicit switch cases is definitely more readable, but machine code size will be also larger with more branches, so in theory it is less efficient. |
shipilev
left a comment
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.
Now that we are doing this... I do wonder if we want to fold _is_promotion and _affiliation into the same bitset?
I'll take a look today and see if folding |
| if (ShenandoahHeapRegion::requires_humongous(req.size())) { | ||
| switch (req.type()) { | ||
| case ShenandoahAllocRequest::_alloc_shared: | ||
| case ShenandoahAllocRequest::_alloc_shared_gc: |
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.
humongous objects never move, not possible to be _alloc_shared_gc here?
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.
Yes, I am not sure why we have the case for _alloc_shared_gc here. But I would leave it for extra safety in this "optimization/cleanup" change. We can yank this case later.
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.
Humongous objects do move under full gc, and may eventually move under concurrent GC with some refactoring.
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.
I have added the line case ShenandoahAllocRequest::_alloc_shared_gc: back.
For full gc, we may move humongous objects in compaction, not by evacuation, so it won't call into ShenandoahFreeSet::allocate method, right?
I have made the change to fold |
shipilev
left a comment
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.
A bit confusing still. How about this:
[x|xx|xxx|xx]
^---- Requester:
00 -- mutator
10 -- mutator (CDS)
01 -- GC
^------- Purpose:
00 -- shared
01 -- TLAB/GCLAB
11 -- PLAB
^---------- Affiliation:
00 -- YOUNG
01 -- OLD
11 -- OLD, promotion
Then:
static constexpr int bit_gc_alloc = 1 << 0;
static constexpr int bit_cds_alloc = 1 << 1;
static constexpr int bit_lab_alloc = 1 << 2;
static constexpr int bit_plab_alloc = 1 << 3;
static constexpr int bit_old_alloc = 1 << 4;
static constexpr int bit_promotion_alloc = 1 << 5;
static constexpr Type _alloc_shared = 0;
static constexpr Type _alloc_tlab = bit_lab_alloc;
static constexpr Type _alloc_cds = bit_cds_alloc;
static constexpr Type _alloc_shared_gc = bit_gc_alloc;
static constexpr Type _alloc_shared_gc_old = bit_gc_alloc | bit_old_alloc;
static constexpr Type _alloc_shared_gc_promotion = bit_gc_alloc | bit_old_alloc | bit_promotion_alloc;
static constexpr Type _alloc_gclab = bit_gc_alloc | bit_lab_alloc;
static constexpr Type _alloc_plab = bit_gc_alloc | bit_plab_alloc | bit_old_alloc;
Thanks Aleksey! This is good, I have applied the change, and fixed the wrong value for _alloc_plab, it should be |
shipilev
left a comment
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.
Thanks, looks reasonable. A few more nits.
| if (ShenandoahHeapRegion::requires_humongous(req.size())) { | ||
| switch (req.type()) { | ||
| case ShenandoahAllocRequest::_alloc_shared: | ||
| case ShenandoahAllocRequest::_alloc_shared_gc: |
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.
Yes, I am not sure why we have the case for _alloc_shared_gc here. But I would leave it for extra safety in this "optimization/cleanup" change. We can yank this case later.
|
Regarding the original code, was that release-build code, with optimization? That looks more like slowdebug code. I would have expected a computed goto rather than cascaded if-then-elses. With computed-goto and with range checks, I suspect there may still be issues with branch-prediction efficiency in hardware. Do we see any measurable impact on performance? |
It was release-build code, I used https://godbolt.org to generated the assembly code for comparison, the one in description is less optimization, here is the one with I am not really expecting much measurable impact on performance, but I did push the change to gitfram CI, here is the result from last run, I say kind of neutral: |
kdnilsen
left a comment
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.
Thanks for this cleanup and these improvements. Just two minor suggestions.
shipilev
left a comment
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.
Looks fine, assuming it passes tests.
kdnilsen
left a comment
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.
Thanks.
|
Note the test failures in GHA. |
Thanks, I looked into the GHA test, it is strange that I only updated some methods and added the missing inline keywords, it has to be related to one of the methods, more likely the |
shipilev
left a comment
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.
Still good.
|
/integrate |
|
Going to push as commit e00dec5.
Your commit was automatically rebased without conflicts. |
|
@pengxiaolong Pushed as commit e00dec5. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
Current alloc request type enum:
With current design, we have to use switch statement in multiple places resulting in unnecessary branches, for instance the function is_mutator_alloc:
In PR, I have re-designed the enum to make the function like is_mutator_alloc much simpler by making the values of the enum follow two simple rules:
Three functions have been simplified to one-line impl w/o branches in machine code:
I didn't check compiled assemble code of hotspot, in instead, I wrote similar/equivalent code and compile with gcc for comparison using godbolt.org:
x86_64 assembly code (https://godbolt.org/z/h7xfz8PaT):
Test:
Progress
Issue
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/28247/head:pull/28247$ git checkout pull/28247Update a local copy of the PR:
$ git checkout pull/28247$ git pull https://git.openjdk.org/jdk.git pull/28247/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 28247View PR using the GUI difftool:
$ git pr show -t 28247Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/28247.diff
Using Webrev
Link to Webrev Comment