Skip to content

Commit f3ea224

Browse files
authored
Bypass JDK-8313796 workaround for the fixed JDK versions (#273)
1 parent bfc63e0 commit f3ea224

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

ddprof-lib/src/main/cpp/profiler.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
// can be still accessed concurrently during VM termination
4444
Profiler *const Profiler::_instance = new Profiler();
4545
volatile bool Profiler::_signals_initialized = false;
46+
volatile bool Profiler::_need_JDK_8313796_workaround = true;
4647

4748
static void (*orig_trapHandler)(int signo, siginfo_t *siginfo, void *ucontext);
4849
static void (*orig_segvHandler)(int signo, siginfo_t *siginfo, void *ucontext);
@@ -917,8 +918,9 @@ bool Profiler::crashHandler(int signo, siginfo_t *siginfo, void *ucontext) {
917918

918919
ddprof::StackWalker::checkFault(thrd);
919920

920-
// Workaround for JDK-8313796. Setting cstack=dwarf also helps
921-
if (VMStructs::isInterpretedFrameValidFunc((const void *)pc) &&
921+
// Workaround for JDK-8313796 if needed. Setting cstack=dwarf also helps
922+
if (_need_JDK_8313796_workaround &&
923+
VMStructs::isInterpretedFrameValidFunc((const void *)pc) &&
922924
frame.skipFaultInstruction()) {
923925
if (thrd != nullptr) {
924926
thrd->exitCrashHandler();
@@ -1101,6 +1103,20 @@ Error Profiler::checkJvmCapabilities() {
11011103
return Error::OK;
11021104
}
11031105

1106+
void Profiler::check_JDK_8313796_workaround() {
1107+
int java_version = VM::java_version();
1108+
int java_update_version = VM::java_update_version();
1109+
1110+
// JDK-8313796 has been fixed in JDK 22 and backported to
1111+
// JDK versions 11.0.21, 17.0.9 and 21.0.1
1112+
bool fixed_version = java_version >= 22 ||
1113+
(java_version == 11 && java_update_version >= 21) ||
1114+
(java_version == 17 && java_update_version >= 9) ||
1115+
(java_version == 21 && java_update_version >= 1);
1116+
_need_JDK_8313796_workaround = !fixed_version;
1117+
}
1118+
1119+
11041120
Error Profiler::start(Arguments &args, bool reset) {
11051121
MutexLocker ml(_state_lock);
11061122
if (_state > IDLE) {

ddprof-lib/src/main/cpp/profiler.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ class Profiler {
6767
// signal handlers
6868
static volatile bool _signals_initialized;
6969

70+
// JDK_8313796 workaround for unfixed versions
71+
static volatile bool _need_JDK_8313796_workaround;
72+
7073
Mutex _state_lock;
7174
State _state;
7275
// class unload hook
@@ -152,6 +155,7 @@ class Profiler {
152155
void unlockAll();
153156

154157
static bool crashHandler(int signo, siginfo_t *siginfo, void *ucontext);
158+
static void check_JDK_8313796_workaround();
155159

156160
static Profiler *const _instance;
157161

ddprof-lib/src/main/cpp/vmEntry.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,7 @@ bool VM::initProfilerBridge(JavaVM *vm, bool attach) {
459459

460460
// Run late initialization when JVM is ready
461461
void VM::ready(jvmtiEnv *jvmti, JNIEnv *jni) {
462+
Profiler::check_JDK_8313796_workaround();
462463
Profiler::setupSignalHandlers();
463464
{
464465
JitWriteProtection jit(true);

0 commit comments

Comments
 (0)