Skip to content

Commit 9ded4c2

Browse files
committed
Harden initCurrentThread() with initCurrentThreadSignalSafe()
1 parent e5d59e7 commit 9ded4c2

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ static CTimer ctimer;
7474
static CTimerJvmti ctimer_jvmti;
7575

7676
void Profiler::onThreadStart(jvmtiEnv *jvmti, JNIEnv *jni, jthread thread) {
77-
ProfiledThread* current = ProfiledThread::initCurrentThread();
77+
// JVMTI callback - outside signal handeler
78+
ProfiledThread* current = ProfiledThread::initCurrentThreadSignalSafe();
7879
if (current == nullptr) {
7980
return;
8081
}
@@ -1245,7 +1246,8 @@ Error Profiler::init() {
12451246
return error;
12461247
}
12471248

1248-
ProfiledThread::initCurrentThread();
1249+
// JNI down call, outside signal handler
1250+
ProfiledThread::initCurrentThreadSignalSafe();
12491251
return Error::OK;
12501252
}
12511253

@@ -1370,7 +1372,7 @@ Error Profiler::start(Arguments &args, bool reset) {
13701372
// Minor optim: Register the current thread (start thread won't be called)
13711373
if (_thread_filter.enabled()) {
13721374
_thread_filter.clearActive();
1373-
ProfiledThread *current = ProfiledThread::initCurrentThread();
1375+
ProfiledThread *current = ProfiledThread::initCurrentThreadSignalSafe();
13741376
assert(current != nullptr);
13751377
int slot_id = current->filterSlotId();
13761378
if (slot_id < 0) {

0 commit comments

Comments
 (0)