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

8309545: Thread.interrupted from virtual thread needlessly resets interrupt status #14361

Closed
wants to merge 2 commits into from

Conversation

AlanBateman
Copy link
Contributor

@AlanBateman AlanBateman commented Jun 7, 2023

Thread.interrupted is used to "get and clear" the current thread's interrupt status. When called from a virtual thread, the current implementation always clears the carrier's interrupt status. There is no need to do this when the interrupt status is not set, it can just read the interrupt status and return false in that case.

This was found by Sergey Kuksenko when comparing platform vs. virtual thread performance. Once CODETOOLS-7903476 is in a released version of JMH then we can start to accumulate benchmarks that execute in virtual threads.

Testing: tier1-5


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-8309545: Thread.interrupted from virtual thread needlessly resets interrupt status (Bug - P3)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 14361

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jun 7, 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 Jun 7, 2023

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

  • core-libs

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the core-libs core-libs-dev@openjdk.org label Jun 7, 2023
@AlanBateman AlanBateman marked this pull request as ready for review June 8, 2023 09:22
@openjdk openjdk bot added the rfr Pull request is ready for review label Jun 8, 2023
@mlbridge
Copy link

mlbridge bot commented Jun 8, 2023

Webrevs

Comment on lines +877 to +879
boolean oldValue = interrupted;
if (oldValue) {
synchronized (interruptLock) {
Copy link
Member

Choose a reason for hiding this comment

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

Don't you still need to read under the lock to synchronize with the interrupt method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The override of interrupt for virtual threads always sets the interrupt status as the first step. So if Thread.interrupted reads the interrupt status as true then it will synchronize. It's not too different to platform threads, I think you added a comment to Thread.interrupted about this when move the interrupted flag into Java.

Copy link
Member

Choose a reason for hiding this comment

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

Changing the synchronization means there is a lot more to think about for what was otherwise a fairly trivial change. But I think you are right, if we don't see interrupted==true then we do nothing; if we do see it then we synchronize.

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.

Changes look fine. Thanks.

@openjdk
Copy link

openjdk bot commented Jun 9, 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:

8309545: Thread.interrupted from virtual thread needlessly resets interrupt status

Reviewed-by: rpressler, dholmes, jpai

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

  • 6f492e8: 8309686: inconsistent URL for https://www.unicode.org/reports/tr35
  • c4e6542: 8309675: Generational ZGC: compiler/gcbarriers/UnsafeIntrinsicsTest.java fails in nmt_commit
  • 34f0a6e: 8305593: Add @SPEC tags in java.desktop
  • 0be3905: 8309595: Allow javadoc to process unnamed classes
  • b2a5271: 8309196: Remove Thread.countStackFrames
  • bb96682: 8309498: [JVMCI] race in CallSiteTargetValue recording
  • 5a706fb: 8306584: Start of release updates for JDK 22
  • bb377b2: 8306841: Generational ZGC: NMT reports Java heap size larger than max heap size
  • ac3ce2b: 8304425: ClassHierarchyResolver from Reflection

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 ready Pull request is ready to be integrated label Jun 9, 2023
@AlanBateman
Copy link
Contributor Author

/integrate

@openjdk
Copy link

openjdk bot commented Jun 9, 2023

Going to push as commit 97df6cf.
Since your change was applied there have been 11 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 9, 2023
@openjdk openjdk bot closed this Jun 9, 2023
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Jun 9, 2023
@openjdk
Copy link

openjdk bot commented Jun 9, 2023

@AlanBateman Pushed as commit 97df6cf.

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

@robm-openjdk
Copy link
Member

/backport jdk21u

@openjdk
Copy link

openjdk bot commented Sep 15, 2023

@robm-openjdk the backport was successfully created on the branch robm-openjdk-backport-97df6cf5 in my personal fork of openjdk/jdk21u. To create a pull request with this backport targeting openjdk/jdk21u: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 97df6cf5 from the openjdk/jdk repository.

The commit being backported was authored by Alan Bateman on 9 Jun 2023 and was reviewed by Ron Pressler, David Holmes and Jaikiran Pai.

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:

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

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
5 participants