Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
JVMTI GetThreadState update for virtual threads
- Loading branch information
|
@@ -587,6 +587,8 @@ class java_lang_VirtualThread : AllStatic { |
|
|
static int _state_offset; |
|
|
// keep in sync with java.lang.VirtualThread |
|
|
static int _jfrTraceId_offset; |
|
|
|
|
|
public: |
|
|
enum { |
|
|
NEW = 0, |
|
|
STARTED = 1, |
|
@@ -598,7 +600,6 @@ class java_lang_VirtualThread : AllStatic { |
|
|
WALKINGSTACK = 51, |
|
|
TERMINATED = 99, |
|
|
}; |
|
|
public: |
|
|
static void compute_offsets(); |
|
|
static void serialize_offsets(SerializeClosure* f) NOT_CDS_RETURN; |
|
|
|
|
|
|
@@ -924,12 +924,21 @@ JvmtiEnv::GetThreadState(jthread thread, jint* thread_state_ptr) { |
|
|
return JVMTI_ERROR_MUST_POSSESS_CAPABILITY; |
|
|
} |
|
|
jshort vthread_state = java_lang_VirtualThread::state(thread_oop); |
|
|
jint state = (jint) java_lang_VirtualThread::map_state_to_thread_status(vthread_state); |
|
|
if (java_lang_Thread::interrupted(thread_oop)) { |
|
|
state |= JVMTI_THREAD_STATE_INTERRUPTED; |
|
|
|
|
|
if (vthread_state != java_lang_VirtualThread::RUNNING) { |
|
|
jint state = (jint) java_lang_VirtualThread::map_state_to_thread_status(vthread_state); |
|
|
if (java_lang_Thread::interrupted(thread_oop)) { |
|
|
state |= JVMTI_THREAD_STATE_INTERRUPTED; |
|
|
} |
|
|
*thread_state_ptr = state; |
|
|
return JVMTI_ERROR_NONE; |
|
|
} |
|
|
*thread_state_ptr = state; |
|
|
return JVMTI_ERROR_NONE; |
|
|
|
|
|
// Need a coordination with carrier thread and state recheck in a VM op. |
|
|
VM_VirtualThreadGetThreadState op(Handle(current_thread, thread_oop), thread_state_ptr); |
|
|
VMThread::execute(&op); |
|
|
|
|
|
return op.result(); |
|
|
} |
|
|
|
|
|
// get most state bits |
|
|
|
@@ -1802,3 +1802,22 @@ VM_VirtualThreadGetFrameLocation::doit() { |
|
|
_result = ((JvmtiEnvBase*)_env)->get_frame_location(_vthread_h(), _depth, |
|
|
_method_ptr, _location_ptr); |
|
|
} |
|
|
|
|
|
void |
|
|
VM_VirtualThreadGetThreadState::doit() { |
|
|
jshort vthread_state = java_lang_VirtualThread::state(_vthread_h()); |
|
|
oop carrier_thread_oop = java_lang_VirtualThread::carrier_thread(_vthread_h()); |
|
|
jint state; |
|
|
|
|
|
if (vthread_state == java_lang_VirtualThread::RUNNING && carrier_thread_oop != NULL) { |
|
|
state = java_lang_Thread::get_thread_status(carrier_thread_oop); |
|
|
} else { |
|
|
state = (jint) java_lang_VirtualThread::map_state_to_thread_status(vthread_state); |
|
|
} |
|
|
if (java_lang_Thread::interrupted(_vthread_h())) { |
|
|
state |= JVMTI_THREAD_STATE_INTERRUPTED; |
|
|
} |
|
|
*_state_ptr = state; |
|
|
_result = JVMTI_ERROR_NONE; |
|
|
} |
|
|
|
|
@@ -744,6 +744,24 @@ class VM_VirtualThreadGetFrameLocation : public VM_Operation { |
|
|
void doit(); |
|
|
}; |
|
|
|
|
|
// VM operation get to virtual thread state at safepoint. |
|
|
class VM_VirtualThreadGetThreadState : public VM_Operation { |
|
|
private: |
|
|
Handle _vthread_h; |
|
|
jint *_state_ptr; |
|
|
jvmtiError _result; |
|
|
|
|
|
public: |
|
|
VM_VirtualThreadGetThreadState(Handle vthread_h, jint *state_ptr) { |
|
|
_vthread_h = vthread_h; |
|
|
_state_ptr = state_ptr; |
|
|
_result = JVMTI_ERROR_NONE; |
|
|
} |
|
|
VMOp_Type type() const { return VMOp_VirtualThreadGetThreadState; } |
|
|
jvmtiError result() { return _result; } |
|
|
void doit(); |
|
|
}; |
|
|
|
|
|
|
|
|
// ResourceTracker |
|
|
// |
|
|
|
@@ -93,6 +93,7 @@ |
|
|
template(VirtualThreadGetCurrentContendedMonitor) \ |
|
|
template(VirtualThreadGetOwnedMonitorInfo) \ |
|
|
template(VirtualThreadGetThread) \ |
|
|
template(VirtualThreadGetThreadState) \ |
|
|
template(VirtualThreadGetStackTrace) \ |
|
|
template(VirtualThreadGetFrameCount) \ |
|
|
template(VirtualThreadGetFrameLocation) \ |
|
|