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

8321270: Virtual Thread.yield consumes parking permit #16953

Closed
wants to merge 4 commits into from

Conversation

AlanBateman
Copy link
Contributor

@AlanBateman AlanBateman commented Dec 4, 2023

When a virtual thread continues after Thread.yield it currently consumes thread's parking permit. This is an oversight, the parking permit should only be consumed when continuing after park.

The changes are straight-forward. The internal "RUNNABLE" state is replaced with UNPARKED and YIELDED state, effectively encoding the previous state. So for the most part, it's just replacing the usages of RUNNABLE. The additional states require refactoring tryGetStackTrace, this is the method that is used for Thread::getStackTrace when the virtual thread is unmounted. It is also changed to not not swallow the REE if the reesubmit fails (tryStackTrace has to resubmit as the task for the thread may run, or the thread unparked, while "suspended" and sampling its stack trace). The changes are a subset of larger changes in the loom repo, future PRs will propose to bring in other changes to get main line up to date.

For testing the existing ThreadAPI has new test cases.

Testing: test1-5. This includes the JVMTI tests as it maps the thread states to JVMTI thread states.


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-8321270: Virtual Thread.yield consumes parking permit (Bug - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 16953

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

Using diff file

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

Webrev

Link to Webrev Comment

Sorry, something went wrong.

@bridgekeeper
Copy link

bridgekeeper bot commented Dec 4, 2023

👋 Welcome back alanb! 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 Dec 4, 2023

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

  • core-libs
  • hotspot-runtime

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-runtime hotspot-runtime-dev@openjdk.org core-libs core-libs-dev@openjdk.org labels Dec 4, 2023
@AlanBateman
Copy link
Contributor Author

/label add serviceability
/label remove hotspot-runtime

@openjdk openjdk bot added the serviceability serviceability-dev@openjdk.org label Dec 4, 2023
@openjdk
Copy link

openjdk bot commented Dec 4, 2023

@AlanBateman
The serviceability label was successfully added.

@openjdk openjdk bot removed the hotspot-runtime hotspot-runtime-dev@openjdk.org label Dec 4, 2023
@openjdk
Copy link

openjdk bot commented Dec 4, 2023

@AlanBateman
The hotspot-runtime label was successfully removed.

@AlanBateman AlanBateman marked this pull request as ready for review December 4, 2023 19:20
@openjdk openjdk bot added the rfr Pull request is ready for review label Dec 4, 2023
@mlbridge
Copy link

mlbridge bot commented Dec 4, 2023

Webrevs

Copy link
Contributor

@sspitsyn sspitsyn left a comment

Choose a reason for hiding this comment

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

The fix looks good to me.
Also, it can be more safe to run mach5 tier6 as well.

@openjdk
Copy link

openjdk bot commented Dec 5, 2023

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

8321270: Virtual Thread.yield consumes parking permit

Reviewed-by: sspitsyn

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

  • 9e57010: 8315149: Add hsperf counters for CPU time of internal GC threads
  • b0d1450: 8321053: Use ByteArrayInputStream.buf directly when parameter of transferTo() is trusted
  • acaf2c8: 8318590: JButton ignores margin when painting HTML text
  • d3df3eb: 8294699: Launcher causes lingering busy cursor
  • fddc02e: 8321225: [JVMCI] HotSpotResolvedObjectTypeImpl.isLeafClass shouldn't create strong references
  • 640d7f3: 8314327: Issues with JShell when using "local" execution engine
  • db5613a: 8317288: [macos] java/awt/Window/Grab/GrabTest.java: Press on the outside area didn't cause ungrab
  • b1cb374: 8320349: Simplify FileChooserSymLinkTest.java by using single-window testUI
  • 18c7922: 8321224: ct.sym for JDK 22 contains references to internal modules
  • 83ffc1a: 8320303: Allow PassFailJFrame to accept single window creator
  • ... and 13 more: https://git.openjdk.org/jdk/compare/aec386596d531345b46be4f674b775df71df1eee...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 Dec 5, 2023
@dholmes-ora
Copy link
Member

Sorry I've deleted my earlier embarassingly stupid comment. The key point of this change is to split RUNNABLE into two states to indicated "runnable after yielding" and "runnable after being unparked".

@AlanBateman
Copy link
Contributor Author

The key point of this change is to split RUNNABLE into two states to indicated "runnable after yielding" and "runnable after being unparked".

That's right. This comes up with upcoming changes for monitors too - in that case it is important that a virtual thread that continues after blocking on monitorenter doesn't consume its parking permit.

@AlanBateman
Copy link
Contributor Author

/integrate

@openjdk
Copy link

openjdk bot commented Dec 7, 2023

Going to push as commit 29d7a22.
Since your change was applied there have been 59 commits pushed to the master branch:

  • 0b0fa47: 8319925: CSS.BackgroundImage incorrectly uses double-checked locking
  • 0048f1d: 8263256: Test java/net/Inet6Address/serialize/Inet6AddressSerializationTest.java fails due to dynamic reconfigurations of network interface during test
  • 49fff01: 8211238: @deprecated JFR event
  • 656b446: 8320969: Shenandoah: Enforce stable number of GC workers
  • 9a87e52: 8320538: Obsolete CSS styles in collection framework doc-file
  • 03c4595: 8321164: javac with annotation processor throws AssertionError: Filling jrt:/... during JarFileObject[/...]
  • 632a3c5: 8305825: getBounds API returns wrong value resulting in multiple Regression Test Failures on Ubuntu 23.04
  • 75a7c19: 8315827: Kitchensink.java and RenaissanceStressTest.java time out with jvmti module errors
  • 91ffdfb: 8320365: IPPPrintService.getAttributes() causes blanket re-initialisation
  • 50baaf4: 8321013: Parallel: Refactor ObjectStartArray
  • ... and 49 more: https://git.openjdk.org/jdk/compare/aec386596d531345b46be4f674b775df71df1eee...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Dec 7, 2023

@AlanBateman Pushed as commit 29d7a22.

💡 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
core-libs core-libs-dev@openjdk.org integrated Pull request has been integrated serviceability serviceability-dev@openjdk.org
Development

Successfully merging this pull request may close these issues.

None yet

4 participants