RFR: 8306324: StopThread results in thread being marked as interrupted, leading to unexpected InterruptedException [v2]

Serguei Spitsyn sspitsyn at openjdk.org
Mon Jul 28 06:38:36 UTC 2025


> If JVMTI `StopThread` is done when the thread is in certain various states (but not all states), after the `async` exception is delivered and handled, hotspot leaves the thread's `interrupted` flag set. The end result is the next time the thread does something like `Thread.sleep()`, it will immediately get an `InterruptedException`.
> 
> The fix is to clear the `interrupted` flag in the `JavaThread::handle_async_exception()` after an `async` pending exception has been set to be thrown with the `set_pending_exception()`.
> 
> There are a couple of concerns with this fix which would be nice to sort out with reviewers:
> 1.  The proposed fix may clear the interrupt state when it was already set prior to the issuing of the `StopThread()` (this concern was raised by @dholmes-ora in a comment of this JBS issue)
> 2.  The impacted code path is shared between the class `InstallAsyncExceptionHandshakeClosure` used by the JVMTI `StopThread` implementation and the class `ScopedAsyncExceptionHandshakeClosure` used by the `ScopedMemoryAccess`
> 
> I feel that clearing the `interrupted` flag byt the `JavaThread::handle_async_exception()` is a right thing to do even though it was set before the call to `JavaThread::install_async_exception()`. Also, it has to be done for both `StopThread` and `ScopedMemoryAccess`.
> 
> The fix also includes minor tweaks of the test `StopThreadTest` to make the issue reproducible with it.
> 
> Testing:
>  - Mach5 tiers 1-6 are passed
>  - Ran the updated reproducer test `hotspot/jtreg/serviceability/jvmti/vthread/StopThreadTest`

Serguei Spitsyn has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains two additional commits since the last revision:

 - Merge
 - 8306324: StopThread results in thread being marked as interrupted, leading to unexpected InterruptedException

-------------

Changes:
  - all: https://git.openjdk.org/jdk/pull/26365/files
  - new: https://git.openjdk.org/jdk/pull/26365/files/cd235460..8338fb55

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=26365&range=01
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=26365&range=00-01

  Stats: 14768 lines in 435 files changed: 7261 ins; 5653 del; 1854 mod
  Patch: https://git.openjdk.org/jdk/pull/26365.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/26365/head:pull/26365

PR: https://git.openjdk.org/jdk/pull/26365


More information about the serviceability-dev mailing list