Skip to content

Commit

Permalink
8331683: Clean up GetCarrierThread
Browse files Browse the repository at this point in the history
Reviewed-by: sspitsyn, cjplummer
  • Loading branch information
Alex Menkov committed May 24, 2024
1 parent 9b1d6d6 commit 424eb60
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 33 deletions.
8 changes: 0 additions & 8 deletions src/hotspot/share/prims/jvmtiEnvBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
18 changes: 0 additions & 18 deletions src/hotspot/share/prims/jvmtiEnvBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -784,24 +784,6 @@ class GetFrameLocationClosure : public JvmtiUnitedHandshakeClosure {
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
Expand Down
17 changes: 10 additions & 7 deletions src/hotspot/share/prims/jvmtiExtensions.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down

1 comment on commit 424eb60

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.