Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions ddprof-lib/src/main/cpp/profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
// can be still accessed concurrently during VM termination
Profiler *const Profiler::_instance = new Profiler();
volatile bool Profiler::_signals_initialized = false;
volatile bool Profiler::_need_JDK_8313796_workaround = true;

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

ddprof::StackWalker::checkFault(thrd);

// Workaround for JDK-8313796. Setting cstack=dwarf also helps
if (VMStructs::isInterpretedFrameValidFunc((const void *)pc) &&
// Workaround for JDK-8313796 if needed. Setting cstack=dwarf also helps
if (_need_JDK_8313796_workaround &&
VMStructs::isInterpretedFrameValidFunc((const void *)pc) &&
frame.skipFaultInstruction()) {
if (thrd != nullptr) {
thrd->exitCrashHandler();
Expand Down Expand Up @@ -1101,6 +1103,20 @@ Error Profiler::checkJvmCapabilities() {
return Error::OK;
}

void Profiler::check_JDK_8313796_workaround() {
int java_version = VM::java_version();
int java_update_version = VM::java_update_version();

// JDK-8313796 has been fixed in JDK 22 and backported to
// JDK versions 11.0.21, 17.0.9 and 21.0.1
bool fixed_version = java_version >= 22 ||
(java_version == 11 && java_update_version >= 21) ||
(java_version == 17 && java_update_version >= 9) ||
(java_version == 21 && java_update_version >= 1);
_need_JDK_8313796_workaround = !fixed_version;
}


Error Profiler::start(Arguments &args, bool reset) {
MutexLocker ml(_state_lock);
if (_state > IDLE) {
Expand Down
4 changes: 4 additions & 0 deletions ddprof-lib/src/main/cpp/profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ class Profiler {
// signal handlers
static volatile bool _signals_initialized;

// JDK_8313796 workaround for unfixed versions
static volatile bool _need_JDK_8313796_workaround;

Mutex _state_lock;
State _state;
// class unload hook
Expand Down Expand Up @@ -152,6 +155,7 @@ class Profiler {
void unlockAll();

static bool crashHandler(int signo, siginfo_t *siginfo, void *ucontext);
static void check_JDK_8313796_workaround();

static Profiler *const _instance;

Expand Down
1 change: 1 addition & 0 deletions ddprof-lib/src/main/cpp/vmEntry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ bool VM::initProfilerBridge(JavaVM *vm, bool attach) {

// Run late initialization when JVM is ready
void VM::ready(jvmtiEnv *jvmti, JNIEnv *jni) {
Profiler::check_JDK_8313796_workaround();
Profiler::setupSignalHandlers();
{
JitWriteProtection jit(true);
Expand Down
Loading