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

8297168: Provide a bulk OopHandle release mechanism with the ServiceThread #11254

Closed

Conversation

dholmes-ora
Copy link
Member

@dholmes-ora dholmes-ora commented Nov 21, 2022

When a JavaThread terminates it has to release all OopHandles that it uses. This can't be done by the thread itself due to timing issues, so it is handed-off to the ServiceThread to do it - ref JDK-8244997.

Initially there was only one OopHandle to handle - that of the threadObj, but since Loom there are another 3 OopHandles to process. The existing logic does the hand-off one OopHandle at a time but that is a potential synchronization bottleneck because each hand-off acquires the ServiceLock, enqueues the OopHandle, issues a notify to (potentially) wakeup the ServiceThread and then releases the ServiceLock. This can lead to high contention on the ServiceLock and also bad scheduling interactions with the ServiceThread.

This PR contains two commits. The first simply changes the API so that we pass the target JavaThread so that all 4 OopHandles can be extracted in one call. The second commit looks at streamlining things further by consolidating into a single OopHandleList instance.

As ServiceThread is a subclass of JavaThread` I wasn't concerned about it having detailed knowledge of the JavaThread implementation.

Testing:

  • tiers 1-3
  • checked still no memory leak (ref JDK-8296463)

Thanks.


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-8297168: Provide a bulk OopHandle release mechanism with the ServiceThread

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 11254

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

Using diff file

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

@bridgekeeper
Copy link

bridgekeeper bot commented Nov 21, 2022

👋 Welcome back dholmes! 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 rfr Pull request is ready for review label Nov 21, 2022
@openjdk
Copy link

openjdk bot commented Nov 21, 2022

@dholmes-ora The following label will be automatically applied to this pull request:

  • hotspot-runtime

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 hotspot-runtime hotspot-runtime-dev@openjdk.org label Nov 21, 2022
@mlbridge
Copy link

mlbridge bot commented Nov 21, 2022

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.

Looks fine!

src/hotspot/share/runtime/serviceThread.cpp Outdated Show resolved Hide resolved
src/hotspot/share/runtime/serviceThread.cpp Outdated Show resolved Hide resolved
@openjdk
Copy link

openjdk bot commented Nov 21, 2022

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

8297168: Provide a bulk OopHandle release mechanism with the ServiceThread

Reviewed-by: rehn, coleenp

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

  • 0696854: 8297299: SequenceInputStream should not use Vector
  • f0e99c6: 8297301: Cleanup unused methods in JavaUtilJarAccess
  • 392ac70: 8297211: Expensive fillInStackTrace operation in HttpURLConnection.getOutputStream0 when no content-length in response
  • 5a45c25: 8297164: Update troff man pages and CheckManPageOptions.java
  • f12710e: 8288047: Accelerate Poly1305 on x86_64 using AVX512 instructions
  • cd6a203: 8297348: make CONF=xxx should match if xxx is an exact match
  • 817e039: 8297352: configure should check pandoc version
  • 15e2e28: 8297353: Regenerated checked-in html files with new pandoc
  • b366d17: 8294073: Performance improvement for message digest implementations
  • 57f5cfd: 8296399: crlNumExtVal might be null inside X509CRLSelector::match
  • ... and 47 more: https://git.openjdk.org/jdk/compare/7b3984cb5a08edb99a233c28331c00b25457d664...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 Nov 21, 2022
@dholmes-ora
Copy link
Member Author

Thanks for the review @robehn .

Copy link
Contributor

@coleenp coleenp left a comment

Choose a reason for hiding this comment

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

So the choice was moving OopHandleList to a header file, or telling ServiceThread about these fields.
Since nothing else calls add_oop_handle_release , I really would have picked the former, and moved the declaration of OopHandleList to javaThread.hpp, constructed the list and passed it to the service thread in javathread.cpp.

Copy link
Contributor

@coleenp coleenp left a comment

Choose a reason for hiding this comment

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

I'm still not happy that ServiceThread knows all about JavaThread's fields that need to be cleared. But all of the OopHandleList code that's in serviceThread.cpp should be moved to javaThread.cpp. And two new functions added to JavaThread for ServiceThread to call (has_oop_handles_to_release and release_oop_handles).
I still think it's better since JavaThread is the only thing that has the necessity of deferred release.

@dholmes-ora
Copy link
Member Author

Thanks for looking at this @coleenp. As I said I didn't think ServiceThread knowing the details was an issue because ServiceThread is-a JavaThread. But sure I can move everything to JavaThread instead if that is preferable.

Copy link
Contributor

@coleenp coleenp 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! Thank you.

src/hotspot/share/runtime/javaThread.hpp Show resolved Hide resolved
@dholmes-ora
Copy link
Member Author

Thanks for the review @coleenp !

@dholmes-ora
Copy link
Member Author

Thanks again @robehn and @coleenp !

/integrate

@openjdk
Copy link

openjdk bot commented Nov 22, 2022

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

  • 4a544bb: 8297091: New langtools test jdk/javadoc/doclet/testValueTag/TestValueFormats.java fails on machines with unexpected number format
  • b6dddf4: 8239801: [macos] java/awt/Focus/UnaccessibleChoice/AccessibleChoiceTest.java fails
  • 260e4dc: 8295011: EC point multiplication improvement for secp256r1
  • fb6c992: 8296957: One more cast in SAFE_SIZE_NEW_ARRAY2
  • ccc6e16: 8291067: macOS should use O_CLOEXEC instead of FD_CLOEXEC
  • 0ac5b55: 8297349: Parallel: Use correct claim value for CLD oop iteration in PSScavengeCLDClosure
  • 932bf35: 8297333: Parallel: Remove unused methods in PCIterateMarkAndPushClosure
  • 42c2037: 8297382: Test fails to compile after JDK-8288047
  • 6d6046b: 8252713: jtreg time out of CtrlASCII.java seems to hang the Xserver.
  • 88957a7: 8297147: UnexpectedSourceImageSize test times out on slow machines when fastdebug is used
  • ... and 57 more: https://git.openjdk.org/jdk/compare/7b3984cb5a08edb99a233c28331c00b25457d664...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Nov 22, 2022

@dholmes-ora Pushed as commit a6c418e.

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

Copy link
Member

@dcubed-ojdk dcubed-ojdk left a comment

Choose a reason for hiding this comment

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

Thumbs up!

src/hotspot/share/runtime/javaThread.hpp Show resolved Hide resolved
private:
// List of OopHandles to be released - guarded by the Service_lock.
static OopHandleList* _oop_handle_list;
// Add our OopHandles to the list for the service thread to release.
Copy link
Member

Choose a reason for hiding this comment

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

nit - s/service thread/ServiceThread/

ServiceThread::add_oop_handle_release(_vthread);
ServiceThread::add_oop_handle_release(_jvmti_vthread);
ServiceThread::add_oop_handle_release(_extentLocalCache);
// Enqueue OopHandles for release by the service thread.
Copy link
Member

Choose a reason for hiding this comment

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

nit - s/service thread/ServiceThread/

@@ -52,7 +52,6 @@ class ServiceThread : public JavaThread {

// Add event to the service thread event queue.
Copy link
Member

Choose a reason for hiding this comment

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

nit - s/service thread/ServiceThread/
Not your typo, but since you're close by...

@dcubed-ojdk
Copy link
Member

Sorry I didn't submit my review on-time...

@dholmes-ora
Copy link
Member Author

Sorry I didn't submit my review on-time...

No problem Dan - thanks for taking a look. I think it is okay to talk about the "service thread" as a concept, just as we talk about "compiler threads" and "gc threads" without always using the classname ServiceThread.

@dholmes-ora dholmes-ora deleted the 8297168-oopHandle-release branch June 27, 2023 06:15
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