8322818: Thread::getStackTrace can fail with InternalError if virtual thread is timed-parked when pinned

Reviewed-by: pchilanomate
This commit is contained in:
Alan Bateman 2024-01-04 05:59:52 +00:00
parent 755722ced6
commit 4db7a1c3bb
2 changed files with 78 additions and 3 deletions

View file

@ -975,12 +975,12 @@ final class VirtualThread extends BaseVirtualThread {
* Returns null if the thread is mounted or in transition.
*/
private StackTraceElement[] tryGetStackTrace() {
int initialState = state();
int initialState = state() & ~SUSPENDED;
switch (initialState) {
case NEW, STARTED, TERMINATED -> {
return new StackTraceElement[0]; // unmounted, empty stack
}
case RUNNING, PINNED -> {
case RUNNING, PINNED, TIMED_PINNED -> {
return null; // mounted
}
case PARKED, TIMED_PARKED -> {
@ -992,7 +992,7 @@ final class VirtualThread extends BaseVirtualThread {
case PARKING, TIMED_PARKING, YIELDING -> {
return null; // in transition
}
default -> throw new InternalError();
default -> throw new InternalError("" + initialState);
}
// thread is unmounted, prevent it from continuing