Skip to content
Permalink
Browse files
JVMTI GetCurrentThreadCpuTime should return INVALID_THREAD for vthread's
  • Loading branch information
sspitsyn committed Mar 12, 2021
1 parent 79e51eb commit e0b8234d0f8af38bf2614113d55fa5e855af4843
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
@@ -3819,6 +3819,16 @@ JvmtiEnv::GetCurrentThreadCpuTimerInfo(jvmtiTimerInfo* info_ptr) {
// nanos_ptr - pre-checked for NULL
jvmtiError
JvmtiEnv::GetCurrentThreadCpuTime(jlong* nanos_ptr) {
Thread* thread = Thread::current();

// Surprizingly the GetCurrentThreadCpuTime is used by non-JavaThread's.
if (thread->is_Java_thread()) {
oop thread_obj = get_vthread_or_thread_oop(thread->as_Java_thread());

if (java_lang_VirtualThread::is_instance(thread_obj)) {
return JVMTI_ERROR_INVALID_THREAD;
}
}
*nanos_ptr = os::current_thread_cpu_time();
return JVMTI_ERROR_NONE;
} /* end GetCurrentThreadCpuTime */
@@ -75,13 +75,13 @@ test_unsupported_jvmti_functions(jvmtiEnv *jvmti, JNIEnv *jni, jthread vthread)

err = jvmti->StopThread(vthread, vthread);
check_jvmti_error_invalid_thread(jni, "StopThread", err);

err = jvmti->InterruptThread(vthread);
check_jvmti_error_invalid_thread(jni, "InterruptThread", err);

err = jvmti->PopFrame(vthread);
check_jvmti_error_invalid_thread(jni, "PopFrame", err);

err = jvmti->ForceEarlyReturnVoid(vthread);
check_jvmti_error_invalid_thread(jni, "ForceEarlyReturnVoid", err);

@@ -152,6 +152,11 @@ VirtualThreadMounted(jvmtiEnv *jvmti, JNIEnv *jni, jthread vthread) {
printf("Got VirtualThreadMounted event\n");
fflush(stdout);
test_unsupported_jvmti_functions(jvmti, jni, vthread);

jlong nanos;
jvmtiError err = jvmti->GetCurrentThreadCpuTime(&nanos);
check_jvmti_error_invalid_thread(jni, "GetCurrentThreadCpuTime", err);

is_completed_test_in_event = JNI_TRUE;
}

@@ -177,6 +182,7 @@ Agent_OnLoad(JavaVM *jvm, char *options, void *reserved) {
caps.can_support_virtual_threads = 1;
caps.can_access_local_variables = 1;
caps.can_get_thread_cpu_time = 1;
caps.can_get_current_thread_cpu_time = 1;

err = jvmti->AddCapabilities(&caps);
if (err != JVMTI_ERROR_NONE) {

0 comments on commit e0b8234

Please sign in to comment.