On Sun, 11 Jan 2026 07:33:12 GMT, Yasumasa Suenaga <[email protected]> wrote:

>> SA does not handle signal handler frame in mixed jstack as following:
>> 
>> 
>> ----------------- 1789 -----------------
>> "main" #1 prio=5 tid=0x00007f654c010000 nid=0x6fd runnable 
>> [0x00007f6551c0b000]
>>    java.lang.Thread.State: RUNNABLE
>>    JavaThread state: _thread_in_native
>> 0x00007f6551c0e735 __GI_abort + 0x8b
>> 0x00007f65511feb39 _ZN2os5abortEbPvPKv + 0x19
>> 0x00007f6551427569 
>> _ZN7VMError14report_and_dieEiPKcS1_P13__va_list_tagP6ThreadPhPvS7_S1_im + 
>> 0x579
>> 0x00007f6551427deb _ZN7VMError14report_and_dieEP6ThreadjPhPvS3_PKcz + 0x8b
>> 0x00007f6551427e1e _ZN7VMError14report_and_dieEP6ThreadjPhPvS3_ + 0x1e
>> 0x00007f6551209950 JVM_handle_linux_signal + 0x1c0
>> 0x00007f65511fd538 _ZL13signalHandleriP7siginfoPv + 0x38
>> 0x00007f6551c27290 ????????
>> 0x00007f653400f890 * NativeSEGV.doSEGV() bci:0 (Interpreted frame)
>> 0x00007f6534009c43 * NativeSEGV.main(java.lang.String[]) bci:76 line:37 
>> (Interpreted frame)
>> 0x00007f6534000849 <StubRoutines>
>> 0x00007f6550e847e9 
>> _ZN9JavaCalls11call_helperEP9JavaValueRK12methodHandleP17JavaCallArgumentsP6Thread
>>  + 0x3b9
>> 0x00007f6550eff1ba 
>> _ZL17jni_invoke_staticP7JNIEnv_P9JavaValueP8_jobject11JNICallTypeP10_jmethodIDP18JNI_ArgumentPusherP6Thread.isra.65.constprop.193
>>  + 0x1ba
>> 0x00007f6550f01824 jni_CallStaticVoidMethod + 0x164
>> 0x00007f6551e0582d JavaMain + 0xe4d
>> 0x00007f6551c7f464 start_thread + 0x2e4
>> 
>> 0x7f6551c27290 is a signal handler frame, and its caller is native frame. 
>> However jstack reports the caller is Java frame (`NativeSEGV.doSEGV()`).
>> 
>> It should be like following:
>> 
>> 
>> 0x00007fdbd170321a JVM_handle_linux_signal + 0x42a
>> 0x00007fdbd267b290 <signal handler called>
>> 0x00007fdbc7ecb3b1 Java_NativeSEGV_doSEGV + 0x18
>> 0x00007fdbb67468ba * NativeSEGV.doSEGV() bci:0 (Interpreted frame)
>> 
>> 
>> This is long standing bug (since JDK 9 at least).
>
> Yasumasa Suenaga has updated the pull request with a new target base due to a 
> merge or a rebase. The incremental webrev excludes the unrelated changes 
> brought in by the merge/rebase. The pull request contains five additional 
> commits since the last revision:
> 
>  - Merge remote-tracking branch 'origin/master' into jhsdb-jstack-sighandler
>  - Merge remote-tracking branch 'origin/master' into jhsdb-jstack-sighandler
>  - Merge remote-tracking branch 'origin/master' into jhsdb-jstack-sighandler
>  - Fix
>  - 8374482: SA does not handle signal handler frame in mixed jstack

This PR enabling signal handlers to be processed correctly, but it revealed a 
bug in DWARF parser.
I fixed it in 
[here](https://github.com/YaSuenag/jdk/compare/jhsdb-jstack-sighandler...YaSuenag:jdk:mixed-jstack-fix-for-optimized-code),
 but I'm wondering whether this fix should also be included in this PR. What do 
you think?
I think it should be fixed in another issue because this PR does not focus 
DWARF. I will file JBS and will create new PR after this of course.


ClhsdbPstack.java for coredump and TestJhsdbJstackMixedCore.java introduced in 
this PR can pass, but they would not find Java caller frame of JNI.
We can see NPE in both .jtr file because DWARF parser in SA could not find 
caller frame. Both tests uses libLingeredApp.c to crash due to access illegal 
address. It is very simple C code like following:


// Borrowed from hotspot vmError.cpp.
// Returns an address which is guaranteed to generate a SIGSEGV on read,
// which is not NULL and contains bits in every word
void* get_segfault_address() {
  return (void*)
#ifdef _LP64
    0xABC0000000000ABCULL;
#else
    0x00000ABC;
#endif
}

JNIEXPORT jint JNICALL
Java_jdk_test_lib_apps_LingeredApp_crash(JNIEnv *env, jclass clss)
{
    return *(jint *)get_segfault_address();
}


And it is compiled with `-O2` compiler option, then it has following assembly 
code - it does not make call frame!


00000000000003a0 <Java_jdk_test_lib_apps_LingeredApp_crash>:
 3a0:   a1 bc 0a 00 00 00 00    movabs 0xabc0000000000abc,%eax
 3a7:   c0 ab
 3a9:   c3                      ret


It does not have any DWARF instructions (NOP only in precise) of course:


00000054 0000000000000010 00000058 FDE cie=00000000 
pc=00000000000003a0..00000000000003aa
  DW_CFA_nop
  DW_CFA_nop
  DW_CFA_nop


I've created [simple 
reproducer](https://github.com/YaSuenag/garakuta/tree/master/NativeSEGV/frameless).
 It does not work on JDK 25.0.1 .

-------------

PR Comment: https://git.openjdk.org/jdk/pull/29023#issuecomment-3734578612

Reply via email to