-
Notifications
You must be signed in to change notification settings - Fork 328
Closed
Labels
Description
Describe the bug
Whenever I try to Profile the CPU for a program with virtual threads it fails with the following error:
Profiler Agent Error: GetCurrentThreadCpuTime failed with 73
Assertion failed: (res == JVMTI_ERROR_NONE), function Java_org_graalvm_visualvm_lib_jfluid_server_system_Timers_getThreadCPUTimeInNanos, file ../src-jdk15/Timers.c, line 108.
Abort trap: 6
The error code 73 corresponds to JVMTI_ERROR_UNSUPPORTED_OPERATION.
The error seems to be triggered in Timers.c:
/*
* Class: org_graalvm_visualvm_lib_jfluid_server_system_Timers
* Method: getThreadCPUTimeInNanos
* Signature: ()J
*/
JNIEXPORT jlong JNICALL Java_org_graalvm_visualvm_lib_jfluid_server_system_Timers_getThreadCPUTimeInNanos
(JNIEnv *env, jclass clz)
{
jlong threadTime;
jvmtiError res;
res = (*_jvmti)->GetCurrentThreadCpuTime(_jvmti,&threadTime);
if (res != JVMTI_ERROR_NONE) fprintf(stderr, "Profiler Agent Error: GetCurrentThreadCpuTime failed with %d\n",res);
assert(res == JVMTI_ERROR_NONE);
return threadTime;
}
Looking into the source code of jdk21 it seems that the function GetCurrentThreadCpuTime doesn't support virtual threads:
// nanos_ptr - pre-checked for null
jvmtiError
JvmtiEnv::GetCurrentThreadCpuTime(jlong* nanos_ptr) {
Thread* thread = Thread::current();
// Surprisingly the GetCurrentThreadCpuTime is used by non-JavaThread's.
if (thread->is_Java_thread()) {
if (JavaThread::cast(thread)->is_vthread_mounted()) {
// No support for a VirtualThread (yet).
return JVMTI_ERROR_UNSUPPORTED_OPERATION;
}
}
*nanos_ptr = os::current_thread_cpu_time();
return JVMTI_ERROR_NONE;
} /* end GetCurrentThreadCpuTime */
To Reproduce
- Create the following program
TriggerVisualVMProfileCrash.java:
class TriggerVisualVMProfileCrash {
public static void main(String... args) throws Exception {
System.out.println("Activate profiling and press key...");
System.in.read();
Thread.ofVirtual().start(() -> print());
}
public static void print() {
System.out.println("print() called");
}
}- Run the program in the console:
java -XX:+EnableDynamicAgentLoading -Xverify:none TriggerVisualVMProfileCrash.java-
Activate de CPU Profiler for the class
TriggerVisualVMProfileCrash:

-
Press
enterin the console so the program continues execution. -
The program will crash
Desktop (please complete the following information):
- OS: macOS
- JDK Temurin-21.0.2+13
- Version 2.1.7
whargrove, arouel, LoranceChen, dsubelman, jayaramcs and 3 more