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

8307068: store a JavaThread* in the java.lang.Thread object after the JavaThread* is added to the main ThreadsList #13723

Closed
wants to merge 11 commits into from

Conversation

dcubed-ojdk
Copy link
Member

@dcubed-ojdk dcubed-ojdk commented Apr 28, 2023

A small fix to store a JavaThread* in the java.lang.Thread object after the JavaThread*
is added to the main ThreadsList. Also adds the following:

  • java_lang_Thread::thread_acquire()
  • java_lang_Thread::release_set_thread()

And uses them on an as-needed basis.


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-8307068: store a JavaThread* in the java.lang.Thread object after the JavaThread* is added to the main ThreadsList

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 13723

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

Using diff file

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

Webrev

Link to Webrev Comment

@dcubed-ojdk
Copy link
Member Author

/label add hotspot-runtime

@bridgekeeper
Copy link

bridgekeeper bot commented Apr 28, 2023

👋 Welcome back dcubed! 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 added the hotspot-runtime hotspot-runtime-dev@openjdk.org label Apr 28, 2023
@openjdk
Copy link

openjdk bot commented Apr 28, 2023

@dcubed-ojdk
The hotspot-runtime label was successfully added.

…ad_oop) in ThreadsListHandle::cv_internal_thread_to_JavaThread().
@dcubed-ojdk dcubed-ojdk marked this pull request as ready for review April 28, 2023 19:23
@openjdk openjdk bot added the rfr Pull request is ready for review label Apr 28, 2023
@dcubed-ojdk dcubed-ojdk changed the base branch from master to pr/13704 April 28, 2023 19:31
@mlbridge
Copy link

mlbridge bot commented Apr 28, 2023

Webrevs

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.

The eetop field is defined as a Java volatile and so the VM should nominally always perform "volatile" reads and writes ie acquires and releases. But I said nominally, because in many cases there are other synchronization "release" barriers that must have occurred before we could get to the operations that read the eetop field. So I think it is only code that could interact with just started threads, that would need the explicit acquire; while I think any set of the eetop to non-null needs to have release semantics.

Comment on lines 1674 to 1675
// on a ThreadsList. There will be a release when the Theads_lock is
// dropped somewhere in the caller, but let's be more proactive.
Copy link
Member

Choose a reason for hiding this comment

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

Any release associated with dropping the Threads_lock may come too late given this thread is now visible via JVMTI, so this is more than just being "proactive" IMO.

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay. I've updated the comment to:

  // Publish the JavaThread* in java.lang.Thread after the JavaThread* is
  // on a ThreadsList. We don't want to wait for the release when the
  // Theads_lock is dropped somewhere in the caller since the JavaThread*
  // is already visible to JVM/TI via the ThreadsList.

@@ -2109,6 +2108,9 @@ void JavaThread::start_internal_daemon(JavaThread* current, JavaThread* target,
target->set_threadOopHandles(thread_oop());

Threads::add(target); // target is now visible for safepoint/handshake
// Publish the JavaThread* in java.lang.Thread after the JavaThread* is
// on a ThreadsList.
java_lang_Thread::set_thread(thread_oop(), target); // isAlive == true now
Copy link
Member

Choose a reason for hiding this comment

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

Why did you decide this doesn't have to be a release?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because the Threads_lock is grabbed in this function and released again
when the mu destructor runs, but I'm going to change my mind. I've changed
the comment and code to:

  // Publish the JavaThread* in java.lang.Thread after the JavaThread* is
  // on a ThreadsList. We don't want to wait for the release when the
  // Theads_lock is dropped when the 'mu' destructor is run since the
  // JavaThread* is already visible to JVM/TI via the ThreadsList.
  java_lang_Thread::release_set_thread(thread_oop(), target); // isAlive == true now

@openjdk
Copy link

openjdk bot commented May 2, 2023

⚠️ @dcubed-ojdk This pull request contains merges that bring in commits not present in the target repository. Since this is not a "merge style" pull request, these changes will be squashed when this pull request in integrated. If this is your intention, then please ignore this message. If you want to preserve the commit structure, you must change the title of this pull request to Merge <project>:<branch> where <project> is the name of another project in the OpenJDK organization (for example Merge jdk:master).

@dcubed-ojdk
Copy link
Member Author

@dholmes-ora - Thanks for the review. I updated the comments and switched
from java_lang_Thread::set_thread() to release_set_thread() in the second
location.

@dcubed-ojdk
Copy link
Member Author

This fix was tested with Mach5 Tier[1-8] when it was part of:
#13519

and is also being tested with Mach5 Tier[1-8] combined with
the fix from JDK-8307067 and what remains in JDK-8305670.

@dcubed-ojdk
Copy link
Member Author

I suppose there isn't any way to give @robehn credit for his reviews when this
fix was part of #13519.

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.

Updates look good and have a nice consistency! Thanks.

@dcubed-ojdk
Copy link
Member Author

@dholmes-ora - thanks for the review.

Mach5 Tier[1-8] testing of v05 results look great.

@dcubed-ojdk
Copy link
Member Author

@robehn - Any chance you are around for a re-review?
@coleenp - Any chance you can review this part since you already reviewed JDK-8307067?
@apangin - You looked at this fix when it was part of #13519. Any chance you can take another look?

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.

Looks good, thanks!

@apangin
Copy link

apangin commented May 4, 2023

Looks good. I only wonder if we can always use release_set_thread and remove plain set_thread entirely to avoid confusion.

@dcubed-ojdk
Copy link
Member Author

@robehn and @apangin - thanks for the re-reviews!

@apangin:

I only wonder if we can always use release_set_thread and remove plain set_thread entirely to avoid confusion.

I think I would prefer to leave that to another PR instead of this one.

@dcubed-ojdk dcubed-ojdk changed the base branch from pr/13704 to master May 13, 2023 14:39
@openjdk
Copy link

openjdk bot commented May 13, 2023

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

8307068: store a JavaThread* in the java.lang.Thread object after the JavaThread* is added to the main ThreadsList

Reviewed-by: dholmes, rehn, apangin

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

  • e54051a: 8307935: Class space argument processing can be simplified
  • 46e3d24: 8155191: Specify that SecureRandom.nextBytes(byte[]) throws NullPointerException when byte array is null
  • 3bf3876: 8307297: Move some DnD tests to open
  • d8afc7b: 8300204: Sealed-class hierarchy graph missing nodes
  • 38838b3: 8307480: Improve SA "transported core" documentation for windows
  • 9842ff4: 8306607: Apply 80-column output to javac supported version output
  • d809823: 8306471: Add virtual threads support to JDWP ThreadReference.Stop and JDI ThreadReference.stop()
  • 4441a23: 6714245: [Col] Collator - Faster Comparison for identical strings.
  • a284920: 8168469: Memory leak in JceSecurity
  • 7455bb2: 8308015: Syntax of "import static" is incorrect in com.sun.source.tree.ImportTree.java
  • ... and 19 more: https://git.openjdk.org/jdk/compare/54c06d2d915e57d822136b403ea7a7675325d6fb...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 May 13, 2023
@dcubed-ojdk
Copy link
Member Author

/integrate

@openjdk
Copy link

openjdk bot commented May 13, 2023

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

  • 5e26e64: 8307067: remove broken EnableThreadSMRExtraValidityChecks option
  • e54051a: 8307935: Class space argument processing can be simplified
  • 46e3d24: 8155191: Specify that SecureRandom.nextBytes(byte[]) throws NullPointerException when byte array is null
  • 3bf3876: 8307297: Move some DnD tests to open
  • d8afc7b: 8300204: Sealed-class hierarchy graph missing nodes
  • 38838b3: 8307480: Improve SA "transported core" documentation for windows
  • 9842ff4: 8306607: Apply 80-column output to javac supported version output
  • d809823: 8306471: Add virtual threads support to JDWP ThreadReference.Stop and JDI ThreadReference.stop()
  • 4441a23: 6714245: [Col] Collator - Faster Comparison for identical strings.
  • a284920: 8168469: Memory leak in JceSecurity
  • ... and 20 more: https://git.openjdk.org/jdk/compare/54c06d2d915e57d822136b403ea7a7675325d6fb...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented May 13, 2023

@dcubed-ojdk Pushed as commit ceca198.

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

@dcubed-ojdk dcubed-ojdk deleted the JDK-8307068 branch June 9, 2023 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot-runtime hotspot-runtime-dev@openjdk.org integrated Pull request has been integrated
4 participants