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
15 changes: 7 additions & 8 deletions ddprof-lib/src/main/cpp/hotspot/hotspotSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ __attribute__((no_sanitize("address"))) int HotspotSupport::walkVM(void* ucontex
// then we end up with multiple HotspotSupport::walkVM() calls on stack,
// each one sets up sigjmp_buf, they need to be chained to jump back to
// correct location.
sigjmp_buf* prev_jmp_buf = prof_thread->getJmpCtx();
JmpCtxScope jmp_scope(prof_thread);
// Should be preserved across sigsetjmp/siglongjmp
volatile int depth = 0;
int actual_max_depth = truncated ? max_depth + 1 : max_depth;
Expand All @@ -288,7 +288,7 @@ __attribute__((no_sanitize("address"))) int HotspotSupport::walkVM(void* ucontex
// checkFault() does a siglongjmp from inside segvHandler, bypassing
// segvHandler's SignalHandlerScope destructor. Compensate.
SIGNAL_HANDLER_UNWIND_AFTER_LONGJMP();
prof_thread->setJmpCtx(prev_jmp_buf);
jmp_scope.restore();
if (depth < max_depth) {
fillFrame(frames[depth++], BCI_ERROR, "break_not_walkable");
}
Expand All @@ -301,7 +301,7 @@ __attribute__((no_sanitize("address"))) int HotspotSupport::walkVM(void* ucontex
return depth;
}

prof_thread->setJmpCtx(&crash_protection_ctx);
jmp_scope.install(&crash_protection_ctx);
VMThread* vm_thread = VMThread::current();
if (vm_thread != NULL && !vm_thread->isThreadAccessible()) {
Counters::increment(WALKVM_THREAD_INACCESSIBLE);
Expand Down Expand Up @@ -991,7 +991,7 @@ __attribute__((no_sanitize("address"))) int HotspotSupport::walkVM(void* ucontex
}

done:
prof_thread->setJmpCtx(prev_jmp_buf);
jmp_scope.restore();

// Drop unknown leaf frame - it provides no useful information and breaks
// aggregation by lumping unrelated samples under a single "unknown" entry
Expand Down Expand Up @@ -1263,13 +1263,13 @@ int HotspotSupport::walkJavaStack(StackWalkRequest& request) {
}
const bool prev_unwinding_java = prof_thread->is_unwinding_Java();
sigjmp_buf crash_protection_ctx;
sigjmp_buf* prev_jmp_buf = prof_thread->getJmpCtx();
JmpCtxScope jmp_scope(prof_thread);

if (sigsetjmp(crash_protection_ctx, 1) != 0) {
// checkFault() does a siglongjmp from inside segvHandler, bypassing
// segvHandler's SignalHandlerScope destructor. Compensate.
SIGNAL_HANDLER_UNWIND_AFTER_LONGJMP();
prof_thread->setJmpCtx(prev_jmp_buf);
jmp_scope.restore();
// A recovered siglongjmp bypasses AsyncSampleMutex destructors, so restore
// the per-thread guard to its pre-walk value.
prof_thread->set_unwinding_Java(prev_unwinding_java);
Expand All @@ -1278,7 +1278,7 @@ int HotspotSupport::walkJavaStack(StackWalkRequest& request) {
}
return java_frames;
}
prof_thread->setJmpCtx(&crash_protection_ctx);
jmp_scope.install(&crash_protection_ctx);

if (features.mixed) {
java_frames = walkVM(ucontext, frames, max_depth, features, eventTypeFromBCI(request.event_type), lock_index, truncated);
Expand Down Expand Up @@ -1332,7 +1332,6 @@ int HotspotSupport::walkJavaStack(StackWalkRequest& request) {
}
}

prof_thread->setJmpCtx(prev_jmp_buf);
return java_frames;
}

Expand Down
17 changes: 7 additions & 10 deletions ddprof-lib/src/main/cpp/stackWalker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "stackWalker.inline.h"
#include "dwarf.h"
#include "faultInjection.h"
#include "guards.h"
#include "profiler.h"
#include "stackFrame.h"
#include "symbols.h"
Expand Down Expand Up @@ -52,13 +53,13 @@ int StackWalker::walkFP(void* ucontext, const void** callchain, int max_depth, S
}

sigjmp_buf crash_protection_ctx;
sigjmp_buf* prev_jmp_buf = prof_thread->getJmpCtx();
JmpCtxScope jmp_scope(prof_thread);

if (sigsetjmp(crash_protection_ctx, 1) != 0) {
// checkFault() does a siglongjmp from inside segvHandler, bypassing
// segvHandler's SignalHandlerScope destructor. Compensate.
SIGNAL_HANDLER_UNWIND_AFTER_LONGJMP();
prof_thread->setJmpCtx(prev_jmp_buf);
jmp_scope.restore();
if (truncated) {
*truncated = true;
if (depth > max_depth) {
Expand All @@ -67,7 +68,7 @@ int StackWalker::walkFP(void* ucontext, const void** callchain, int max_depth, S
}
return depth;
}
prof_thread->setJmpCtx(&crash_protection_ctx);
jmp_scope.install(&crash_protection_ctx);

// Walk until the bottom of the stack or until the first Java frame
while (depth < actual_max_depth) {
Expand Down Expand Up @@ -98,8 +99,6 @@ int StackWalker::walkFP(void* ucontext, const void** callchain, int max_depth, S
fp = (uintptr_t)SafeAccess::load(INJECT_FAULT_ADDRESS_LIKELY((void**)fp));
}

prof_thread->setJmpCtx(prev_jmp_buf);

if (truncated && depth > max_depth) {
*truncated = true;
depth = max_depth;
Expand Down Expand Up @@ -140,13 +139,13 @@ int StackWalker::walkDwarf(void* ucontext, const void** callchain, int max_depth
}

sigjmp_buf crash_protection_ctx;
sigjmp_buf* prev_jmp_buf = prof_thread->getJmpCtx();
JmpCtxScope jmp_scope(prof_thread);

if (sigsetjmp(crash_protection_ctx, 1) != 0) {
// checkFault() does a siglongjmp from inside segvHandler, bypassing
// segvHandler's SignalHandlerScope destructor. Compensate.
SIGNAL_HANDLER_UNWIND_AFTER_LONGJMP();
prof_thread->setJmpCtx(prev_jmp_buf);
jmp_scope.restore();
if (truncated) {
*truncated = true;
if (depth > max_depth) {
Expand All @@ -155,7 +154,7 @@ int StackWalker::walkDwarf(void* ucontext, const void** callchain, int max_depth
}
return depth;
}
prof_thread->setJmpCtx(&crash_protection_ctx);
jmp_scope.install(&crash_protection_ctx);

// Walk until the bottom of the stack or until the first Java frame
while (depth < actual_max_depth) {
Expand Down Expand Up @@ -233,8 +232,6 @@ int StackWalker::walkDwarf(void* ucontext, const void** callchain, int max_depth
}
}

prof_thread->setJmpCtx(prev_jmp_buf);

if (truncated && depth > max_depth) {
*truncated = true;
depth = max_depth;
Expand Down
Loading