Skip to content
Permalink
Browse files
get rid of unneded calls to JvmtiExport::can_support_virtual_threads
  • Loading branch information
sspitsyn committed Mar 11, 2021
1 parent 41b1ed0 commit c3b70c8352c3651e15cced7d9c96e8f27122b668
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 104 deletions.
@@ -614,11 +614,6 @@ JvmtiEnv::SetEventNotificationMode(jvmtiEventMode mode, jvmtiEvent event_type, j
return JVMTI_ERROR_ILLEGAL_ARGUMENT;
}

// assure that needed capabilities are present
if (java_lang_VirtualThread::is_instance(thread_obj) && !JvmtiExport::can_support_virtual_threads()) {
return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
}

JvmtiEventController::set_user_enabled(this, java_thread, thread_obj, event_type, enabled);
}

@@ -950,9 +945,6 @@ JvmtiEnv::GetThreadState(jthread thread, jint* thread_state_ptr) {

// Support for virtual thread
if (java_lang_VirtualThread::is_instance(thread_oop)) {
if (!JvmtiExport::can_support_virtual_threads()) {
return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
}
*thread_state_ptr = JvmtiEnvBase::get_vthread_state(thread_oop);
} else {
*thread_state_ptr = JvmtiEnvBase::get_thread_state(thread_oop, java_thread);
@@ -1303,9 +1295,6 @@ JvmtiEnv::GetThreadInfo(jthread thread, jvmtiThreadInfo* info_ptr) {

// Support for virtual threads
if (java_lang_VirtualThread::is_instance(thread_obj())) {
if (!JvmtiExport::can_support_virtual_threads()) {
return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
}
priority = (ThreadPriority)JVMTI_THREAD_NORM_PRIORITY;
is_daemon = true;
if (java_lang_VirtualThread::state(thread_obj()) == java_lang_VirtualThread::TERMINATED) {
@@ -1381,9 +1370,6 @@ JvmtiEnv::GetOwnedMonitorInfo(jthread thread, jint* owned_monitor_count_ptr, job

// Support for virtual threads
if (java_lang_VirtualThread::is_instance(thread_oop)) {
if (!JvmtiExport::can_support_virtual_threads()) {
return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
}
// there is no monitor info to collect if target virtual thread is unmounted
if (java_thread != NULL) {
VThreadGetOwnedMonitorInfoClosure op(this,
@@ -1461,9 +1447,6 @@ JvmtiEnv::GetOwnedMonitorStackDepthInfo(jthread thread, jint* monitor_info_count

// Support for virtual threads
if (java_lang_VirtualThread::is_instance(thread_oop)) {
if (!JvmtiExport::can_support_virtual_threads()) {
return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
}
// there is no monitor info to collect if target virtual thread is unmounted
if (java_thread != NULL) {
VThreadGetOwnedMonitorInfoClosure op(this,
@@ -1538,9 +1521,6 @@ JvmtiEnv::GetCurrentContendedMonitor(jthread thread, jobject* monitor_ptr) {

// Support for virtual threads
if (java_lang_VirtualThread::is_instance(thread_oop)) {
if (!JvmtiExport::can_support_virtual_threads()) {
return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
}
// there is no monitor info to collect if target virtual thread is unmounted
if (java_thread != NULL) {
VThreadGetCurrentContendedMonitorClosure op(this,
@@ -1758,9 +1738,6 @@ JvmtiEnv::GetStackTrace(jthread thread, jint start_depth, jint max_frame_count,

// Support for virtual threads
if (java_lang_VirtualThread::is_instance(thread_obj)) {
if (!JvmtiExport::can_support_virtual_threads()) {
return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
}
if (java_thread == NULL) { // target virtual thread is unmounted
ResourceMark rm(current_thread);
javaVFrame *jvf = JvmtiEnvBase::get_vthread_jvf(thread_obj);
@@ -1830,9 +1807,6 @@ JvmtiEnv::GetThreadListStackTraces(jint thread_count, const jthread* thread_list

// Support for virtual threads
if (java_lang_VirtualThread::is_instance(thread_obj)) {
if (!JvmtiExport::can_support_virtual_threads()) {
return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
}
if (java_thread == NULL) { // target virtual thread is unmounted
ResourceMark rm(current_thread);
MultipleStackTracesCollector collector(this, max_frame_count);
@@ -1883,9 +1857,6 @@ JvmtiEnv::GetFrameCount(jthread thread, jint* count_ptr) {

// Support for virtual threads
if (java_lang_VirtualThread::is_instance(thread_obj)) {
if (!JvmtiExport::can_support_virtual_threads()) {
return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
}
if (java_thread == NULL) { // target virtual thread is unmounted
err = get_frame_count(thread_obj, count_ptr);
return err;
@@ -1961,9 +1932,6 @@ JvmtiEnv::GetFrameLocation(jthread thread, jint depth, jmethodID* method_ptr, jl

// Support for virtual threads
if (java_lang_VirtualThread::is_instance(thread_obj)) {
if (!JvmtiExport::can_support_virtual_threads()) {
return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
}
if (java_thread == NULL) { // target virtual thread is unmounted
err = get_frame_location(thread_obj, depth, method_ptr, location_ptr);
return err;
@@ -2007,9 +1975,6 @@ JvmtiEnv::NotifyFramePop(jthread thread, jint depth) {

// Support for virtual threads
if (java_lang_VirtualThread::is_instance(thread_obj)) {
if (!JvmtiExport::can_support_virtual_threads()) {
return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
}
if (java_thread == NULL) {
// java_thread is NULL if virtual thread is unmounted
JvmtiThreadState *state = JvmtiThreadState::state_for(java_thread, thread_obj);
@@ -2289,9 +2254,6 @@ JvmtiEnv::GetLocalObject(jthread thread, jint depth, jint slot, jobject* value_p

if (java_lang_VirtualThread::is_instance(thread_obj)) {
// Support for virtual threads
if (!JvmtiExport::can_support_virtual_threads()) {
return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
}
VM_VirtualThreadGetOrSetLocal op(this, Handle(current_thread, thread_obj),
current_thread, depth, slot);
VMThread::execute(&op);
@@ -2333,9 +2295,6 @@ JvmtiEnv::GetLocalInstance(jthread thread, jint depth, jobject* value_ptr){

if (java_lang_VirtualThread::is_instance(thread_obj)) {
// Support for virtual threads
if (!JvmtiExport::can_support_virtual_threads()) {
return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
}
VM_VirtualThreadGetReceiver op(this, Handle(current_thread, thread_obj),
current_thread, depth);
VMThread::execute(&op);
@@ -2378,9 +2337,6 @@ JvmtiEnv::GetLocalInt(jthread thread, jint depth, jint slot, jint* value_ptr) {

if (java_lang_VirtualThread::is_instance(thread_obj)) {
// Support for virtual threads
if (!JvmtiExport::can_support_virtual_threads()) {
return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
}
VM_VirtualThreadGetOrSetLocal op(this, Handle(current_thread, thread_obj),
depth, slot, T_INT);
VMThread::execute(&op);
@@ -2423,9 +2379,6 @@ JvmtiEnv::GetLocalLong(jthread thread, jint depth, jint slot, jlong* value_ptr)

if (java_lang_VirtualThread::is_instance(thread_obj)) {
// Support for virtual threads
if (!JvmtiExport::can_support_virtual_threads()) {
return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
}
VM_VirtualThreadGetOrSetLocal op(this, Handle(current_thread, thread_obj),
depth, slot, T_LONG);
VMThread::execute(&op);
@@ -2468,9 +2421,6 @@ JvmtiEnv::GetLocalFloat(jthread thread, jint depth, jint slot, jfloat* value_ptr

if (java_lang_VirtualThread::is_instance(thread_obj)) {
// Support for virtual threads
if (!JvmtiExport::can_support_virtual_threads()) {
return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
}
VM_VirtualThreadGetOrSetLocal op(this, Handle(current_thread, thread_obj),
depth, slot, T_FLOAT);
VMThread::execute(&op);
@@ -2513,9 +2463,6 @@ JvmtiEnv::GetLocalDouble(jthread thread, jint depth, jint slot, jdouble* value_p

if (java_lang_VirtualThread::is_instance(thread_obj)) {
// Support for virtual threads
if (!JvmtiExport::can_support_virtual_threads()) {
return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
}
VM_VirtualThreadGetOrSetLocal op(this, Handle(current_thread, thread_obj),
depth, slot, T_DOUBLE);
VMThread::execute(&op);
@@ -1215,18 +1215,13 @@ bool
JvmtiEnvBase::cthread_with_mounted_vthread(JavaThread* jt) {
oop thread_oop = jt->threadObj();
assert(thread_oop != NULL, "sanity check");
if (!JvmtiExport::can_support_virtual_threads()) {
return false;
}
oop mounted_vt = jt->mounted_vthread();

return (mounted_vt != NULL && mounted_vt != thread_oop);
}

bool
JvmtiEnvBase::cthread_with_continuation(JavaThread* jt) {
if (!JvmtiExport::can_support_virtual_threads()) {
return false;
}
ContinuationEntry* cont = NULL;
if (jt->has_last_Java_frame()) {
cont = jt->last_continuation(java_lang_VirtualThread::vthread_scope());
@@ -1259,8 +1254,7 @@ JvmtiEnvBase::get_threadOop_and_JavaThread(ThreadsList* t_list, jthread thread,
return err;
}
}
if (java_thread == NULL && JvmtiExport::can_support_virtual_threads() &&
java_lang_VirtualThread::is_instance(thread_oop)) {
if (java_thread == NULL && java_lang_VirtualThread::is_instance(thread_oop)) {
oop cont = java_lang_VirtualThread::continuation(thread_oop);
if (java_lang_Continuation::is_mounted(cont)) {
oop carrier_thread = java_lang_VirtualThread::carrier_thread(thread_oop);
@@ -1473,9 +1467,6 @@ jvmtiError
JvmtiEnvBase::suspend_thread(oop thread_oop, JavaThread* java_thread, bool single_suspend,
int* need_safepoint_p) {
if (java_lang_VirtualThread::is_instance(thread_oop)) {
if (!JvmtiExport::can_support_virtual_threads()) {
return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
}
if (single_suspend) {
bool vthread_ext_suspended = JvmtiVTSuspender::vthread_is_ext_suspended(thread_oop);
if (vthread_ext_suspended) {
@@ -1505,8 +1496,7 @@ JvmtiEnvBase::suspend_thread(oop thread_oop, JavaThread* java_thread, bool singl
MutexLocker ml(java_thread->SR_lock(), Mutex::_no_safepoint_check_flag);
oop mounted_vt = java_thread->mounted_vthread();

if (single_suspend && JvmtiExport::can_support_virtual_threads() &&
!java_lang_VirtualThread::is_instance(thread_oop) &&
if (single_suspend && !java_lang_VirtualThread::is_instance(thread_oop) &&
mounted_vt != NULL && thread_oop != mounted_vt) {
// A case of a carrier thread executing a mounted virtual thread.
assert(java_lang_VirtualThread::is_instance(mounted_vt), "sanity check");
@@ -1550,9 +1540,6 @@ JvmtiEnvBase::suspend_thread(oop thread_oop, JavaThread* java_thread, bool singl
jvmtiError
JvmtiEnvBase::resume_thread(oop thread_oop, JavaThread* java_thread, bool single_suspend) {
if (java_lang_VirtualThread::is_instance(thread_oop)) {
if (!JvmtiExport::can_support_virtual_threads()) {
return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
}
if (single_suspend) {
bool vthread_ext_suspended = JvmtiVTSuspender::vthread_is_ext_suspended(thread_oop);
if (!vthread_ext_suspended) {
@@ -1666,7 +1653,6 @@ MultipleStackTracesCollector::fill_frames(jthread jt, JavaThread *thr, oop threa

// Support for virtual threads
if (java_lang_VirtualThread::is_instance(thread_oop)) {
// The can_support_virtual_threads capability is checked by the caller.
state = JvmtiEnvBase::get_vthread_state(thread_oop);

if ((state & JVMTI_THREAD_STATE_ALIVE) != 0) {
@@ -1746,12 +1732,6 @@ VM_GetThreadListStackTraces::doit() {
}
// We have a valid thread_oop.
}
if (java_lang_VirtualThread::is_instance(thread_oop)) {
if (!JvmtiExport::can_support_virtual_threads()) {
_collector.set_result(JVMTI_ERROR_MUST_POSSESS_CAPABILITY);
return;
}
}
_collector.fill_frames(jt, java_thread, thread_oop);
}
_collector.allocate_and_fill_stacks(_thread_count);
@@ -168,11 +168,11 @@ class JvmtiEnvBase : public CHeapObj<mtInternal> {
return err;
}

// If can_support_virtual_threads capability is enabled and there is a virtual thread mounted
// to the JavaThread* then return virtual thread oop. Otherwise, return thread oop.
// If there is a virtual thread mounted to the JavaThread* then
// return virtual thread oop. Otherwise, return thread oop.
static oop get_vthread_or_thread_oop(JavaThread* jt) {
oop result = jt->threadObj();
if (JvmtiExport::can_support_virtual_threads() && jt->mounted_vthread() != NULL) {
if (jt->mounted_vthread() != NULL) {
result = jt->mounted_vthread();
}
return result;
@@ -329,7 +329,7 @@ class JvmtiEnvBase : public CHeapObj<mtInternal> {
// get virtual thread last java vframe
static javaVFrame* get_vthread_jvf(oop vthread);

// get carrier thread last java vframe depending on can_support_virtual_threads capability
// get carrier thread last java vframe
static javaVFrame* get_last_java_vframe(JavaThread* jt, RegisterMap* reg_map);

// get ordinary thread thread state
@@ -637,11 +637,9 @@ JvmtiEventControllerPrivate::recompute_enabled() {
JvmtiThreadState* state = JvmtiThreadState::state_for_while_locked(tp, jt_oop);

// create the thread state for mounted virtual thread if missing
if (JvmtiExport::can_support_virtual_threads()) {
oop vt_oop = tp->mounted_vthread();
if (vt_oop != NULL && java_lang_VirtualThread::is_instance(vt_oop)) {
state = JvmtiThreadState::state_for_while_locked(tp, vt_oop);
}
oop vt_oop = tp->mounted_vthread();
if (vt_oop != NULL && java_lang_VirtualThread::is_instance(vt_oop)) {
state = JvmtiThreadState::state_for_while_locked(tp, vt_oop);
}
}
}
@@ -231,8 +231,7 @@ class JvmtiVirtualThreadEventMark : public JvmtiEventMark {
JvmtiVirtualThreadEventMark(JavaThread *thread) :
JvmtiEventMark(thread) {
JvmtiThreadState* state = thread->jvmti_thread_state();
if (JvmtiExport::can_support_virtual_threads() &&
state != NULL && state->is_virtual()) {
if (state != NULL && state->is_virtual()) {
_jt = (jthread)(to_jobject(thread->vthread()));
} else {
_jt = (jthread)(to_jobject(thread->threadObj()));
@@ -272,9 +272,8 @@ jvmtiError JvmtiManageCapabilities::add_capabilities(const jvmtiCapabilities *cu
either(current, desired, result);

// special case for virtual thread events
if (result->can_support_virtual_threads == 1) {
java_lang_VirtualThread::set_notify_jvmti_events(true);
}
// TBD: There can be a performance impact after check for can_support_virtual_threads has been removed.
java_lang_VirtualThread::set_notify_jvmti_events(true);

update();

@@ -216,9 +216,6 @@ unsigned short JvmtiVTMTDisabler::_VTMT_disable_count = 0;

void
JvmtiVTMTDisabler::disable_VTMT() {
if (!JvmtiExport::can_support_virtual_threads()) {
return;
}
JavaThread* thread = JavaThread::current();
ThreadBlockInVM tbivm(thread);
MonitorLocker ml(JvmtiVTMT_lock, Mutex::_no_safepoint_check_flag);
@@ -233,9 +230,6 @@ JvmtiVTMTDisabler::disable_VTMT() {

void
JvmtiVTMTDisabler::enable_VTMT() {
if (!JvmtiExport::can_support_virtual_threads()) {
return;
}
MonitorLocker ml(JvmtiVTMT_lock, Mutex::_no_safepoint_check_flag);
assert(_VTMT_count == 0 && _VTMT_disable_count > 0, "VTMT sanity check");

@@ -246,9 +240,6 @@ JvmtiVTMTDisabler::enable_VTMT() {

void
JvmtiVTMTDisabler::start_VTMT(jthread vthread, int callsite_tag) {
if (!JvmtiExport::can_support_virtual_threads()) {
return;
}
JavaThread* thread = JavaThread::current();
HandleMark hm(thread);
Handle vth = Handle(thread, JNIHandles::resolve_external_guard(vthread));
@@ -268,9 +259,6 @@ JvmtiVTMTDisabler::start_VTMT(jthread vthread, int callsite_tag) {

void
JvmtiVTMTDisabler::finish_VTMT(jthread vthread, int callsite_tag) {
if (!JvmtiExport::can_support_virtual_threads()) {
return;
}
JavaThread* thread = JavaThread::current();
MonitorLocker ml(JvmtiVTMT_lock, Mutex::_no_safepoint_check_flag);

@@ -78,8 +78,6 @@ void JvmtiThreadState::set_head_env_thread_state(JvmtiEnvThreadState* ets) {
inline JvmtiThreadState* JvmtiThreadState::state_for_while_locked(JavaThread *thread, oop thread_oop) {
assert(JvmtiThreadState_lock->is_locked(), "sanity check");
assert(thread != NULL || thread_oop != NULL, "sanity check");
assert(thread_oop == NULL || !java_lang_VirtualThread::is_instance(thread_oop) ||
JvmtiExport::can_support_virtual_threads(), "sanity check");

if (thread_oop == NULL) { // then thread should not be NULL (see assert above)
thread_oop = thread->mounted_vthread() != NULL ? thread->mounted_vthread() : thread->threadObj();

0 comments on commit c3b70c8

Please sign in to comment.