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

8325587: Shenandoah: ShenandoahLock should allow blocking in VM #17813

Closed

Conversation

shipilev
Copy link
Member

@shipilev shipilev commented Feb 12, 2024

ShenandoahLock is a spinlock that is supposed to guard heap state. That lock is normally only lightly contended, as threads normally only allocate large TLABs/GCLABs. So we just summarily delegated to Thread::{SpinAcquire,SpinRelease}, which spins a bit, and then starts going to sleep/yield dance on contention.

This does not work well when there are lots of threads near the OOM conditions. Then, most of these threads would fail to allocate the TLAB, go for out-of-TLAB alloc, start lock acquisition, and spend a lot of time trying to acquire the lock. The handshake/safepoint would think those threads are running, even when they are actually yielding or sleeping. As seen in bug report, a handshake operation over many such threads could then take hundreds of seconds.

The solution is to notify VM that we are blocking before going for sleep or yield. This is similar to what other VM code does near such yields. This involves state transitions, so it is only cheap to do near the actual blocking. Protecting the whole lock with VM transition would be very slow.

I also de-uglified bits of adjacent code.

Additional testing:

  • Original Extremem reproducer does not have outliers anymore
  • Linux x86_64 server fastdebug, hotspot_gc_shenandoah
  • Linux x86_64 server fastdebug, all passes with -XX:+UseShenandoahGC (some old failures, but quite a few "timeouts" also disappear)

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-8325587: Shenandoah: ShenandoahLock should allow blocking in VM (Bug - P3)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 17813

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

Using diff file

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

Webrev

Link to Webrev Comment

@shipilev shipilev force-pushed the JDK-8325587-shenandoah-lock-yield branch from ab70d4e to 8f9da4f Compare February 12, 2024 17:40
@bridgekeeper
Copy link

bridgekeeper bot commented Feb 12, 2024

👋 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
Copy link

openjdk bot commented Feb 12, 2024

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

  • hotspot-gc
  • 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 added hotspot-gc hotspot-gc-dev@openjdk.org shenandoah shenandoah-dev@openjdk.org labels Feb 12, 2024
@robehn
Copy link
Contributor

robehn commented Feb 12, 2024

Think about if you can add missing pieces to: https://github.com/openjdk/jdk/blob/master/src/hotspot/share/utilities/spinYield.hpp
And utilize that, as it is would be nice to have one? configurable back-off strategy in the future.

Fix

Try to block in VM

Only enter VM on actual blocking

Cleanups

Cleanups

Only block when in VM state

Only block for mutator allocs

Simplify
@shipilev shipilev force-pushed the JDK-8325587-shenandoah-lock-yield branch from fbd242a to 42bcbe8 Compare February 13, 2024 09:58
@shipilev
Copy link
Member Author

Think about if you can add missing pieces to: https://github.com/openjdk/jdk/blob/master/src/hotspot/share/utilities/spinYield.hpp And utilize that, as it is would be nice to have one? configurable back-off strategy in the future.

Thought about it. The way current patch is done, there is little leeway to make the code common or reuse it, unfortunately.

@shipilev shipilev marked this pull request as ready for review February 14, 2024 18:26
@openjdk openjdk bot added the rfr Pull request is ready for review label Feb 14, 2024
@mlbridge
Copy link

mlbridge bot commented Feb 14, 2024

Webrevs

Copy link
Contributor

@robehn robehn left a comment

Choose a reason for hiding this comment

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

I know to little about Shenandoah to say if blocking is always okay, sorry.
Other than that I don't spot any issues, had some minor suggestion.

src/hotspot/share/gc/shenandoah/shenandoahLock.cpp Outdated Show resolved Hide resolved
src/hotspot/share/gc/shenandoah/shenandoahLock.hpp Outdated Show resolved Hide resolved
src/hotspot/share/gc/shenandoah/shenandoahLock.hpp Outdated Show resolved Hide resolved
src/hotspot/share/gc/shenandoah/shenandoahLock.hpp Outdated Show resolved Hide resolved
Copy link
Contributor

@robehn robehn left a comment

Choose a reason for hiding this comment

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

Nice work!
I'll review it, but as stated don't trust me that it's works :)

Looks good, thanks!

@openjdk
Copy link

openjdk bot commented Feb 15, 2024

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

8325587: Shenandoah: ShenandoahLock should allow blocking in VM

Reviewed-by: rehn, rkennke

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

  • 921507c: 8326319: G1: Remove unused G1ConcurrentMark::_init_times
  • 68eb5a1: 8321075: RISC-V: UseSystemMemoryBarrier lacking proper OS support
  • 04d43c4: 8187759: Background not refreshed when painting over a transparent JFrame
  • d5f3d5c: 8326201: [S390] Need to bailout cleanly if creation of stubs fails when code cache is out of space
  • d31fd78: 8325496: Make TrimNativeHeapInterval a product switch
  • 27003b5: 8326090: Rename jvmti_aod.h
  • 36246c9: 8326233: Utils#copySSLParameters loses needClientAuth Setting
  • 14f9aba: 8326371: [BACKOUT] Clean up NativeCompilation.gmk and its newly created parts
  • 1bd91cd: 8325963: Clean up NativeCompilation.gmk and its newly created parts
  • 4d50ee6: 8326368: compare.sh -2bins prints ugly errors on Windows
  • ... and 104 more: https://git.openjdk.org/jdk/compare/618af397b4c636c89049f7398c14f37f0065df59...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 ready Pull request is ready to be integrated label Feb 15, 2024
Copy link
Contributor

@rkennke rkennke left a comment

Choose a reason for hiding this comment

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

Looks good. I have one question (and leave it up to you to make the change).

Thanks,
Roman

@shipilev
Copy link
Member Author

Thanks!

/integrate

@openjdk
Copy link

openjdk bot commented Feb 21, 2024

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

  • 5f16f34: 8326370: Remove redundant and misplaced micros from StringBuffers
  • 921507c: 8326319: G1: Remove unused G1ConcurrentMark::_init_times
  • 68eb5a1: 8321075: RISC-V: UseSystemMemoryBarrier lacking proper OS support
  • 04d43c4: 8187759: Background not refreshed when painting over a transparent JFrame
  • d5f3d5c: 8326201: [S390] Need to bailout cleanly if creation of stubs fails when code cache is out of space
  • d31fd78: 8325496: Make TrimNativeHeapInterval a product switch
  • 27003b5: 8326090: Rename jvmti_aod.h
  • 36246c9: 8326233: Utils#copySSLParameters loses needClientAuth Setting
  • 14f9aba: 8326371: [BACKOUT] Clean up NativeCompilation.gmk and its newly created parts
  • 1bd91cd: 8325963: Clean up NativeCompilation.gmk and its newly created parts
  • ... and 105 more: https://git.openjdk.org/jdk/compare/618af397b4c636c89049f7398c14f37f0065df59...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Feb 21, 2024

@shipilev Pushed as commit 492e8bf.

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

@shipilev shipilev deleted the JDK-8325587-shenandoah-lock-yield branch March 1, 2024 12:15
@mmyxym
Copy link

mmyxym commented May 8, 2024

/backport jdk21u-dev

@openjdk
Copy link

openjdk bot commented May 8, 2024

@mmyxym the backport was successfully created on the branch backport-mmyxym-492e8bf5 in my personal fork of openjdk/jdk21u-dev. To create a pull request with this backport targeting openjdk/jdk21u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 492e8bf5 from the openjdk/jdk repository.

The commit being backported was authored by Aleksey Shipilev on 21 Feb 2024 and was reviewed by Robbin Ehn and Roman Kennke.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk21u-dev:

$ git fetch https://github.com/openjdk-bots/jdk21u-dev.git backport-mmyxym-492e8bf5:backport-mmyxym-492e8bf5
$ git checkout backport-mmyxym-492e8bf5
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk21u-dev.git backport-mmyxym-492e8bf5

@mmyxym
Copy link

mmyxym commented May 10, 2024

/backport jdk22u-dev

@openjdk
Copy link

openjdk bot commented May 10, 2024

@mmyxym The target repository jdk22u-dev is not a valid target for backports.
List of valid target repositories: openjdk/jdk, openjdk/jdk11u, openjdk/jdk11u-dev, openjdk/jdk17u, openjdk/jdk17u-dev, openjdk/jdk21u, openjdk/jdk21u-dev, openjdk/jdk22u, openjdk/jdk7u, openjdk/jdk8u, openjdk/jdk8u-dev, openjdk/jfx, openjdk/jfx17u, openjdk/jfx21u, openjdk/jfx22u, openjdk/lilliput-jdk17u, openjdk/lilliput-jdk21u, openjdk/shenandoah-jdk21u, openjdk/shenandoah-jdk8u.
Supplying the organization/group prefix is optional.

@mmyxym
Copy link

mmyxym commented May 10, 2024

/backport jdk22u

@openjdk
Copy link

openjdk bot commented May 10, 2024

@mmyxym the backport was successfully created on the branch backport-mmyxym-492e8bf5 in my personal fork of openjdk/jdk22u. To create a pull request with this backport targeting openjdk/jdk22u:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 492e8bf5 from the openjdk/jdk repository.

The commit being backported was authored by Aleksey Shipilev on 21 Feb 2024 and was reviewed by Robbin Ehn and Roman Kennke.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk22u:

$ git fetch https://github.com/openjdk-bots/jdk22u.git backport-mmyxym-492e8bf5:backport-mmyxym-492e8bf5
$ git checkout backport-mmyxym-492e8bf5
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk22u.git backport-mmyxym-492e8bf5

⚠️ @mmyxym You are not yet a collaborator in my fork openjdk-bots/jdk22u. An invite will be sent out and you need to accept it before you can proceed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot-gc hotspot-gc-dev@openjdk.org integrated Pull request has been integrated shenandoah shenandoah-dev@openjdk.org
Development

Successfully merging this pull request may close these issues.

4 participants