From 8099035a83bb9de7a38acc39ab2a328ee6010b95 Mon Sep 17 00:00:00 2001 From: David Holmes Date: Mon, 14 Jul 2025 01:30:18 -0400 Subject: [PATCH 1/7] Adapt thread conversion routines to return (and protect) the carrier for virtual threads, and add a new oop variant. --- src/hotspot/share/runtime/threadSMR.cpp | 46 ++++++++++++++++++++----- src/hotspot/share/runtime/threadSMR.hpp | 27 +++++++++------ 2 files changed, 54 insertions(+), 19 deletions(-) diff --git a/src/hotspot/share/runtime/threadSMR.cpp b/src/hotspot/share/runtime/threadSMR.cpp index 631a7ed8d7973..4fd56a0c41b2e 100644 --- a/src/hotspot/share/runtime/threadSMR.cpp +++ b/src/hotspot/share/runtime/threadSMR.cpp @@ -789,12 +789,14 @@ ThreadsListHandle::~ThreadsListHandle() { // Convert an internal thread reference to a JavaThread found on the // associated ThreadsList. This ThreadsListHandle "protects" the -// returned JavaThread *. +// returned JavaThread *. If the jthread resolves to a virtual thread +// then the JavaThread * for its current carrier thread (if any) is +// returned via *jt_pp. // // If thread_oop_p is not null, then the caller wants to use the oop -// after this call so the oop is returned. On success, *jt_pp is set +// after this call so the oop is always returned. On success, *jt_pp is set // to the converted JavaThread * and true is returned. On error, -// returns false. +// returns false, and *jt_pp is unchanged. // bool ThreadsListHandle::cv_internal_thread_to_JavaThread(jobject jthread, JavaThread ** jt_pp, @@ -815,13 +817,41 @@ bool ThreadsListHandle::cv_internal_thread_to_JavaThread(jobject jthread, // the oop even if this function returns false. *thread_oop_p = thread_oop; } + return cv_thread_oop_to_JavaThread(thread_oop, jt_pp); +} + +// Convert a thread oop to a JavaThread found on the associated ThreadsList. +// This ThreadsListHandle "protects" the returned JavaThread *. If the oop +// is a virtual thread then the JavaThread * for its current carrier thread +// (if any) is returned via *jt_pp. +// On success, *jt_pp is set to the converted JavaThread * and true is returned. +// On error, returns false, and *jt_pp is unchanged. +// +bool ThreadsListHandle::cv_thread_oop_to_JavaThread(oop thread_oop, + JavaThread ** jt_pp) { + + assert(this->list() != nullptr, "must have a ThreadsList"); + assert(jt_pp != nullptr, "must have a return JavaThread pointer"); + assert(thread_oop->is_a(vmClasses::Thread_klass()), "must be a valid j.l.Thread oop"); - JavaThread *java_thread = java_lang_Thread::thread_acquire(thread_oop); + JavaThread* java_thread = java_lang_Thread::thread_acquire(thread_oop); if (java_thread == nullptr) { - // The java.lang.Thread does not contain a JavaThread* so it has not - // run enough to be put on a ThreadsList or it has exited enough to - // make it past ensure_join() where the JavaThread* is cleared. - return false; + if (!java_lang_VirtualThread::is_instance(thread_oop)) { + // The java.lang.Thread does not contain a JavaThread* so it has not + // run enough to be put on a ThreadsList or it has exited enough to + // make it past ensure_join() where the JavaThread* is cleared. + return false; + } else { + // For virtual thread's we need to extract the carrier's JavaThread - if any. + oop carrier_thread = java_lang_VirtualThread::carrier_thread(thread_oop); + if (carrier_thread != nullptr) { + java_thread = java_lang_Thread::thread(carrier_thread); + } + if (java_thread == nullptr) { + // Virtual thread was unbound, or else carrier has now terminated. + return false; + } + } } // Looks like a live JavaThread at this point. diff --git a/src/hotspot/share/runtime/threadSMR.hpp b/src/hotspot/share/runtime/threadSMR.hpp index a379e82058714..fdf4d4f034ed9 100644 --- a/src/hotspot/share/runtime/threadSMR.hpp +++ b/src/hotspot/share/runtime/threadSMR.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -46,7 +46,7 @@ class ThreadsList; // perform an operation on a target thread. // // There are several different ways to refer to java.lang.Thread objects -// so we have a few ways to get a protected JavaThread *: +// so we have a few ways to get a protected JavaThread*: // // JNI jobject example: // jobject jthread = ...; @@ -69,23 +69,27 @@ class ThreadsList; // } // : // do stuff with 'jt'... // -// JVM/TI oop example (this one should be very rare): +// Java oop example // oop thread_obj = ...; // : // JavaThread *jt = nullptr; // ThreadsListHandle tlh; -// jvmtiError err = JvmtiExport::cv_oop_to_JavaThread(tlh.list(), thread_obj, &jt); -// if (err != JVMTI_ERROR_NONE) { -// return err; +// bool is_alive = tlh.cv_thread_oop_to_JavaThread(thread_oop, &jt); +// if (is_alive) { +// : // do stuff with 'jt'... // } -// : // do stuff with 'jt'... // -// A JavaThread * that is included in the ThreadsList that is held by +// A JavaThread* that is included in the ThreadsList that is held by // a ThreadsListHandle is protected as long as the ThreadsListHandle -// remains in scope. The target JavaThread * may have logically exited, -// but that target JavaThread * will not be deleted until it is no +// remains in scope. The target JavaThread* may have logically exited, +// but that target JavaThread* will not be deleted until it is no // longer protected by a ThreadsListHandle. // +// Note that for virtual threads, we obtain a reference to the carrier JavaThread +// on which it is mounted (if any). It is up to the caller to prevent the virtual +// thread from changing its mounted status, or else account for it when acting on +// the carrier JavaThread. +// // SMR Support for the Threads class. // class ThreadsSMRSupport : AllStatic { @@ -318,7 +322,8 @@ class ThreadsListHandle : public StackObj { inline Iterator begin(); inline Iterator end(); - bool cv_internal_thread_to_JavaThread(jobject jthread, JavaThread ** jt_pp, oop * thread_oop_p); + bool cv_internal_thread_to_JavaThread(jobject jthread, JavaThread** jt_pp, oop* thread_oop_p); + bool cv_thread_oop_to_JavaThread(oop thread_oop, JavaThread** jt_pp); bool includes(JavaThread* p) { return list()->includes(p); From 4ed9035dd8ee84eca8f841ff59864e7d39c2f69d Mon Sep 17 00:00:00 2001 From: David Holmes Date: Mon, 14 Jul 2025 01:32:14 -0400 Subject: [PATCH 2/7] Adapt ThreadSnapshotFactory::get_thread_snapshot to use the new API --- src/hotspot/share/services/threadService.cpp | 69 ++++++++++---------- 1 file changed, 34 insertions(+), 35 deletions(-) diff --git a/src/hotspot/share/services/threadService.cpp b/src/hotspot/share/services/threadService.cpp index f30b0c170a69a..32bd1815c4154 100644 --- a/src/hotspot/share/services/threadService.cpp +++ b/src/hotspot/share/services/threadService.cpp @@ -1434,6 +1434,27 @@ int jdk_internal_vm_ThreadSnapshot::_locks_offset; int jdk_internal_vm_ThreadSnapshot::_blockerTypeOrdinal_offset; int jdk_internal_vm_ThreadSnapshot::_blockerObject_offset; +// wrapper to auto delete JvmtiVTMSTransitionDisabler +class TransitionDisabler { + JvmtiVTMSTransitionDisabler* _transition_disabler; + public: + TransitionDisabler(): _transition_disabler(nullptr) {} + ~TransitionDisabler() { + reset(); + } + // Invoke this when you know you have a virtual thread. + void init(jobject jthread) { + _transition_disabler = new (mtInternal) JvmtiVTMSTransitionDisabler(jthread); + } + // Manually re-enable transitions. + void reset() { + if (_transition_disabler != nullptr) { + delete _transition_disabler; + _transition_disabler = nullptr; + } + } +}; + oop ThreadSnapshotFactory::get_thread_snapshot(jobject jthread, TRAPS) { ThreadsListHandle tlh(THREAD); @@ -1441,46 +1462,22 @@ oop ThreadSnapshotFactory::get_thread_snapshot(jobject jthread, TRAPS) { HandleMark hm(THREAD); JavaThread* java_thread = nullptr; - oop thread_oop; - bool has_javathread = tlh.cv_internal_thread_to_JavaThread(jthread, &java_thread, &thread_oop); - assert((has_javathread && thread_oop != nullptr) || !has_javathread, "Missing Thread oop"); + oop thread_oop = JNIHandles::resolve_non_null(jthread); Handle thread_h(THREAD, thread_oop); bool is_virtual = java_lang_VirtualThread::is_instance(thread_h()); // Deals with null - if (!has_javathread && !is_virtual) { - return nullptr; // thread terminated so not of interest - } + TransitionDisabler transition_disabler; - // wrapper to auto delete JvmtiVTMSTransitionDisabler - class TransitionDisabler { - JvmtiVTMSTransitionDisabler* _transition_disabler; - public: - TransitionDisabler(): _transition_disabler(nullptr) {} - ~TransitionDisabler() { - reset(); - } - void init(jobject jthread) { - _transition_disabler = new (mtInternal) JvmtiVTMSTransitionDisabler(jthread); - } - void reset() { - if (_transition_disabler != nullptr) { - delete _transition_disabler; - _transition_disabler = nullptr; - } - } - } transition_disabler; - - Handle carrier_thread; if (is_virtual) { - // 1st need to disable mount/unmount transitions + // We must disable mount/unmount transitions transition_disabler.init(jthread); + } - carrier_thread = Handle(THREAD, java_lang_VirtualThread::carrier_thread(thread_h())); - if (carrier_thread != nullptr) { - java_thread = java_lang_Thread::thread(carrier_thread()); - } - } else { - java_thread = java_lang_Thread::thread(thread_h()); + bool has_javathread = tlh.cv_thread_oop_to_JavaThread(thread_oop, &java_thread); + assert((has_javathread && thread_oop != nullptr) || !has_javathread, "Missing Thread oop"); + + if (!has_javathread && !is_virtual) { + return nullptr; // thread terminated so not of interest } // Handshake with target @@ -1544,7 +1541,10 @@ oop ThreadSnapshotFactory::get_thread_snapshot(jobject jthread, TRAPS) { Handle snapshot = jdk_internal_vm_ThreadSnapshot::allocate(InstanceKlass::cast(snapshot_klass), CHECK_NULL); jdk_internal_vm_ThreadSnapshot::set_name(snapshot(), cl._thread_name.resolve()); jdk_internal_vm_ThreadSnapshot::set_thread_status(snapshot(), (int)cl._thread_status); - jdk_internal_vm_ThreadSnapshot::set_carrier_thread(snapshot(), carrier_thread()); + if (is_virtual) { + Handle carrier_thread = Handle(THREAD, java_lang_VirtualThread::carrier_thread(thread_h())); + jdk_internal_vm_ThreadSnapshot::set_carrier_thread(snapshot(), carrier_thread()); + } jdk_internal_vm_ThreadSnapshot::set_stack_trace(snapshot(), trace()); jdk_internal_vm_ThreadSnapshot::set_locks(snapshot(), locks()); if (!cl._blocker.is_empty()) { @@ -1554,4 +1554,3 @@ oop ThreadSnapshotFactory::get_thread_snapshot(jobject jthread, TRAPS) { } #endif // INCLUDE_JVMTI - From 9e135961b4e30208a0895b06bf948744fa1b8970 Mon Sep 17 00:00:00 2001 From: David Holmes Date: Mon, 14 Jul 2025 01:32:49 -0400 Subject: [PATCH 3/7] Remove unused JvmtiExport::cv_oop_to_JavaThread API --- src/hotspot/share/prims/jvmtiExport.cpp | 41 ------------------------- src/hotspot/share/prims/jvmtiExport.hpp | 2 -- 2 files changed, 43 deletions(-) diff --git a/src/hotspot/share/prims/jvmtiExport.cpp b/src/hotspot/share/prims/jvmtiExport.cpp index 10614f445d3d8..b98311b92f69b 100644 --- a/src/hotspot/share/prims/jvmtiExport.cpp +++ b/src/hotspot/share/prims/jvmtiExport.cpp @@ -859,47 +859,6 @@ JvmtiExport::cv_external_thread_to_JavaThread(ThreadsList * t_list, return JVMTI_ERROR_NONE; } -// Convert an oop to a JavaThread found on the specified ThreadsList. -// The ThreadsListHandle in the caller "protects" the returned -// JavaThread *. -// -// On success, *jt_pp is set to the converted JavaThread * and -// JVMTI_ERROR_NONE is returned. On error, returns various -// JVMTI_ERROR_* values. -// -jvmtiError -JvmtiExport::cv_oop_to_JavaThread(ThreadsList * t_list, oop thread_oop, - JavaThread ** jt_pp) { - assert(t_list != nullptr, "must have a ThreadsList"); - assert(thread_oop != nullptr, "must have an oop"); - assert(jt_pp != nullptr, "must have a return JavaThread pointer"); - - if (!thread_oop->is_a(vmClasses::Thread_klass())) { - // The oop is not a java.lang.Thread. - return JVMTI_ERROR_INVALID_THREAD; - } - // Looks like a java.lang.Thread oop at this point. - - JavaThread * java_thread = java_lang_Thread::thread(thread_oop); - if (java_thread == nullptr) { - // The java.lang.Thread does not contain a JavaThread * so it has - // not yet run or it has died. - return JVMTI_ERROR_THREAD_NOT_ALIVE; - } - // Looks like a live JavaThread at this point. - - if (!t_list->includes(java_thread)) { - // Not on the JavaThreads list so it is not alive. - return JVMTI_ERROR_THREAD_NOT_ALIVE; - } - - // Return a live JavaThread that is "protected" by the - // ThreadsListHandle in the caller. - *jt_pp = java_thread; - - return JVMTI_ERROR_NONE; -} - class JvmtiClassFileLoadHookPoster : public StackObj { private: Symbol* _h_name; diff --git a/src/hotspot/share/prims/jvmtiExport.hpp b/src/hotspot/share/prims/jvmtiExport.hpp index e47cd3d6363db..4f8c3016908d2 100644 --- a/src/hotspot/share/prims/jvmtiExport.hpp +++ b/src/hotspot/share/prims/jvmtiExport.hpp @@ -454,8 +454,6 @@ class JvmtiExport : public AllStatic { jthread thread, JavaThread ** jt_pp, oop * thread_oop_p); - static jvmtiError cv_oop_to_JavaThread(ThreadsList * t_list, oop thread_oop, - JavaThread ** jt_pp); }; // Support class used by JvmtiDynamicCodeEventCollector and others. It From 5d7eb807639fd38d50f99cc9189de12b04db6066 Mon Sep 17 00:00:00 2001 From: David Holmes Date: Mon, 21 Jul 2025 03:48:38 -0400 Subject: [PATCH 4/7] Revert "Adapt ThreadSnapshotFactory::get_thread_snapshot to use the new API" This reverts commit 4ed9035dd8ee84eca8f841ff59864e7d39c2f69d. --- src/hotspot/share/services/threadService.cpp | 69 ++++++++++---------- 1 file changed, 35 insertions(+), 34 deletions(-) diff --git a/src/hotspot/share/services/threadService.cpp b/src/hotspot/share/services/threadService.cpp index 32bd1815c4154..f30b0c170a69a 100644 --- a/src/hotspot/share/services/threadService.cpp +++ b/src/hotspot/share/services/threadService.cpp @@ -1434,27 +1434,6 @@ int jdk_internal_vm_ThreadSnapshot::_locks_offset; int jdk_internal_vm_ThreadSnapshot::_blockerTypeOrdinal_offset; int jdk_internal_vm_ThreadSnapshot::_blockerObject_offset; -// wrapper to auto delete JvmtiVTMSTransitionDisabler -class TransitionDisabler { - JvmtiVTMSTransitionDisabler* _transition_disabler; - public: - TransitionDisabler(): _transition_disabler(nullptr) {} - ~TransitionDisabler() { - reset(); - } - // Invoke this when you know you have a virtual thread. - void init(jobject jthread) { - _transition_disabler = new (mtInternal) JvmtiVTMSTransitionDisabler(jthread); - } - // Manually re-enable transitions. - void reset() { - if (_transition_disabler != nullptr) { - delete _transition_disabler; - _transition_disabler = nullptr; - } - } -}; - oop ThreadSnapshotFactory::get_thread_snapshot(jobject jthread, TRAPS) { ThreadsListHandle tlh(THREAD); @@ -1462,22 +1441,46 @@ oop ThreadSnapshotFactory::get_thread_snapshot(jobject jthread, TRAPS) { HandleMark hm(THREAD); JavaThread* java_thread = nullptr; - oop thread_oop = JNIHandles::resolve_non_null(jthread); + oop thread_oop; + bool has_javathread = tlh.cv_internal_thread_to_JavaThread(jthread, &java_thread, &thread_oop); + assert((has_javathread && thread_oop != nullptr) || !has_javathread, "Missing Thread oop"); Handle thread_h(THREAD, thread_oop); bool is_virtual = java_lang_VirtualThread::is_instance(thread_h()); // Deals with null - TransitionDisabler transition_disabler; + if (!has_javathread && !is_virtual) { + return nullptr; // thread terminated so not of interest + } + // wrapper to auto delete JvmtiVTMSTransitionDisabler + class TransitionDisabler { + JvmtiVTMSTransitionDisabler* _transition_disabler; + public: + TransitionDisabler(): _transition_disabler(nullptr) {} + ~TransitionDisabler() { + reset(); + } + void init(jobject jthread) { + _transition_disabler = new (mtInternal) JvmtiVTMSTransitionDisabler(jthread); + } + void reset() { + if (_transition_disabler != nullptr) { + delete _transition_disabler; + _transition_disabler = nullptr; + } + } + } transition_disabler; + + Handle carrier_thread; if (is_virtual) { - // We must disable mount/unmount transitions + // 1st need to disable mount/unmount transitions transition_disabler.init(jthread); - } - - bool has_javathread = tlh.cv_thread_oop_to_JavaThread(thread_oop, &java_thread); - assert((has_javathread && thread_oop != nullptr) || !has_javathread, "Missing Thread oop"); - if (!has_javathread && !is_virtual) { - return nullptr; // thread terminated so not of interest + carrier_thread = Handle(THREAD, java_lang_VirtualThread::carrier_thread(thread_h())); + if (carrier_thread != nullptr) { + java_thread = java_lang_Thread::thread(carrier_thread()); + } + } else { + java_thread = java_lang_Thread::thread(thread_h()); } // Handshake with target @@ -1541,10 +1544,7 @@ oop ThreadSnapshotFactory::get_thread_snapshot(jobject jthread, TRAPS) { Handle snapshot = jdk_internal_vm_ThreadSnapshot::allocate(InstanceKlass::cast(snapshot_klass), CHECK_NULL); jdk_internal_vm_ThreadSnapshot::set_name(snapshot(), cl._thread_name.resolve()); jdk_internal_vm_ThreadSnapshot::set_thread_status(snapshot(), (int)cl._thread_status); - if (is_virtual) { - Handle carrier_thread = Handle(THREAD, java_lang_VirtualThread::carrier_thread(thread_h())); - jdk_internal_vm_ThreadSnapshot::set_carrier_thread(snapshot(), carrier_thread()); - } + jdk_internal_vm_ThreadSnapshot::set_carrier_thread(snapshot(), carrier_thread()); jdk_internal_vm_ThreadSnapshot::set_stack_trace(snapshot(), trace()); jdk_internal_vm_ThreadSnapshot::set_locks(snapshot(), locks()); if (!cl._blocker.is_empty()) { @@ -1554,3 +1554,4 @@ oop ThreadSnapshotFactory::get_thread_snapshot(jobject jthread, TRAPS) { } #endif // INCLUDE_JVMTI + From a195fe227b11a1c5717ce1612988414962899054 Mon Sep 17 00:00:00 2001 From: David Holmes Date: Mon, 21 Jul 2025 04:16:45 -0400 Subject: [PATCH 5/7] Revert to simpler fix without new API --- src/hotspot/share/runtime/threadSMR.cpp | 20 ++------------------ src/hotspot/share/runtime/threadSMR.hpp | 15 ++------------- 2 files changed, 4 insertions(+), 31 deletions(-) diff --git a/src/hotspot/share/runtime/threadSMR.cpp b/src/hotspot/share/runtime/threadSMR.cpp index 4fd56a0c41b2e..4e5f9e4e8e758 100644 --- a/src/hotspot/share/runtime/threadSMR.cpp +++ b/src/hotspot/share/runtime/threadSMR.cpp @@ -817,24 +817,8 @@ bool ThreadsListHandle::cv_internal_thread_to_JavaThread(jobject jthread, // the oop even if this function returns false. *thread_oop_p = thread_oop; } - return cv_thread_oop_to_JavaThread(thread_oop, jt_pp); -} - -// Convert a thread oop to a JavaThread found on the associated ThreadsList. -// This ThreadsListHandle "protects" the returned JavaThread *. If the oop -// is a virtual thread then the JavaThread * for its current carrier thread -// (if any) is returned via *jt_pp. -// On success, *jt_pp is set to the converted JavaThread * and true is returned. -// On error, returns false, and *jt_pp is unchanged. -// -bool ThreadsListHandle::cv_thread_oop_to_JavaThread(oop thread_oop, - JavaThread ** jt_pp) { - - assert(this->list() != nullptr, "must have a ThreadsList"); - assert(jt_pp != nullptr, "must have a return JavaThread pointer"); - assert(thread_oop->is_a(vmClasses::Thread_klass()), "must be a valid j.l.Thread oop"); - JavaThread* java_thread = java_lang_Thread::thread_acquire(thread_oop); + JavaThread *java_thread = java_lang_Thread::thread_acquire(thread_oop); if (java_thread == nullptr) { if (!java_lang_VirtualThread::is_instance(thread_oop)) { // The java.lang.Thread does not contain a JavaThread* so it has not @@ -848,7 +832,7 @@ bool ThreadsListHandle::cv_thread_oop_to_JavaThread(oop thread_oop, java_thread = java_lang_Thread::thread(carrier_thread); } if (java_thread == nullptr) { - // Virtual thread was unbound, or else carrier has now terminated. + // Virtual thread was unmounted, or else carrier has now terminated. return false; } } diff --git a/src/hotspot/share/runtime/threadSMR.hpp b/src/hotspot/share/runtime/threadSMR.hpp index fdf4d4f034ed9..6351e456e24bc 100644 --- a/src/hotspot/share/runtime/threadSMR.hpp +++ b/src/hotspot/share/runtime/threadSMR.hpp @@ -45,8 +45,8 @@ class ThreadsList; // operation. It is no longer necessary to hold the Threads_lock to safely // perform an operation on a target thread. // -// There are several different ways to refer to java.lang.Thread objects -// so we have a few ways to get a protected JavaThread*: +// There two ways to refer to java.lang.Thread objects so we have two ways +// to get a protected JavaThread*: // // JNI jobject example: // jobject jthread = ...; @@ -69,16 +69,6 @@ class ThreadsList; // } // : // do stuff with 'jt'... // -// Java oop example -// oop thread_obj = ...; -// : -// JavaThread *jt = nullptr; -// ThreadsListHandle tlh; -// bool is_alive = tlh.cv_thread_oop_to_JavaThread(thread_oop, &jt); -// if (is_alive) { -// : // do stuff with 'jt'... -// } -// // A JavaThread* that is included in the ThreadsList that is held by // a ThreadsListHandle is protected as long as the ThreadsListHandle // remains in scope. The target JavaThread* may have logically exited, @@ -323,7 +313,6 @@ class ThreadsListHandle : public StackObj { inline Iterator end(); bool cv_internal_thread_to_JavaThread(jobject jthread, JavaThread** jt_pp, oop* thread_oop_p); - bool cv_thread_oop_to_JavaThread(oop thread_oop, JavaThread** jt_pp); bool includes(JavaThread* p) { return list()->includes(p); From 820f26e4b93673c0d0b68f4dd816addb5c6f723e Mon Sep 17 00:00:00 2001 From: David Holmes Date: Tue, 22 Jul 2025 01:42:31 -0400 Subject: [PATCH 6/7] Move comment --- src/hotspot/share/runtime/threadSMR.cpp | 10 +++++++--- src/hotspot/share/runtime/threadSMR.hpp | 5 ----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/hotspot/share/runtime/threadSMR.cpp b/src/hotspot/share/runtime/threadSMR.cpp index 4e5f9e4e8e758..90e1b4e8d3bbb 100644 --- a/src/hotspot/share/runtime/threadSMR.cpp +++ b/src/hotspot/share/runtime/threadSMR.cpp @@ -789,9 +789,13 @@ ThreadsListHandle::~ThreadsListHandle() { // Convert an internal thread reference to a JavaThread found on the // associated ThreadsList. This ThreadsListHandle "protects" the -// returned JavaThread *. If the jthread resolves to a virtual thread -// then the JavaThread * for its current carrier thread (if any) is -// returned via *jt_pp. +// returned JavaThread *. +// +// If the jthread resolves to a virtual thread then the JavaThread * +// for its current carrier thread (if any) is returned via *jt_pp. +// It is up to the caller to prevent the virtual thread from changing +// its mounted status, or else account for it when acting on the carrier +// JavaThread. // // If thread_oop_p is not null, then the caller wants to use the oop // after this call so the oop is always returned. On success, *jt_pp is set diff --git a/src/hotspot/share/runtime/threadSMR.hpp b/src/hotspot/share/runtime/threadSMR.hpp index 6351e456e24bc..42eaa4c18f125 100644 --- a/src/hotspot/share/runtime/threadSMR.hpp +++ b/src/hotspot/share/runtime/threadSMR.hpp @@ -75,11 +75,6 @@ class ThreadsList; // but that target JavaThread* will not be deleted until it is no // longer protected by a ThreadsListHandle. // -// Note that for virtual threads, we obtain a reference to the carrier JavaThread -// on which it is mounted (if any). It is up to the caller to prevent the virtual -// thread from changing its mounted status, or else account for it when acting on -// the carrier JavaThread. -// // SMR Support for the Threads class. // class ThreadsSMRSupport : AllStatic { From d863add53be5cfb2dfe23624608c6e1da518acef Mon Sep 17 00:00:00 2001 From: David Holmes Date: Sun, 27 Jul 2025 17:32:38 -0400 Subject: [PATCH 7/7] Fix comments --- src/hotspot/share/runtime/threadSMR.cpp | 2 +- src/hotspot/share/runtime/threadSMR.hpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/hotspot/share/runtime/threadSMR.cpp b/src/hotspot/share/runtime/threadSMR.cpp index 90e1b4e8d3bbb..c8af260f66e9f 100644 --- a/src/hotspot/share/runtime/threadSMR.cpp +++ b/src/hotspot/share/runtime/threadSMR.cpp @@ -830,7 +830,7 @@ bool ThreadsListHandle::cv_internal_thread_to_JavaThread(jobject jthread, // make it past ensure_join() where the JavaThread* is cleared. return false; } else { - // For virtual thread's we need to extract the carrier's JavaThread - if any. + // For virtual threads we need to extract the carrier's JavaThread - if any. oop carrier_thread = java_lang_VirtualThread::carrier_thread(thread_oop); if (carrier_thread != nullptr) { java_thread = java_lang_Thread::thread(carrier_thread); diff --git a/src/hotspot/share/runtime/threadSMR.hpp b/src/hotspot/share/runtime/threadSMR.hpp index 42eaa4c18f125..d2e716eaddfa3 100644 --- a/src/hotspot/share/runtime/threadSMR.hpp +++ b/src/hotspot/share/runtime/threadSMR.hpp @@ -45,7 +45,7 @@ class ThreadsList; // operation. It is no longer necessary to hold the Threads_lock to safely // perform an operation on a target thread. // -// There two ways to refer to java.lang.Thread objects so we have two ways +// There are two ways to refer to java.lang.Thread objects so we have two ways // to get a protected JavaThread*: // // JNI jobject example: @@ -69,7 +69,7 @@ class ThreadsList; // } // : // do stuff with 'jt'... // -// A JavaThread* that is included in the ThreadsList that is held by +// A JavaThread * that is included in the ThreadsList that is held by // a ThreadsListHandle is protected as long as the ThreadsListHandle // remains in scope. The target JavaThread* may have logically exited, // but that target JavaThread* will not be deleted until it is no