Skip to content

Commit e5a8012

Browse files
committed
Debug failure in SafeAccess::load
1 parent b1052b3 commit e5a8012

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "debugSupport.h"
2121
#include "profiler.h"
2222
#include "vmStructs.h"
23+
#include <assert.h>
2324
#include <stdlib.h>
2425
#include <sys/syscall.h>
2526
#include <time.h>
@@ -202,6 +203,7 @@ void CTimer::signalHandler(int signo, siginfo_t *siginfo, void *ucontext) {
202203
return;
203204
int tid = 0;
204205
ProfiledThread *current = ProfiledThread::current();
206+
assert(current == nullptr || !current->isDeepCrashHandler());
205207
if (current != NULL) {
206208
current->noteCPUSample(Profiler::instance()->recordingEpoch());
207209
tid = current->tid();

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "os.h"
55
#include "threadLocalData.h"
66
#include <atomic>
7+
#include <cstdint>
78
#include <jvmti.h>
89
#include <pthread.h>
910
#include <stdlib.h>
@@ -12,6 +13,13 @@
1213

1314
class ProfiledThread : public ThreadLocalData {
1415
private:
16+
// We are allowing several levels of nesting because we can be
17+
// eg. in a crash handler when wallclock signal kicks in,
18+
// catching sigseg while also triggering CPU signal handler
19+
// which would also potentially trigger sigseg we need to handle.
20+
// This means 3 levels but we allow for some wiggling space, just in case.
21+
// Even with 5 levels cap we will need any highly recursing signal handlers
22+
static constexpr u32 CRASH_HANDLER_NESTING_LIMIT = 5;
1523
static pthread_key_t _tls_key;
1624
static int _buffer_size;
1725
static std::atomic<int> _running_buffer_pos;
@@ -81,17 +89,21 @@ class ProfiledThread : public ThreadLocalData {
8189
// this is called in the crash handler to avoid recursing
8290
bool enterCrashHandler() {
8391
u32 prev = _crash_depth;
84-
// this is thread local; no need for atomic cmpxchg
85-
if (prev == 0) {
86-
_crash_depth = 1;
92+
// This is thread local; no need for atomic cmpxchg
93+
if (prev < CRASH_HANDLER_NESTING_LIMIT) {
94+
_crash_depth++;
8795
return true;
8896
}
8997
return false;
9098
}
9199

92100
// needs to be called when the crash handler exits
93101
void exitCrashHandler() {
94-
_crash_depth = 0;
102+
_crash_depth--;
103+
}
104+
105+
bool isDeepCrashHandler() {
106+
return _crash_depth > CRASH_HANDLER_NESTING_LIMIT;
95107
}
96108

97109
static void signalHandler(int signo, siginfo_t *siginfo, void *ucontext);

0 commit comments

Comments
 (0)