Skip to content

Commit 94fa671

Browse files
jbachorikclaude
andcommitted
fix(profiler): restore signal depth after longjmp unwinds segvHandler
longjmp() in checkFault() bypasses C++ destructors, leaving _in_signal_handler_depth stuck at an inflated value after crash recovery. When SIGSEGV fires inside walkVM (depth=1 from SIGPROF handler), segvHandler increments depth to 2, then longjmp unwinds back to setjmp in walkVM without running SignalHandlerScope::~SignalHandlerScope(). Explicitly decrement depth at the longjmp recovery site to undo the skipped destructor. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
1 parent 1d27f6e commit 94fa671

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

ddprof-lib/src/main/cpp/hotspot/hotspotSupport.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "hotspot/vmStructs.inline.h"
1414
#include "jvmSupport.h"
1515
#include "profiler.h"
16+
#include "signalSafety.h"
1617
#include "stackWalker.inline.h"
1718
#include "frames.h"
1819

@@ -187,6 +188,11 @@ __attribute__((no_sanitize("address"))) int HotspotSupport::walkVM(void* ucontex
187188
profiled_thread->setCrashProtectionActive(true);
188189
}
189190
if (setjmp(crash_protection_ctx) != 0) {
191+
// longjmp from segvHandler bypasses its SignalHandlerScope destructor,
192+
// leaving _in_signal_handler_depth inflated by one. Undo that here.
193+
if (_in_signal_handler_depth > 0) {
194+
--_in_signal_handler_depth;
195+
}
190196
if (profiled_thread != nullptr) {
191197
profiled_thread->setCrashProtectionActive(false);
192198
}

0 commit comments

Comments
 (0)