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

8338417: Explicitly pin a virtual thread before acquiring the JFR string pool monitor #20588

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

mgronlun
Copy link

@mgronlun mgronlun commented Aug 14, 2024

Greetings,

Explicitly pin a virtual thread before acquiring the JFR string pool monitor because migrating a carrier thread local event writer object onto another carrier thread is impossible.

During event commit, the thread is in a critical section because it has loaded a carrier thread local event writer object. For virtual threads, a contended monitor, such as a synchronized block, is a point where a thread could become unmounted.

A monitor guards the JFR string pool, but remounting a virtual thread onto another carrier is impossible because of the event writer.

Therefore, it's imperative to use explicit pin constructs to prevent unmounting at this location.

Testing: jdk_jfr

Thanks
Markus


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-8338417: Explicitly pin a virtual thread before acquiring the JFR string pool monitor (Bug - P3)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 20588

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Aug 14, 2024

👋 Welcome back mgronlun! 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 Aug 14, 2024

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

8338417: Explicitly pin a virtual thread before acquiring the JFR string pool monitor

Reviewed-by: dholmes, alanb

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

  • 74fdd68: 8333791: Fix memory barriers for @stable fields
  • da7311b: 8338286: GHA: Demote x86_32 to hotspot build only
  • f536f5a: 8336086: G1: Use one G1CardSet instance for all young regions
  • 4c34433: 8338304: clang on Linux - check for lld presence after JDK-8333189
  • 4669e7b: 8337102: JITTester: Fix breaks in static initialization blocks

Please see this link for an up-to-date comparison between the source branch of this pull request and 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 the rfr Pull request is ready for review label Aug 14, 2024
@openjdk
Copy link

openjdk bot commented Aug 14, 2024

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

  • core-libs
  • hotspot-jfr

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.

@mlbridge
Copy link

mlbridge bot commented Aug 14, 2024

Webrevs

@openjdk openjdk bot added ready Pull request is ready to be integrated and removed ready Pull request is ready to be integrated labels Aug 15, 2024
Copy link
Member

@dholmes-ora dholmes-ora left a comment

Choose a reason for hiding this comment

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

Functionally seems fine. Could be optimised a bit.

}

private static void unpinVirtualThread() {
if (Thread.currentThread().isVirtual() && ContinuationSupport.isSupported()) {
Copy link
Member

Choose a reason for hiding this comment

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

If you are at all concerned about overhead here then pin could return a boolean to indicate if the pin happened and oyu could then unpin just by checking that boolean and avoid doing the isVirtual and isSupported checks again.

Copy link
Member

@egahlin egahlin Aug 15, 2024

Choose a reason for hiding this comment

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

Would it be possible to create a boolean in the EventWriter that indicates if it is associated with a carrier thread or a normal thread (which can never be virtual) and then have two methods.

long l = this.carrierThread ? StringPool.addPinnedString(s) : StringPool.addString(s);

Copy link
Contributor

Choose a reason for hiding this comment

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

Thread.currentThread() has an intrinsic, and isVirtual is just a type check. ContinuationSupport.isSupported reads a static final so will disappear once compiled. The pattern we are using in other areas is for the pin to return a boolean (like David suggested).

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Aug 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-libs [email protected] hotspot-jfr [email protected] ready Pull request is ready to be integrated rfr Pull request is ready for review
4 participants