Skip to content

Commit 5e544f1

Browse files
author
Serguei Spitsyn
committed
8329491: GetThreadListStackTraces function should use JvmtiHandshake
Reviewed-by: pchilanomate, lmesnik
1 parent 643dd48 commit 5e544f1

File tree

3 files changed

+24
-26
lines changed

3 files changed

+24
-26
lines changed

src/hotspot/share/prims/jvmtiEnv.cpp

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1678,39 +1678,22 @@ JvmtiEnv::GetAllStackTraces(jint max_frame_count, jvmtiStackInfo** stack_info_pt
16781678
jvmtiError
16791679
JvmtiEnv::GetThreadListStackTraces(jint thread_count, const jthread* thread_list, jint max_frame_count, jvmtiStackInfo** stack_info_ptr) {
16801680
jvmtiError err = JVMTI_ERROR_NONE;
1681-
JvmtiVTMSTransitionDisabler disabler;
16821681

16831682
if (thread_count == 1) {
1684-
16851683
// Use direct handshake if we need to get only one stack trace.
16861684
JavaThread *current_thread = JavaThread::current();
1687-
ThreadsListHandle tlh(current_thread);
16881685

16891686
jthread thread = thread_list[0];
1690-
JavaThread *java_thread;
1691-
oop thread_obj = nullptr;
1692-
err = get_threadOop_and_JavaThread(tlh.list(), thread, &java_thread, &thread_obj);
1693-
if (err != JVMTI_ERROR_NONE) {
1694-
return err;
1695-
}
1696-
1697-
if (java_lang_VirtualThread::is_instance(thread_obj) && java_thread == nullptr) {
1698-
// Target virtual thread is unmounted.
1699-
ResourceMark rm(current_thread);
1700-
MultipleStackTracesCollector collector(this, max_frame_count);
1701-
collector.fill_frames(thread, java_thread, thread_obj);
1702-
collector.allocate_and_fill_stacks(/* thread_count */ 1);
1703-
*stack_info_ptr = collector.stack_info();
1704-
return collector.result();
1705-
}
17061687

17071688
GetSingleStackTraceClosure op(this, current_thread, thread, max_frame_count);
1708-
Handshake::execute(&op, &tlh, java_thread);
1689+
JvmtiHandshake::execute(&op, thread);
17091690
err = op.result();
17101691
if (err == JVMTI_ERROR_NONE) {
17111692
*stack_info_ptr = op.stack_info();
17121693
}
17131694
} else {
1695+
JvmtiVTMSTransitionDisabler disabler;
1696+
17141697
// JVMTI get stack traces at safepoint.
17151698
VM_GetThreadListStackTraces op(this, thread_count, thread_list, max_frame_count);
17161699
VMThread::execute(&op);

src/hotspot/share/prims/jvmtiEnvBase.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2053,17 +2053,30 @@ VM_GetThreadListStackTraces::doit() {
20532053
}
20542054

20552055
void
2056-
GetSingleStackTraceClosure::do_thread(Thread *target) {
2057-
JavaThread *jt = JavaThread::cast(target);
2056+
GetSingleStackTraceClosure::doit() {
2057+
JavaThread *jt = _target_jt;
20582058
oop thread_oop = JNIHandles::resolve_external_guard(_jthread);
20592059

2060-
if (!jt->is_exiting() && thread_oop != nullptr) {
2060+
if ((jt == nullptr || !jt->is_exiting()) && thread_oop != nullptr) {
20612061
ResourceMark rm;
20622062
_collector.fill_frames(_jthread, jt, thread_oop);
20632063
_collector.allocate_and_fill_stacks(1);
2064+
set_result(_collector.result());
20642065
}
20652066
}
20662067

2068+
void
2069+
GetSingleStackTraceClosure::do_thread(Thread *target) {
2070+
assert(_target_jt == JavaThread::cast(target), "sanity check");
2071+
doit();
2072+
}
2073+
2074+
void
2075+
GetSingleStackTraceClosure::do_vthread(Handle target_h) {
2076+
assert(_target_jt == nullptr || _target_jt->vthread() == target_h(), "sanity check");
2077+
doit();
2078+
}
2079+
20672080
void
20682081
VM_GetAllStackTraces::doit() {
20692082
assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");

src/hotspot/share/prims/jvmtiEnvBase.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ class VM_GetThreadListStackTraces : public VM_Operation {
724724
};
725725

726726
// HandshakeClosure to get single stack trace.
727-
class GetSingleStackTraceClosure : public HandshakeClosure {
727+
class GetSingleStackTraceClosure : public JvmtiUnitedHandshakeClosure {
728728
private:
729729
JavaThread *_calling_thread;
730730
jthread _jthread;
@@ -733,14 +733,16 @@ class GetSingleStackTraceClosure : public HandshakeClosure {
733733
public:
734734
GetSingleStackTraceClosure(JvmtiEnv *env, JavaThread *calling_thread,
735735
jthread thread, jint max_frame_count)
736-
: HandshakeClosure("GetSingleStackTrace"),
736+
: JvmtiUnitedHandshakeClosure("GetSingleStackTrace"),
737737
_calling_thread(calling_thread),
738738
_jthread(thread),
739739
_collector(env, max_frame_count) {
740740
}
741741
void do_thread(Thread *target);
742+
void do_vthread(Handle target_h);
743+
void doit();
742744
jvmtiStackInfo *stack_info() { return _collector.stack_info(); }
743-
jvmtiError result() { return _collector.result(); }
745+
jvmtiError result() { return _result; }
744746
};
745747

746748
// HandshakeClosure to count stack frames.

0 commit comments

Comments
 (0)