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

8290732: JNI DestroyJavaVM can start shutdown when one non-daemon thread remains #9803

Closed
wants to merge 5 commits into from

Conversation

dholmes-ora
Copy link
Member

@dholmes-ora dholmes-ora commented Aug 9, 2022

Please review this fix for a problem discovered by @stuart-marks in the course of examining the VM shutdown behaviour. The VM code assumed that only unattached threads called JNI's DestroyJavaVM and so they were always attached as non-daemon threads. But it is perfectly valid to call DestroyJavaVM from an already attached thread, which could be a daemon. The fix simply checks whether the caller is a daemon or not and adjusts the expected count of active threads to see. There is also an adjustment to the thread termination logic to also notify at the right time.

Thanks to @stuart-marks for the reproducer in JBS - the longest part of this by many hours was converting the test over the jtreg. :)

Testing:

  • the new test on all core platforms
  • tiers 1-3
    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-8290732: JNI DestroyJavaVM can start shutdown when one non-daemon thread remains

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 9803

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

Using diff file

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

@bridgekeeper
Copy link

bridgekeeper bot commented Aug 9, 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 Aug 9, 2022
@openjdk
Copy link

openjdk bot commented Aug 9, 2022

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

  • build
  • 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 build build-dev@openjdk.org labels Aug 9, 2022
@mlbridge
Copy link

mlbridge bot commented Aug 9, 2022

Webrevs

Copy link
Member

@tstuefe tstuefe left a comment

Choose a reason for hiding this comment

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

Hi David,

that was interesting. I always thought you have to detach before destroying the VM.

I looked into https://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/invocation.html and it says:

"Detaching from the VM: A native thread attached to the VM must call DetachCurrentThread() to detach itself before exiting."

Cheers, Thomas

test/hotspot/jtreg/runtime/jni/daemonDestroy/Main.java Outdated Show resolved Hide resolved
* @build Main
* @run main/native TestDaemonDestroy
* @run main/native TestDaemonDestroy daemon
*/
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 do two @test sections, you can give them speaking names(e.g. @test id=demon) and they can run in parallel.

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't think that was warranted/necessary here.

Copy link
Member

Choose a reason for hiding this comment

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

I disagree. Splitting the test leads causes better runtime (on my 24 core machine: 10.5 seconds vs 16 seconds). It also makes the jtr file easier to read, since it only contains one test. It also is simpler to run a selected test if you want to reproduce an error.

It is regrettable that splitting the test section causes too much duplication. Maybe we could improve the jtreg syntax in the future.

Copy link
Member Author

Choose a reason for hiding this comment

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

But you also have to duplicate the build instructions and building takes longer than execution on my systems (7 seconds versus 5) so if I had to pay for machine time I'd actually be worse off now!

Copy link
Member

Choose a reason for hiding this comment

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

Oh, you are right. That's unfortunate.

@dholmes-ora
Copy link
Member Author

Thanks for looking at this @tstuefe and @magicus

@stuart-marks
Copy link
Member

Thanks for fixing this. I'm glad my reproducer gave you a good start, but you had to do all the grunt work of error checking and jtreg conversion. :-) Things look reasonable to me, but I'm not too familiar with this code and with Hotspot testing, so I'll defer to other reviewers.

Copy link
Member

@tstuefe tstuefe 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.

@openjdk
Copy link

openjdk bot commented Aug 11, 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:

8290732: JNI DestroyJavaVM can start shutdown when one non-daemon thread remains

Reviewed-by: stuefe, rehn

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

  • 083e014: 8292233: Increase symtab hash table size
  • 45e5b31: 8292244: Remove unnecessary include directories
  • 9bfffa0: 8291945: Add OSInfo API for static OS information
  • bd58553: 8290833: Remove ConstantPoolCache::walk_entries_for_initialization()
  • 755ecf6: 8292153: x86: Represent Registers as values
  • dedc05c: 8291640: java/beans/XMLDecoder/8028054/Task.java should use the 3-arg Class.forName
  • 3d20a8b: 8291959: FileFontStrike#initNative does not properly initialize IG Table on Windows
  • a28ab7b: 8288568: Reduce runtime of java.security microbenchmarks
  • 7ea9ba1: 8292064: Convert java/lang/management/MemoryMXBean shell tests to java version
  • fc1d94e: 8292232: AIX build failure by JDK-8290840
  • ... and 53 more: https://git.openjdk.org/jdk/compare/8e2c006cd14905c06e8c2cc30f13de249d54ed79...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 Aug 11, 2022
Copy link
Member

@tstuefe tstuefe left a comment

Choose a reason for hiding this comment

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

Still good.

@dholmes-ora
Copy link
Member Author

Thanks @tstuefe !

Can I get second review please.

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.

Thanks!

@dholmes-ora
Copy link
Member Author

Thanks @robehn !

/integrate

@openjdk
Copy link

openjdk bot commented Aug 12, 2022

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

  • 083e014: 8292233: Increase symtab hash table size
  • 45e5b31: 8292244: Remove unnecessary include directories
  • 9bfffa0: 8291945: Add OSInfo API for static OS information
  • bd58553: 8290833: Remove ConstantPoolCache::walk_entries_for_initialization()
  • 755ecf6: 8292153: x86: Represent Registers as values
  • dedc05c: 8291640: java/beans/XMLDecoder/8028054/Task.java should use the 3-arg Class.forName
  • 3d20a8b: 8291959: FileFontStrike#initNative does not properly initialize IG Table on Windows
  • a28ab7b: 8288568: Reduce runtime of java.security microbenchmarks
  • 7ea9ba1: 8292064: Convert java/lang/management/MemoryMXBean shell tests to java version
  • fc1d94e: 8292232: AIX build failure by JDK-8290840
  • ... and 53 more: https://git.openjdk.org/jdk/compare/8e2c006cd14905c06e8c2cc30f13de249d54ed79...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Aug 12, 2022

@dholmes-ora Pushed as commit 6eb7c3a.

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

@dholmes-ora dholmes-ora deleted the 8290732-destroyJavaVM branch August 12, 2022 06:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build build-dev@openjdk.org hotspot-runtime hotspot-runtime-dev@openjdk.org integrated Pull request has been integrated
5 participants