JDK-8322818 : Thread::getStackTrace can fail with InternalError if virtual thread is timed-parked when pinned
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 22,23
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2024-01-02
  • Updated: 2024-07-25
  • Resolved: 2024-01-04
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 21 JDK 22 JDK 23
21.0.4-oracleFixed 22Fixed 23 b05Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Description
VirtualThread::tryGetStackTrace needs to handle TIMED_PINNED. If Thread::getStackTrace is called on a virtual Thread goes quickly from unmounted to a timed-park-while-pinned when getStackTrace will fail with:

java.lang.InternalError
	at java.base/java.lang.VirtualThread.tryGetStackTrace(VirtualThread.java:995)
	at java.base/java.lang.VirtualThread.asyncGetStackTrace(VirtualThread.java:965)
	at java.base/java.lang.Thread.getStackTrace(Thread.java:2376)
	at GetStackTraceALotWhenPinned.main(GetStackTraceALotWhenPinned.java:72)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at com.sun.javatest.regtest.agent.MainActionHelper$AgentVMRunnable.run(MainActionHelper.java:333)
	at java.base/java.lang.Thread.run(Thread.java:1570)

This is a regression since JDK-8312498, needs a stress test to provoke this scenario.
Comments
[jdk21u-fix-request] Approval Request from Aleksey Shipilëv Fixes the bug introduced by JDK-8312498. In mainline since Jan 2023. Has two additional follow-ups: JDK-8323002 and JDK-8323296. The fix is part of large atomic change, see 21u PR.
15-02-2024

A pull request was submitted for review. URL: https://git.openjdk.org/jdk21u-dev/pull/245 Date: 2024-02-08 11:17:02 +0000
15-02-2024

A pull request was submitted for review. URL: https://git.openjdk.org/jdk22/pull/72 Date: 2024-01-13 18:08:03 +0000
15-01-2024

Changeset: 4db7a1c3 Author: Alan Bateman <alanb@openjdk.org> Date: 2024-01-04 05:59:52 +0000 URL: https://git.openjdk.org/jdk/commit/4db7a1c3bb6b56cc7416aa27350406da27fe04a8
04-01-2024

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/17217 Date: 2024-01-02 08:55:37 +0000
02-01-2024