From 794b0f5e1b905f9c2d2e1bb690182cd08e60063a Mon Sep 17 00:00:00 2001 From: Babneet Singh Date: Thu, 20 Oct 2022 09:57:29 -0400 Subject: [PATCH] Acquire VM access before the virtual thread check VM access is required before checking if a thread is a virtual thread instance. Signed-off-by: Babneet Singh --- runtime/jvmti/jvmtiTimers.c | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/runtime/jvmti/jvmtiTimers.c b/runtime/jvmti/jvmtiTimers.c index 93973ad051c..e41aea09cf4 100644 --- a/runtime/jvmti/jvmtiTimers.c +++ b/runtime/jvmti/jvmtiTimers.c @@ -61,31 +61,37 @@ jvmtiGetCurrentThreadCpuTime(jvmtiEnv* env, J9JavaVM *vm = JAVAVM_FROM_ENV(env); J9VMThread *currentThread = NULL; #endif /* JAVA_SPEC_VERSION >= 19 */ - jvmtiError rc; + jvmtiError rc = JVMTI_ERROR_NONE; jlong rv_nanos = 0; Trc_JVMTI_jvmtiGetCurrentThreadCpuTime_Entry(env); - ENSURE_PHASE_START_OR_LIVE(env); - ENSURE_CAPABILITY(env, can_get_current_thread_cpu_time); +#if JAVA_SPEC_VERSION >= 19 + rc = getCurrentVMThread(vm, ¤tThread); + if (JVMTI_ERROR_NONE == rc) { + vm->internalVMFunctions->internalEnterVMFromJNI(currentThread); +#endif /* JAVA_SPEC_VERSION >= 19 */ - ENSURE_NON_NULL(nanos_ptr); + ENSURE_PHASE_START_OR_LIVE(env); + ENSURE_CAPABILITY(env, can_get_current_thread_cpu_time); + + ENSURE_NON_NULL(nanos_ptr); #if JAVA_SPEC_VERSION >= 19 - rc = getCurrentVMThread(vm, ¤tThread); - if (JVMTI_ERROR_NONE != rc) { - goto done; - } - ENSURE_JTHREADOBJECT_NOT_VIRTUAL( - currentThread, - currentThread->threadObject, - JVMTI_ERROR_UNSUPPORTED_OPERATION); + ENSURE_JTHREADOBJECT_NOT_VIRTUAL( + currentThread, + currentThread->threadObject, + JVMTI_ERROR_UNSUPPORTED_OPERATION); #endif /* JAVA_SPEC_VERSION >= 19 */ - rv_nanos = (jlong)omrthread_get_self_cpu_time(omrthread_self()); - rc = JVMTI_ERROR_NONE; + rv_nanos = (jlong)omrthread_get_self_cpu_time(omrthread_self()); done: +#if JAVA_SPEC_VERSION >= 19 + vm->internalVMFunctions->internalExitVMToJNI(currentThread); + } +#endif /* JAVA_SPEC_VERSION >= 19 */ + if (NULL != nanos_ptr) { *nanos_ptr = rv_nanos; }