From 424eb60dedb332237b8ec97e9da6bd95442c0083 Mon Sep 17 00:00:00 2001 From: Alex Menkov Date: Fri, 24 May 2024 00:32:49 +0000 Subject: [PATCH] 8331683: Clean up GetCarrierThread Reviewed-by: sspitsyn, cjplummer --- src/hotspot/share/prims/jvmtiEnvBase.cpp | 8 -------- src/hotspot/share/prims/jvmtiEnvBase.hpp | 18 ------------------ src/hotspot/share/prims/jvmtiExtensions.cpp | 17 ++++++++++------- 3 files changed, 10 insertions(+), 33 deletions(-) diff --git a/src/hotspot/share/prims/jvmtiEnvBase.cpp b/src/hotspot/share/prims/jvmtiEnvBase.cpp index de3d3f76528..94472baf27c 100644 --- a/src/hotspot/share/prims/jvmtiEnvBase.cpp +++ b/src/hotspot/share/prims/jvmtiEnvBase.cpp @@ -2642,11 +2642,3 @@ GetFrameLocationClosure::do_vthread(Handle target_h) { _result = ((JvmtiEnvBase*)_env)->get_frame_location(target_h(), _depth, _method_ptr, _location_ptr); } - -void -VirtualThreadGetThreadClosure::do_thread(Thread *target) { - assert(target->is_Java_thread(), "just checking"); - JavaThread *jt = JavaThread::cast(target); - oop carrier_thread = java_lang_VirtualThread::carrier_thread(_vthread_h()); - *_carrier_thread_ptr = (jthread)JNIHandles::make_local(jt, carrier_thread); -} diff --git a/src/hotspot/share/prims/jvmtiEnvBase.hpp b/src/hotspot/share/prims/jvmtiEnvBase.hpp index 00de17a8a6b..d984cc8bd37 100644 --- a/src/hotspot/share/prims/jvmtiEnvBase.hpp +++ b/src/hotspot/share/prims/jvmtiEnvBase.hpp @@ -784,24 +784,6 @@ public: void do_vthread(Handle target_h); }; -// HandshakeClosure to get virtual thread thread at safepoint. -class VirtualThreadGetThreadClosure : public HandshakeClosure { -private: - Handle _vthread_h; - jthread* _carrier_thread_ptr; - jvmtiError _result; - -public: - VirtualThreadGetThreadClosure(Handle vthread_h, jthread* carrier_thread_ptr) - : HandshakeClosure("VirtualThreadGetThread"), - _vthread_h(vthread_h), - _carrier_thread_ptr(carrier_thread_ptr), - _result(JVMTI_ERROR_NONE) {} - - void do_thread(Thread *target); - jvmtiError result() { return _result; } -}; - // ResourceTracker // // ResourceTracker works a little like a ResourceMark. All allocates diff --git a/src/hotspot/share/prims/jvmtiExtensions.cpp b/src/hotspot/share/prims/jvmtiExtensions.cpp index c1767454227..ec6c6689673 100644 --- a/src/hotspot/share/prims/jvmtiExtensions.cpp +++ b/src/hotspot/share/prims/jvmtiExtensions.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2024, 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 @@ -130,6 +130,10 @@ static jvmtiError JNICALL GetCarrierThread(const jvmtiEnv* env, ...) { thread_ptr = va_arg(ap, jthread*); va_end(ap); + if (thread_ptr == nullptr) { + return JVMTI_ERROR_NULL_POINTER; + } + MACOS_AARCH64_ONLY(ThreadWXEnable __wx(WXWrite, current_thread)); ThreadInVMfromNative tiv(current_thread); JvmtiVTMSTransitionDisabler disabler; @@ -156,12 +160,11 @@ static jvmtiError JNICALL GetCarrierThread(const jvmtiEnv* env, ...) { if (!java_lang_VirtualThread::is_instance(vthread_oop)) { return JVMTI_ERROR_INVALID_THREAD; } - if (thread_ptr == nullptr) { - return JVMTI_ERROR_NULL_POINTER; - } - VirtualThreadGetThreadClosure op(Handle(current_thread, vthread_oop), thread_ptr); - Handshake::execute(&op, &tlh, current_thread); - return op.result(); + + oop carrier_thread = java_lang_VirtualThread::carrier_thread(vthread_oop); + *thread_ptr = (jthread)JNIHandles::make_local(current_thread, carrier_thread); + + return JVMTI_ERROR_NONE; } // register extension functions and events. In this implementation we