8331683: Clean up GetCarrierThread

Reviewed-by: sspitsyn, cjplummer
This commit is contained in:
Alex Menkov 2024-05-24 00:32:49 +00:00
parent 9b1d6d66b8
commit 424eb60ded
3 changed files with 10 additions and 33 deletions

View File

@ -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);
}

View File

@ -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

View File

@ -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