Skip to content

Commit f8a8ca8

Browse files
authored
Re-connect crash recursion protection with VM stackwalker (#214)
1 parent 718678a commit f8a8ca8

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

ddprof-lib/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ def copyUpstreamFiles = tasks.register('copyUpstreamFiles', Copy) {
143143
configure {
144144
dependsOn cloneAPTask
145145
}
146+
onlyIf {
147+
!project.hasProperty("debug-ap")
148+
}
146149
description = 'Copy shared upstream files'
147150
from("${projectDir}/build/async-profiler/src") {
148151
include "arch.h"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,7 @@ bool Profiler::crashHandler(int signo, siginfo_t *siginfo, void *ucontext) {
910910
if (VM::isHotspot()) {
911911
// the following checks require vmstructs and therefore HotSpot
912912

913-
StackWalker::checkFault();
913+
ddprof::StackWalker::checkFault(thrd);
914914

915915
// Workaround for JDK-8313796. Setting cstack=dwarf also helps
916916
if (VMStructs::isInterpretedFrameValidFunc((const void *)pc) &&

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,19 @@
1818
#define _STACKWALKER_DD_H
1919

2020
#include "stackWalker.h"
21+
#include "thread.h"
22+
#include "vmStructs_dd.h"
2123

2224

2325
namespace ddprof {
26+
// === copied over from the upstream stackWalker.cpp because of visibility issues ===
27+
const uintptr_t SAME_STACK_DISTANCE = 8192;
28+
29+
static inline bool sameStack(void* hi, void* lo) {
30+
return (uintptr_t)hi - (uintptr_t)lo < SAME_STACK_DISTANCE;
31+
}
32+
// === end of copied code ===
33+
2434
class StackWalker : public ::StackWalker {
2535
public:
2636
inline static int walkFP(void* ucontext, const void** callchain, int max_depth, StackContext* java_ctx, bool* truncated) {
@@ -66,6 +76,20 @@ namespace ddprof {
6676
}
6777
return walked;
6878
}
79+
80+
static void checkFault(ProfiledThread* thrd) {
81+
// We need to copy the following checks from the upstream stackWalker.cpp because we need a callback
82+
// when the crash is actually handled and this is DD specific
83+
VMThread *vm_thread = VMThread::current();
84+
if (vm_thread != NULL && sameStack(vm_thread->exception(), &vm_thread)) {
85+
if (thrd) {
86+
// going to longjmp out of the signal handler, reset the crash handler depth counter
87+
thrd->resetCrashHandler();
88+
}
89+
}
90+
// delegate back to the upstream code
91+
::StackWalker::checkFault();
92+
}
6993
};
7094
}
7195

0 commit comments

Comments
 (0)