Skip to content

8386292: Shenandoah: Simplify and strengthen C1 barriers - #31576

Closed
shipilev wants to merge 13 commits into
openjdk:masterfrom
shipilev:JDK-8386292-shenandoah-c1-barriers
Closed

8386292: Shenandoah: Simplify and strengthen C1 barriers#31576
shipilev wants to merge 13 commits into
openjdk:masterfrom
shipilev:JDK-8386292-shenandoah-c1-barriers

Conversation

@shipilev

@shipilev shipilev commented Jun 18, 2026

Copy link
Copy Markdown
Member

For Valhalla enablement, I was chasing a few issues that reproduce under stress testing. A few of them are in C1 barriers, where we apparently clobber registers. This shows up prominently under heavy register pressure in Valhalla tests. We can and should simplify C1 barriers by delegating them to assembler barriers where possible. The whole lot of complexity would go away then.

Currently, Shenandoah C1 barriers are shaped like this:

  1. Method main body: inline gc-state check, jumps to (2)
  2. Method outline "C1 stub" that sometimes does filters, like cset checks, calls to (3)
  3. Slow "C1 runtime stub" that optionally does even more checks, saves/restores the registers and calls the runtime

Steps (2) and (3) are the bulk of C1 barriers, those implementations are written specifically for C1. But there is no real point in having them for baseline compiler like C1. For maintainability reasons, we can delegate to assembler barriers that are at the same efficiency ballpark.

In this change, the shape of the barriers is:

  1. Method main body: inline gc-state check, jumps to (2)
  2. Method outline "C1 stub" that is a thin adapter for (3)
  3. Slow "C1 runtime stub" that now delegates to assembler barrier set to generate the real meat

There are maintainability savings at steps (2) and (3), since we push down most of the implementation to (3); I believe I have fixed some register clobbering bugs that were showing up in Valhalla because of this simplification. We now do fairly little code in C1, which I am very happy with.

There are code density savings at step (2), because we do not generate a lot extra code that shows up in every C1 method. There are also assorted quality of life improvements along the way to make the code more straight-forward.

If you stand way back and look at it from a distance, you can think about this as LBE-shaped refactoring of C1 barriers. In contrast to LBE, this rewrite favors maintainability over peak performance. At some point in the future we might be able to coalesce the assembler, C1 and C2 barriers completely, but I am not 100% confident it is going to work for peak perf.

I am throwing more testing at this now, but would appreciate early review in case there are obvious gaps.

Additional testing:

  • Linux x86_64 server fastdebug, hotspot_gc_shenandoah
  • Linux x86_64 server fastdebug, tier1 with -XX:+UseShenandoahGC -XX:TieredStopAtLevel=1
  • Linux x86_64 server fastdebug, all with -XX:+UseShenandoahGC -XX:TieredStopAtLevel=1
  • Linux AArch64 server fastdebug, all with -XX:+UseShenandoahGC -XX:TieredStopAtLevel=1
  • Linux PPC64 / RISC-V cross-compilation and basic smoke tests


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed (2 reviews required, with at least 1 Reviewer, 1 Author)

Issue

  • JDK-8386292: Shenandoah: Simplify and strengthen C1 barriers (Enhancement - P4)

Reviewers

Contributors

  • Martin Doerr <mdoerr@openjdk.org>

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 31576

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper

bridgekeeper Bot commented Jun 18, 2026

Copy link
Copy Markdown

👋 Welcome back shade! 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

openjdk Bot commented Jun 18, 2026

Copy link
Copy Markdown

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

8386292: Shenandoah: Simplify and strengthen C1 barriers

Co-authored-by: Martin Doerr <mdoerr@openjdk.org>
Reviewed-by: rkennke, fyang, kdnilsen

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

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 hotspot hotspot-dev@openjdk.org shenandoah shenandoah-dev@openjdk.org labels Jun 18, 2026
@openjdk

openjdk Bot commented Jun 18, 2026

Copy link
Copy Markdown

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

  • hotspot
  • shenandoah

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.

@openjdk

openjdk Bot commented Jun 18, 2026

Copy link
Copy Markdown

The total number of required reviews for this PR has been set to 2 based on the presence of this label: hotspot. This can be overridden with the /reviewers command.

@openjdk openjdk Bot added the rfr Pull request is ready for review label Jun 18, 2026
@mlbridge

mlbridge Bot commented Jun 18, 2026

Copy link
Copy Markdown

Comment thread src/hotspot/cpu/ppc/gc/shenandoah/shenandoahBarrierSetAssembler_ppc.cpp Outdated
@shipilev

Copy link
Copy Markdown
Member Author

/contributor add @TheRealMDoerr

@openjdk

openjdk Bot commented Jun 22, 2026

Copy link
Copy Markdown

@shipilev
Contributor Martin Doerr <mdoerr@openjdk.org> successfully added.

__ prologue("shenandoah_keepalive_barrier", false);
const Register tmp_obj = x10;
const Register tmp1 = t1;
const Register tmp2 = t2;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

t1 is one of the two reserved scratch registers which may be clobbered implicitly by some macro-assemblers.
Can we simply use x11 and x12 for tmp1 and tmp2 respectively? I think that should be safer.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Right! I think the risk is low, given we immediately stash these registers here. But you are right we might conflict somewhere down the line. If you feel x11/x12 is safer, let's do that. Done in new commit.

Comment thread src/hotspot/cpu/riscv/gc/shenandoah/shenandoahBarrierSetAssembler_riscv.cpp Outdated

@rkennke rkennke left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is great! And it's the right thing to do: C1 LIR should not really get any fancy stuff/control flow inserted into its basic blocks. Checking a flag and branching to a stub is about all that C1 can realistically handle.
I have carefully checked the changes and could not find anything wrong with it. (I'm not really familiar with RISCV and PPC assembly, though.)

@shipilev

Copy link
Copy Markdown
Member Author

Thanks for looking!

@TheRealMDoerr, @RealFYang -- do you guys want to run PPC64/RISC-V testing before I integrate?

@TheRealMDoerr

Copy link
Copy Markdown
Contributor

I had already run some tests on PPC64 and they were good. Thanks!

@RealFYang RealFYang left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The RISC-V part seems fine to me. My local hotspot_gc_shenandoah test using fastdebug build on linux-riscv64 is good.

@openjdk openjdk Bot added the ready Pull request is ready to be integrated label Jun 25, 2026
@shipilev

Copy link
Copy Markdown
Member Author

Awesome, thanks for testing!

@kdnilsen kdnilsen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not fluent in C1, but everything looks good to me. I agree that this simplification is the right direction to move.

@shipilev

Copy link
Copy Markdown
Member Author

Thanks for reviews! Here goes.

/integrate

@openjdk

openjdk Bot commented Jun 26, 2026

Copy link
Copy Markdown

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

Your commit was automatically rebased without conflicts.

@openjdk openjdk Bot added the integrated Pull request has been integrated label Jun 26, 2026
@openjdk openjdk Bot closed this Jun 26, 2026
@openjdk openjdk Bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Jun 26, 2026
@openjdk

openjdk Bot commented Jun 26, 2026

Copy link
Copy Markdown

@shipilev Pushed as commit 60e4b91.

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

Development

Successfully merging this pull request may close these issues.

5 participants