8286960: Test serviceability/jvmti/vthread/SuspendResume2 crashed: missing ThreadsListHandle in calling context

Reviewed-by: dholmes, pchilanomate, amenkov
This commit is contained in:
Serguei Spitsyn 2022-05-26 00:29:31 +00:00
parent 3d6d7b7e73
commit 94811c0dc7
2 changed files with 10 additions and 9 deletions

View file

@ -929,13 +929,13 @@ JvmtiEnv::GetAllThreads(jint* threads_count_ptr, jthread** threads_ptr) {
jvmtiError jvmtiError
JvmtiEnv::SuspendThread(jthread thread) { JvmtiEnv::SuspendThread(jthread thread) {
JavaThread* current = JavaThread::current(); JavaThread* current = JavaThread::current();
ThreadsListHandle tlh(current);
jvmtiError err; jvmtiError err;
JavaThread* java_thread = NULL; JavaThread* java_thread = NULL;
oop thread_oop = NULL; oop thread_oop = NULL;
{ {
JvmtiVTMSTransitionDisabler disabler(true); JvmtiVTMSTransitionDisabler disabler(true);
ThreadsListHandle tlh(current);
err = get_threadOop_and_JavaThread(tlh.list(), thread, &java_thread, &thread_oop); err = get_threadOop_and_JavaThread(tlh.list(), thread, &java_thread, &thread_oop);
if (err != JVMTI_ERROR_NONE) { if (err != JVMTI_ERROR_NONE) {
@ -960,13 +960,13 @@ JvmtiEnv::SuspendThread(jthread thread) {
jvmtiError jvmtiError
JvmtiEnv::SuspendThreadList(jint request_count, const jthread* request_list, jvmtiError* results) { JvmtiEnv::SuspendThreadList(jint request_count, const jthread* request_list, jvmtiError* results) {
JavaThread* current = JavaThread::current(); JavaThread* current = JavaThread::current();
ThreadsListHandle tlh(current);
HandleMark hm(current); HandleMark hm(current);
Handle self_tobj = Handle(current, NULL); Handle self_tobj = Handle(current, NULL);
int self_idx = -1; int self_idx = -1;
{ {
JvmtiVTMSTransitionDisabler disabler(true); JvmtiVTMSTransitionDisabler disabler(true);
ThreadsListHandle tlh(current);
for (int i = 0; i < request_count; i++) { for (int i = 0; i < request_count; i++) {
JavaThread *java_thread = NULL; JavaThread *java_thread = NULL;
@ -1013,19 +1013,20 @@ JvmtiEnv::SuspendAllVirtualThreads(jint except_count, const jthread* except_list
return JVMTI_ERROR_NONE; // Nothing to do when there are no virtual threads; return JVMTI_ERROR_NONE; // Nothing to do when there are no virtual threads;
} }
JavaThread* current = JavaThread::current(); JavaThread* current = JavaThread::current();
ThreadsListHandle tlh(current);
jvmtiError err = JvmtiEnvBase::check_thread_list(except_count, except_list);
if (err != JVMTI_ERROR_NONE) {
return err;
}
HandleMark hm(current); HandleMark hm(current);
Handle self_tobj = Handle(current, NULL); Handle self_tobj = Handle(current, NULL);
{ {
ResourceMark rm(current); ResourceMark rm(current);
JvmtiVTMSTransitionDisabler disabler(true); JvmtiVTMSTransitionDisabler disabler(true);
ThreadsListHandle tlh(current);
GrowableArray<jthread>* elist = new GrowableArray<jthread>(except_count); GrowableArray<jthread>* elist = new GrowableArray<jthread>(except_count);
jvmtiError err = JvmtiEnvBase::check_thread_list(except_count, except_list);
if (err != JVMTI_ERROR_NONE) {
return err;
}
// Collect threads from except_list for which resumed status must be restored. // Collect threads from except_list for which resumed status must be restored.
for (int idx = 0; idx < except_count; idx++) { for (int idx = 0; idx < except_count; idx++) {
jthread thread = except_list[idx]; jthread thread = except_list[idx];

View file

@ -1778,8 +1778,8 @@ bool JavaThread::java_suspend() {
assert(!is_VTMS_transition_disabler(), "no suspend allowed for VTMS transition disablers"); assert(!is_VTMS_transition_disabler(), "no suspend allowed for VTMS transition disablers");
#endif #endif
guarantee(Thread::is_JavaThread_protected_by_TLH(/* target */ this), guarantee(Thread::is_JavaThread_protected(/* target */ this),
"missing ThreadsListHandle in calling context."); "target JavaThread is not protected in calling context.");
return this->handshake_state()->suspend(); return this->handshake_state()->suspend();
} }