From 4882b2db8c88a57dc79cbd6be3a704933f56b44c Mon Sep 17 00:00:00 2001 From: Evgeny Astigeevich Date: Wed, 20 Aug 2025 15:20:17 +0000 Subject: [PATCH 1/2] 8277444: Race condition on Instrumentation.retransformClasses() and class linking --- src/hotspot/share/prims/jvmtiClassFileReconstituter.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/hotspot/share/prims/jvmtiClassFileReconstituter.cpp b/src/hotspot/share/prims/jvmtiClassFileReconstituter.cpp index 831f407e7ecc2..2e6a7c979cb23 100644 --- a/src/hotspot/share/prims/jvmtiClassFileReconstituter.cpp +++ b/src/hotspot/share/prims/jvmtiClassFileReconstituter.cpp @@ -996,6 +996,14 @@ void JvmtiClassFileReconstituter::write_u8(u8 x) { void JvmtiClassFileReconstituter::copy_bytecodes(const methodHandle& mh, unsigned char* bytecodes) { + // Method bytecodes can be rewritten during linking. + // Whilst the linking process rewriting bytescodes, + // is_rewritten() returns false. So we won't restore the original bytecodes. + // We hold a lock to guarantee we are not getting bytecodes + // at the same time the linking process are rewriting them. + Handle h_init_lock(Thread::current(), mh->method_holder()->init_lock()); + ObjectLocker ol(h_init_lock, JavaThread::current()); + // use a BytecodeStream to iterate over the bytecodes. JVM/fast bytecodes // and the breakpoint bytecode are converted to their original bytecodes. From d6895181675e62bcd66e06b1c3d6ec4f5f26770b Mon Sep 17 00:00:00 2001 From: Evgeny Astigeevich Date: Wed, 20 Aug 2025 17:27:33 +0000 Subject: [PATCH 2/2] Add missing include runtime/synchronizer.hpp --- src/hotspot/share/prims/jvmtiClassFileReconstituter.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/hotspot/share/prims/jvmtiClassFileReconstituter.cpp b/src/hotspot/share/prims/jvmtiClassFileReconstituter.cpp index 2e6a7c979cb23..fc56c03ac1b46 100644 --- a/src/hotspot/share/prims/jvmtiClassFileReconstituter.cpp +++ b/src/hotspot/share/prims/jvmtiClassFileReconstituter.cpp @@ -32,6 +32,7 @@ #include "prims/jvmtiClassFileReconstituter.hpp" #include "runtime/handles.inline.hpp" #include "runtime/signature.hpp" +#include "runtime/synchronizer.hpp" #include "utilities/bytes.hpp" #include "utilities/checkedCast.hpp"