Reputation: 322
I'm using gdb to debug C code, which is being called from Java. I attach the gdb to running Java process and it works. Somewhat. The curios thing is GDB is periodically reporting SIGSEGV and it doesn't crash Java. I would expect the JVM to go down and generate hs_err_pid with information about the error. I am wondering if those faults are actually caused by gdb (no idea how) and don't really occur in the running code, or if under some circumstances Java can recover from SIGSEGV (no idea how).
EDIT: Here is full gdb output: https://pastebin.com/Mk44kWXQ
Example:
Thread
52 "java" received signal SIGSEGV, Segmentation fault.
0x00007f9f3a93d4b1 in ?? ()
-exec-continue
[New Thread 0x7f9ea4b46700 (LWP 10135)]
[New Thread 0x7f9eb4079700 (LWP 10137)]
[Thread 0x7f9eac95e700 (LWP 10130) exited]
Thread
52 "java" received signal SIGSEGV, Segmentation fault.
0x00007f9f3a93d4b1 in ?? ()
-exec-continue
[Thread 0x7f9ea534c700 (LWP 9960) exited]
Upvotes: 2
Views: 2135
Reputation: 718768
Can a SIGSEGV in Java not crash the JVM?
Sure, if a SIGSEGV occurs while executing Java code (not native code) it is most likely due to dereferencing a Java null
. That can be trapped and turned into a NullPointerException
and "thrown". An application can recover from this; i.e. by "catching" the exception.
I think that a SIGSEGV could also be triggered by a Java stack overflow causing the Java code to read or write an address in a stack's "red zone" memory segment.
Anyhow, there are definitely scenarios where the JVM's SIGSEGV signal handler may turn the SIGSEGV event into a Java exception. You will only get a JVM hard crash if that can't happen; e.g. if the thread that triggered the SIGSEGV was executing code in a native library when the event happened.
Upvotes: 4