Skip to content

Commit

Permalink
8315373: Change VirtualThread to unmount after freezing, re-mount bef…
Browse files Browse the repository at this point in the history
…ore thawing

8312498: Thread::getState and JVM TI GetThreadState should return TIMED_WAITING virtual thread is timed parked
8312777: notifyJvmtiMount before notifyJvmtiUnmount
8321270: Virtual Thread.yield consumes parking permit
8322818: Thread::getStackTrace can fail with InternalError if virtual thread is timed-parked when pinned
8323002: test/jdk/java/lang/Thread/virtual/stress/GetStackTraceALotWhenPinned.java times out on macosx-x64
8323296: java/lang/Thread/virtual/stress/GetStackTraceALotWhenPinned.java#id1 timed out
8316924: java/lang/Thread/virtual/stress/ParkALot.java times out

Backport-of: 9a83d55887e5e3a0a2e1e020c6ccb91604672358
  • Loading branch information
shipilev committed Feb 28, 2024
1 parent cea29fe commit 3eb5517
Show file tree
Hide file tree
Showing 13 changed files with 1,102 additions and 285 deletions.
28 changes: 16 additions & 12 deletions src/hotspot/share/classfile/javaClasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1986,24 +1986,28 @@ int java_lang_VirtualThread::state(oop vthread) {

JavaThreadStatus java_lang_VirtualThread::map_state_to_thread_status(int state) {
JavaThreadStatus status = JavaThreadStatus::NEW;
switch (state) {
case NEW :
switch (state & ~SUSPENDED) {
case NEW:
status = JavaThreadStatus::NEW;
break;
case STARTED :
case RUNNABLE :
case RUNNABLE_SUSPENDED :
case RUNNING :
case PARKING :
case YIELDING :
case STARTED:
case RUNNING:
case PARKING:
case TIMED_PARKING:
case UNPARKED:
case YIELDING:
case YIELDED:
status = JavaThreadStatus::RUNNABLE;
break;
case PARKED :
case PARKED_SUSPENDED :
case PINNED :
case PARKED:
case PINNED:
status = JavaThreadStatus::PARKED;
break;
case TERMINATED :
case TIMED_PARKED:
case TIMED_PINNED:
status = JavaThreadStatus::PARKED_TIMED;
break;
case TERMINATED:
status = JavaThreadStatus::TERMINATED;
break;
default:
Expand Down
30 changes: 16 additions & 14 deletions src/hotspot/share/classfile/javaClasses.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -519,20 +519,22 @@ class java_lang_VirtualThread : AllStatic {
JFR_ONLY(static int _jfr_epoch_offset;)
public:
enum {
NEW = 0,
STARTED = 1,
RUNNABLE = 2,
RUNNING = 3,
PARKING = 4,
PARKED = 5,
PINNED = 6,
YIELDING = 7,
TERMINATED = 99,

// can be suspended from scheduling when unmounted
SUSPENDED = 1 << 8,
RUNNABLE_SUSPENDED = (RUNNABLE | SUSPENDED),
PARKED_SUSPENDED = (PARKED | SUSPENDED)
NEW = 0,
STARTED = 1,
RUNNING = 2,
PARKING = 3,
PARKED = 4,
PINNED = 5,
TIMED_PARKING = 6,
TIMED_PARKED = 7,
TIMED_PINNED = 8,
UNPARKED = 9,
YIELDING = 10,
YIELDED = 11,
TERMINATED = 99,

// additional state bits
SUSPENDED = 1 << 8, // suspended when unmounted
};

static void compute_offsets();
Expand Down
7 changes: 4 additions & 3 deletions src/hotspot/share/jfr/recorder/stacktrace/jfrStackTrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ void JfrStackFrame::write(JfrCheckpointWriter& cpw) const {

class JfrVframeStream : public vframeStreamCommon {
private:
bool _vthread;
const ContinuationEntry* _cont_entry;
bool _async_mode;
bool _vthread;
bool step_to_sender();
void next_frame();
public:
Expand All @@ -165,8 +165,9 @@ JfrVframeStream::JfrVframeStream(JavaThread* jt, const frame& fr, bool stop_at_j
RegisterMap::UpdateMap::skip,
RegisterMap::ProcessFrames::skip,
walk_continuation(jt))),
_cont_entry(JfrThreadLocal::is_vthread(jt) ? jt->last_continuation() : nullptr),
_async_mode(async_mode), _vthread(JfrThreadLocal::is_vthread(jt)) {
_vthread(JfrThreadLocal::is_vthread(jt)),
_cont_entry(_vthread ? jt->last_continuation() : nullptr),
_async_mode(async_mode) {
assert(!_vthread || _cont_entry != nullptr, "invariant");
_reg_map.set_async(async_mode);
_frame = fr;
Expand Down
9 changes: 6 additions & 3 deletions src/hotspot/share/jfr/support/jfrThreadLocal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,11 +395,14 @@ traceid JfrThreadLocal::thread_id(const Thread* t) {
return t->jfr_thread_local()->_thread_id_alias;
}
JfrThreadLocal* const tl = t->jfr_thread_local();
if (!t->is_Java_thread() || !Atomic::load_acquire(&tl->_vthread)) {
if (!t->is_Java_thread()) {
return jvm_thread_id(t, tl);
}
// virtual thread
const JavaThread* jt = JavaThread::cast(t);
if (!is_vthread(jt)) {
return jvm_thread_id(t, tl);
}
// virtual thread
const traceid tid = vthread_id(jt);
assert(tid != 0, "invariant");
if (!tl->is_vthread_excluded()) {
Expand Down Expand Up @@ -456,7 +459,7 @@ traceid JfrThreadLocal::jvm_thread_id(const Thread* t) {

bool JfrThreadLocal::is_vthread(const JavaThread* jt) {
assert(jt != nullptr, "invariant");
return Atomic::load_acquire(&jt->jfr_thread_local()->_vthread);
return Atomic::load_acquire(&jt->jfr_thread_local()->_vthread) && jt->last_continuation() != nullptr;
}

inline bool is_virtual(const JavaThread* jt, oop thread) {
Expand Down
Loading

1 comment on commit 3eb5517

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

Please sign in to comment.