From 2451c5a4620d5aec0ea9bc52fee5f3a54eb89d62 Mon Sep 17 00:00:00 2001 From: Doug Simon Date: Wed, 1 Mar 2023 10:47:49 +0000 Subject: [PATCH] 8303357: [JVMCI] thread is _thread_in_vm when committing JFR compilation event Reviewed-by: never, kvn --- src/hotspot/share/compiler/compilerEvent.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/hotspot/share/compiler/compilerEvent.cpp b/src/hotspot/share/compiler/compilerEvent.cpp index 5000d313c82..0e14f62a468 100644 --- a/src/hotspot/share/compiler/compilerEvent.cpp +++ b/src/hotspot/share/compiler/compilerEvent.cpp @@ -120,11 +120,18 @@ int CompilerEvent::PhaseEvent::get_phase_id(const char* phase_name, bool may_exi // As part of event commit, a Method* is tagged as a function of an epoch. // Epochs evolve during safepoints. To ensure the event is tagged in the correct epoch, // that is, to avoid a race, the thread will participate in the safepoint protocol -// by transitioning from _thread_in_native to _thread_in_vm. +// by doing the commit while the thread is _thread_in_vm. template static inline void commit(EventType& event) { - ThreadInVMfromNative transition(JavaThread::current()); - event.commit(); + JavaThread* thread = JavaThread::current(); + JavaThreadState state = thread->thread_state(); + if (state == _thread_in_native) { + ThreadInVMfromNative transition(thread); + event.commit(); + } else { + assert(state == _thread_in_vm, "coming from wrong thread state %d", state); + event.commit(); + } } void CompilerEvent::CompilationEvent::post(EventCompilation& event, int compile_id, CompilerType compiler_type, Method* method, int compile_level, bool success, bool is_osr, int code_size, int inlined_bytecodes) {